From 78de10954ea71cda96dbb96ba7f9afb2cda769e7 Mon Sep 17 00:00:00 2001 From: ZhiqianXia Date: Mon, 2 Aug 2021 16:20:02 +0800 Subject: [PATCH 01/21] Support the textureQueryLOD at #extension GL_ARB_texture_query_lod. Signed-off-by: ZhiqianXia --- Test/150.frag | 30 +++--- Test/baseResults/150.frag.out | 8 +- Test/baseResults/textureQueryLOD.frag.out | 115 ++++++++++++++++++++++ Test/textureQueryLOD.frag | 39 ++++++++ glslang/MachineIndependent/Initialize.cpp | 63 ++++++------ gtests/AST.FromFile.cpp | 1 + 6 files changed, 209 insertions(+), 47 deletions(-) create mode 100644 Test/baseResults/textureQueryLOD.frag.out create mode 100644 Test/textureQueryLOD.frag diff --git a/Test/150.frag b/Test/150.frag index 228e4f0d..90b1e274 100644 --- a/Test/150.frag +++ b/Test/150.frag @@ -111,8 +111,8 @@ void qlodFail() vec2 pf2; vec3 pf3; - lod = textureQueryLod(samp1D, pf); // ERROR, extension GL_ARB_texture_query_lod needed - lod = textureQueryLod(samp2Ds, pf2); // ERROR, extension GL_ARB_texture_query_lod needed + lod = textureQueryLOD(samp1D, pf); // ERROR, extension GL_ARB_texture_query_lod needed + lod = textureQueryLOD(samp2Ds, pf2); // ERROR, extension GL_ARB_texture_query_lod needed } #extension GL_ARB_texture_query_lod : enable @@ -138,21 +138,21 @@ void qlodPass() vec2 pf2; vec3 pf3; - lod = textureQueryLod(samp1D, pf); - lod = textureQueryLod(isamp2D, pf2); - lod = textureQueryLod(usamp3D, pf3); - lod = textureQueryLod(sampCube, pf3); - lod = textureQueryLod(isamp1DA, pf); - lod = textureQueryLod(usamp2DA, pf2); + lod = textureQueryLOD(samp1D, pf); + lod = textureQueryLOD(isamp2D, pf2); + lod = textureQueryLOD(usamp3D, pf3); + lod = textureQueryLOD(sampCube, pf3); + lod = textureQueryLOD(isamp1DA, pf); + lod = textureQueryLOD(usamp2DA, pf2); - lod = textureQueryLod(samp1Ds, pf); - lod = textureQueryLod(samp2Ds, pf2); - lod = textureQueryLod(sampCubes, pf3); - lod = textureQueryLod(samp1DAs, pf); - lod = textureQueryLod(samp2DAs, pf2); + lod = textureQueryLOD(samp1Ds, pf); + lod = textureQueryLOD(samp2Ds, pf2); + lod = textureQueryLOD(sampCubes, pf3); + lod = textureQueryLOD(samp1DAs, pf); + lod = textureQueryLOD(samp2DAs, pf2); - lod = textureQueryLod(sampBuf, pf); // ERROR - lod = textureQueryLod(sampRect, pf2); // ERROR + lod = textureQueryLOD(sampBuf, pf); // ERROR + lod = textureQueryLOD(sampRect, pf2); // ERROR } // Test extension GL_EXT_shader_integer_mix diff --git a/Test/baseResults/150.frag.out b/Test/baseResults/150.frag.out index 2192e14a..3e666586 100644 --- a/Test/baseResults/150.frag.out +++ b/Test/baseResults/150.frag.out @@ -10,11 +10,11 @@ ERROR: 0:53: 'double' : must be qualified as flat in ERROR: 0:57: '=' : cannot convert from ' global double' to ' global int' ERROR: 0:80: 'floatBitsToInt' : required extension not requested: GL_ARB_shader_bit_encoding ERROR: 0:100: 'packSnorm2x16' : required extension not requested: GL_ARB_shading_language_packing -ERROR: 0:114: 'textureQueryLod' : required extension not requested: GL_ARB_texture_query_lod -ERROR: 0:115: 'textureQueryLod' : required extension not requested: GL_ARB_texture_query_lod -ERROR: 0:154: 'textureQueryLod' : no matching overloaded function found +ERROR: 0:114: 'textureQueryLOD' : required extension not requested: GL_ARB_texture_query_lod +ERROR: 0:115: 'textureQueryLOD' : required extension not requested: GL_ARB_texture_query_lod +ERROR: 0:154: 'textureQueryLOD' : no matching overloaded function found ERROR: 0:154: 'assign' : cannot convert from ' const float' to ' temp 2-component vector of float' -ERROR: 0:155: 'textureQueryLod' : no matching overloaded function found +ERROR: 0:155: 'textureQueryLOD' : no matching overloaded function found ERROR: 0:155: 'assign' : cannot convert from ' const float' to ' temp 2-component vector of float' ERROR: 0:183: 'mix' : required extension not requested: GL_EXT_shader_integer_mix ERROR: 18 compilation errors. No code generated. diff --git a/Test/baseResults/textureQueryLOD.frag.out b/Test/baseResults/textureQueryLOD.frag.out new file mode 100644 index 00000000..b565a005 --- /dev/null +++ b/Test/baseResults/textureQueryLOD.frag.out @@ -0,0 +1,115 @@ +textureQueryLOD.frag +WARNING: 0:7: '#extension' : extension is only partially supported: GL_ARB_gpu_shader5 + +Shader version: 150 +Requested GL_ARB_gpu_shader5 +Requested GL_ARB_texture_query_lod +0:? Sequence +0:24 Function Definition: main( ( global void) +0:24 Function Parameters: +0:26 Sequence +0:26 switch +0:26 condition +0:26 'funct' ( uniform int) +0:26 body +0:26 Sequence +0:28 case: with expression +0:28 Constant: +0:28 0 (const int) +0:? Sequence +0:29 Sequence +0:29 move second child to first child ( temp 2-component vector of int) +0:29 'iv2' ( temp 2-component vector of int) +0:29 textureSize ( global 2-component vector of int) +0:29 'sampler' ( uniform sampler2DShadow) +0:29 Constant: +0:29 0 (const int) +0:31 Sequence +0:31 move second child to first child ( temp 2-component vector of float) +0:31 'fv2' ( temp 2-component vector of float) +0:31 textureQueryLod ( global 2-component vector of float) +0:31 'sampler' ( uniform sampler2DShadow) +0:31 Constant: +0:31 0.000000 +0:31 0.000000 +0:33 move second child to first child ( temp 4-component vector of float) +0:33 'color' ( out 4-component vector of float) +0:33 Construct vec4 ( temp 4-component vector of float) +0:33 Convert int to float ( temp 2-component vector of float) +0:33 'iv2' ( temp 2-component vector of int) +0:33 'fv2' ( temp 2-component vector of float) +0:34 Branch: Break +0:35 default: +0:? Sequence +0:36 move second child to first child ( temp 4-component vector of float) +0:36 'color' ( out 4-component vector of float) +0:36 Constant: +0:36 1.000000 +0:36 1.000000 +0:36 1.000000 +0:36 1.000000 +0:37 Branch: Break +0:? Linker Objects +0:? 'vUV' ( smooth in 2-component vector of float) +0:? 'color' ( out 4-component vector of float) +0:? 'sampler' ( uniform sampler2DShadow) +0:? 'funct' ( uniform int) + + +Linked fragment stage: + + +Shader version: 150 +Requested GL_ARB_gpu_shader5 +Requested GL_ARB_texture_query_lod +0:? Sequence +0:24 Function Definition: main( ( global void) +0:24 Function Parameters: +0:26 Sequence +0:26 switch +0:26 condition +0:26 'funct' ( uniform int) +0:26 body +0:26 Sequence +0:28 case: with expression +0:28 Constant: +0:28 0 (const int) +0:? Sequence +0:29 Sequence +0:29 move second child to first child ( temp 2-component vector of int) +0:29 'iv2' ( temp 2-component vector of int) +0:29 textureSize ( global 2-component vector of int) +0:29 'sampler' ( uniform sampler2DShadow) +0:29 Constant: +0:29 0 (const int) +0:31 Sequence +0:31 move second child to first child ( temp 2-component vector of float) +0:31 'fv2' ( temp 2-component vector of float) +0:31 textureQueryLod ( global 2-component vector of float) +0:31 'sampler' ( uniform sampler2DShadow) +0:31 Constant: +0:31 0.000000 +0:31 0.000000 +0:33 move second child to first child ( temp 4-component vector of float) +0:33 'color' ( out 4-component vector of float) +0:33 Construct vec4 ( temp 4-component vector of float) +0:33 Convert int to float ( temp 2-component vector of float) +0:33 'iv2' ( temp 2-component vector of int) +0:33 'fv2' ( temp 2-component vector of float) +0:34 Branch: Break +0:35 default: +0:? Sequence +0:36 move second child to first child ( temp 4-component vector of float) +0:36 'color' ( out 4-component vector of float) +0:36 Constant: +0:36 1.000000 +0:36 1.000000 +0:36 1.000000 +0:36 1.000000 +0:37 Branch: Break +0:? Linker Objects +0:? 'vUV' ( smooth in 2-component vector of float) +0:? 'color' ( out 4-component vector of float) +0:? 'sampler' ( uniform sampler2DShadow) +0:? 'funct' ( uniform int) + diff --git a/Test/textureQueryLOD.frag b/Test/textureQueryLOD.frag new file mode 100644 index 00000000..0d0ae3c7 --- /dev/null +++ b/Test/textureQueryLOD.frag @@ -0,0 +1,39 @@ +#version 150 + +#ifdef GL_ARB_texture_query_lod +#extension GL_ARB_texture_query_lod : enable +#endif +#ifdef GL_ARB_gpu_shader5 +#extension GL_ARB_gpu_shader5 : enable +#endif + +#ifdef GL_ES +precision highp float; +#endif + +in vec2 vUV; // vert->frag +out vec4 color; // frag->fb +#define UV vUV + +#define bias 1.5 +#define TEX 128.0 +#define offset ivec2(1,1) +uniform highp sampler2DShadow sampler; +uniform int funct; + +void main (void) +{ + switch (funct) + { + case 0: + ivec2 iv2 = textureSize(sampler, 0); +#ifdef GL_ARB_texture_query_lod + vec2 fv2 = textureQueryLOD(sampler, vec2(0.0, 0.0)); +#endif + color = vec4(iv2,fv2); + break; + default: + color = vec4(1.0, 1.0, 1.0, 1.0); + break; + } +} diff --git a/glslang/MachineIndependent/Initialize.cpp b/glslang/MachineIndependent/Initialize.cpp index a79925d3..71321ce3 100644 --- a/glslang/MachineIndependent/Initialize.cpp +++ b/glslang/MachineIndependent/Initialize.cpp @@ -316,6 +316,7 @@ const CustomFunction CustomFunctions[] = { { EOpTextureQuerySize, "textureSize", nullptr }, { EOpTextureQueryLod, "textureQueryLod", nullptr }, + { EOpTextureQueryLod, "textureQueryLOD", nullptr }, // extension GL_ARB_texture_query_lod { EOpTextureQueryLevels, "textureQueryLevels", nullptr }, { EOpTextureQuerySamples, "textureSamples", nullptr }, { EOpTexture, "texture", nullptr }, @@ -6307,38 +6308,44 @@ void TBuiltIns::addQueryFunctions(TSampler sampler, const TString& typeName, int // // textureQueryLod(), fragment stage only // Also enabled with extension GL_ARB_texture_query_lod + // Extension GL_ARB_texture_query_lod says that textureQueryLOD() also exist at extension. if (profile != EEsProfile && version >= 150 && sampler.isCombined() && sampler.dim != EsdRect && ! sampler.isMultiSample() && ! sampler.isBuffer()) { - for (int f16TexAddr = 0; f16TexAddr < 2; ++f16TexAddr) { - if (f16TexAddr && sampler.type != EbtFloat16) - continue; - stageBuiltins[EShLangFragment].append("vec2 textureQueryLod("); - stageBuiltins[EShLangFragment].append(typeName); - if (dimMap[sampler.dim] == 1) - if (f16TexAddr) - stageBuiltins[EShLangFragment].append(", float16_t"); - else - stageBuiltins[EShLangFragment].append(", float"); - else { - if (f16TexAddr) - stageBuiltins[EShLangFragment].append(", f16vec"); - else - stageBuiltins[EShLangFragment].append(", vec"); - stageBuiltins[EShLangFragment].append(postfixes[dimMap[sampler.dim]]); - } - stageBuiltins[EShLangFragment].append(");\n"); - } - stageBuiltins[EShLangCompute].append("vec2 textureQueryLod("); - stageBuiltins[EShLangCompute].append(typeName); - if (dimMap[sampler.dim] == 1) - stageBuiltins[EShLangCompute].append(", float"); - else { - stageBuiltins[EShLangCompute].append(", vec"); - stageBuiltins[EShLangCompute].append(postfixes[dimMap[sampler.dim]]); + const TString funcName[2] = {"vec2 textureQueryLod(", "vec2 textureQueryLOD("}; + + for (int i = 0; i < 2; ++i){ + for (int f16TexAddr = 0; f16TexAddr < 2; ++f16TexAddr) { + if (f16TexAddr && sampler.type != EbtFloat16) + continue; + stageBuiltins[EShLangFragment].append(funcName[i]); + stageBuiltins[EShLangFragment].append(typeName); + if (dimMap[sampler.dim] == 1) + if (f16TexAddr) + stageBuiltins[EShLangFragment].append(", float16_t"); + else + stageBuiltins[EShLangFragment].append(", float"); + else { + if (f16TexAddr) + stageBuiltins[EShLangFragment].append(", f16vec"); + else + stageBuiltins[EShLangFragment].append(", vec"); + stageBuiltins[EShLangFragment].append(postfixes[dimMap[sampler.dim]]); + } + stageBuiltins[EShLangFragment].append(");\n"); + } + + stageBuiltins[EShLangCompute].append(funcName[i]); + stageBuiltins[EShLangCompute].append(typeName); + if (dimMap[sampler.dim] == 1) + stageBuiltins[EShLangCompute].append(", float"); + else { + stageBuiltins[EShLangCompute].append(", vec"); + stageBuiltins[EShLangCompute].append(postfixes[dimMap[sampler.dim]]); + } + stageBuiltins[EShLangCompute].append(");\n"); } - stageBuiltins[EShLangCompute].append(");\n"); } // @@ -8118,7 +8125,7 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion } if (profile != EEsProfile && version < 400) { - symbolTable.setFunctionExtensions("textureQueryLod", 1, &E_GL_ARB_texture_query_lod); + symbolTable.setFunctionExtensions("textureQueryLOD", 1, &E_GL_ARB_texture_query_lod); } if (profile != EEsProfile && version >= 460) { diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp index b63825b6..7737627f 100644 --- a/gtests/AST.FromFile.cpp +++ b/gtests/AST.FromFile.cpp @@ -284,6 +284,7 @@ INSTANTIATE_TEST_SUITE_P( "textureoffset_sampler2darrayshadow.vert", "atomicAdd.comp", "GL_ARB_gpu_shader5.u2i.vert", + "textureQueryLOD.frag", })), FileNameAsCustomTestSuffix ); From 9600b97c6af4c90b0837be0c22bb3268fa0624c3 Mon Sep 17 00:00:00 2001 From: Greg Fischer Date: Tue, 9 Nov 2021 15:46:08 -0700 Subject: [PATCH 02/21] Fix test spv.1.4.OpEntryPoint.frag Cannot apply binding qualifier to push_constant --- Test/baseResults/spv.1.4.OpEntryPoint.frag.out | 2 -- Test/spv.1.4.OpEntryPoint.frag | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Test/baseResults/spv.1.4.OpEntryPoint.frag.out b/Test/baseResults/spv.1.4.OpEntryPoint.frag.out index 2c6e6dcc..e43e954e 100644 --- a/Test/baseResults/spv.1.4.OpEntryPoint.frag.out +++ b/Test/baseResults/spv.1.4.OpEntryPoint.frag.out @@ -1,5 +1,4 @@ spv.1.4.OpEntryPoint.frag -Validation failed // Module Version 10400 // Generated by (magic number): 8000a // Id's are bound by 64 @@ -32,7 +31,6 @@ Validation failed Decorate 25(uniformv) Binding 0 MemberDecorate 31(pushB) 0 Offset 0 Decorate 31(pushB) Block - Decorate 33(pushv) Binding 2 MemberDecorate 39(bbt) 0 Offset 0 Decorate 39(bbt) Block Decorate 41(bufferv) DescriptorSet 0 diff --git a/Test/spv.1.4.OpEntryPoint.frag b/Test/spv.1.4.OpEntryPoint.frag index ef1235a4..a12b1b37 100644 --- a/Test/spv.1.4.OpEntryPoint.frag +++ b/Test/spv.1.4.OpEntryPoint.frag @@ -13,7 +13,7 @@ layout(binding = 1) buffer bbt { float f; } bufferv; -layout(binding = 2, push_constant) uniform pushB { +layout(push_constant) uniform pushB { int a; } pushv; From 77b0d72c6838d5587f8defba61dfc98bcfdb5f1a Mon Sep 17 00:00:00 2001 From: ZhiqianXia Date: Mon, 2 Aug 2021 16:41:21 +0800 Subject: [PATCH 03/21] #extension GL_ARB_gpu_shader5 support the implicit conversion , So the best function matching algorithm should be actived. Signed-off-by: ZhiqianXia --- Test/BestMatchFunction.vert | 20 ++ Test/baseResults/BestMatchFunction.vert.out | 206 ++++++++++++++++++++ glslang/MachineIndependent/ParseHelper.cpp | 6 +- gtests/AST.FromFile.cpp | 1 + 4 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 Test/BestMatchFunction.vert create mode 100644 Test/baseResults/BestMatchFunction.vert.out diff --git a/Test/BestMatchFunction.vert b/Test/BestMatchFunction.vert new file mode 100644 index 00000000..eb092339 --- /dev/null +++ b/Test/BestMatchFunction.vert @@ -0,0 +1,20 @@ +#version 150 +#extension GL_ARB_gpu_shader5 : require + +uniform ivec4 u1; +uniform uvec4 u2; +out vec4 result; +vec4 f(in vec4 a, in vec4 b){ return a * b;} // choice 1 +vec4 f(in uvec4 a, in uvec4 b){ return vec4(a - b);} // choice 2 + +void main() +{ + result = f(u1, u2); // should match choice 2. which have less implicit conversion. + switch (gl_VertexID) + { + case 0: gl_Position = vec4(-1.0, 1.0, 0.0, 1.0); break; + case 1: gl_Position = vec4( 1.0, 1.0, 0.0, 1.0); break; + case 2: gl_Position = vec4(-1.0,-1.0, 0.0, 1.0); break; + case 3: gl_Position = vec4( 1.0,-1.0, 0.0, 1.0); break; + } +} diff --git a/Test/baseResults/BestMatchFunction.vert.out b/Test/baseResults/BestMatchFunction.vert.out new file mode 100644 index 00000000..843ffd79 --- /dev/null +++ b/Test/baseResults/BestMatchFunction.vert.out @@ -0,0 +1,206 @@ +BestMatchFunction.vert +WARNING: 0:2: '#extension' : extension is only partially supported: GL_ARB_gpu_shader5 + +Shader version: 150 +Requested GL_ARB_gpu_shader5 +0:? Sequence +0:7 Function Definition: f(vf4;vf4; ( global 4-component vector of float) +0:7 Function Parameters: +0:7 'a' ( in 4-component vector of float) +0:7 'b' ( in 4-component vector of float) +0:7 Sequence +0:7 Branch: Return with expression +0:7 component-wise multiply ( temp 4-component vector of float) +0:7 'a' ( in 4-component vector of float) +0:7 'b' ( in 4-component vector of float) +0:8 Function Definition: f(vu4;vu4; ( global 4-component vector of float) +0:8 Function Parameters: +0:8 'a' ( in 4-component vector of uint) +0:8 'b' ( in 4-component vector of uint) +0:8 Sequence +0:8 Branch: Return with expression +0:8 Convert uint to float ( temp 4-component vector of float) +0:8 subtract ( temp 4-component vector of uint) +0:8 'a' ( in 4-component vector of uint) +0:8 'b' ( in 4-component vector of uint) +0:10 Function Definition: main( ( global void) +0:10 Function Parameters: +0:12 Sequence +0:12 move second child to first child ( temp 4-component vector of float) +0:12 'result' ( smooth out 4-component vector of float) +0:12 Function Call: f(vu4;vu4; ( global 4-component vector of float) +0:12 Convert int to uint ( temp 4-component vector of uint) +0:12 'u1' ( uniform 4-component vector of int) +0:12 'u2' ( uniform 4-component vector of uint) +0:13 switch +0:13 condition +0:13 'gl_VertexID' ( gl_VertexId int VertexId) +0:13 body +0:13 Sequence +0:15 case: with expression +0:15 Constant: +0:15 0 (const int) +0:? Sequence +0:15 move second child to first child ( temp 4-component vector of float) +0:15 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:15 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:15 Constant: +0:15 0 (const uint) +0:15 Constant: +0:15 -1.000000 +0:15 1.000000 +0:15 0.000000 +0:15 1.000000 +0:15 Branch: Break +0:16 case: with expression +0:16 Constant: +0:16 1 (const int) +0:? Sequence +0:16 move second child to first child ( temp 4-component vector of float) +0:16 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:16 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:16 Constant: +0:16 0 (const uint) +0:16 Constant: +0:16 1.000000 +0:16 1.000000 +0:16 0.000000 +0:16 1.000000 +0:16 Branch: Break +0:17 case: with expression +0:17 Constant: +0:17 2 (const int) +0:? Sequence +0:17 move second child to first child ( temp 4-component vector of float) +0:17 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:17 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:17 Constant: +0:17 0 (const uint) +0:17 Constant: +0:17 -1.000000 +0:17 -1.000000 +0:17 0.000000 +0:17 1.000000 +0:17 Branch: Break +0:18 case: with expression +0:18 Constant: +0:18 3 (const int) +0:? Sequence +0:18 move second child to first child ( temp 4-component vector of float) +0:18 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:18 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:18 Constant: +0:18 0 (const uint) +0:18 Constant: +0:18 1.000000 +0:18 -1.000000 +0:18 0.000000 +0:18 1.000000 +0:18 Branch: Break +0:? Linker Objects +0:? 'u1' ( uniform 4-component vector of int) +0:? 'u2' ( uniform 4-component vector of uint) +0:? 'result' ( smooth out 4-component vector of float) +0:? 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + + +Linked vertex stage: + + +Shader version: 150 +Requested GL_ARB_gpu_shader5 +0:? Sequence +0:8 Function Definition: f(vu4;vu4; ( global 4-component vector of float) +0:8 Function Parameters: +0:8 'a' ( in 4-component vector of uint) +0:8 'b' ( in 4-component vector of uint) +0:8 Sequence +0:8 Branch: Return with expression +0:8 Convert uint to float ( temp 4-component vector of float) +0:8 subtract ( temp 4-component vector of uint) +0:8 'a' ( in 4-component vector of uint) +0:8 'b' ( in 4-component vector of uint) +0:10 Function Definition: main( ( global void) +0:10 Function Parameters: +0:12 Sequence +0:12 move second child to first child ( temp 4-component vector of float) +0:12 'result' ( smooth out 4-component vector of float) +0:12 Function Call: f(vu4;vu4; ( global 4-component vector of float) +0:12 Convert int to uint ( temp 4-component vector of uint) +0:12 'u1' ( uniform 4-component vector of int) +0:12 'u2' ( uniform 4-component vector of uint) +0:13 switch +0:13 condition +0:13 'gl_VertexID' ( gl_VertexId int VertexId) +0:13 body +0:13 Sequence +0:15 case: with expression +0:15 Constant: +0:15 0 (const int) +0:? Sequence +0:15 move second child to first child ( temp 4-component vector of float) +0:15 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:15 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:15 Constant: +0:15 0 (const uint) +0:15 Constant: +0:15 -1.000000 +0:15 1.000000 +0:15 0.000000 +0:15 1.000000 +0:15 Branch: Break +0:16 case: with expression +0:16 Constant: +0:16 1 (const int) +0:? Sequence +0:16 move second child to first child ( temp 4-component vector of float) +0:16 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:16 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:16 Constant: +0:16 0 (const uint) +0:16 Constant: +0:16 1.000000 +0:16 1.000000 +0:16 0.000000 +0:16 1.000000 +0:16 Branch: Break +0:17 case: with expression +0:17 Constant: +0:17 2 (const int) +0:? Sequence +0:17 move second child to first child ( temp 4-component vector of float) +0:17 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:17 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:17 Constant: +0:17 0 (const uint) +0:17 Constant: +0:17 -1.000000 +0:17 -1.000000 +0:17 0.000000 +0:17 1.000000 +0:17 Branch: Break +0:18 case: with expression +0:18 Constant: +0:18 3 (const int) +0:? Sequence +0:18 move second child to first child ( temp 4-component vector of float) +0:18 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:18 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:18 Constant: +0:18 0 (const uint) +0:18 Constant: +0:18 1.000000 +0:18 -1.000000 +0:18 0.000000 +0:18 1.000000 +0:18 Branch: Break +0:? Linker Objects +0:? 'u1' ( uniform 4-component vector of int) +0:? 'u2' ( uniform 4-component vector of uint) +0:? 'result' ( smooth out 4-component vector of float) +0:? 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 9ab1207f..e4d47917 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -6650,8 +6650,10 @@ const TFunction* TParseContext::findFunction(const TSourceLoc& loc, const TFunct : findFunctionExact(loc, call, builtIn)); else if (version < 120) function = findFunctionExact(loc, call, builtIn); - else if (version < 400) - function = extensionTurnedOn(E_GL_ARB_gpu_shader_fp64) ? findFunction400(loc, call, builtIn) : findFunction120(loc, call, builtIn); + else if (version < 400) { + bool needfindFunction400 = extensionTurnedOn(E_GL_ARB_gpu_shader_fp64) || extensionTurnedOn(E_GL_ARB_gpu_shader5); + function = needfindFunction400 ? findFunction400(loc, call, builtIn) : findFunction120(loc, call, builtIn); + } else if (explicitTypesEnabled) function = findFunctionExplicitTypes(loc, call, builtIn); else diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp index f9680dd6..6976d9e3 100644 --- a/gtests/AST.FromFile.cpp +++ b/gtests/AST.FromFile.cpp @@ -287,6 +287,7 @@ INSTANTIATE_TEST_SUITE_P( "atomicCounterARBOps.vert", "GL_EXT_shader_integer_mix.vert", "GL_ARB_draw_instanced.vert", + "BestMatchFunction.vert", })), FileNameAsCustomTestSuffix ); From 22a5e364460523413e1791e9280bda1397b9b515 Mon Sep 17 00:00:00 2001 From: Greg Fischer Date: Wed, 10 Nov 2021 14:13:37 -0700 Subject: [PATCH 04/21] Revert "Use intermOut.cpp's IsNan and IsInfinity for parse-time constant folding" --- glslang/Include/Common.h | 29 --------------------- glslang/MachineIndependent/Constant.cpp | 33 ++++++++++++++++++++++-- glslang/MachineIndependent/intermOut.cpp | 31 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 31 deletions(-) diff --git a/glslang/Include/Common.h b/glslang/Include/Common.h index a24977f8..e7b5e072 100644 --- a/glslang/Include/Common.h +++ b/glslang/Include/Common.h @@ -39,7 +39,6 @@ #include #include -#include #include #include #include @@ -303,34 +302,6 @@ template int IntLog2(T n) return result; } -inline bool IsInfinity(double x) { -#ifdef _MSC_VER - switch (_fpclass(x)) { - case _FPCLASS_NINF: - case _FPCLASS_PINF: - return true; - default: - return false; - } -#else - return std::isinf(x); -#endif -} - -inline bool IsNan(double x) { -#ifdef _MSC_VER - switch (_fpclass(x)) { - case _FPCLASS_SNAN: - case _FPCLASS_QNAN: - return true; - default: - return false; - } -#else - return std::isnan(x); -#endif -} - } // end namespace glslang #endif // _COMMON_INCLUDED_ diff --git a/glslang/MachineIndependent/Constant.cpp b/glslang/MachineIndependent/Constant.cpp index 5fc61dbb..7f5d4c4f 100644 --- a/glslang/MachineIndependent/Constant.cpp +++ b/glslang/MachineIndependent/Constant.cpp @@ -46,6 +46,35 @@ namespace { using namespace glslang; +typedef union { + double d; + int i[2]; +} DoubleIntUnion; + +// Some helper functions + +bool isNan(double x) +{ + DoubleIntUnion u; + // tough to find a platform independent library function, do it directly + u.d = x; + int bitPatternL = u.i[0]; + int bitPatternH = u.i[1]; + return (bitPatternH & 0x7ff80000) == 0x7ff80000 && + ((bitPatternH & 0xFFFFF) != 0 || bitPatternL != 0); +} + +bool isInf(double x) +{ + DoubleIntUnion u; + // tough to find a platform independent library function, do it directly + u.d = x; + int bitPatternL = u.i[0]; + int bitPatternH = u.i[1]; + return (bitPatternH & 0x7ff00000) == 0x7ff00000 && + (bitPatternH & 0xFFFFF) == 0 && bitPatternL == 0; +} + const double pi = 3.1415926535897932384626433832795; } // end anonymous namespace @@ -634,12 +663,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType) case EOpIsNan: { - newConstArray[i].setBConst(IsNan(unionArray[i].getDConst())); + newConstArray[i].setBConst(isNan(unionArray[i].getDConst())); break; } case EOpIsInf: { - newConstArray[i].setBConst(IsInfinity(unionArray[i].getDConst())); + newConstArray[i].setBConst(isInf(unionArray[i].getDConst())); break; } diff --git a/glslang/MachineIndependent/intermOut.cpp b/glslang/MachineIndependent/intermOut.cpp index d8a3aab5..a0fade16 100644 --- a/glslang/MachineIndependent/intermOut.cpp +++ b/glslang/MachineIndependent/intermOut.cpp @@ -48,6 +48,37 @@ #endif #include +namespace { + +bool IsInfinity(double x) { +#ifdef _MSC_VER + switch (_fpclass(x)) { + case _FPCLASS_NINF: + case _FPCLASS_PINF: + return true; + default: + return false; + } +#else + return std::isinf(x); +#endif +} + +bool IsNan(double x) { +#ifdef _MSC_VER + switch (_fpclass(x)) { + case _FPCLASS_SNAN: + case _FPCLASS_QNAN: + return true; + default: + return false; + } +#else + return std::isnan(x); +#endif +} + +} namespace glslang { From 002b3f55c7852408100cc20b799aeb0f8646a77a Mon Sep 17 00:00:00 2001 From: Greg Fischer Date: Wed, 10 Nov 2021 15:03:07 -0700 Subject: [PATCH 05/21] Generate error for binding on push_constant --- Test/baseResults/vulkan.frag.out | 53 +++++++++++----------- Test/vulkan.frag | 3 ++ glslang/MachineIndependent/ParseHelper.cpp | 2 + 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Test/baseResults/vulkan.frag.out b/Test/baseResults/vulkan.frag.out index e6208980..28134aed 100644 --- a/Test/baseResults/vulkan.frag.out +++ b/Test/baseResults/vulkan.frag.out @@ -24,37 +24,38 @@ ERROR: 0:39: 'push_constant' : can only be used with a uniform ERROR: 0:43: 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan ERROR: 0:43: 'push_constant' : can only be used with a block ERROR: 0:45: 'push_constant' : cannot declare a default, can only be used on a block -ERROR: 0:51: 'binding' : sampler/texture/image requires layout(binding=X) -ERROR: 0:52: 'binding' : sampler/texture/image requires layout(binding=X) -ERROR: 0:52: 'input_attachment_index' : can only be used with a subpass -ERROR: 0:53: 'binding' : sampler/texture/image requires layout(binding=X) -ERROR: 0:53: 'input_attachment_index' : can only be used with a subpass +ERROR: 0:46: 'binding' : cannot be used with push_constant ERROR: 0:54: 'binding' : sampler/texture/image requires layout(binding=X) -ERROR: 0:54: 'subpass' : requires an input_attachment_index layout qualifier ERROR: 0:55: 'binding' : sampler/texture/image requires layout(binding=X) -ERROR: 0:60: 'subpassLoadMS' : no matching overloaded function found -ERROR: 0:61: 'subpassLoad' : no matching overloaded function found +ERROR: 0:55: 'input_attachment_index' : can only be used with a subpass +ERROR: 0:56: 'binding' : sampler/texture/image requires layout(binding=X) +ERROR: 0:56: 'input_attachment_index' : can only be used with a subpass +ERROR: 0:57: 'binding' : sampler/texture/image requires layout(binding=X) +ERROR: 0:57: 'subpass' : requires an input_attachment_index layout qualifier +ERROR: 0:58: 'binding' : sampler/texture/image requires layout(binding=X) ERROR: 0:63: 'subpassLoadMS' : no matching overloaded function found -ERROR: 0:66: 'subroutine' : not allowed when generating SPIR-V -ERROR: 0:66: 'subroutine' : feature not yet implemented -ERROR: 0:67: 'subroutine' : not allowed when generating SPIR-V -ERROR: 0:67: 'subroutine' : feature not yet implemented -ERROR: 0:69: 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan -ERROR: 0:73: 'texture' : no matching overloaded function found -ERROR: 0:74: 'imageStore' : no matching overloaded function found -WARNING: 0:82: '' : all default precisions are highp; use precision statements to quiet warning, e.g.: +ERROR: 0:64: 'subpassLoad' : no matching overloaded function found +ERROR: 0:66: 'subpassLoadMS' : no matching overloaded function found +ERROR: 0:69: 'subroutine' : not allowed when generating SPIR-V +ERROR: 0:69: 'subroutine' : feature not yet implemented +ERROR: 0:70: 'subroutine' : not allowed when generating SPIR-V +ERROR: 0:70: 'subroutine' : feature not yet implemented +ERROR: 0:72: 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan +ERROR: 0:76: 'texture' : no matching overloaded function found +ERROR: 0:77: 'imageStore' : no matching overloaded function found +WARNING: 0:85: '' : all default precisions are highp; use precision statements to quiet warning, e.g.: "precision mediump int; precision highp float;" -ERROR: 0:91: 'call argument' : sampler constructor must appear at point of use -ERROR: 0:92: 'call argument' : sampler constructor must appear at point of use -ERROR: 0:93: ',' : sampler constructor must appear at point of use -ERROR: 0:94: ':' : wrong operand types: no operation ':' exists that takes a left-hand operand of type ' temp sampler2D' and a right operand of type ' temp sampler2D' (or there is no acceptable conversion) ERROR: 0:94: 'call argument' : sampler constructor must appear at point of use -ERROR: 0:96: 'gl_NumSamples' : undeclared identifier -ERROR: 0:101: 'noise1' : no matching overloaded function found -ERROR: 0:102: 'noise2' : no matching overloaded function found -ERROR: 0:103: 'noise3' : no matching overloaded function found -ERROR: 0:104: 'noise4' : no matching overloaded function found -ERROR: 53 compilation errors. No code generated. +ERROR: 0:95: 'call argument' : sampler constructor must appear at point of use +ERROR: 0:96: ',' : sampler constructor must appear at point of use +ERROR: 0:97: ':' : wrong operand types: no operation ':' exists that takes a left-hand operand of type ' temp sampler2D' and a right operand of type ' temp sampler2D' (or there is no acceptable conversion) +ERROR: 0:97: 'call argument' : sampler constructor must appear at point of use +ERROR: 0:99: 'gl_NumSamples' : undeclared identifier +ERROR: 0:104: 'noise1' : no matching overloaded function found +ERROR: 0:105: 'noise2' : no matching overloaded function found +ERROR: 0:106: 'noise3' : no matching overloaded function found +ERROR: 0:107: 'noise4' : no matching overloaded function found +ERROR: 54 compilation errors. No code generated. ERROR: Linking fragment stage: Only one push_constant block is allowed per stage diff --git a/Test/vulkan.frag b/Test/vulkan.frag index 46c14f31..25bfefec 100644 --- a/Test/vulkan.frag +++ b/Test/vulkan.frag @@ -43,6 +43,9 @@ layout(push_constant) buffer pcb { // ERROR, not on a buffer layout(push_constant) uniform float pcfloat; // ERROR 2X: not on a non-block, and non-opaque outside block layout(push_constant) uniform; // ERROR, needs an object +layout(binding=2, push_constant) uniform pcbnd1 { // ERROR, can't have binding + int a; +} pcbnd1inst; layout(std430, push_constant) uniform pcb1 { int a; } pcb1inst; layout(push_constant) uniform pcb2 { int a; diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 9ab1207f..7f2f171b 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -6496,6 +6496,8 @@ void TParseContext::layoutQualifierCheck(const TSourceLoc& loc, const TQualifier error(loc, "can only be used with a uniform", "push_constant", ""); if (qualifier.hasSet()) error(loc, "cannot be used with push_constant", "set", ""); + if (qualifier.hasBinding()) + error(loc, "cannot be used with push_constant", "binding", ""); } if (qualifier.hasBufferReference()) { if (qualifier.storage != EvqBuffer) From 77415296b2174ea6113107fbbb59c0db0a870197 Mon Sep 17 00:00:00 2001 From: Greg Fischer Date: Thu, 11 Nov 2021 08:43:30 -0700 Subject: [PATCH 06/21] Update to latest spirv-headers --- SPIRV/spirv.hpp | 4 ++-- known_good.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SPIRV/spirv.hpp b/SPIRV/spirv.hpp index e0fe2498..f6b7be92 100644 --- a/SPIRV/spirv.hpp +++ b/SPIRV/spirv.hpp @@ -1543,7 +1543,7 @@ enum Op { OpUSubSatINTEL = 5596, OpIMul32x16INTEL = 5597, OpUMul32x16INTEL = 5598, - OpConstFunctionPointerINTEL = 5600, + OpConstantFunctionPointerINTEL = 5600, OpFunctionPointerCallINTEL = 5601, OpAsmTargetINTEL = 5609, OpAsmINTEL = 5610, @@ -2131,7 +2131,7 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) { case OpUSubSatINTEL: *hasResult = true; *hasResultType = true; break; case OpIMul32x16INTEL: *hasResult = true; *hasResultType = true; break; case OpUMul32x16INTEL: *hasResult = true; *hasResultType = true; break; - case OpConstFunctionPointerINTEL: *hasResult = true; *hasResultType = true; break; + case OpConstantFunctionPointerINTEL: *hasResult = true; *hasResultType = true; break; case OpFunctionPointerCallINTEL: *hasResult = true; *hasResultType = true; break; case OpAsmTargetINTEL: *hasResult = true; *hasResultType = true; break; case OpAsmINTEL: *hasResult = true; *hasResultType = true; break; diff --git a/known_good.json b/known_good.json index bed5dd80..96c27dea 100644 --- a/known_good.json +++ b/known_good.json @@ -5,14 +5,14 @@ "site" : "github", "subrepo" : "KhronosGroup/SPIRV-Tools", "subdir" : "External/spirv-tools", - "commit" : "339d4475c1a806c187c57678af26733575d1cecd" + "commit" : "21e3f681e2004590c7865bc8c0195a4ab8e66c88" }, { "name" : "spirv-tools/external/spirv-headers", "site" : "github", "subrepo" : "KhronosGroup/SPIRV-Headers", "subdir" : "External/spirv-tools/external/spirv-headers", - "commit" : "29817199b7069bac971e5365d180295d4b077ebe" + "commit" : "814e728b30ddd0f4509233099a3ad96fd4318c07" } ] } From 0eda343970e04e7c9447d264271b1c4cfdc923f4 Mon Sep 17 00:00:00 2001 From: Marius Hillenbrand Date: Tue, 9 Nov 2021 16:31:22 +0100 Subject: [PATCH 07/21] Use intermOut.cpp's IsNan and IsInfinity for parse-time constant folding (updated) There were two implementations of isInf() and isNan(), in Constant.cpp and in intermOut.cpp. The former only works on little-endian systems, the latter is a wrapper for library functions and works regardless of endianness. Move the second version into Common.h and adopt it in both places. Thereby avoid the duplication and fix for big-endian systems. A previous commit with the same intent and purpose had missed a required header for builds on Windows. On s390x, this fixes the test case Glsl/CompileToAstTest.FromFile/constFold_frag. Fixes #2802 --- glslang/Include/Common.h | 33 ++++++++++++++++++++++++ glslang/MachineIndependent/Constant.cpp | 33 ++---------------------- glslang/MachineIndependent/intermOut.cpp | 31 ---------------------- 3 files changed, 35 insertions(+), 62 deletions(-) diff --git a/glslang/Include/Common.h b/glslang/Include/Common.h index e7b5e072..9042a1aa 100644 --- a/glslang/Include/Common.h +++ b/glslang/Include/Common.h @@ -39,6 +39,11 @@ #include #include +#ifdef _MSC_VER +#include +#else +#include +#endif #include #include #include @@ -302,6 +307,34 @@ template int IntLog2(T n) return result; } +inline bool IsInfinity(double x) { +#ifdef _MSC_VER + switch (_fpclass(x)) { + case _FPCLASS_NINF: + case _FPCLASS_PINF: + return true; + default: + return false; + } +#else + return std::isinf(x); +#endif +} + +inline bool IsNan(double x) { +#ifdef _MSC_VER + switch (_fpclass(x)) { + case _FPCLASS_SNAN: + case _FPCLASS_QNAN: + return true; + default: + return false; + } +#else + return std::isnan(x); +#endif +} + } // end namespace glslang #endif // _COMMON_INCLUDED_ diff --git a/glslang/MachineIndependent/Constant.cpp b/glslang/MachineIndependent/Constant.cpp index 7f5d4c4f..5fc61dbb 100644 --- a/glslang/MachineIndependent/Constant.cpp +++ b/glslang/MachineIndependent/Constant.cpp @@ -46,35 +46,6 @@ namespace { using namespace glslang; -typedef union { - double d; - int i[2]; -} DoubleIntUnion; - -// Some helper functions - -bool isNan(double x) -{ - DoubleIntUnion u; - // tough to find a platform independent library function, do it directly - u.d = x; - int bitPatternL = u.i[0]; - int bitPatternH = u.i[1]; - return (bitPatternH & 0x7ff80000) == 0x7ff80000 && - ((bitPatternH & 0xFFFFF) != 0 || bitPatternL != 0); -} - -bool isInf(double x) -{ - DoubleIntUnion u; - // tough to find a platform independent library function, do it directly - u.d = x; - int bitPatternL = u.i[0]; - int bitPatternH = u.i[1]; - return (bitPatternH & 0x7ff00000) == 0x7ff00000 && - (bitPatternH & 0xFFFFF) == 0 && bitPatternL == 0; -} - const double pi = 3.1415926535897932384626433832795; } // end anonymous namespace @@ -663,12 +634,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType) case EOpIsNan: { - newConstArray[i].setBConst(isNan(unionArray[i].getDConst())); + newConstArray[i].setBConst(IsNan(unionArray[i].getDConst())); break; } case EOpIsInf: { - newConstArray[i].setBConst(isInf(unionArray[i].getDConst())); + newConstArray[i].setBConst(IsInfinity(unionArray[i].getDConst())); break; } diff --git a/glslang/MachineIndependent/intermOut.cpp b/glslang/MachineIndependent/intermOut.cpp index a0fade16..d8a3aab5 100644 --- a/glslang/MachineIndependent/intermOut.cpp +++ b/glslang/MachineIndependent/intermOut.cpp @@ -48,37 +48,6 @@ #endif #include -namespace { - -bool IsInfinity(double x) { -#ifdef _MSC_VER - switch (_fpclass(x)) { - case _FPCLASS_NINF: - case _FPCLASS_PINF: - return true; - default: - return false; - } -#else - return std::isinf(x); -#endif -} - -bool IsNan(double x) { -#ifdef _MSC_VER - switch (_fpclass(x)) { - case _FPCLASS_SNAN: - case _FPCLASS_QNAN: - return true; - default: - return false; - } -#else - return std::isnan(x); -#endif -} - -} namespace glslang { From 0bc8932aba15a5707a6123e07ed2cab8573d3375 Mon Sep 17 00:00:00 2001 From: Greg Fischer Date: Thu, 11 Nov 2021 09:08:05 -0700 Subject: [PATCH 08/21] Release 11.7.0 --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ad4fa400..ebab4da0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## 11.7.0 2021-11-11 + +### Other changes +* Add support for targeting Vulkan 1.2 in the C API + ## 11.6.0 2021-08-25 ### Other changes From 1f8c8b88c71072fa8b79e401042cd52063e5ff78 Mon Sep 17 00:00:00 2001 From: Greg Fischer Date: Thu, 11 Nov 2021 18:48:05 -0700 Subject: [PATCH 09/21] Revert port of GL_EXT_shader_realtime_clock to GL_EXT_spirv_intrinsics Could not be found by glslang library interface. Blocking SDK build. --- .../GL_EXT_shader_realtime_clock.glsl | 16 ---------------- glslang/MachineIndependent/Initialize.cpp | 7 ++++++- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/glslang/ExtensionHeaders/GL_EXT_shader_realtime_clock.glsl b/glslang/ExtensionHeaders/GL_EXT_shader_realtime_clock.glsl index f74df6fc..7cf545d9 100644 --- a/glslang/ExtensionHeaders/GL_EXT_shader_realtime_clock.glsl +++ b/glslang/ExtensionHeaders/GL_EXT_shader_realtime_clock.glsl @@ -36,19 +36,3 @@ // POSSIBILITY OF SUCH DAMAGE. // -#extension GL_EXT_spirv_intrinsics : enable -#extension GL_ARB_gpu_shader_int64 : enable - -uvec2 clockRealtime2x32EXT(void) { - spirv_instruction (extensions = ["SPV_KHR_shader_clock"], capabilities = [5055], id = 5056) - uvec2 clockRealtime2x32EXT_internal(uint scope); - - return clockRealtime2x32EXT_internal(1 /*Device scope*/); -} - -uint64_t clockRealtimeEXT(void) { - spirv_instruction (extensions = ["SPV_KHR_shader_clock"], capabilities = [5055], id = 5056) - uint64_t clockRealtimeEXT_internal(uint scope); - - return clockRealtimeEXT_internal(1 /*Device scope*/); -} \ No newline at end of file diff --git a/glslang/MachineIndependent/Initialize.cpp b/glslang/MachineIndependent/Initialize.cpp index 728cd4a6..b5f48fb4 100644 --- a/glslang/MachineIndependent/Initialize.cpp +++ b/glslang/MachineIndependent/Initialize.cpp @@ -4553,11 +4553,13 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV "\n"); } - // GL_ARB_shader_clock + // GL_ARB_shader_clock& GL_EXT_shader_realtime_clock if (profile != EEsProfile && version >= 450) { commonBuiltins.append( "uvec2 clock2x32ARB();" "uint64_t clockARB();" + "uvec2 clockRealtime2x32EXT();" + "uint64_t clockRealtimeEXT();" "\n"); } @@ -8324,6 +8326,9 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion symbolTable.setFunctionExtensions("clockARB", 1, &E_GL_ARB_shader_clock); symbolTable.setFunctionExtensions("clock2x32ARB", 1, &E_GL_ARB_shader_clock); + symbolTable.setFunctionExtensions("clockRealtimeEXT", 1, &E_GL_EXT_shader_realtime_clock); + symbolTable.setFunctionExtensions("clockRealtime2x32EXT", 1, &E_GL_EXT_shader_realtime_clock); + if (profile == EEsProfile && version < 320) { symbolTable.setVariableExtensions("gl_PrimitiveID", Num_AEP_geometry_shader, AEP_geometry_shader); symbolTable.setVariableExtensions("gl_Layer", Num_AEP_geometry_shader, AEP_geometry_shader); From f1fa8afa25c99a550b3d80c516b7cfa3ac725de5 Mon Sep 17 00:00:00 2001 From: Marius Hillenbrand Date: Wed, 10 Nov 2021 18:10:58 +0100 Subject: [PATCH 10/21] TIntermediate::promoteConstantUnion(): fix conversion to int8 The signedness of type char is implementation-defined in C++. The conversion to (signed) int8 currently uses a cast to char, which is undefined for negative values when the type char is implemented as unsigned. Thus, fix to cast to "signed char", which has the intended semantic on all implementations. Fixes #2807 --- glslang/MachineIndependent/Intermediate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index 1283f449..6aea5b3d 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -3902,7 +3902,7 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC case EbtFloat16: PROMOTE(setDConst, double, Get); break; \ case EbtFloat: PROMOTE(setDConst, double, Get); break; \ case EbtDouble: PROMOTE(setDConst, double, Get); break; \ - case EbtInt8: PROMOTE(setI8Const, char, Get); break; \ + case EbtInt8: PROMOTE(setI8Const, signed char, Get); break; \ case EbtInt16: PROMOTE(setI16Const, short, Get); break; \ case EbtInt: PROMOTE(setIConst, int, Get); break; \ case EbtInt64: PROMOTE(setI64Const, long long, Get); break; \ From 10be28ac9b9edd1d82e872c69333c563759fb912 Mon Sep 17 00:00:00 2001 From: Greg Fischer Date: Fri, 12 Nov 2021 16:54:22 -0700 Subject: [PATCH 11/21] Fix struct type sharing Fixes #2812 --- .../hlsl.structbuffer.rwbyte2.comp.out | 140 ++++++++++++++++++ Test/hlsl.structbuffer.rwbyte2.comp | 10 ++ glslang/HLSL/hlslParseHelper.cpp | 3 + gtests/Hlsl.FromFile.cpp | 1 + 4 files changed, 154 insertions(+) create mode 100644 Test/baseResults/hlsl.structbuffer.rwbyte2.comp.out create mode 100644 Test/hlsl.structbuffer.rwbyte2.comp diff --git a/Test/baseResults/hlsl.structbuffer.rwbyte2.comp.out b/Test/baseResults/hlsl.structbuffer.rwbyte2.comp.out new file mode 100644 index 00000000..127d52cc --- /dev/null +++ b/Test/baseResults/hlsl.structbuffer.rwbyte2.comp.out @@ -0,0 +1,140 @@ +hlsl.structbuffer.rwbyte2.comp +Shader version: 500 +local_size = (1, 1, 1) +0:? Sequence +0:6 Function Definition: @main( ( temp void) +0:6 Function Parameters: +0:? Sequence +0:7 Sequence +0:7 move second child to first child ( temp uint) +0:7 'f' ( temp uint) +0:7 indirect index (layout( row_major std430) buffer uint) +0:7 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of uint) +0:7 'g_bbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data}) +0:7 Constant: +0:7 0 (const uint) +0:7 right-shift ( temp int) +0:7 Constant: +0:7 16 (const int) +0:7 Constant: +0:7 2 (const int) +0:8 move second child to first child ( temp uint) +0:8 direct index (layout( row_major std430) buffer uint) +0:8 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of uint) +0:8 'g_sbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data}) +0:8 Constant: +0:8 0 (const uint) +0:8 Constant: +0:8 0 (const int) +0:8 'f' ( temp uint) +0:6 Function Definition: main( ( temp void) +0:6 Function Parameters: +0:? Sequence +0:6 Function Call: @main( ( temp void) +0:? Linker Objects +0:? 'g_sbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data}) +0:? 'g_bbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data}) + + +Linked compute stage: + + +Shader version: 500 +local_size = (1, 1, 1) +0:? Sequence +0:6 Function Definition: @main( ( temp void) +0:6 Function Parameters: +0:? Sequence +0:7 Sequence +0:7 move second child to first child ( temp uint) +0:7 'f' ( temp uint) +0:7 indirect index (layout( row_major std430) buffer uint) +0:7 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of uint) +0:7 'g_bbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data}) +0:7 Constant: +0:7 0 (const uint) +0:7 right-shift ( temp int) +0:7 Constant: +0:7 16 (const int) +0:7 Constant: +0:7 2 (const int) +0:8 move second child to first child ( temp uint) +0:8 direct index (layout( row_major std430) buffer uint) +0:8 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of uint) +0:8 'g_sbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data}) +0:8 Constant: +0:8 0 (const uint) +0:8 Constant: +0:8 0 (const int) +0:8 'f' ( temp uint) +0:6 Function Definition: main( ( temp void) +0:6 Function Parameters: +0:? Sequence +0:6 Function Call: @main( ( temp void) +0:? Linker Objects +0:? 'g_sbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data}) +0:? 'g_bbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data}) + +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 30 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint GLCompute 4 "main" + ExecutionMode 4 LocalSize 1 1 1 + Source HLSL 500 + Name 4 "main" + Name 6 "@main(" + Name 10 "f" + Name 12 "g_bbuf" + MemberName 12(g_bbuf) 0 "@data" + Name 14 "g_bbuf" + Name 24 "g_sbuf" + MemberName 24(g_sbuf) 0 "@data" + Name 26 "g_sbuf" + Decorate 11 ArrayStride 4 + MemberDecorate 12(g_bbuf) 0 Offset 0 + Decorate 12(g_bbuf) BufferBlock + Decorate 14(g_bbuf) DescriptorSet 0 + Decorate 14(g_bbuf) Binding 1 + Decorate 23 ArrayStride 4 + MemberDecorate 24(g_sbuf) 0 Offset 0 + Decorate 24(g_sbuf) BufferBlock + Decorate 26(g_sbuf) DescriptorSet 0 + Decorate 26(g_sbuf) Binding 0 + 2: TypeVoid + 3: TypeFunction 2 + 8: TypeInt 32 0 + 9: TypePointer Function 8(int) + 11: TypeRuntimeArray 8(int) + 12(g_bbuf): TypeStruct 11 + 13: TypePointer Uniform 12(g_bbuf) + 14(g_bbuf): 13(ptr) Variable Uniform + 15: TypeInt 32 1 + 16: 15(int) Constant 0 + 17: 15(int) Constant 16 + 18: 15(int) Constant 2 + 20: TypePointer Uniform 8(int) + 23: TypeRuntimeArray 8(int) + 24(g_sbuf): TypeStruct 23 + 25: TypePointer Uniform 24(g_sbuf) + 26(g_sbuf): 25(ptr) Variable Uniform + 4(main): 2 Function None 3 + 5: Label + 29: 2 FunctionCall 6(@main() + Return + FunctionEnd + 6(@main(): 2 Function None 3 + 7: Label + 10(f): 9(ptr) Variable Function + 19: 15(int) ShiftRightArithmetic 17 18 + 21: 20(ptr) AccessChain 14(g_bbuf) 16 19 + 22: 8(int) Load 21 + Store 10(f) 22 + 27: 8(int) Load 10(f) + 28: 20(ptr) AccessChain 26(g_sbuf) 16 16 + Store 28 27 + Return + FunctionEnd diff --git a/Test/hlsl.structbuffer.rwbyte2.comp b/Test/hlsl.structbuffer.rwbyte2.comp new file mode 100644 index 00000000..42d61c00 --- /dev/null +++ b/Test/hlsl.structbuffer.rwbyte2.comp @@ -0,0 +1,10 @@ +RWStructuredBuffer g_sbuf; +RWByteAddressBuffer g_bbuf; + + +void main() +{ + uint f = g_bbuf.Load(16); + g_sbuf[0] = f; +} + diff --git a/glslang/HLSL/hlslParseHelper.cpp b/glslang/HLSL/hlslParseHelper.cpp index 39b3ecac..0936bd3a 100644 --- a/glslang/HLSL/hlslParseHelper.cpp +++ b/glslang/HLSL/hlslParseHelper.cpp @@ -6935,6 +6935,9 @@ void HlslParseContext::shareStructBufferType(TType& type) if (lhs.isStruct() != rhs.isStruct()) return false; + if (lhs.getQualifier().builtIn != rhs.getQualifier().builtIn) + return false; + if (lhs.isStruct() && rhs.isStruct()) { if (lhs.getStruct()->size() != rhs.getStruct()->size()) return false; diff --git a/gtests/Hlsl.FromFile.cpp b/gtests/Hlsl.FromFile.cpp index 5e1cbdae..3e29896d 100644 --- a/gtests/Hlsl.FromFile.cpp +++ b/gtests/Hlsl.FromFile.cpp @@ -385,6 +385,7 @@ INSTANTIATE_TEST_SUITE_P( {"hlsl.structbuffer.fn2.comp", "main"}, {"hlsl.structbuffer.rw.frag", "main"}, {"hlsl.structbuffer.rwbyte.frag", "main"}, + {"hlsl.structbuffer.rwbyte2.comp", "main"}, {"hlsl.structin.vert", "main"}, {"hlsl.structIoFourWay.frag", "main"}, {"hlsl.structStructName.frag", "main"}, From 0d85595e3388237368bc312b64dd95b59d31c3d3 Mon Sep 17 00:00:00 2001 From: Marius Hillenbrand Date: Mon, 15 Nov 2021 16:30:15 +0100 Subject: [PATCH 12/21] add negative float conversions to test constantUnaryConversion.comp Add conversions from negative float16_t and float32_t to bool, all signed integer types (i.e., including those in GL_EXT_shader_explicit_arithmetic_types), and all float types (from the same extension) to extend coverage. Note that converting negative float values to unsigned integers is undefined behavior. Thus, we exclude them. --- .../constantUnaryConversion.comp.out | 116 +++++++++++++++++- Test/constantUnaryConversion.comp | 21 ++++ 2 files changed, 133 insertions(+), 4 deletions(-) diff --git a/Test/baseResults/constantUnaryConversion.comp.out b/Test/baseResults/constantUnaryConversion.comp.out index fcaf6f22..752745a8 100644 --- a/Test/baseResults/constantUnaryConversion.comp.out +++ b/Test/baseResults/constantUnaryConversion.comp.out @@ -3,8 +3,8 @@ Shader version: 450 Requested GL_EXT_shader_explicit_arithmetic_types local_size = (1, 1, 1) 0:? Sequence -0:48 Function Definition: main( ( global void) -0:48 Function Parameters: +0:69 Function Definition: main( ( global void) +0:69 Function Parameters: 0:? Linker Objects 0:? 'bool_init' ( const bool) 0:? true (const bool) @@ -30,6 +30,12 @@ local_size = (1, 1, 1) 0:? 13.000000 0:? 'float64_t_init' ( const double) 0:? -4.000000 +0:? 'neg_float16_t_init' ( const float16_t) +0:? -42.000000 +0:? 'neg_float32_t_init' ( const float) +0:? -13.000000 +0:? 'neg_float64_t_init' ( const double) +0:? -4.000000 0:? 'bool_to_bool' ( const bool) 0:? true (const bool) 0:? 'int8_t_to_bool' ( const bool) @@ -318,6 +324,54 @@ local_size = (1, 1, 1) 0:? 13.000000 0:? 'float64_t_to_float64_t' ( const double) 0:? -4.000000 +0:? 'neg_float16_t_to_bool' ( const bool) +0:? true (const bool) +0:? 'neg_float32_t_to_bool' ( const bool) +0:? true (const bool) +0:? 'neg_float64_t_to_bool' ( const bool) +0:? true (const bool) +0:? 'neg_float16_t_to_int8_t' ( const int8_t) +0:? -42 (const int8_t) +0:? 'neg_float32_t_to_int8_t' ( const int8_t) +0:? -13 (const int8_t) +0:? 'neg_float64_t_to_int8_t' ( const int8_t) +0:? -4 (const int8_t) +0:? 'neg_float16_t_to_int16_t' ( const int16_t) +0:? -42 (const int16_t) +0:? 'neg_float32_t_to_int16_t' ( const int16_t) +0:? -13 (const int16_t) +0:? 'neg_float64_t_to_int16_t' ( const int16_t) +0:? -4 (const int16_t) +0:? 'neg_float16_t_to_int32_t' ( const int) +0:? -42 (const int) +0:? 'neg_float32_t_to_int32_t' ( const int) +0:? -13 (const int) +0:? 'neg_float64_t_to_int32_t' ( const int) +0:? -4 (const int) +0:? 'neg_float16_t_to_int64_t' ( const int64_t) +0:? -42 (const int64_t) +0:? 'neg_float32_t_to_int64_t' ( const int64_t) +0:? -13 (const int64_t) +0:? 'neg_float64_t_to_int64_t' ( const int64_t) +0:? -4 (const int64_t) +0:? 'neg_float16_t_to_float16_t' ( const float16_t) +0:? -42.000000 +0:? 'neg_float32_t_to_float16_t' ( const float16_t) +0:? -13.000000 +0:? 'neg_float64_t_to_float16_t' ( const float16_t) +0:? -4.000000 +0:? 'neg_float16_t_to_float32_t' ( const float) +0:? -42.000000 +0:? 'neg_float32_t_to_float32_t' ( const float) +0:? -13.000000 +0:? 'neg_float64_t_to_float32_t' ( const float) +0:? -4.000000 +0:? 'neg_float16_t_to_float64_t' ( const double) +0:? -42.000000 +0:? 'neg_float32_t_to_float64_t' ( const double) +0:? -13.000000 +0:? 'neg_float64_t_to_float64_t' ( const double) +0:? -4.000000 Linked compute stage: @@ -327,8 +381,8 @@ Shader version: 450 Requested GL_EXT_shader_explicit_arithmetic_types local_size = (1, 1, 1) 0:? Sequence -0:48 Function Definition: main( ( global void) -0:48 Function Parameters: +0:69 Function Definition: main( ( global void) +0:69 Function Parameters: 0:? Linker Objects 0:? 'bool_init' ( const bool) 0:? true (const bool) @@ -354,6 +408,12 @@ local_size = (1, 1, 1) 0:? 13.000000 0:? 'float64_t_init' ( const double) 0:? -4.000000 +0:? 'neg_float16_t_init' ( const float16_t) +0:? -42.000000 +0:? 'neg_float32_t_init' ( const float) +0:? -13.000000 +0:? 'neg_float64_t_init' ( const double) +0:? -4.000000 0:? 'bool_to_bool' ( const bool) 0:? true (const bool) 0:? 'int8_t_to_bool' ( const bool) @@ -642,4 +702,52 @@ local_size = (1, 1, 1) 0:? 13.000000 0:? 'float64_t_to_float64_t' ( const double) 0:? -4.000000 +0:? 'neg_float16_t_to_bool' ( const bool) +0:? true (const bool) +0:? 'neg_float32_t_to_bool' ( const bool) +0:? true (const bool) +0:? 'neg_float64_t_to_bool' ( const bool) +0:? true (const bool) +0:? 'neg_float16_t_to_int8_t' ( const int8_t) +0:? -42 (const int8_t) +0:? 'neg_float32_t_to_int8_t' ( const int8_t) +0:? -13 (const int8_t) +0:? 'neg_float64_t_to_int8_t' ( const int8_t) +0:? -4 (const int8_t) +0:? 'neg_float16_t_to_int16_t' ( const int16_t) +0:? -42 (const int16_t) +0:? 'neg_float32_t_to_int16_t' ( const int16_t) +0:? -13 (const int16_t) +0:? 'neg_float64_t_to_int16_t' ( const int16_t) +0:? -4 (const int16_t) +0:? 'neg_float16_t_to_int32_t' ( const int) +0:? -42 (const int) +0:? 'neg_float32_t_to_int32_t' ( const int) +0:? -13 (const int) +0:? 'neg_float64_t_to_int32_t' ( const int) +0:? -4 (const int) +0:? 'neg_float16_t_to_int64_t' ( const int64_t) +0:? -42 (const int64_t) +0:? 'neg_float32_t_to_int64_t' ( const int64_t) +0:? -13 (const int64_t) +0:? 'neg_float64_t_to_int64_t' ( const int64_t) +0:? -4 (const int64_t) +0:? 'neg_float16_t_to_float16_t' ( const float16_t) +0:? -42.000000 +0:? 'neg_float32_t_to_float16_t' ( const float16_t) +0:? -13.000000 +0:? 'neg_float64_t_to_float16_t' ( const float16_t) +0:? -4.000000 +0:? 'neg_float16_t_to_float32_t' ( const float) +0:? -42.000000 +0:? 'neg_float32_t_to_float32_t' ( const float) +0:? -13.000000 +0:? 'neg_float64_t_to_float32_t' ( const float) +0:? -4.000000 +0:? 'neg_float16_t_to_float64_t' ( const double) +0:? -42.000000 +0:? 'neg_float32_t_to_float64_t' ( const double) +0:? -13.000000 +0:? 'neg_float64_t_to_float64_t' ( const double) +0:? -4.000000 diff --git a/Test/constantUnaryConversion.comp b/Test/constantUnaryConversion.comp index 3c479ae6..7226a267 100644 --- a/Test/constantUnaryConversion.comp +++ b/Test/constantUnaryConversion.comp @@ -15,9 +15,16 @@ const float16_t float16_t_init = float16_t(42.0); const float32_t float32_t_init = float32_t(13.0); const float64_t float64_t_init = float64_t(-4.0); +const float16_t neg_float16_t_init = float16_t(-42.0); +const float32_t neg_float32_t_init = float32_t(-13.0); +const float64_t neg_float64_t_init = float64_t(-4.0); + #define TYPE_TO_TYPE(x, y) \ const x y##_to_##x = x(y##_init) +#define TYPE_TO_TYPE_PREFIX(prefix, x, y) \ + const x prefix##_##y##_to_##x = x(prefix##_##y##_init) + #define TYPE_TO(x) \ TYPE_TO_TYPE(x, bool); \ TYPE_TO_TYPE(x, int8_t); \ @@ -45,4 +52,18 @@ TYPE_TO(float16_t); TYPE_TO(float32_t); TYPE_TO(float64_t); +#define NEG_FLOAT_TO(x) \ + TYPE_TO_TYPE_PREFIX(neg, x, float16_t); \ + TYPE_TO_TYPE_PREFIX(neg, x, float32_t); \ + TYPE_TO_TYPE_PREFIX(neg, x, float64_t) + +NEG_FLOAT_TO(bool); +NEG_FLOAT_TO(int8_t); +NEG_FLOAT_TO(int16_t); +NEG_FLOAT_TO(int32_t); +NEG_FLOAT_TO(int64_t); +NEG_FLOAT_TO(float16_t); +NEG_FLOAT_TO(float32_t); +NEG_FLOAT_TO(float64_t); + void main() {} From d13f81510f73bc33f53ea6228debd9a1f0862770 Mon Sep 17 00:00:00 2001 From: Marius Hillenbrand Date: Mon, 15 Nov 2021 16:31:50 +0100 Subject: [PATCH 13/21] remove undefined conversions from test constantUnaryConversion.comp Remove remaining conversions from negative float64_t to unsigned integers, which are undefined behavior. As a result, this test will also succeed on platforms that implement those conversions differently than x86. That addresses one of the issues in #2815. --- .../constantUnaryConversion.comp.out | 48 +++++++++---------- Test/constantUnaryConversion.comp | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Test/baseResults/constantUnaryConversion.comp.out b/Test/baseResults/constantUnaryConversion.comp.out index 752745a8..78372f06 100644 --- a/Test/baseResults/constantUnaryConversion.comp.out +++ b/Test/baseResults/constantUnaryConversion.comp.out @@ -29,7 +29,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_init' ( const float) 0:? 13.000000 0:? 'float64_t_init' ( const double) -0:? -4.000000 +0:? 4.000000 0:? 'neg_float16_t_init' ( const float16_t) 0:? -42.000000 0:? 'neg_float32_t_init' ( const float) @@ -83,7 +83,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_int8_t' ( const int8_t) 0:? 13 (const int8_t) 0:? 'float64_t_to_int8_t' ( const int8_t) -0:? -4 (const int8_t) +0:? 4 (const int8_t) 0:? 'bool_to_int16_t' ( const int16_t) 0:? 1 (const int16_t) 0:? 'int8_t_to_int16_t' ( const int16_t) @@ -107,7 +107,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_int16_t' ( const int16_t) 0:? 13 (const int16_t) 0:? 'float64_t_to_int16_t' ( const int16_t) -0:? -4 (const int16_t) +0:? 4 (const int16_t) 0:? 'bool_to_int32_t' ( const int) 0:? 1 (const int) 0:? 'int8_t_to_int32_t' ( const int) @@ -131,7 +131,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_int32_t' ( const int) 0:? 13 (const int) 0:? 'float64_t_to_int32_t' ( const int) -0:? -4 (const int) +0:? 4 (const int) 0:? 'bool_to_int64_t' ( const int64_t) 0:? 1 (const int64_t) 0:? 'int8_t_to_int64_t' ( const int64_t) @@ -155,7 +155,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_int64_t' ( const int64_t) 0:? 13 (const int64_t) 0:? 'float64_t_to_int64_t' ( const int64_t) -0:? -4 (const int64_t) +0:? 4 (const int64_t) 0:? 'bool_to_uint8_t' ( const uint8_t) 0:? 1 (const uint8_t) 0:? 'int8_t_to_uint8_t' ( const uint8_t) @@ -179,7 +179,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_uint8_t' ( const uint8_t) 0:? 13 (const uint8_t) 0:? 'float64_t_to_uint8_t' ( const uint8_t) -0:? 252 (const uint8_t) +0:? 4 (const uint8_t) 0:? 'bool_to_uint16_t' ( const uint16_t) 0:? 1 (const uint16_t) 0:? 'int8_t_to_uint16_t' ( const uint16_t) @@ -203,7 +203,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_uint16_t' ( const uint16_t) 0:? 13 (const uint16_t) 0:? 'float64_t_to_uint16_t' ( const uint16_t) -0:? 65532 (const uint16_t) +0:? 4 (const uint16_t) 0:? 'bool_to_uint32_t' ( const uint) 0:? 1 (const uint) 0:? 'int8_t_to_uint32_t' ( const uint) @@ -227,7 +227,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_uint32_t' ( const uint) 0:? 13 (const uint) 0:? 'float64_t_to_uint32_t' ( const uint) -0:? 4294967292 (const uint) +0:? 4 (const uint) 0:? 'bool_to_uint64_t' ( const uint64_t) 0:? 1 (const uint64_t) 0:? 'int8_t_to_uint64_t' ( const uint64_t) @@ -251,7 +251,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_uint64_t' ( const uint64_t) 0:? 13 (const uint64_t) 0:? 'float64_t_to_uint64_t' ( const uint64_t) -0:? 18446744073709551612 (const uint64_t) +0:? 4 (const uint64_t) 0:? 'bool_to_float16_t' ( const float16_t) 0:? 1.000000 0:? 'int8_t_to_float16_t' ( const float16_t) @@ -275,7 +275,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_float16_t' ( const float16_t) 0:? 13.000000 0:? 'float64_t_to_float16_t' ( const float16_t) -0:? -4.000000 +0:? 4.000000 0:? 'bool_to_float32_t' ( const float) 0:? 1.000000 0:? 'int8_t_to_float32_t' ( const float) @@ -299,7 +299,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_float32_t' ( const float) 0:? 13.000000 0:? 'float64_t_to_float32_t' ( const float) -0:? -4.000000 +0:? 4.000000 0:? 'bool_to_float64_t' ( const double) 0:? 1.000000 0:? 'int8_t_to_float64_t' ( const double) @@ -323,7 +323,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_float64_t' ( const double) 0:? 13.000000 0:? 'float64_t_to_float64_t' ( const double) -0:? -4.000000 +0:? 4.000000 0:? 'neg_float16_t_to_bool' ( const bool) 0:? true (const bool) 0:? 'neg_float32_t_to_bool' ( const bool) @@ -407,7 +407,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_init' ( const float) 0:? 13.000000 0:? 'float64_t_init' ( const double) -0:? -4.000000 +0:? 4.000000 0:? 'neg_float16_t_init' ( const float16_t) 0:? -42.000000 0:? 'neg_float32_t_init' ( const float) @@ -461,7 +461,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_int8_t' ( const int8_t) 0:? 13 (const int8_t) 0:? 'float64_t_to_int8_t' ( const int8_t) -0:? -4 (const int8_t) +0:? 4 (const int8_t) 0:? 'bool_to_int16_t' ( const int16_t) 0:? 1 (const int16_t) 0:? 'int8_t_to_int16_t' ( const int16_t) @@ -485,7 +485,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_int16_t' ( const int16_t) 0:? 13 (const int16_t) 0:? 'float64_t_to_int16_t' ( const int16_t) -0:? -4 (const int16_t) +0:? 4 (const int16_t) 0:? 'bool_to_int32_t' ( const int) 0:? 1 (const int) 0:? 'int8_t_to_int32_t' ( const int) @@ -509,7 +509,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_int32_t' ( const int) 0:? 13 (const int) 0:? 'float64_t_to_int32_t' ( const int) -0:? -4 (const int) +0:? 4 (const int) 0:? 'bool_to_int64_t' ( const int64_t) 0:? 1 (const int64_t) 0:? 'int8_t_to_int64_t' ( const int64_t) @@ -533,7 +533,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_int64_t' ( const int64_t) 0:? 13 (const int64_t) 0:? 'float64_t_to_int64_t' ( const int64_t) -0:? -4 (const int64_t) +0:? 4 (const int64_t) 0:? 'bool_to_uint8_t' ( const uint8_t) 0:? 1 (const uint8_t) 0:? 'int8_t_to_uint8_t' ( const uint8_t) @@ -557,7 +557,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_uint8_t' ( const uint8_t) 0:? 13 (const uint8_t) 0:? 'float64_t_to_uint8_t' ( const uint8_t) -0:? 252 (const uint8_t) +0:? 4 (const uint8_t) 0:? 'bool_to_uint16_t' ( const uint16_t) 0:? 1 (const uint16_t) 0:? 'int8_t_to_uint16_t' ( const uint16_t) @@ -581,7 +581,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_uint16_t' ( const uint16_t) 0:? 13 (const uint16_t) 0:? 'float64_t_to_uint16_t' ( const uint16_t) -0:? 65532 (const uint16_t) +0:? 4 (const uint16_t) 0:? 'bool_to_uint32_t' ( const uint) 0:? 1 (const uint) 0:? 'int8_t_to_uint32_t' ( const uint) @@ -605,7 +605,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_uint32_t' ( const uint) 0:? 13 (const uint) 0:? 'float64_t_to_uint32_t' ( const uint) -0:? 4294967292 (const uint) +0:? 4 (const uint) 0:? 'bool_to_uint64_t' ( const uint64_t) 0:? 1 (const uint64_t) 0:? 'int8_t_to_uint64_t' ( const uint64_t) @@ -629,7 +629,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_uint64_t' ( const uint64_t) 0:? 13 (const uint64_t) 0:? 'float64_t_to_uint64_t' ( const uint64_t) -0:? 18446744073709551612 (const uint64_t) +0:? 4 (const uint64_t) 0:? 'bool_to_float16_t' ( const float16_t) 0:? 1.000000 0:? 'int8_t_to_float16_t' ( const float16_t) @@ -653,7 +653,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_float16_t' ( const float16_t) 0:? 13.000000 0:? 'float64_t_to_float16_t' ( const float16_t) -0:? -4.000000 +0:? 4.000000 0:? 'bool_to_float32_t' ( const float) 0:? 1.000000 0:? 'int8_t_to_float32_t' ( const float) @@ -677,7 +677,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_float32_t' ( const float) 0:? 13.000000 0:? 'float64_t_to_float32_t' ( const float) -0:? -4.000000 +0:? 4.000000 0:? 'bool_to_float64_t' ( const double) 0:? 1.000000 0:? 'int8_t_to_float64_t' ( const double) @@ -701,7 +701,7 @@ local_size = (1, 1, 1) 0:? 'float32_t_to_float64_t' ( const double) 0:? 13.000000 0:? 'float64_t_to_float64_t' ( const double) -0:? -4.000000 +0:? 4.000000 0:? 'neg_float16_t_to_bool' ( const bool) 0:? true (const bool) 0:? 'neg_float32_t_to_bool' ( const bool) diff --git a/Test/constantUnaryConversion.comp b/Test/constantUnaryConversion.comp index 7226a267..f0710cd0 100644 --- a/Test/constantUnaryConversion.comp +++ b/Test/constantUnaryConversion.comp @@ -13,7 +13,7 @@ const uint32_t uint32_t_init = uint32_t(3); const uint64_t uint64_t_init = uint64_t(4); const float16_t float16_t_init = float16_t(42.0); const float32_t float32_t_init = float32_t(13.0); -const float64_t float64_t_init = float64_t(-4.0); +const float64_t float64_t_init = float64_t(4.0); const float16_t neg_float16_t_init = float16_t(-42.0); const float32_t neg_float32_t_init = float32_t(-13.0); From cd187e201a43d31e1e740edc99d184e806a46f6d Mon Sep 17 00:00:00 2001 From: Kevin Athey Date: Mon, 15 Nov 2021 16:33:08 -0800 Subject: [PATCH 14/21] Initialize member TSymbol::uniqueId. --- glslang/MachineIndependent/SymbolTable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glslang/MachineIndependent/SymbolTable.h b/glslang/MachineIndependent/SymbolTable.h index 720999a3..31312ecb 100644 --- a/glslang/MachineIndependent/SymbolTable.h +++ b/glslang/MachineIndependent/SymbolTable.h @@ -84,7 +84,7 @@ typedef TVector TExtensionList; class TSymbol { public: POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator()) - explicit TSymbol(const TString *n) : name(n), extensions(0), writable(true) { } + explicit TSymbol(const TString *n) : name(n), uniqueId(0), extensions(0), writable(true) { } virtual TSymbol* clone() const = 0; virtual ~TSymbol() { } // rely on all symbol owned memory coming from the pool From 1025f4736a78363acdad236c7550989f5160d9db Mon Sep 17 00:00:00 2001 From: Alan Baker Date: Tue, 16 Nov 2021 19:03:12 -0500 Subject: [PATCH 15/21] Update SPIRV-Tools * Fix test expectations --- Test/baseLegalResults/hlsl.flattenSubset.frag.out | 6 +----- Test/baseLegalResults/hlsl.flattenSubset2.frag.out | 6 +----- known_good.json | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Test/baseLegalResults/hlsl.flattenSubset.frag.out b/Test/baseLegalResults/hlsl.flattenSubset.frag.out index 0edf7120..46d3afba 100644 --- a/Test/baseLegalResults/hlsl.flattenSubset.frag.out +++ b/Test/baseLegalResults/hlsl.flattenSubset.frag.out @@ -6,19 +6,17 @@ hlsl.flattenSubset.frag Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 4 "main" 47 50 + EntryPoint Fragment 4 "main" 50 ExecutionMode 4 OriginUpperLeft Source HLSL 500 Name 4 "main" Name 21 "samp" Name 33 "tex" - Name 47 "vpos" Name 50 "@entryPointOutput" Decorate 21(samp) DescriptorSet 0 Decorate 21(samp) Binding 0 Decorate 33(tex) DescriptorSet 0 Decorate 33(tex) Binding 1 - Decorate 47(vpos) Location 0 Decorate 50(@entryPointOutput) Location 0 2: TypeVoid 3: TypeFunction 2 @@ -34,8 +32,6 @@ hlsl.flattenSubset.frag 39: TypeVector 6(float) 2 40: 6(float) Constant 1056964608 41: 39(fvec2) ConstantComposite 40 40 - 46: TypePointer Input 7(fvec4) - 47(vpos): 46(ptr) Variable Input 49: TypePointer Output 7(fvec4) 50(@entryPointOutput): 49(ptr) Variable Output 4(main): 2 Function None 3 diff --git a/Test/baseLegalResults/hlsl.flattenSubset2.frag.out b/Test/baseLegalResults/hlsl.flattenSubset2.frag.out index 00bd55be..408c0eac 100644 --- a/Test/baseLegalResults/hlsl.flattenSubset2.frag.out +++ b/Test/baseLegalResults/hlsl.flattenSubset2.frag.out @@ -6,13 +6,11 @@ hlsl.flattenSubset2.frag Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 4 "main" 49 52 + EntryPoint Fragment 4 "main" 52 ExecutionMode 4 OriginUpperLeft Source HLSL 500 Name 4 "main" - Name 49 "vpos" Name 52 "@entryPointOutput" - Decorate 49(vpos) Location 0 Decorate 52(@entryPointOutput) Location 0 2: TypeVoid 3: TypeFunction 2 @@ -20,8 +18,6 @@ hlsl.flattenSubset2.frag 7: TypeVector 6(float) 4 43: 6(float) Constant 0 44: 7(fvec4) ConstantComposite 43 43 43 43 - 48: TypePointer Input 7(fvec4) - 49(vpos): 48(ptr) Variable Input 51: TypePointer Output 7(fvec4) 52(@entryPointOutput): 51(ptr) Variable Output 4(main): 2 Function None 3 diff --git a/known_good.json b/known_good.json index 96c27dea..5da639d6 100644 --- a/known_good.json +++ b/known_good.json @@ -5,7 +5,7 @@ "site" : "github", "subrepo" : "KhronosGroup/SPIRV-Tools", "subdir" : "External/spirv-tools", - "commit" : "21e3f681e2004590c7865bc8c0195a4ab8e66c88" + "commit" : "4b092d2ab81854e61632bdd1e658907f0071c37e" }, { "name" : "spirv-tools/external/spirv-headers", From e9564feb55492127cc3c556502bfa46875fc3992 Mon Sep 17 00:00:00 2001 From: Greg Fischer Date: Tue, 16 Nov 2021 18:42:12 -0700 Subject: [PATCH 16/21] Add --hlsl-dx-position-w option This reciprocates the w component of SV_Position in HLSL fragment shaders to provide DirectX compatibility for HLSL shaders in Vulkan. Fixes #2244 --- StandAlone/StandAlone.cpp | 8 + Test/baseResults/hlsl.w-recip.frag.out | 268 ++++++++++++++++++ Test/hlsl.w-recip.frag | 12 + Test/runtests | 7 + glslang/HLSL/hlslParseHelper.cpp | 17 +- glslang/MachineIndependent/ShaderLang.cpp | 1 + glslang/MachineIndependent/linkValidate.cpp | 1 + .../MachineIndependent/localintermediate.h | 10 + glslang/Public/ShaderLang.h | 1 + 9 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 Test/baseResults/hlsl.w-recip.frag.out create mode 100644 Test/hlsl.w-recip.frag diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 23e510c2..4deaf4d9 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -177,6 +177,7 @@ const char* shaderStageName = nullptr; const char* variableName = nullptr; bool HlslEnable16BitTypes = false; bool HlslDX9compatible = false; +bool HlslDxPositionW = false; bool DumpBuiltinSymbols = false; std::vector IncludeDirectoryList; @@ -662,6 +663,8 @@ void ProcessArguments(std::vector>& workItem HlslEnable16BitTypes = true; } else if (lowerword == "hlsl-dx9-compatible") { HlslDX9compatible = true; + } else if (lowerword == "hlsl-dx-position-w") { + HlslDxPositionW = true; } else if (lowerword == "auto-sampled-textures") { autoSampledTextures = true; } else if (lowerword == "invert-y" || // synonyms @@ -1284,6 +1287,9 @@ void CompileAndLinkShaderUnits(std::vector compUnits) if (Options & EOptionInvertY) shader->setInvertY(true); + if (HlslDxPositionW) + shader->setDxPositionW(true); + // Set up the environment, some subsettings take precedence over earlier // ways of setting things. if (Options & EOptionSpv) { @@ -1847,6 +1853,8 @@ void usage() " --hlsl-dx9-compatible interprets sampler declarations as a\n" " texture/sampler combo like DirectX9 would,\n" " and recognizes DirectX9-specific semantics\n" + " --hlsl-dx-position-w W component of SV_Position in HLSL fragment\n" + " shaders compatible with DirectX\n" " --invert-y | --iy invert position.Y output in vertex shader\n" " --keep-uncalled | --ku don't eliminate uncalled functions\n" " --nan-clamp favor non-NaN operand in min, max, and clamp\n" diff --git a/Test/baseResults/hlsl.w-recip.frag.out b/Test/baseResults/hlsl.w-recip.frag.out new file mode 100644 index 00000000..b72f361e --- /dev/null +++ b/Test/baseResults/hlsl.w-recip.frag.out @@ -0,0 +1,268 @@ +hlsl.w-recip.frag +Shader version: 500 +gl_FragCoord origin is upper left +0:? Sequence +0:5 Function Definition: @main(vf4; ( temp 4-component vector of float) +0:5 Function Parameters: +0:5 'vpos' ( in 4-component vector of float) +0:? Sequence +0:6 Sequence +0:6 move second child to first child ( temp 4-component vector of float) +0:6 'vpos_t' ( temp 4-component vector of float) +0:6 Construct vec4 ( temp 4-component vector of float) +0:6 vector swizzle ( temp 3-component vector of float) +0:6 'vpos' ( in 4-component vector of float) +0:6 Sequence +0:6 Constant: +0:6 0 (const int) +0:6 Constant: +0:6 1 (const int) +0:6 Constant: +0:6 2 (const int) +0:6 divide ( temp float) +0:6 Constant: +0:6 1.000000 +0:6 direct index ( temp float) +0:6 'vpos' ( in 4-component vector of float) +0:6 Constant: +0:6 3 (const int) +0:7 Test condition and select ( temp void) +0:7 Condition +0:7 Compare Less Than ( temp bool) +0:7 direct index ( temp float) +0:7 'vpos_t' ( temp 4-component vector of float) +0:7 Constant: +0:7 0 (const int) +0:7 Constant: +0:7 400.000000 +0:7 true case +0:8 Branch: Return with expression +0:8 AmbientColor: direct index for structure ( uniform 4-component vector of float) +0:8 'anon@0' (layout( row_major std140) uniform block{ uniform 4-component vector of float AmbientColor, uniform 4-component vector of float AmbientColor2}) +0:8 Constant: +0:8 0 (const uint) +0:7 false case +0:10 Branch: Return with expression +0:10 AmbientColor2: direct index for structure ( uniform 4-component vector of float) +0:10 'anon@0' (layout( row_major std140) uniform block{ uniform 4-component vector of float AmbientColor, uniform 4-component vector of float AmbientColor2}) +0:10 Constant: +0:10 1 (const uint) +0:5 Function Definition: main( ( temp void) +0:5 Function Parameters: +0:? Sequence +0:5 move second child to first child ( temp 4-component vector of float) +0:? 'vpos' ( temp 4-component vector of float) +0:5 Construct vec4 ( temp 4-component vector of float) +0:5 vector swizzle ( temp 3-component vector of float) +0:? 'vpos' ( in 4-component vector of float FragCoord) +0:5 Sequence +0:5 Constant: +0:5 0 (const int) +0:5 Constant: +0:5 1 (const int) +0:5 Constant: +0:5 2 (const int) +0:5 divide ( temp float) +0:5 Constant: +0:5 1.000000 +0:5 direct index ( temp float) +0:? 'vpos' ( in 4-component vector of float FragCoord) +0:5 Constant: +0:5 3 (const int) +0:5 move second child to first child ( temp 4-component vector of float) +0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) +0:5 Function Call: @main(vf4; ( temp 4-component vector of float) +0:? 'vpos' ( temp 4-component vector of float) +0:? Linker Objects +0:? 'anon@0' (layout( row_major std140) uniform block{ uniform 4-component vector of float AmbientColor, uniform 4-component vector of float AmbientColor2}) +0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) +0:? 'vpos' ( in 4-component vector of float FragCoord) + + +Linked fragment stage: + + +Shader version: 500 +gl_FragCoord origin is upper left +0:? Sequence +0:5 Function Definition: @main(vf4; ( temp 4-component vector of float) +0:5 Function Parameters: +0:5 'vpos' ( in 4-component vector of float) +0:? Sequence +0:6 Sequence +0:6 move second child to first child ( temp 4-component vector of float) +0:6 'vpos_t' ( temp 4-component vector of float) +0:6 Construct vec4 ( temp 4-component vector of float) +0:6 vector swizzle ( temp 3-component vector of float) +0:6 'vpos' ( in 4-component vector of float) +0:6 Sequence +0:6 Constant: +0:6 0 (const int) +0:6 Constant: +0:6 1 (const int) +0:6 Constant: +0:6 2 (const int) +0:6 divide ( temp float) +0:6 Constant: +0:6 1.000000 +0:6 direct index ( temp float) +0:6 'vpos' ( in 4-component vector of float) +0:6 Constant: +0:6 3 (const int) +0:7 Test condition and select ( temp void) +0:7 Condition +0:7 Compare Less Than ( temp bool) +0:7 direct index ( temp float) +0:7 'vpos_t' ( temp 4-component vector of float) +0:7 Constant: +0:7 0 (const int) +0:7 Constant: +0:7 400.000000 +0:7 true case +0:8 Branch: Return with expression +0:8 AmbientColor: direct index for structure ( uniform 4-component vector of float) +0:8 'anon@0' (layout( row_major std140) uniform block{ uniform 4-component vector of float AmbientColor, uniform 4-component vector of float AmbientColor2}) +0:8 Constant: +0:8 0 (const uint) +0:7 false case +0:10 Branch: Return with expression +0:10 AmbientColor2: direct index for structure ( uniform 4-component vector of float) +0:10 'anon@0' (layout( row_major std140) uniform block{ uniform 4-component vector of float AmbientColor, uniform 4-component vector of float AmbientColor2}) +0:10 Constant: +0:10 1 (const uint) +0:5 Function Definition: main( ( temp void) +0:5 Function Parameters: +0:? Sequence +0:5 move second child to first child ( temp 4-component vector of float) +0:? 'vpos' ( temp 4-component vector of float) +0:5 Construct vec4 ( temp 4-component vector of float) +0:5 vector swizzle ( temp 3-component vector of float) +0:? 'vpos' ( in 4-component vector of float FragCoord) +0:5 Sequence +0:5 Constant: +0:5 0 (const int) +0:5 Constant: +0:5 1 (const int) +0:5 Constant: +0:5 2 (const int) +0:5 divide ( temp float) +0:5 Constant: +0:5 1.000000 +0:5 direct index ( temp float) +0:? 'vpos' ( in 4-component vector of float FragCoord) +0:5 Constant: +0:5 3 (const int) +0:5 move second child to first child ( temp 4-component vector of float) +0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) +0:5 Function Call: @main(vf4; ( temp 4-component vector of float) +0:? 'vpos' ( temp 4-component vector of float) +0:? Linker Objects +0:? 'anon@0' (layout( row_major std140) uniform block{ uniform 4-component vector of float AmbientColor, uniform 4-component vector of float AmbientColor2}) +0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) +0:? 'vpos' ( in 4-component vector of float FragCoord) + +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 69 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Fragment 4 "main" 53 65 + ExecutionMode 4 OriginUpperLeft + Source HLSL 500 + Name 4 "main" + Name 11 "@main(vf4;" + Name 10 "vpos" + Name 13 "vpos_t" + Name 36 "$Global" + MemberName 36($Global) 0 "AmbientColor" + MemberName 36($Global) 1 "AmbientColor2" + Name 38 "" + Name 51 "vpos" + Name 53 "vpos" + Name 65 "@entryPointOutput" + Name 66 "param" + MemberDecorate 36($Global) 0 Offset 0 + MemberDecorate 36($Global) 1 Offset 16 + Decorate 36($Global) Block + Decorate 38 DescriptorSet 0 + Decorate 38 Binding 0 + Decorate 53(vpos) BuiltIn FragCoord + Decorate 65(@entryPointOutput) Location 0 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypePointer Function 7(fvec4) + 9: TypeFunction 7(fvec4) 8(ptr) + 14: TypeVector 6(float) 3 + 17: 6(float) Constant 1065353216 + 18: TypeInt 32 0 + 19: 18(int) Constant 3 + 20: TypePointer Function 6(float) + 28: 18(int) Constant 0 + 31: 6(float) Constant 1137180672 + 32: TypeBool + 36($Global): TypeStruct 7(fvec4) 7(fvec4) + 37: TypePointer Uniform 36($Global) + 38: 37(ptr) Variable Uniform + 39: TypeInt 32 1 + 40: 39(int) Constant 0 + 41: TypePointer Uniform 7(fvec4) + 46: 39(int) Constant 1 + 52: TypePointer Input 7(fvec4) + 53(vpos): 52(ptr) Variable Input + 56: TypePointer Input 6(float) + 64: TypePointer Output 7(fvec4) +65(@entryPointOutput): 64(ptr) Variable Output + 4(main): 2 Function None 3 + 5: Label + 51(vpos): 8(ptr) Variable Function + 66(param): 8(ptr) Variable Function + 54: 7(fvec4) Load 53(vpos) + 55: 14(fvec3) VectorShuffle 54 54 0 1 2 + 57: 56(ptr) AccessChain 53(vpos) 19 + 58: 6(float) Load 57 + 59: 6(float) FDiv 17 58 + 60: 6(float) CompositeExtract 55 0 + 61: 6(float) CompositeExtract 55 1 + 62: 6(float) CompositeExtract 55 2 + 63: 7(fvec4) CompositeConstruct 60 61 62 59 + Store 51(vpos) 63 + 67: 7(fvec4) Load 51(vpos) + Store 66(param) 67 + 68: 7(fvec4) FunctionCall 11(@main(vf4;) 66(param) + Store 65(@entryPointOutput) 68 + Return + FunctionEnd + 11(@main(vf4;): 7(fvec4) Function None 9 + 10(vpos): 8(ptr) FunctionParameter + 12: Label + 13(vpos_t): 8(ptr) Variable Function + 15: 7(fvec4) Load 10(vpos) + 16: 14(fvec3) VectorShuffle 15 15 0 1 2 + 21: 20(ptr) AccessChain 10(vpos) 19 + 22: 6(float) Load 21 + 23: 6(float) FDiv 17 22 + 24: 6(float) CompositeExtract 16 0 + 25: 6(float) CompositeExtract 16 1 + 26: 6(float) CompositeExtract 16 2 + 27: 7(fvec4) CompositeConstruct 24 25 26 23 + Store 13(vpos_t) 27 + 29: 20(ptr) AccessChain 13(vpos_t) 28 + 30: 6(float) Load 29 + 33: 32(bool) FOrdLessThan 30 31 + SelectionMerge 35 None + BranchConditional 33 34 45 + 34: Label + 42: 41(ptr) AccessChain 38 40 + 43: 7(fvec4) Load 42 + ReturnValue 43 + 45: Label + 47: 41(ptr) AccessChain 38 46 + 48: 7(fvec4) Load 47 + ReturnValue 48 + 35: Label + Unreachable + FunctionEnd diff --git a/Test/hlsl.w-recip.frag b/Test/hlsl.w-recip.frag new file mode 100644 index 00000000..4812d269 --- /dev/null +++ b/Test/hlsl.w-recip.frag @@ -0,0 +1,12 @@ +float4 AmbientColor = float4(1, 0.5, 0, 1); +float4 AmbientColor2 = float4(0.5, 1, 0, 0); + +float4 main(float4 vpos : SV_POSITION) : SV_TARGET +{ + float4 vpos_t = float4(vpos.xyz, 1 / vpos.w); + if (vpos_t.x < 400) + return AmbientColor; + else + return AmbientColor2; +} + diff --git a/Test/runtests b/Test/runtests index a7bdda79..f27b6d83 100755 --- a/Test/runtests +++ b/Test/runtests @@ -254,6 +254,13 @@ diff -b $BASEDIR/hlsl.y-negate-2.vert.out $TARGETDIR/hlsl.y-negate-2.vert.out || run -H -e main -V -D -Od -H -i --invert-y hlsl.y-negate-3.vert > $TARGETDIR/hlsl.y-negate-3.vert.out diff -b $BASEDIR/hlsl.y-negate-3.vert.out $TARGETDIR/hlsl.y-negate-3.vert.out || HASERROR=1 +# +# Testing position W reciprocal +# +echo "Testing position W reciprocal" +run -H -e main -V -D -Od -H -i --hlsl-dx-position-w hlsl.w-recip.frag > $TARGETDIR/hlsl.w-recip.frag.out +diff -b $BASEDIR/hlsl.w-recip.frag.out $TARGETDIR/hlsl.w-recip.frag.out || HASERROR=1 + # # Testing hlsl_functionality1 # diff --git a/glslang/HLSL/hlslParseHelper.cpp b/glslang/HLSL/hlslParseHelper.cpp index 0936bd3a..9122973a 100644 --- a/glslang/HLSL/hlslParseHelper.cpp +++ b/glslang/HLSL/hlslParseHelper.cpp @@ -2167,8 +2167,21 @@ TIntermNode* HlslParseContext::transformEntryPoint(const TSourceLoc& loc, TFunct TIntermSymbol* arg = intermediate.addSymbol(*argVars.back()); handleFunctionArgument(&callee, callingArgs, arg); if (param.type->getQualifier().isParamInput()) { - intermediate.growAggregate(synthBody, handleAssign(loc, EOpAssign, arg, - intermediate.addSymbol(**inputIt))); + TIntermTyped* input = intermediate.addSymbol(**inputIt); + if (input->getType().getQualifier().builtIn == EbvFragCoord && intermediate.getDxPositionW()) { + // Replace FragCoord W with reciprocal + auto pos_xyz = handleDotDereference(loc, input, "xyz"); + auto pos_w = handleDotDereference(loc, input, "w"); + auto one = intermediate.addConstantUnion(1.0, EbtFloat, loc); + auto recip_w = intermediate.addBinaryMath(EOpDiv, one, pos_w, loc); + TIntermAggregate* dst = new TIntermAggregate(EOpConstructVec4); + dst->getSequence().push_back(pos_xyz); + dst->getSequence().push_back(recip_w); + dst->setType(TType(EbtFloat, EvqTemporary, 4)); + dst->setLoc(loc); + input = dst; + } + intermediate.growAggregate(synthBody, handleAssign(loc, EOpAssign, arg, input)); inputIt++; } if (param.type->getQualifier().storage == EvqUniform) { diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index a2dd71cf..bcf2c33f 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -1829,6 +1829,7 @@ void TShader::setUniqueId(unsigned long long id) } void TShader::setInvertY(bool invert) { intermediate->setInvertY(invert); } +void TShader::setDxPositionW(bool invert) { intermediate->setDxPositionW(invert); } void TShader::setNanMinMaxClamp(bool useNonNan) { intermediate->setNanMinMaxClamp(useNonNan); } #ifndef GLSLANG_WEB diff --git a/glslang/MachineIndependent/linkValidate.cpp b/glslang/MachineIndependent/linkValidate.cpp index b1adfc93..d2eb9026 100644 --- a/glslang/MachineIndependent/linkValidate.cpp +++ b/glslang/MachineIndependent/linkValidate.cpp @@ -312,6 +312,7 @@ void TIntermediate::mergeModes(TInfoSink& infoSink, TIntermediate& unit) MERGE_TRUE(autoMapBindings); MERGE_TRUE(autoMapLocations); MERGE_TRUE(invertY); + MERGE_TRUE(dxPositionW); MERGE_TRUE(flattenUniformArrays); MERGE_TRUE(useUnknownFormat); MERGE_TRUE(hlslOffsets); diff --git a/glslang/MachineIndependent/localintermediate.h b/glslang/MachineIndependent/localintermediate.h index 6aa9399d..940abf79 100644 --- a/glslang/MachineIndependent/localintermediate.h +++ b/glslang/MachineIndependent/localintermediate.h @@ -290,6 +290,7 @@ public: resources(TBuiltInResource{}), numEntryPoints(0), numErrors(0), numPushConstants(0), recursive(false), invertY(false), + dxPositionW(false), useStorageBuffer(false), invariantAll(false), nanMinMaxClamp(false), @@ -460,6 +461,14 @@ public: } bool getInvertY() const { return invertY; } + void setDxPositionW(bool dxPosW) + { + dxPositionW = dxPosW; + if (dxPositionW) + processes.addProcess("dx-position-w"); + } + bool getDxPositionW() const { return dxPositionW; } + #ifdef ENABLE_HLSL void setSource(EShSource s) { source = s; } EShSource getSource() const { return source; } @@ -1070,6 +1079,7 @@ protected: int numPushConstants; bool recursive; bool invertY; + bool dxPositionW; bool useStorageBuffer; bool invariantAll; bool nanMinMaxClamp; // true if desiring min/max/clamp to favor non-NaN over NaN diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index d2a4bf40..9d3e9be1 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -485,6 +485,7 @@ public: GLSLANG_EXPORT void addUniformLocationOverride(const char* name, int loc); GLSLANG_EXPORT void setUniformLocationBase(int base); GLSLANG_EXPORT void setInvertY(bool invert); + GLSLANG_EXPORT void setDxPositionW(bool dxPosW); #ifdef ENABLE_HLSL GLSLANG_EXPORT void setHlslIoMapping(bool hlslIoMap); GLSLANG_EXPORT void setFlattenUniformArrays(bool flatten); From cbab732905af5161693fa12c46e16938a16e5fd8 Mon Sep 17 00:00:00 2001 From: Kevin McCullough Date: Wed, 13 Oct 2021 15:32:38 -0700 Subject: [PATCH 17/21] Fix issue with separable shader validation in iomapper --- .../iomap.blockOutVariableIn.2.vert.out | 413 ++++++++++++++++++ .../iomap.blockOutVariableIn.vert.out | 234 ++++++++++ .../iomap.variableOutBlockIn.2.vert.out | 276 ++++++++++++ .../iomap.variableOutBlockIn.vert.out | 236 ++++++++++ Test/iomap.blockOutVariableIn.2.vert | 14 + Test/iomap.blockOutVariableIn.frag | 11 + Test/iomap.blockOutVariableIn.geom | 28 ++ Test/iomap.blockOutVariableIn.vert | 14 + Test/iomap.variableOutBlockIn.2.vert | 11 + Test/iomap.variableOutBlockIn.frag | 13 + Test/iomap.variableOutBlockIn.geom | 19 + Test/iomap.variableOutBlockIn.vert | 11 + glslang/MachineIndependent/iomapper.cpp | 18 + glslang/MachineIndependent/linkValidate.cpp | 5 +- gtests/GlslMapIO.FromFile.cpp | 49 ++- 15 files changed, 1350 insertions(+), 2 deletions(-) create mode 100644 Test/baseResults/iomap.blockOutVariableIn.2.vert.out create mode 100644 Test/baseResults/iomap.blockOutVariableIn.vert.out create mode 100644 Test/baseResults/iomap.variableOutBlockIn.2.vert.out create mode 100644 Test/baseResults/iomap.variableOutBlockIn.vert.out create mode 100644 Test/iomap.blockOutVariableIn.2.vert create mode 100644 Test/iomap.blockOutVariableIn.frag create mode 100644 Test/iomap.blockOutVariableIn.geom create mode 100644 Test/iomap.blockOutVariableIn.vert create mode 100644 Test/iomap.variableOutBlockIn.2.vert create mode 100644 Test/iomap.variableOutBlockIn.frag create mode 100644 Test/iomap.variableOutBlockIn.geom create mode 100644 Test/iomap.variableOutBlockIn.vert diff --git a/Test/baseResults/iomap.blockOutVariableIn.2.vert.out b/Test/baseResults/iomap.blockOutVariableIn.2.vert.out new file mode 100644 index 00000000..0b4c0ac9 --- /dev/null +++ b/Test/baseResults/iomap.blockOutVariableIn.2.vert.out @@ -0,0 +1,413 @@ +iomap.blockOutVariableIn.2.vert +Shader version: 440 +0:? Sequence +0:9 Function Definition: main( ( global void) +0:9 Function Parameters: +0:11 Sequence +0:11 move second child to first child ( temp 4-component vector of float) +0:11 a1: direct index for structure ( out 4-component vector of float) +0:11 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:11 Constant: +0:11 0 (const uint) +0:11 Constant: +0:11 1.000000 +0:11 1.000000 +0:11 1.000000 +0:11 1.000000 +0:12 move second child to first child ( temp 2-component vector of float) +0:12 a2: direct index for structure ( out 2-component vector of float) +0:12 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:12 Constant: +0:12 1 (const uint) +0:12 Constant: +0:12 0.500000 +0:12 0.500000 +0:13 move second child to first child ( temp 4-component vector of float) +0:13 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:13 'anon@1' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:13 Constant: +0:13 0 (const uint) +0:13 Constant: +0:13 1.000000 +0:13 1.000000 +0:13 1.000000 +0:13 1.000000 +0:? Linker Objects +0:? 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:? 'anon@1' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + +iomap.blockOutVariableIn.geom +Shader version: 440 +invocations = -1 +max_vertices = 3 +input primitive = triangles +output primitive = triangle_strip +0:? Sequence +0:12 Function Definition: main( ( global void) +0:12 Function Parameters: +0:14 Sequence +0:14 move second child to first child ( temp 4-component vector of float) +0:14 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:14 direct index (layout( location=0) temp 4-component vector of float) +0:14 'in_a1' (layout( location=0) in 3-element array of 4-component vector of float) +0:14 Constant: +0:14 0 (const int) +0:15 move second child to first child ( temp 2-component vector of float) +0:15 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:15 direct index (layout( location=1) temp 2-component vector of float) +0:15 'in_a2' (layout( location=1) in 3-element array of 2-component vector of float) +0:15 Constant: +0:15 0 (const int) +0:16 move second child to first child ( temp 4-component vector of float) +0:16 gl_Position: direct index for structure (layout( stream=0) gl_Position 4-component vector of float Position) +0:16 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:16 Constant: +0:16 0 (const uint) +0:16 Constant: +0:16 1.000000 +0:16 1.000000 +0:16 1.000000 +0:16 1.000000 +0:17 EmitVertex ( global void) +0:19 move second child to first child ( temp 4-component vector of float) +0:19 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:19 direct index (layout( location=0) temp 4-component vector of float) +0:19 'in_a1' (layout( location=0) in 3-element array of 4-component vector of float) +0:19 Constant: +0:19 1 (const int) +0:20 move second child to first child ( temp 2-component vector of float) +0:20 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:20 direct index (layout( location=1) temp 2-component vector of float) +0:20 'in_a2' (layout( location=1) in 3-element array of 2-component vector of float) +0:20 Constant: +0:20 1 (const int) +0:21 move second child to first child ( temp 4-component vector of float) +0:21 gl_Position: direct index for structure (layout( stream=0) gl_Position 4-component vector of float Position) +0:21 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:21 Constant: +0:21 0 (const uint) +0:21 Constant: +0:21 1.000000 +0:21 1.000000 +0:21 1.000000 +0:21 1.000000 +0:22 EmitVertex ( global void) +0:24 move second child to first child ( temp 4-component vector of float) +0:24 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:24 direct index (layout( location=0) temp 4-component vector of float) +0:24 'in_a1' (layout( location=0) in 3-element array of 4-component vector of float) +0:24 Constant: +0:24 2 (const int) +0:25 move second child to first child ( temp 2-component vector of float) +0:25 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:25 direct index (layout( location=1) temp 2-component vector of float) +0:25 'in_a2' (layout( location=1) in 3-element array of 2-component vector of float) +0:25 Constant: +0:25 2 (const int) +0:26 move second child to first child ( temp 4-component vector of float) +0:26 gl_Position: direct index for structure (layout( stream=0) gl_Position 4-component vector of float Position) +0:26 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:26 Constant: +0:26 0 (const uint) +0:26 Constant: +0:26 1.000000 +0:26 1.000000 +0:26 1.000000 +0:26 1.000000 +0:27 EmitVertex ( global void) +0:? Linker Objects +0:? 'in_a1' (layout( location=0) in 3-element array of 4-component vector of float) +0:? 'in_a2' (layout( location=1) in 3-element array of 2-component vector of float) +0:? 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:? 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:? 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out unsized 1-element array of float ClipDistance gl_ClipDistance}) + + +Linked vertex stage: + + +Linked geometry stage: + + +Shader version: 440 +0:? Sequence +0:9 Function Definition: main( ( global void) +0:9 Function Parameters: +0:11 Sequence +0:11 move second child to first child ( temp 4-component vector of float) +0:11 a1: direct index for structure ( out 4-component vector of float) +0:11 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:11 Constant: +0:11 0 (const uint) +0:11 Constant: +0:11 1.000000 +0:11 1.000000 +0:11 1.000000 +0:11 1.000000 +0:12 move second child to first child ( temp 2-component vector of float) +0:12 a2: direct index for structure ( out 2-component vector of float) +0:12 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:12 Constant: +0:12 1 (const uint) +0:12 Constant: +0:12 0.500000 +0:12 0.500000 +0:13 move second child to first child ( temp 4-component vector of float) +0:13 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:13 'anon@1' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:13 Constant: +0:13 0 (const uint) +0:13 Constant: +0:13 1.000000 +0:13 1.000000 +0:13 1.000000 +0:13 1.000000 +0:? Linker Objects +0:? 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:? 'anon@1' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) +Shader version: 440 +invocations = 1 +max_vertices = 3 +input primitive = triangles +output primitive = triangle_strip +0:? Sequence +0:12 Function Definition: main( ( global void) +0:12 Function Parameters: +0:14 Sequence +0:14 move second child to first child ( temp 4-component vector of float) +0:14 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:14 direct index (layout( location=0) temp 4-component vector of float) +0:14 'in_a1' (layout( location=0) in 3-element array of 4-component vector of float) +0:14 Constant: +0:14 0 (const int) +0:15 move second child to first child ( temp 2-component vector of float) +0:15 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:15 direct index (layout( location=1) temp 2-component vector of float) +0:15 'in_a2' (layout( location=1) in 3-element array of 2-component vector of float) +0:15 Constant: +0:15 0 (const int) +0:16 move second child to first child ( temp 4-component vector of float) +0:16 gl_Position: direct index for structure (layout( stream=0) gl_Position 4-component vector of float Position) +0:16 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out 1-element array of float ClipDistance gl_ClipDistance}) +0:16 Constant: +0:16 0 (const uint) +0:16 Constant: +0:16 1.000000 +0:16 1.000000 +0:16 1.000000 +0:16 1.000000 +0:17 EmitVertex ( global void) +0:19 move second child to first child ( temp 4-component vector of float) +0:19 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:19 direct index (layout( location=0) temp 4-component vector of float) +0:19 'in_a1' (layout( location=0) in 3-element array of 4-component vector of float) +0:19 Constant: +0:19 1 (const int) +0:20 move second child to first child ( temp 2-component vector of float) +0:20 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:20 direct index (layout( location=1) temp 2-component vector of float) +0:20 'in_a2' (layout( location=1) in 3-element array of 2-component vector of float) +0:20 Constant: +0:20 1 (const int) +0:21 move second child to first child ( temp 4-component vector of float) +0:21 gl_Position: direct index for structure (layout( stream=0) gl_Position 4-component vector of float Position) +0:21 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out 1-element array of float ClipDistance gl_ClipDistance}) +0:21 Constant: +0:21 0 (const uint) +0:21 Constant: +0:21 1.000000 +0:21 1.000000 +0:21 1.000000 +0:21 1.000000 +0:22 EmitVertex ( global void) +0:24 move second child to first child ( temp 4-component vector of float) +0:24 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:24 direct index (layout( location=0) temp 4-component vector of float) +0:24 'in_a1' (layout( location=0) in 3-element array of 4-component vector of float) +0:24 Constant: +0:24 2 (const int) +0:25 move second child to first child ( temp 2-component vector of float) +0:25 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:25 direct index (layout( location=1) temp 2-component vector of float) +0:25 'in_a2' (layout( location=1) in 3-element array of 2-component vector of float) +0:25 Constant: +0:25 2 (const int) +0:26 move second child to first child ( temp 4-component vector of float) +0:26 gl_Position: direct index for structure (layout( stream=0) gl_Position 4-component vector of float Position) +0:26 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out 1-element array of float ClipDistance gl_ClipDistance}) +0:26 Constant: +0:26 0 (const uint) +0:26 Constant: +0:26 1.000000 +0:26 1.000000 +0:26 1.000000 +0:26 1.000000 +0:27 EmitVertex ( global void) +0:? Linker Objects +0:? 'in_a1' (layout( location=0) in 3-element array of 4-component vector of float) +0:? 'in_a2' (layout( location=1) in 3-element array of 2-component vector of float) +0:? 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:? 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:? 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out 1-element array of float ClipDistance gl_ClipDistance}) + +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 33 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" 11 28 31 32 + Source GLSL 440 + Name 4 "main" + Name 9 "Block" + MemberName 9(Block) 0 "a1" + MemberName 9(Block) 1 "a2" + Name 11 "" + Name 26 "gl_PerVertex" + MemberName 26(gl_PerVertex) 0 "gl_Position" + MemberName 26(gl_PerVertex) 1 "gl_PointSize" + MemberName 26(gl_PerVertex) 2 "gl_ClipDistance" + Name 28 "" + Name 31 "gl_VertexID" + Name 32 "gl_InstanceID" + Decorate 9(Block) Block + Decorate 11 Location 0 + MemberDecorate 26(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 26(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 26(gl_PerVertex) 2 BuiltIn ClipDistance + Decorate 26(gl_PerVertex) Block + Decorate 31(gl_VertexID) BuiltIn VertexId + Decorate 32(gl_InstanceID) BuiltIn InstanceId + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypeVector 6(float) 2 + 9(Block): TypeStruct 7(fvec4) 8(fvec2) + 10: TypePointer Output 9(Block) + 11: 10(ptr) Variable Output + 12: TypeInt 32 1 + 13: 12(int) Constant 0 + 14: 6(float) Constant 1065353216 + 15: 7(fvec4) ConstantComposite 14 14 14 14 + 16: TypePointer Output 7(fvec4) + 18: 12(int) Constant 1 + 19: 6(float) Constant 1056964608 + 20: 8(fvec2) ConstantComposite 19 19 + 21: TypePointer Output 8(fvec2) + 23: TypeInt 32 0 + 24: 23(int) Constant 1 + 25: TypeArray 6(float) 24 +26(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 25 + 27: TypePointer Output 26(gl_PerVertex) + 28: 27(ptr) Variable Output + 30: TypePointer Input 12(int) + 31(gl_VertexID): 30(ptr) Variable Input +32(gl_InstanceID): 30(ptr) Variable Input + 4(main): 2 Function None 3 + 5: Label + 17: 16(ptr) AccessChain 11 13 + Store 17 15 + 22: 21(ptr) AccessChain 11 18 + Store 22 20 + 29: 16(ptr) AccessChain 28 13 + Store 29 15 + Return + FunctionEnd +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 49 + + Capability Geometry + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Geometry 4 "main" 9 14 22 25 33 + ExecutionMode 4 Triangles + ExecutionMode 4 Invocations 1 + ExecutionMode 4 OutputTriangleStrip + ExecutionMode 4 OutputVertices 3 + Source GLSL 440 + Name 4 "main" + Name 9 "a1" + Name 14 "in_a1" + Name 22 "a2" + Name 25 "in_a2" + Name 31 "gl_PerVertex" + MemberName 31(gl_PerVertex) 0 "gl_Position" + MemberName 31(gl_PerVertex) 1 "gl_PointSize" + MemberName 31(gl_PerVertex) 2 "gl_ClipDistance" + Name 33 "" + Decorate 9(a1) Location 0 + Decorate 14(in_a1) Location 0 + Decorate 22(a2) Location 1 + Decorate 25(in_a2) Location 1 + MemberDecorate 31(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 31(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 31(gl_PerVertex) 2 BuiltIn ClipDistance + Decorate 31(gl_PerVertex) Block + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypePointer Output 7(fvec4) + 9(a1): 8(ptr) Variable Output + 10: TypeInt 32 0 + 11: 10(int) Constant 3 + 12: TypeArray 7(fvec4) 11 + 13: TypePointer Input 12 + 14(in_a1): 13(ptr) Variable Input + 15: TypeInt 32 1 + 16: 15(int) Constant 0 + 17: TypePointer Input 7(fvec4) + 20: TypeVector 6(float) 2 + 21: TypePointer Output 20(fvec2) + 22(a2): 21(ptr) Variable Output + 23: TypeArray 20(fvec2) 11 + 24: TypePointer Input 23 + 25(in_a2): 24(ptr) Variable Input + 26: TypePointer Input 20(fvec2) + 29: 10(int) Constant 1 + 30: TypeArray 6(float) 29 +31(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 30 + 32: TypePointer Output 31(gl_PerVertex) + 33: 32(ptr) Variable Output + 34: 6(float) Constant 1065353216 + 35: 7(fvec4) ConstantComposite 34 34 34 34 + 37: 15(int) Constant 1 + 43: 15(int) Constant 2 + 4(main): 2 Function None 3 + 5: Label + 18: 17(ptr) AccessChain 14(in_a1) 16 + 19: 7(fvec4) Load 18 + Store 9(a1) 19 + 27: 26(ptr) AccessChain 25(in_a2) 16 + 28: 20(fvec2) Load 27 + Store 22(a2) 28 + 36: 8(ptr) AccessChain 33 16 + Store 36 35 + EmitVertex + 38: 17(ptr) AccessChain 14(in_a1) 37 + 39: 7(fvec4) Load 38 + Store 9(a1) 39 + 40: 26(ptr) AccessChain 25(in_a2) 37 + 41: 20(fvec2) Load 40 + Store 22(a2) 41 + 42: 8(ptr) AccessChain 33 16 + Store 42 35 + EmitVertex + 44: 17(ptr) AccessChain 14(in_a1) 43 + 45: 7(fvec4) Load 44 + Store 9(a1) 45 + 46: 26(ptr) AccessChain 25(in_a2) 43 + 47: 20(fvec2) Load 46 + Store 22(a2) 47 + 48: 8(ptr) AccessChain 33 16 + Store 48 35 + EmitVertex + Return + FunctionEnd diff --git a/Test/baseResults/iomap.blockOutVariableIn.vert.out b/Test/baseResults/iomap.blockOutVariableIn.vert.out new file mode 100644 index 00000000..dd12cbc2 --- /dev/null +++ b/Test/baseResults/iomap.blockOutVariableIn.vert.out @@ -0,0 +1,234 @@ +iomap.blockOutVariableIn.vert +Shader version: 440 +0:? Sequence +0:9 Function Definition: main( ( global void) +0:9 Function Parameters: +0:11 Sequence +0:11 move second child to first child ( temp 4-component vector of float) +0:11 a1: direct index for structure ( out 4-component vector of float) +0:11 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:11 Constant: +0:11 0 (const uint) +0:11 Constant: +0:11 1.000000 +0:11 1.000000 +0:11 1.000000 +0:11 1.000000 +0:12 move second child to first child ( temp 2-component vector of float) +0:12 a2: direct index for structure ( out 2-component vector of float) +0:12 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:12 Constant: +0:12 1 (const uint) +0:12 Constant: +0:12 0.500000 +0:12 0.500000 +0:13 move second child to first child ( temp 4-component vector of float) +0:13 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:13 'anon@1' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:13 Constant: +0:13 0 (const uint) +0:13 Constant: +0:13 1.000000 +0:13 1.000000 +0:13 1.000000 +0:13 1.000000 +0:? Linker Objects +0:? 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:? 'anon@1' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + +iomap.blockOutVariableIn.frag +Shader version: 440 +0:? Sequence +0:8 Function Definition: main( ( global void) +0:8 Function Parameters: +0:10 Sequence +0:10 move second child to first child ( temp 4-component vector of float) +0:10 'color' (layout( location=0) out 4-component vector of float) +0:10 Construct vec4 ( temp 4-component vector of float) +0:10 vector swizzle ( temp 2-component vector of float) +0:10 'a1' (layout( location=0) smooth in 4-component vector of float) +0:10 Sequence +0:10 Constant: +0:10 0 (const int) +0:10 Constant: +0:10 1 (const int) +0:10 'a2' (layout( location=1) smooth in 2-component vector of float) +0:? Linker Objects +0:? 'a1' (layout( location=0) smooth in 4-component vector of float) +0:? 'a2' (layout( location=1) smooth in 2-component vector of float) +0:? 'color' (layout( location=0) out 4-component vector of float) + + +Linked vertex stage: + + +Linked fragment stage: + + +Shader version: 440 +0:? Sequence +0:9 Function Definition: main( ( global void) +0:9 Function Parameters: +0:11 Sequence +0:11 move second child to first child ( temp 4-component vector of float) +0:11 a1: direct index for structure ( out 4-component vector of float) +0:11 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:11 Constant: +0:11 0 (const uint) +0:11 Constant: +0:11 1.000000 +0:11 1.000000 +0:11 1.000000 +0:11 1.000000 +0:12 move second child to first child ( temp 2-component vector of float) +0:12 a2: direct index for structure ( out 2-component vector of float) +0:12 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:12 Constant: +0:12 1 (const uint) +0:12 Constant: +0:12 0.500000 +0:12 0.500000 +0:13 move second child to first child ( temp 4-component vector of float) +0:13 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:13 'anon@1' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:13 Constant: +0:13 0 (const uint) +0:13 Constant: +0:13 1.000000 +0:13 1.000000 +0:13 1.000000 +0:13 1.000000 +0:? Linker Objects +0:? 'anon@0' (layout( location=0) out block{ out 4-component vector of float a1, out 2-component vector of float a2}) +0:? 'anon@1' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) +Shader version: 440 +0:? Sequence +0:8 Function Definition: main( ( global void) +0:8 Function Parameters: +0:10 Sequence +0:10 move second child to first child ( temp 4-component vector of float) +0:10 'color' (layout( location=0) out 4-component vector of float) +0:10 Construct vec4 ( temp 4-component vector of float) +0:10 vector swizzle ( temp 2-component vector of float) +0:10 'a1' (layout( location=0) smooth in 4-component vector of float) +0:10 Sequence +0:10 Constant: +0:10 0 (const int) +0:10 Constant: +0:10 1 (const int) +0:10 'a2' (layout( location=1) smooth in 2-component vector of float) +0:? Linker Objects +0:? 'a1' (layout( location=0) smooth in 4-component vector of float) +0:? 'a2' (layout( location=1) smooth in 2-component vector of float) +0:? 'color' (layout( location=0) out 4-component vector of float) + +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 33 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" 11 28 31 32 + Source GLSL 440 + Name 4 "main" + Name 9 "Block" + MemberName 9(Block) 0 "a1" + MemberName 9(Block) 1 "a2" + Name 11 "" + Name 26 "gl_PerVertex" + MemberName 26(gl_PerVertex) 0 "gl_Position" + MemberName 26(gl_PerVertex) 1 "gl_PointSize" + MemberName 26(gl_PerVertex) 2 "gl_ClipDistance" + Name 28 "" + Name 31 "gl_VertexID" + Name 32 "gl_InstanceID" + Decorate 9(Block) Block + Decorate 11 Location 0 + MemberDecorate 26(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 26(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 26(gl_PerVertex) 2 BuiltIn ClipDistance + Decorate 26(gl_PerVertex) Block + Decorate 31(gl_VertexID) BuiltIn VertexId + Decorate 32(gl_InstanceID) BuiltIn InstanceId + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypeVector 6(float) 2 + 9(Block): TypeStruct 7(fvec4) 8(fvec2) + 10: TypePointer Output 9(Block) + 11: 10(ptr) Variable Output + 12: TypeInt 32 1 + 13: 12(int) Constant 0 + 14: 6(float) Constant 1065353216 + 15: 7(fvec4) ConstantComposite 14 14 14 14 + 16: TypePointer Output 7(fvec4) + 18: 12(int) Constant 1 + 19: 6(float) Constant 1056964608 + 20: 8(fvec2) ConstantComposite 19 19 + 21: TypePointer Output 8(fvec2) + 23: TypeInt 32 0 + 24: 23(int) Constant 1 + 25: TypeArray 6(float) 24 +26(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 25 + 27: TypePointer Output 26(gl_PerVertex) + 28: 27(ptr) Variable Output + 30: TypePointer Input 12(int) + 31(gl_VertexID): 30(ptr) Variable Input +32(gl_InstanceID): 30(ptr) Variable Input + 4(main): 2 Function None 3 + 5: Label + 17: 16(ptr) AccessChain 11 13 + Store 17 15 + 22: 21(ptr) AccessChain 11 18 + Store 22 20 + 29: 16(ptr) AccessChain 28 13 + Store 29 15 + Return + FunctionEnd +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 23 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Fragment 4 "main" 9 11 16 + ExecutionMode 4 OriginLowerLeft + Source GLSL 440 + Name 4 "main" + Name 9 "color" + Name 11 "a1" + Name 16 "a2" + Decorate 9(color) Location 0 + Decorate 11(a1) Location 0 + Decorate 16(a2) Location 1 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypePointer Output 7(fvec4) + 9(color): 8(ptr) Variable Output + 10: TypePointer Input 7(fvec4) + 11(a1): 10(ptr) Variable Input + 12: TypeVector 6(float) 2 + 15: TypePointer Input 12(fvec2) + 16(a2): 15(ptr) Variable Input + 4(main): 2 Function None 3 + 5: Label + 13: 7(fvec4) Load 11(a1) + 14: 12(fvec2) VectorShuffle 13 13 0 1 + 17: 12(fvec2) Load 16(a2) + 18: 6(float) CompositeExtract 14 0 + 19: 6(float) CompositeExtract 14 1 + 20: 6(float) CompositeExtract 17 0 + 21: 6(float) CompositeExtract 17 1 + 22: 7(fvec4) CompositeConstruct 18 19 20 21 + Store 9(color) 22 + Return + FunctionEnd diff --git a/Test/baseResults/iomap.variableOutBlockIn.2.vert.out b/Test/baseResults/iomap.variableOutBlockIn.2.vert.out new file mode 100644 index 00000000..6ef7d4e3 --- /dev/null +++ b/Test/baseResults/iomap.variableOutBlockIn.2.vert.out @@ -0,0 +1,276 @@ +iomap.variableOutBlockIn.2.vert +Shader version: 440 +0:? Sequence +0:6 Function Definition: main( ( global void) +0:6 Function Parameters: +0:8 Sequence +0:8 move second child to first child ( temp 4-component vector of float) +0:8 'a1' (layout( location=0) smooth out 4-component vector of float) +0:8 Constant: +0:8 1.000000 +0:8 1.000000 +0:8 1.000000 +0:8 1.000000 +0:9 move second child to first child ( temp 2-component vector of float) +0:9 'a2' (layout( location=1) smooth out 2-component vector of float) +0:9 Constant: +0:9 0.500000 +0:9 0.500000 +0:10 move second child to first child ( temp 4-component vector of float) +0:10 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:10 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:10 Constant: +0:10 0 (const uint) +0:10 Constant: +0:10 1.000000 +0:10 1.000000 +0:10 1.000000 +0:10 1.000000 +0:? Linker Objects +0:? 'a1' (layout( location=0) smooth out 4-component vector of float) +0:? 'a2' (layout( location=1) smooth out 2-component vector of float) +0:? 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + +iomap.variableOutBlockIn.geom +Shader version: 440 +invocations = -1 +max_vertices = 3 +input primitive = triangles +output primitive = triangle_strip +0:? Sequence +0:14 Function Definition: main( ( global void) +0:14 Function Parameters: +0:16 Sequence +0:16 move second child to first child ( temp 4-component vector of float) +0:16 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:16 Constant: +0:16 1.000000 +0:16 1.000000 +0:16 1.000000 +0:16 1.000000 +0:17 move second child to first child ( temp 2-component vector of float) +0:17 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:17 Constant: +0:17 0.500000 +0:17 0.500000 +0:18 move second child to first child ( temp 4-component vector of float) +0:18 gl_Position: direct index for structure (layout( stream=0) gl_Position 4-component vector of float Position) +0:18 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:18 Constant: +0:18 0 (const uint) +0:18 Constant: +0:18 1.000000 +0:18 1.000000 +0:18 1.000000 +0:18 1.000000 +0:? Linker Objects +0:? 'gin' (layout( location=0) in 3-element array of block{ in 4-component vector of float a1, in 2-component vector of float a2}) +0:? 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:? 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:? 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out unsized 1-element array of float ClipDistance gl_ClipDistance}) + + +Linked vertex stage: + + +Linked geometry stage: + + +Shader version: 440 +0:? Sequence +0:6 Function Definition: main( ( global void) +0:6 Function Parameters: +0:8 Sequence +0:8 move second child to first child ( temp 4-component vector of float) +0:8 'a1' (layout( location=0) smooth out 4-component vector of float) +0:8 Constant: +0:8 1.000000 +0:8 1.000000 +0:8 1.000000 +0:8 1.000000 +0:9 move second child to first child ( temp 2-component vector of float) +0:9 'a2' (layout( location=1) smooth out 2-component vector of float) +0:9 Constant: +0:9 0.500000 +0:9 0.500000 +0:10 move second child to first child ( temp 4-component vector of float) +0:10 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:10 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:10 Constant: +0:10 0 (const uint) +0:10 Constant: +0:10 1.000000 +0:10 1.000000 +0:10 1.000000 +0:10 1.000000 +0:? Linker Objects +0:? 'a1' (layout( location=0) smooth out 4-component vector of float) +0:? 'a2' (layout( location=1) smooth out 2-component vector of float) +0:? 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) +Shader version: 440 +invocations = 1 +max_vertices = 3 +input primitive = triangles +output primitive = triangle_strip +0:? Sequence +0:14 Function Definition: main( ( global void) +0:14 Function Parameters: +0:16 Sequence +0:16 move second child to first child ( temp 4-component vector of float) +0:16 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:16 Constant: +0:16 1.000000 +0:16 1.000000 +0:16 1.000000 +0:16 1.000000 +0:17 move second child to first child ( temp 2-component vector of float) +0:17 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:17 Constant: +0:17 0.500000 +0:17 0.500000 +0:18 move second child to first child ( temp 4-component vector of float) +0:18 gl_Position: direct index for structure (layout( stream=0) gl_Position 4-component vector of float Position) +0:18 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out 1-element array of float ClipDistance gl_ClipDistance}) +0:18 Constant: +0:18 0 (const uint) +0:18 Constant: +0:18 1.000000 +0:18 1.000000 +0:18 1.000000 +0:18 1.000000 +0:? Linker Objects +0:? 'gin' (layout( location=0) in 3-element array of block{ in 4-component vector of float a1, in 2-component vector of float a2}) +0:? 'a1' (layout( location=0 stream=0) out 4-component vector of float) +0:? 'a2' (layout( location=1 stream=0) out 2-component vector of float) +0:? 'anon@0' (layout( stream=0) out block{layout( stream=0) gl_Position 4-component vector of float Position gl_Position, layout( stream=0) gl_PointSize float PointSize gl_PointSize, layout( stream=0) out 1-element array of float ClipDistance gl_ClipDistance}) + +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 29 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" 9 14 22 27 28 + Source GLSL 440 + Name 4 "main" + Name 9 "a1" + Name 14 "a2" + Name 20 "gl_PerVertex" + MemberName 20(gl_PerVertex) 0 "gl_Position" + MemberName 20(gl_PerVertex) 1 "gl_PointSize" + MemberName 20(gl_PerVertex) 2 "gl_ClipDistance" + Name 22 "" + Name 27 "gl_VertexID" + Name 28 "gl_InstanceID" + Decorate 9(a1) Location 0 + Decorate 14(a2) Location 1 + MemberDecorate 20(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 20(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 20(gl_PerVertex) 2 BuiltIn ClipDistance + Decorate 20(gl_PerVertex) Block + Decorate 27(gl_VertexID) BuiltIn VertexId + Decorate 28(gl_InstanceID) BuiltIn InstanceId + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypePointer Output 7(fvec4) + 9(a1): 8(ptr) Variable Output + 10: 6(float) Constant 1065353216 + 11: 7(fvec4) ConstantComposite 10 10 10 10 + 12: TypeVector 6(float) 2 + 13: TypePointer Output 12(fvec2) + 14(a2): 13(ptr) Variable Output + 15: 6(float) Constant 1056964608 + 16: 12(fvec2) ConstantComposite 15 15 + 17: TypeInt 32 0 + 18: 17(int) Constant 1 + 19: TypeArray 6(float) 18 +20(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 19 + 21: TypePointer Output 20(gl_PerVertex) + 22: 21(ptr) Variable Output + 23: TypeInt 32 1 + 24: 23(int) Constant 0 + 26: TypePointer Input 23(int) + 27(gl_VertexID): 26(ptr) Variable Input +28(gl_InstanceID): 26(ptr) Variable Input + 4(main): 2 Function None 3 + 5: Label + Store 9(a1) 11 + Store 14(a2) 16 + 25: 8(ptr) AccessChain 22 24 + Store 25 11 + Return + FunctionEnd +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 31 + + Capability Geometry + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Geometry 4 "main" 9 14 22 30 + ExecutionMode 4 Triangles + ExecutionMode 4 Invocations 1 + ExecutionMode 4 OutputTriangleStrip + ExecutionMode 4 OutputVertices 3 + Source GLSL 440 + Name 4 "main" + Name 9 "a1" + Name 14 "a2" + Name 20 "gl_PerVertex" + MemberName 20(gl_PerVertex) 0 "gl_Position" + MemberName 20(gl_PerVertex) 1 "gl_PointSize" + MemberName 20(gl_PerVertex) 2 "gl_ClipDistance" + Name 22 "" + Name 26 "Inputs" + MemberName 26(Inputs) 0 "a1" + MemberName 26(Inputs) 1 "a2" + Name 30 "gin" + Decorate 9(a1) Location 0 + Decorate 14(a2) Location 1 + MemberDecorate 20(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 20(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 20(gl_PerVertex) 2 BuiltIn ClipDistance + Decorate 20(gl_PerVertex) Block + Decorate 26(Inputs) Block + Decorate 30(gin) Location 0 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypePointer Output 7(fvec4) + 9(a1): 8(ptr) Variable Output + 10: 6(float) Constant 1065353216 + 11: 7(fvec4) ConstantComposite 10 10 10 10 + 12: TypeVector 6(float) 2 + 13: TypePointer Output 12(fvec2) + 14(a2): 13(ptr) Variable Output + 15: 6(float) Constant 1056964608 + 16: 12(fvec2) ConstantComposite 15 15 + 17: TypeInt 32 0 + 18: 17(int) Constant 1 + 19: TypeArray 6(float) 18 +20(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 19 + 21: TypePointer Output 20(gl_PerVertex) + 22: 21(ptr) Variable Output + 23: TypeInt 32 1 + 24: 23(int) Constant 0 + 26(Inputs): TypeStruct 7(fvec4) 12(fvec2) + 27: 17(int) Constant 3 + 28: TypeArray 26(Inputs) 27 + 29: TypePointer Input 28 + 30(gin): 29(ptr) Variable Input + 4(main): 2 Function None 3 + 5: Label + Store 9(a1) 11 + Store 14(a2) 16 + 25: 8(ptr) AccessChain 22 24 + Store 25 11 + Return + FunctionEnd diff --git a/Test/baseResults/iomap.variableOutBlockIn.vert.out b/Test/baseResults/iomap.variableOutBlockIn.vert.out new file mode 100644 index 00000000..8fef640d --- /dev/null +++ b/Test/baseResults/iomap.variableOutBlockIn.vert.out @@ -0,0 +1,236 @@ +iomap.variableOutBlockIn.vert +Shader version: 440 +0:? Sequence +0:6 Function Definition: main( ( global void) +0:6 Function Parameters: +0:8 Sequence +0:8 move second child to first child ( temp 4-component vector of float) +0:8 'a1' (layout( location=0) smooth out 4-component vector of float) +0:8 Constant: +0:8 1.000000 +0:8 1.000000 +0:8 1.000000 +0:8 1.000000 +0:9 move second child to first child ( temp 2-component vector of float) +0:9 'a2' (layout( location=1) smooth out 2-component vector of float) +0:9 Constant: +0:9 0.500000 +0:9 0.500000 +0:10 move second child to first child ( temp 4-component vector of float) +0:10 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:10 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:10 Constant: +0:10 0 (const uint) +0:10 Constant: +0:10 1.000000 +0:10 1.000000 +0:10 1.000000 +0:10 1.000000 +0:? Linker Objects +0:? 'a1' (layout( location=0) smooth out 4-component vector of float) +0:? 'a2' (layout( location=1) smooth out 2-component vector of float) +0:? 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + +iomap.variableOutBlockIn.frag +Shader version: 440 +0:? Sequence +0:10 Function Definition: main( ( global void) +0:10 Function Parameters: +0:12 Sequence +0:12 move second child to first child ( temp 4-component vector of float) +0:12 'color' (layout( location=0) out 4-component vector of float) +0:12 Construct vec4 ( temp 4-component vector of float) +0:12 vector swizzle ( temp 2-component vector of float) +0:12 a1: direct index for structure ( in 4-component vector of float) +0:12 'anon@0' (layout( location=0) in block{ in 4-component vector of float a1, in 2-component vector of float a2}) +0:12 Constant: +0:12 0 (const uint) +0:12 Sequence +0:12 Constant: +0:12 0 (const int) +0:12 Constant: +0:12 1 (const int) +0:12 a2: direct index for structure ( in 2-component vector of float) +0:12 'anon@0' (layout( location=0) in block{ in 4-component vector of float a1, in 2-component vector of float a2}) +0:12 Constant: +0:12 1 (const uint) +0:? Linker Objects +0:? 'anon@0' (layout( location=0) in block{ in 4-component vector of float a1, in 2-component vector of float a2}) +0:? 'color' (layout( location=0) out 4-component vector of float) + + +Linked vertex stage: + + +Linked fragment stage: + + +Shader version: 440 +0:? Sequence +0:6 Function Definition: main( ( global void) +0:6 Function Parameters: +0:8 Sequence +0:8 move second child to first child ( temp 4-component vector of float) +0:8 'a1' (layout( location=0) smooth out 4-component vector of float) +0:8 Constant: +0:8 1.000000 +0:8 1.000000 +0:8 1.000000 +0:8 1.000000 +0:9 move second child to first child ( temp 2-component vector of float) +0:9 'a2' (layout( location=1) smooth out 2-component vector of float) +0:9 Constant: +0:9 0.500000 +0:9 0.500000 +0:10 move second child to first child ( temp 4-component vector of float) +0:10 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:10 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:10 Constant: +0:10 0 (const uint) +0:10 Constant: +0:10 1.000000 +0:10 1.000000 +0:10 1.000000 +0:10 1.000000 +0:? Linker Objects +0:? 'a1' (layout( location=0) smooth out 4-component vector of float) +0:? 'a2' (layout( location=1) smooth out 2-component vector of float) +0:? 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) +Shader version: 440 +0:? Sequence +0:10 Function Definition: main( ( global void) +0:10 Function Parameters: +0:12 Sequence +0:12 move second child to first child ( temp 4-component vector of float) +0:12 'color' (layout( location=0) out 4-component vector of float) +0:12 Construct vec4 ( temp 4-component vector of float) +0:12 vector swizzle ( temp 2-component vector of float) +0:12 a1: direct index for structure ( in 4-component vector of float) +0:12 'anon@0' (layout( location=0) in block{ in 4-component vector of float a1, in 2-component vector of float a2}) +0:12 Constant: +0:12 0 (const uint) +0:12 Sequence +0:12 Constant: +0:12 0 (const int) +0:12 Constant: +0:12 1 (const int) +0:12 a2: direct index for structure ( in 2-component vector of float) +0:12 'anon@0' (layout( location=0) in block{ in 4-component vector of float a1, in 2-component vector of float a2}) +0:12 Constant: +0:12 1 (const uint) +0:? Linker Objects +0:? 'anon@0' (layout( location=0) in block{ in 4-component vector of float a1, in 2-component vector of float a2}) +0:? 'color' (layout( location=0) out 4-component vector of float) + +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 29 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" 9 14 22 27 28 + Source GLSL 440 + Name 4 "main" + Name 9 "a1" + Name 14 "a2" + Name 20 "gl_PerVertex" + MemberName 20(gl_PerVertex) 0 "gl_Position" + MemberName 20(gl_PerVertex) 1 "gl_PointSize" + MemberName 20(gl_PerVertex) 2 "gl_ClipDistance" + Name 22 "" + Name 27 "gl_VertexID" + Name 28 "gl_InstanceID" + Decorate 9(a1) Location 0 + Decorate 14(a2) Location 1 + MemberDecorate 20(gl_PerVertex) 0 BuiltIn Position + MemberDecorate 20(gl_PerVertex) 1 BuiltIn PointSize + MemberDecorate 20(gl_PerVertex) 2 BuiltIn ClipDistance + Decorate 20(gl_PerVertex) Block + Decorate 27(gl_VertexID) BuiltIn VertexId + Decorate 28(gl_InstanceID) BuiltIn InstanceId + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypePointer Output 7(fvec4) + 9(a1): 8(ptr) Variable Output + 10: 6(float) Constant 1065353216 + 11: 7(fvec4) ConstantComposite 10 10 10 10 + 12: TypeVector 6(float) 2 + 13: TypePointer Output 12(fvec2) + 14(a2): 13(ptr) Variable Output + 15: 6(float) Constant 1056964608 + 16: 12(fvec2) ConstantComposite 15 15 + 17: TypeInt 32 0 + 18: 17(int) Constant 1 + 19: TypeArray 6(float) 18 +20(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 19 + 21: TypePointer Output 20(gl_PerVertex) + 22: 21(ptr) Variable Output + 23: TypeInt 32 1 + 24: 23(int) Constant 0 + 26: TypePointer Input 23(int) + 27(gl_VertexID): 26(ptr) Variable Input +28(gl_InstanceID): 26(ptr) Variable Input + 4(main): 2 Function None 3 + 5: Label + Store 9(a1) 11 + Store 14(a2) 16 + 25: 8(ptr) AccessChain 22 24 + Store 25 11 + Return + FunctionEnd +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 29 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Fragment 4 "main" 9 13 + ExecutionMode 4 OriginLowerLeft + Source GLSL 440 + Name 4 "main" + Name 9 "color" + Name 11 "Inputs" + MemberName 11(Inputs) 0 "a1" + MemberName 11(Inputs) 1 "a2" + Name 13 "" + Decorate 9(color) Location 0 + Decorate 11(Inputs) Block + Decorate 13 Location 0 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypePointer Output 7(fvec4) + 9(color): 8(ptr) Variable Output + 10: TypeVector 6(float) 2 + 11(Inputs): TypeStruct 7(fvec4) 10(fvec2) + 12: TypePointer Input 11(Inputs) + 13: 12(ptr) Variable Input + 14: TypeInt 32 1 + 15: 14(int) Constant 0 + 16: TypePointer Input 7(fvec4) + 20: 14(int) Constant 1 + 21: TypePointer Input 10(fvec2) + 4(main): 2 Function None 3 + 5: Label + 17: 16(ptr) AccessChain 13 15 + 18: 7(fvec4) Load 17 + 19: 10(fvec2) VectorShuffle 18 18 0 1 + 22: 21(ptr) AccessChain 13 20 + 23: 10(fvec2) Load 22 + 24: 6(float) CompositeExtract 19 0 + 25: 6(float) CompositeExtract 19 1 + 26: 6(float) CompositeExtract 23 0 + 27: 6(float) CompositeExtract 23 1 + 28: 7(fvec4) CompositeConstruct 24 25 26 27 + Store 9(color) 28 + Return + FunctionEnd diff --git a/Test/iomap.blockOutVariableIn.2.vert b/Test/iomap.blockOutVariableIn.2.vert new file mode 100644 index 00000000..67f45c97 --- /dev/null +++ b/Test/iomap.blockOutVariableIn.2.vert @@ -0,0 +1,14 @@ +#version 440 + +layout(location = 0) out Block +{ + vec4 a1; + vec2 a2; +}; + +void main() +{ + a1 = vec4(1.0); + a2 = vec2(0.5); + gl_Position = vec4(1.0); +} diff --git a/Test/iomap.blockOutVariableIn.frag b/Test/iomap.blockOutVariableIn.frag new file mode 100644 index 00000000..f2cb26e7 --- /dev/null +++ b/Test/iomap.blockOutVariableIn.frag @@ -0,0 +1,11 @@ +#version 440 + +layout(location = 0) in vec4 a1; +layout(location = 1) in vec2 a2; + +layout(location = 0) out vec4 color; + +void main() +{ + color = vec4(a1.xy, a2); +} diff --git a/Test/iomap.blockOutVariableIn.geom b/Test/iomap.blockOutVariableIn.geom new file mode 100644 index 00000000..feefdd13 --- /dev/null +++ b/Test/iomap.blockOutVariableIn.geom @@ -0,0 +1,28 @@ +#version 440 + +layout(triangles) in; +layout(triangle_strip, max_vertices=3) out; + +layout(location = 0) in vec4 in_a1[3]; +layout(location = 1) in vec2 in_a2[3]; + +layout(location = 0) out vec4 a1; +layout(location = 1) out vec2 a2; + +void main() +{ + a1 = in_a1[0]; + a2 = in_a2[0]; + gl_Position = vec4(1.0); + EmitVertex(); + + a1 = in_a1[1]; + a2 = in_a2[1]; + gl_Position = vec4(1.0); + EmitVertex(); + + a1 = in_a1[2]; + a2 = in_a2[2]; + gl_Position = vec4(1.0); + EmitVertex(); +} diff --git a/Test/iomap.blockOutVariableIn.vert b/Test/iomap.blockOutVariableIn.vert new file mode 100644 index 00000000..67f45c97 --- /dev/null +++ b/Test/iomap.blockOutVariableIn.vert @@ -0,0 +1,14 @@ +#version 440 + +layout(location = 0) out Block +{ + vec4 a1; + vec2 a2; +}; + +void main() +{ + a1 = vec4(1.0); + a2 = vec2(0.5); + gl_Position = vec4(1.0); +} diff --git a/Test/iomap.variableOutBlockIn.2.vert b/Test/iomap.variableOutBlockIn.2.vert new file mode 100644 index 00000000..f9b80b46 --- /dev/null +++ b/Test/iomap.variableOutBlockIn.2.vert @@ -0,0 +1,11 @@ +#version 440 + +layout(location = 0) out vec4 a1; +layout(location = 1) out vec2 a2; + +void main() +{ + a1 = vec4(1.0); + a2 = vec2(0.5); + gl_Position = vec4(1.0); +} diff --git a/Test/iomap.variableOutBlockIn.frag b/Test/iomap.variableOutBlockIn.frag new file mode 100644 index 00000000..967d7698 --- /dev/null +++ b/Test/iomap.variableOutBlockIn.frag @@ -0,0 +1,13 @@ +#version 440 + +layout(location = 0) in Inputs { + vec4 a1; + vec2 a2; +}; + +layout(location = 0) out vec4 color; + +void main() +{ + color = vec4(a1.xy, a2); +} diff --git a/Test/iomap.variableOutBlockIn.geom b/Test/iomap.variableOutBlockIn.geom new file mode 100644 index 00000000..637ddabb --- /dev/null +++ b/Test/iomap.variableOutBlockIn.geom @@ -0,0 +1,19 @@ +#version 440 + +layout(triangles) in; +layout(triangle_strip, max_vertices=3) out; + +layout(location = 0) in Inputs { + vec4 a1; + vec2 a2; +} gin[3]; + +layout(location = 0) out vec4 a1; +layout(location = 1) out vec2 a2; + +void main() +{ + a1 = vec4(1.0); + a2 = vec2(0.5); + gl_Position = vec4(1.0); +} diff --git a/Test/iomap.variableOutBlockIn.vert b/Test/iomap.variableOutBlockIn.vert new file mode 100644 index 00000000..f9b80b46 --- /dev/null +++ b/Test/iomap.variableOutBlockIn.vert @@ -0,0 +1,11 @@ +#version 440 + +layout(location = 0) out vec4 a1; +layout(location = 1) out vec2 a2; + +void main() +{ + a1 = vec4(1.0); + a2 = vec2(0.5); + gl_Position = vec4(1.0); +} diff --git a/glslang/MachineIndependent/iomapper.cpp b/glslang/MachineIndependent/iomapper.cpp index a1db5c13..288a6c97 100644 --- a/glslang/MachineIndependent/iomapper.cpp +++ b/glslang/MachineIndependent/iomapper.cpp @@ -514,6 +514,24 @@ struct TSymbolValidater return; } else { + // Deal with input/output pairs where one is a block member but the other is loose, + // e.g. with ARB_separate_shader_objects + if (type1.getBasicType() == EbtBlock && + type1.isStruct() && !type2.isStruct()) { + // Iterate through block members tracking layout + glslang::TString name; + type1.getStruct()->begin()->type->appendMangledName(name); + if (name == mangleName2 + && type1.getQualifier().layoutLocation == type2.getQualifier().layoutLocation) return; + } + if (type2.getBasicType() == EbtBlock && + type2.isStruct() && !type1.isStruct()) { + // Iterate through block members tracking layout + glslang::TString name; + type2.getStruct()->begin()->type->appendMangledName(name); + if (name == mangleName1 + && type1.getQualifier().layoutLocation == type2.getQualifier().layoutLocation) return; + } TString err = "Invalid In/Out variable type : " + entKey.first; infoSink.info.message(EPrefixInternalError, err.c_str()); hadError = true; diff --git a/glslang/MachineIndependent/linkValidate.cpp b/glslang/MachineIndependent/linkValidate.cpp index 4edd2a90..9d7db887 100644 --- a/glslang/MachineIndependent/linkValidate.cpp +++ b/glslang/MachineIndependent/linkValidate.cpp @@ -759,7 +759,10 @@ void TIntermediate::mergeLinkerObjects(TInfoSink& infoSink, TIntermSequence& lin auto checkName = [this, unitSymbol, &infoSink](const TString& name) { for (unsigned int i = 0; i < unitSymbol->getType().getStruct()->size(); ++i) { - if (name == (*unitSymbol->getType().getStruct())[i].type->getFieldName()) { + if (name == (*unitSymbol->getType().getStruct())[i].type->getFieldName() + && !((*unitSymbol->getType().getStruct())[i].type->getQualifier().hasLocation() + || unitSymbol->getType().getQualifier().hasLocation()) + ) { error(infoSink, "Anonymous member name used for global variable or other anonymous member: "); infoSink.info << (*unitSymbol->getType().getStruct())[i].type->getCompleteString() << "\n"; } diff --git a/gtests/GlslMapIO.FromFile.cpp b/gtests/GlslMapIO.FromFile.cpp index 574e905f..73fdec4e 100644 --- a/gtests/GlslMapIO.FromFile.cpp +++ b/gtests/GlslMapIO.FromFile.cpp @@ -109,7 +109,50 @@ bool verifyIOMapping(std::string& linkingError, glslang::TProgram& program) { success &= outQualifier.layoutLocation == inQualifier.layoutLocation; } else { - success &= false; + if (!in.getType()->isStruct()) { + bool found = false; + for (auto outIt : pipeOut) { + if (outIt.second->getType()->isStruct()) { + unsigned int baseLoc = outIt.second->getType()->getQualifier().hasLocation() ? outIt.second->getType()->getQualifier().layoutLocation : -1; + for (int j = 0; j < outIt.second->getType()->getStruct()->size(); j++) { + baseLoc = (*outIt.second->getType()->getStruct())[j].type->getQualifier().hasLocation() ? + (*outIt.second->getType()->getStruct())[j].type->getQualifier().layoutLocation : baseLoc; + if (baseLoc != -1) { + if (baseLoc == in.getType()->getQualifier().layoutLocation) { + found = true; + break; + } + baseLoc += glslang::TIntermediate::computeTypeLocationSize(*(*outIt.second->getType()->getStruct())[j].type, EShLangVertex); + } + } + if (found) { + break; + } + } + } + success &= found; + } + else { + unsigned int baseLoc = in.getType()->getQualifier().hasLocation() ? in.getType()->getQualifier().layoutLocation : -1; + for (int j = 0; j < in.getType()->getStruct()->size(); j++) { + baseLoc = (*in.getType()->getStruct())[j].type->getQualifier().hasLocation() ? + (*in.getType()->getStruct())[j].type->getQualifier().layoutLocation : baseLoc; + if (baseLoc != -1) { + bool isMemberFound = false; + for (auto outIt : pipeOut) { + if (baseLoc == outIt.second->getType()->getQualifier().layoutLocation) { + isMemberFound = true; + break; + } + } + if (!isMemberFound) { + success &= false; + break; + } + baseLoc += glslang::TIntermediate::computeTypeLocationSize(*(*in.getType()->getStruct())[j].type, EShLangVertex); + } + } + } } } } @@ -295,6 +338,10 @@ INSTANTIATE_TEST_SUITE_P( ::testing::ValuesIn(std::vector({ {{"iomap.crossStage.vert", "iomap.crossStage.frag" }, Semantics::OpenGL}, {{"iomap.crossStage.2.vert", "iomap.crossStage.2.geom", "iomap.crossStage.2.frag" }, Semantics::OpenGL}, + {{"iomap.blockOutVariableIn.vert", "iomap.blockOutVariableIn.frag"}, Semantics::OpenGL}, + {{"iomap.variableOutBlockIn.vert", "iomap.variableOutBlockIn.frag"}, Semantics::OpenGL}, + {{"iomap.blockOutVariableIn.2.vert", "iomap.blockOutVariableIn.geom"}, Semantics::OpenGL}, + {{"iomap.variableOutBlockIn.2.vert", "iomap.variableOutBlockIn.geom"}, Semantics::OpenGL}, // vulkan semantics {{"iomap.crossStage.vk.vert", "iomap.crossStage.vk.geom", "iomap.crossStage.vk.frag" }, Semantics::Vulkan}, })) From eebb48f5fc8631830e04e6ac1de623413008a526 Mon Sep 17 00:00:00 2001 From: Malcolm Bechard Date: Mon, 15 Nov 2021 10:44:08 -0500 Subject: [PATCH 18/21] remove unneeded extra constructions now that pool allocation is fixed --- glslang/MachineIndependent/SymbolTable.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/glslang/MachineIndependent/SymbolTable.cpp b/glslang/MachineIndependent/SymbolTable.cpp index 5b7e27fa..a3ffa0c4 100644 --- a/glslang/MachineIndependent/SymbolTable.cpp +++ b/glslang/MachineIndependent/SymbolTable.cpp @@ -426,12 +426,7 @@ TSymbolTableLevel* TSymbolTableLevel::clone() const symTableLevel->thisLevel = thisLevel; symTableLevel->retargetedSymbols.clear(); for (auto &s : retargetedSymbols) { - // Extra constructions to make sure they use the correct allocator pool - TString newFrom; - newFrom = s.first; - TString newTo; - newTo = s.second; - symTableLevel->retargetedSymbols.push_back({std::move(newFrom), std::move(newTo)}); + symTableLevel->retargetedSymbols.push_back({s.first, s.second}); } std::vector containerCopied(anonId, false); tLevel::const_iterator iter; @@ -462,11 +457,7 @@ TSymbolTableLevel* TSymbolTableLevel::clone() const TSymbol* sym = symTableLevel->find(s.second); if (!sym) continue; - - // Need to declare and assign so newS is using the correct pool allocator - TString newS; - newS = s.first; - symTableLevel->insert(newS, sym); + symTableLevel->insert(s.first, sym); } return symTableLevel; From bee91eb479ee38ce4f268c363154e5175c7a9bd0 Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Wed, 17 Nov 2021 23:32:27 +0800 Subject: [PATCH 19/21] Fix an issue of spirv_type used in local variable definitions We previously use createOp() in SPV builder to create type declaration. However, all type declarations should be placed in const-type-variable declaration section. And duplicated type defintions ought to be avoided. We now make a method in SPV builder to perform this operation with a more general solution: makeGenericType(). --- SPIRV/GlslangToSpv.cpp | 25 +++++------ SPIRV/SpvBuilder.cpp | 31 +++++++++++++ SPIRV/SpvBuilder.h | 1 + .../spv.intrinsicsSpirvType.rgen.out | 4 +- .../spv.intrinsicsSpirvTypeLocalVar.vert.out | 43 +++++++++++++++++++ Test/spv.intrinsicsSpirvTypeLocalVar.vert | 14 ++++++ gtests/Spv.FromFile.cpp | 1 + 7 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 Test/baseResults/spv.intrinsicsSpirvTypeLocalVar.vert.out create mode 100644 Test/spv.intrinsicsSpirvTypeLocalVar.vert diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 43aba9cb..3a906189 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -4148,23 +4148,23 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty const auto& spirvType = type.getSpirvType(); const auto& spirvInst = spirvType.spirvInst; - std::vector operands; + std::vector operands; for (const auto& typeParam : spirvType.typeParams) { // Constant expression if (typeParam.constant->isLiteral()) { if (typeParam.constant->getBasicType() == glslang::EbtFloat) { float floatValue = static_cast(typeParam.constant->getConstArray()[0].getDConst()); unsigned literal = *reinterpret_cast(&floatValue); - operands.push_back(literal); + operands.push_back({false, literal}); } else if (typeParam.constant->getBasicType() == glslang::EbtInt) { unsigned literal = typeParam.constant->getConstArray()[0].getIConst(); - operands.push_back(literal); + operands.push_back({false, literal}); } else if (typeParam.constant->getBasicType() == glslang::EbtUint) { unsigned literal = typeParam.constant->getConstArray()[0].getUConst(); - operands.push_back(literal); + operands.push_back({false, literal}); } else if (typeParam.constant->getBasicType() == glslang::EbtBool) { unsigned literal = typeParam.constant->getConstArray()[0].getBConst(); - operands.push_back(literal); + operands.push_back({false, literal}); } else if (typeParam.constant->getBasicType() == glslang::EbtString) { auto str = typeParam.constant->getConstArray()[0].getSConst()->c_str(); unsigned literal = 0; @@ -4176,7 +4176,7 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty *(literalPtr++) = ch; ++charCount; if (charCount == 4) { - operands.push_back(literal); + operands.push_back({false, literal}); literalPtr = reinterpret_cast(&literal); charCount = 0; } @@ -4186,20 +4186,17 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty if (charCount > 0) { for (; charCount < 4; ++charCount) *(literalPtr++) = 0; - operands.push_back(literal); + operands.push_back({false, literal}); } } else assert(0); // Unexpected type } else - operands.push_back(createSpvConstant(*typeParam.constant)); + operands.push_back({true, createSpvConstant(*typeParam.constant)}); } - if (spirvInst.set == "") - spvType = builder.createOp(static_cast(spirvInst.id), spv::NoType, operands); - else { - spvType = builder.createBuiltinCall( - spv::NoType, getExtBuiltins(spirvInst.set.c_str()), spirvInst.id, operands); - } + assert(spirvInst.set == ""); // Currently, couldn't be extended instructions. + spvType = builder.makeGenericType(static_cast(spirvInst.id), operands); + break; } #endif diff --git a/SPIRV/SpvBuilder.cpp b/SPIRV/SpvBuilder.cpp index e83306eb..838f916a 100644 --- a/SPIRV/SpvBuilder.cpp +++ b/SPIRV/SpvBuilder.cpp @@ -427,6 +427,37 @@ Id Builder::makeCooperativeMatrixType(Id component, Id scope, Id rows, Id cols) return type->getResultId(); } +Id Builder::makeGenericType(spv::Op opcode, std::vector& operands) +{ + // try to find it + Instruction* type; + for (int t = 0; t < (int)groupedTypes[opcode].size(); ++t) { + type = groupedTypes[opcode][t]; + if (type->getNumOperands() != operands.size()) + continue; // Number mismatch, find next + + bool match = true; + for (int op = 0; match && op < operands.size(); ++op) { + match = (operands[op].isId ? type->getIdOperand(op) : type->getImmediateOperand(op)) == operands[op].word; + } + if (match) + return type->getResultId(); + } + + // not found, make it + type = new Instruction(getUniqueId(), NoType, opcode); + for (int op = 0; op < operands.size(); ++op) { + if (operands[op].isId) + type->addIdOperand(operands[op].word); + else + type->addImmediateOperand(operands[op].word); + } + groupedTypes[opcode].push_back(type); + constantsTypesGlobals.push_back(std::unique_ptr(type)); + module.mapInstruction(type); + + return type->getResultId(); +} // TODO: performance: track arrays per stride // If a stride is supplied (non-zero) make an array. diff --git a/SPIRV/SpvBuilder.h b/SPIRV/SpvBuilder.h index 251b9ee8..c72d9b28 100644 --- a/SPIRV/SpvBuilder.h +++ b/SPIRV/SpvBuilder.h @@ -181,6 +181,7 @@ public: Id makeSamplerType(); Id makeSampledImageType(Id imageType); Id makeCooperativeMatrixType(Id component, Id scope, Id rows, Id cols); + Id makeGenericType(spv::Op opcode, std::vector& operands); // accelerationStructureNV type Id makeAccelerationStructureType(); diff --git a/Test/baseResults/spv.intrinsicsSpirvType.rgen.out b/Test/baseResults/spv.intrinsicsSpirvType.rgen.out index ac0c9464..021e7a6d 100644 --- a/Test/baseResults/spv.intrinsicsSpirvType.rgen.out +++ b/Test/baseResults/spv.intrinsicsSpirvType.rgen.out @@ -22,7 +22,9 @@ Validation failed Decorate 11(as) Binding 0 2: TypeVoid 3: TypeFunction 2 + 6: TypeRayQueryKHR 7: TypePointer Function 6 + 9: TypeAccelerationStructureKHR 10: TypePointer UniformConstant 9 11(as): 10(ptr) Variable UniformConstant 13: TypeInt 32 0 @@ -36,8 +38,6 @@ Validation failed 4(main): 2 Function None 3 5: Label 8(rq): 7(ptr) Variable Function - 6: TypeRayQueryKHR - 9: TypeAccelerationStructureKHR 12: 9 Load 11(as) RayQueryInitializeKHR 8(rq) 12 14 14 18 17 20 19 RayQueryTerminateKHR 8(rq) diff --git a/Test/baseResults/spv.intrinsicsSpirvTypeLocalVar.vert.out b/Test/baseResults/spv.intrinsicsSpirvTypeLocalVar.vert.out new file mode 100644 index 00000000..75515be0 --- /dev/null +++ b/Test/baseResults/spv.intrinsicsSpirvTypeLocalVar.vert.out @@ -0,0 +1,43 @@ +spv.intrinsicsSpirvTypeLocalVar.vert +// Module Version 10000 +// Generated by (magic number): 8000a +// Id's are bound by 22 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" + Source GLSL 460 + SourceExtension "GL_EXT_spirv_intrinsics" + Name 4 "main" + Name 10 "func(spv-t1;" + Name 9 "emptyStruct" + Name 13 "size" + Name 16 "dummy" + Name 18 "param" + Decorate 13(size) SpecId 9 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeStruct + 7: TypePointer Function 6(struct) + 8: TypeFunction 2 7(ptr) + 12: TypeInt 32 1 + 13(size): 12(int) SpecConstant 9 + 14: TypeArray 6(struct) 13(size) + 15: TypePointer Function 14 + 17: 12(int) Constant 1 + 4(main): 2 Function None 3 + 5: Label + 16(dummy): 15(ptr) Variable Function + 18(param): 7(ptr) Variable Function + 19: 7(ptr) AccessChain 16(dummy) 17 + 20: 6(struct) Load 19 + Store 18(param) 20 + 21: 2 FunctionCall 10(func(spv-t1;) 18(param) + Return + FunctionEnd +10(func(spv-t1;): 2 Function None 8 + 9(emptyStruct): 7(ptr) FunctionParameter + 11: Label + Return + FunctionEnd diff --git a/Test/spv.intrinsicsSpirvTypeLocalVar.vert b/Test/spv.intrinsicsSpirvTypeLocalVar.vert new file mode 100644 index 00000000..203d9007 --- /dev/null +++ b/Test/spv.intrinsicsSpirvTypeLocalVar.vert @@ -0,0 +1,14 @@ +#version 460 core + +#extension GL_EXT_spirv_intrinsics: enable + +layout(constant_id = 9) const int size = 9; + +#define EmptyStruct spirv_type(id = 30) +void func(EmptyStruct emptyStruct) {} + +void main() +{ + EmptyStruct dummy[size]; + func(dummy[1]); +} diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index ef117640..460c1d22 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -373,6 +373,7 @@ INSTANTIATE_TEST_SUITE_P( "spv.intrinsicsSpirvLiteral.vert", "spv.intrinsicsSpirvStorageClass.rchit", "spv.intrinsicsSpirvType.rgen", + "spv.intrinsicsSpirvTypeLocalVar.vert", "spv.invariantAll.vert", "spv.layer.tese", "spv.layoutNested.vert", From 3e9e60af8636cd5a4740bc8244c72605cb1df3a0 Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Mon, 22 Nov 2021 20:05:06 +0800 Subject: [PATCH 20/21] Remove the test spv.intrinsicsSpecConst According to current SPIR-V spec, we couldn't write a valid case that references OpExecutionModeId and OpDecorateId. --- SPIRV/doc.cpp | 6 ++++ .../spv.intrinsicsSpecConst.vert.out | 35 ------------------- Test/spv.intrinsicsSpecConst.vert | 14 -------- gtests/Spv.FromFile.cpp | 1 - 4 files changed, 6 insertions(+), 50 deletions(-) delete mode 100644 Test/baseResults/spv.intrinsicsSpecConst.vert.out delete mode 100644 Test/spv.intrinsicsSpecConst.vert diff --git a/SPIRV/doc.cpp b/SPIRV/doc.cpp index dbdf7077..9a569e0d 100644 --- a/SPIRV/doc.cpp +++ b/SPIRV/doc.cpp @@ -900,6 +900,12 @@ const char* CapabilityString(int info) case CapabilityDeviceGroup: return "DeviceGroup"; case CapabilityMultiView: return "MultiView"; + case CapabilityDenormPreserve: return "DenormPreserve"; + case CapabilityDenormFlushToZero: return "DenormFlushToZero"; + case CapabilitySignedZeroInfNanPreserve: return "SignedZeroInfNanPreserve"; + case CapabilityRoundingModeRTE: return "RoundingModeRTE"; + case CapabilityRoundingModeRTZ: return "RoundingModeRTZ"; + case CapabilityStencilExportEXT: return "StencilExportEXT"; case CapabilityFloat16ImageAMD: return "Float16ImageAMD"; diff --git a/Test/baseResults/spv.intrinsicsSpecConst.vert.out b/Test/baseResults/spv.intrinsicsSpecConst.vert.out deleted file mode 100644 index 11751d64..00000000 --- a/Test/baseResults/spv.intrinsicsSpecConst.vert.out +++ /dev/null @@ -1,35 +0,0 @@ -spv.intrinsicsSpecConst.vert -Validation failed -// Module Version 10000 -// Generated by (magic number): 8000a -// Id's are bound by 13 - - Capability Shader - 1: ExtInstImport "GLSL.std.450" - MemoryModel Logical GLSL450 - EntryPoint Vertex 4 "main" 10 - ExecutionModeId 4 DenormFlushToZero 7 - Source GLSL 450 - SourceExtension "GL_EXT_spirv_intrinsics" - Name 4 "main" - Name 7 "targetWidth" - Name 10 "pointSize" - Name 11 "builtIn" - Decorate 7(targetWidth) SpecId 5 - Decorate 10(pointSize) Location 0 - Decorate 11(builtIn) SpecId 6 - DecorateId 10(pointSize) BuiltIn 11(builtIn) - 2: TypeVoid - 3: TypeFunction 2 - 6: TypeInt 32 0 - 7(targetWidth): 6(int) SpecConstant 32 - 8: TypeFloat 32 - 9: TypePointer Output 8(float) - 10(pointSize): 9(ptr) Variable Output - 11(builtIn): 6(int) SpecConstant 1 - 12: 8(float) Constant 1082130432 - 4(main): 2 Function None 3 - 5: Label - Store 10(pointSize) 12 - Return - FunctionEnd diff --git a/Test/spv.intrinsicsSpecConst.vert b/Test/spv.intrinsicsSpecConst.vert deleted file mode 100644 index 19cc5ef4..00000000 --- a/Test/spv.intrinsicsSpecConst.vert +++ /dev/null @@ -1,14 +0,0 @@ -#version 450 core - -#extension GL_EXT_spirv_intrinsics: enable - -layout(constant_id = 5) const uint targetWidth = 32; -spirv_execution_mode_id(4460/*=DenormFlushToZero*/, targetWidth); - -layout(constant_id = 6) const uint builtIn = 1; -spirv_decorate_id(11/*=BuiltIn*/, builtIn) out float pointSize; - -void main() -{ - pointSize = 4.0; -} diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index 460c1d22..885707c2 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -365,7 +365,6 @@ INSTANTIATE_TEST_SUITE_P( "spv.int64.frag", "spv.intcoopmat.comp", "spv.intOps.vert", - "spv.intrinsicsSpecConst.vert", "spv.intrinsicsSpirvByReference.vert", "spv.intrinsicsSpirvDecorate.frag", "spv.intrinsicsSpirvExecutionMode.frag", From fe54126c05863564eab8325b2725f65d96c450b6 Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Tue, 23 Nov 2021 16:40:45 +0800 Subject: [PATCH 21/21] Fix an issue of spirv_by_reference When using this qualifier for a parameter, we make it as a pointer. However, the function TranslateStorageClass() is therefore called and the storage class should only be set to Function when it is invoked to translate parameter types rather than actual argument types. --- SPIRV/GlslangToSpv.cpp | 6 ++++-- .../spv.intrinsicsSpirvLiteral.vert.out | 20 +++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 3a906189..e471b9ff 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -1256,8 +1256,10 @@ spv::StorageClass TGlslangToSpvTraverser::TranslateStorageClass(const glslang::T if (type.getBasicType() == glslang::EbtRayQuery) return spv::StorageClassPrivate; #ifndef GLSLANG_WEB - if (type.getQualifier().isSpirvByReference()) - return spv::StorageClassFunction; + if (type.getQualifier().isSpirvByReference()) { + if (type.getQualifier().isParamInput() || type.getQualifier().isParamOutput()) + return spv::StorageClassFunction; + } #endif if (type.getQualifier().isPipeInput()) return spv::StorageClassInput; diff --git a/Test/baseResults/spv.intrinsicsSpirvLiteral.vert.out b/Test/baseResults/spv.intrinsicsSpirvLiteral.vert.out index 68ad949b..096cc611 100644 --- a/Test/baseResults/spv.intrinsicsSpirvLiteral.vert.out +++ b/Test/baseResults/spv.intrinsicsSpirvLiteral.vert.out @@ -1,30 +1,30 @@ spv.intrinsicsSpirvLiteral.vert -Validation failed // Module Version 10000 // Generated by (magic number): 8000a -// Id's are bound by 12 +// Id's are bound by 13 Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Vertex 4 "main" + EntryPoint Vertex 4 "main" 9 11 Source GLSL 450 SourceExtension "GL_EXT_spirv_intrinsics" Name 4 "main" Name 9 "vec4Out" - Name 10 "vec4In" + Name 11 "vec4In" Decorate 9(vec4Out) Location 1 - Decorate 10(vec4In) Location 0 + Decorate 11(vec4In) Location 0 2: TypeVoid 3: TypeFunction 2 6: TypeFloat 32 7: TypeVector 6(float) 4 - 8: TypePointer Function 7(fvec4) + 8: TypePointer Output 7(fvec4) + 9(vec4Out): 8(ptr) Variable Output + 10: TypePointer Input 7(fvec4) + 11(vec4In): 10(ptr) Variable Input 4(main): 2 Function None 3 5: Label - 9(vec4Out): 8(ptr) Variable Function - 10(vec4In): 8(ptr) Variable Function - 11: 7(fvec4) Load 10(vec4In) None - Store 9(vec4Out) 11 Volatile + 12: 7(fvec4) Load 11(vec4In) None + Store 9(vec4Out) 12 Volatile Return FunctionEnd