summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-glsl.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-02-06 01:03:42 -0800
committerGitHub <noreply@github.com>2024-02-06 01:03:42 -0800
commitb301c93753eaddb4571999f209cb8c1faa2fe205 (patch)
tree72fef2e499abecad0dda5ba2347e5890346ac173 /source/slang/slang-emit-glsl.cpp
parent23c65b873f8002b74d60f61cacb3614da60e078d (diff)
Unify GLSL and HLSL buffer block parsing. (#3552)
* Unify GLSL and HLSL buffer block parsing. Automatic GLSL module recognition. * Fix.
Diffstat (limited to 'source/slang/slang-emit-glsl.cpp')
-rw-r--r--source/slang/slang-emit-glsl.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp
index bae34b6fa..e394804c7 100644
--- a/source/slang/slang-emit-glsl.cpp
+++ b/source/slang/slang-emit-glsl.cpp
@@ -229,7 +229,39 @@ void GLSLSourceEmitter::emitSSBOHeader(IRGlobalParam* varDecl, IRType* bufferTyp
_requireGLSLVersion(430);
m_writer->emit("layout(");
- m_writer->emit(getTargetReq()->getForceGLSLScalarBufferLayout() ? "scalar" : "std430");
+ IROp layoutOp = kIROp_DefaultBufferLayoutType;
+ if (auto structBufferType = as<IRHLSLStructuredBufferTypeBase>(bufferType))
+ {
+ layoutOp = structBufferType->getDataLayout()? structBufferType->getDataLayout()->getOp() : kIROp_DefaultBufferLayoutType;
+ }
+ else if (auto ssboType = as<IRGLSLShaderStorageBufferType>(bufferType))
+ {
+ layoutOp = ssboType->getDataLayout() ? ssboType->getDataLayout()->getOp() : kIROp_DefaultBufferLayoutType;
+ }
+
+ if (layoutOp == kIROp_DefaultBufferLayoutType)
+ {
+ m_writer->emit(getTargetReq()->getForceGLSLScalarBufferLayout() ? "scalar" : "std430");
+ }
+ else
+ {
+ switch (layoutOp)
+ {
+ case kIROp_DefaultBufferLayoutType:
+ m_writer->emit(getTargetReq()->getForceGLSLScalarBufferLayout() ? "scalar" : "std430");
+ break;
+ case kIROp_Std430BufferLayoutType:
+ m_writer->emit("std430");
+ break;
+ case kIROp_Std140BufferLayoutType:
+ m_writer->emit("std140");
+ break;
+ case kIROp_ScalarBufferLayoutType:
+ _requireGLSLExtension(toSlice("GL_EXT_scalar_block_layout"));
+ m_writer->emit("scalar");
+ break;
+ }
+ }
auto layout = getVarLayout(varDecl);
if (layout)