From d4cfe5781284551d7c5ccf2cf1d28a86211bb1df Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Sun, 23 Jul 2017 18:22:30 -0700 Subject: Work around glslang issue 988 The basic bug there is that if you have a member of `struct` type in a `uniform` block and then pass a reference to that member directly to a call: ``` struct Foo { vec4 bar; }; uniform U { Foo foo; }; void main() { doSomething(foo); } ``` then glslang generates invalid SPIR-V which seems to cause an issue for some drivers. This change works around the problem by detecting cases where an argument to a function call is a reference to `uniform` block member (of `struct` type) and then rewrites the code to move that value to a temporary before the call. --- tests/rewriter/glslang-bug-988-workaround.frag | 58 +++++++++++++++++++++++++ tests/rewriter/glslang-bug-988-workaround.slang | 6 +++ tests/rewriter/resources-in-structs.glsl | 3 +- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/rewriter/glslang-bug-988-workaround.frag create mode 100644 tests/rewriter/glslang-bug-988-workaround.slang (limited to 'tests') diff --git a/tests/rewriter/glslang-bug-988-workaround.frag b/tests/rewriter/glslang-bug-988-workaround.frag new file mode 100644 index 000000000..8c9692aed --- /dev/null +++ b/tests/rewriter/glslang-bug-988-workaround.frag @@ -0,0 +1,58 @@ +#version 450 +//TEST:COMPARE_GLSL: + +// Test workaround for glslang issue #988 +// (https://github.com/KhronosGroup/glslang/issues/988) + + +#if defined(__SLANG__) + + +__import glslang_bug_988_workaround; + +uniform U +{ + Foo foo; +}; + +vec4 doIt(Foo foo) +{ + return foo.bar; +} + +layout(location = 0) +out vec4 result; + +void main() +{ + result = doIt(foo); +} + +#else + +struct Foo +{ + vec4 bar; +}; + +layout(binding = 0) +uniform U +{ + Foo foo; +}; + +vec4 doIt(Foo foo) +{ + return foo.bar; +} + +layout(location = 0) +out vec4 result; + +void main() +{ + Foo SLANG_tmp_0 = foo; + result = doIt(SLANG_tmp_0); +} + +#endif diff --git a/tests/rewriter/glslang-bug-988-workaround.slang b/tests/rewriter/glslang-bug-988-workaround.slang new file mode 100644 index 000000000..841375923 --- /dev/null +++ b/tests/rewriter/glslang-bug-988-workaround.slang @@ -0,0 +1,6 @@ +//TEST_IGNORE_FILE: + +struct Foo +{ + float4 bar; +}; diff --git a/tests/rewriter/resources-in-structs.glsl b/tests/rewriter/resources-in-structs.glsl index 6273e8720..206e4a8d8 100644 --- a/tests/rewriter/resources-in-structs.glsl +++ b/tests/rewriter/resources-in-structs.glsl @@ -55,8 +55,9 @@ out vec4 color; void main() { + Material SLANG_tmp_0 = m; color = evaluateMaterial( - m, + SLANG_tmp_0, SLANG_parameterBlock_U_m_t, SLANG_parameterBlock_U_m_s, uv); } -- cgit v1.2.3