diff options
| -rw-r--r-- | source/slang/slang-ir-collect-global-uniforms.cpp | 13 | ||||
| -rw-r--r-- | tests/glsl/global-uniform-with-varyings.slang | 30 |
2 files changed, 37 insertions, 6 deletions
diff --git a/source/slang/slang-ir-collect-global-uniforms.cpp b/source/slang/slang-ir-collect-global-uniforms.cpp index 372ef298e..fb2a2233c 100644 --- a/source/slang/slang-ir-collect-global-uniforms.cpp +++ b/source/slang/slang-ir-collect-global-uniforms.cpp @@ -179,16 +179,15 @@ struct CollectGlobalUniformParametersContext // We expect the IR layout pass to have encoded field per-field // layout so that the "key" for the field is the corresponding // global shader parameter. - // + + // Save the original global param before replacement. auto globalParam = _getGlobalParamFromLayoutFieldKey(fieldLayoutAttr->getFieldKey()); - SLANG_ASSERT(globalParam); auto globalParamLayout = fieldLayoutAttr->getLayout(); - // Once we have decided to do replacement, we need to - // set ourselves up to emit the replacement code. - // - builder->setInsertBefore(globalParam); + // Set insert position to a valid instruction under the global parent scope so we can + // create struct keys. + builder->setInsertAfter(fieldLayoutAttr->getFieldKey()); // This global parameter needs to be turned into a field of the global // parameter structure type, and that field will need a key. @@ -216,6 +215,8 @@ struct CollectGlobalUniformParametersContext if (!globalParamLayout->getTypeLayout()->findSizeAttr(LayoutResourceKind::Uniform)) continue; + SLANG_ASSERT(globalParam); + // The new structure field will need to have whatever decorations // had been put on the global parameter (notably including any name hint) // diff --git a/tests/glsl/global-uniform-with-varyings.slang b/tests/glsl/global-uniform-with-varyings.slang new file mode 100644 index 000000000..678855dbf --- /dev/null +++ b/tests/glsl/global-uniform-with-varyings.slang @@ -0,0 +1,30 @@ +//TEST:SIMPLE(filecheck=CHECK_SPIRV): -target spirv -entry main -stage vertex +//TEST:SIMPLE(filecheck=CHECK_GLSL): -target glsl -entry main -stage vertex + +// CHECK_SPIRV: OpEntryPoint +// CHECK_SPIRV: OpVariable {{.*}} Input {{.*}} Location 0 +// CHECK_SPIRV: OpVariable {{.*}} Uniform +// CHECK_SPIRV: OpVariable {{.*}} Input {{.*}} Location 1 +// CHECK_SPIRV: OpVariable {{.*}} Output {{.*}} Location 0 + +// CHECK_GLSL: layout(location = 0) +// CHECK_GLSL-NEXT: in +// CHECK_GLSL: layout(location = 1) +// CHECK_GLSL-NEXT: in +// CHECK_GLSL: layout(std140) uniform +// CHECK_GLSL: layout(location = 0) +// CHECK_GLSL-NEXT: out +// CHECK_GLSL: void main + +#version 330 core +layout(location=0) in float3 a_position; +layout(location=1) in float4 a_color; + +out float4 v_color; + +uniform matrix<float,4,4> u_transform; + +void main() { + gl_Position = u_transform * vec4(a_position, 1.0); + v_color = a_color; +} |
