glslang
glslang copied to clipboard
About the change of custom "set"

I try to changeing this problem.
@mbechard
Can you elaborate on the issue you are looking to fix?
I assigned different "sets" to the shader at different stages, but after iomapping it was merged into the same set ID, which was not what I expected.
I used this code to fix:
if( resolvedSet >= 0 && resolvedSet != p.second.newSet ) return;
seems likely correct. Any chance you can post your example case so I can trace through the code?
Sure, Maybe you can see this example.
`std::array<std::string, 2> codes[] = { R"(#version 310 es precision mediump float; #define attribute in #define varying out
attribute vec2 a_position; varying vec2 v_texcoord;
uniform float u_float;
void main() { v_texcoord = a_position * 0.5 + 0.5; gl_Position = vec4( a_position, u_float, 1.0 ); } )", R"(#version 310 es precision mediump float; #define gl_FragColor outFragColor layout(location = 0) out vec4 gl_FragColor; #define varying in
varying vec2 v_texcoord;
uniform sampler2D sTexture; uniform float u_float;
void main() { gl_FragColor = vec4(texture( sTexture, v_texcoord ).xyz, u_float); } )", };
const char* szEntryPointName = "main";
glslang::TProgram program; std::array<std::vectorstd::string, 2> aryBindingSet = {{ {"0"}, {"1"} }}; std::array<glslang::TShader, 2> aryShader;
aryShader[0].setStringsWithLengths(&(codes[0].c_str()), &(codes[0].length()), 1); aryShader[0].setEntryPoint(szEntryPointName); aryShader[0].setSourceEntryPoint(szEntryPointName); aryShader[0].setEnvInput(eInLangague, EShLangVertex, glslang::EShClientVulkan, 100); aryShader[0].setEnvClient(glslang::EShClientVulkan, glslang::EShTargetVulkan_1_0); aryShader[0].setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_0); aryShader[0].setAutoMapLocations(true ); aryShader[0].setAutoMapBindings(true ); aryShader[0].setEnvInputVulkanRulesRelaxed(); aryShader[0].setGlobalUniformBlockName("DefaultUniformBlock_0"); aryShader[0].setResourceSetBinding(aryBindingSet[0]); aryShader[0].parse(&glslang::DefaultTBuiltInResource, 100, true, EShMsgDefault);
aryShader[1].setStringsWithLengths(&(codes[1].c_str()), &(codes[1].length()), 1); aryShader[1].setEntryPoint(szEntryPointName); aryShader[1].setSourceEntryPoint(szEntryPointName); aryShader[1].setEnvInput(eInLangague, EShLangFragment, glslang::EShClientVulkan, 100); aryShader[1].setEnvClient(glslang::EShClientVulkan, glslang::EShTargetVulkan_1_0); aryShader[1].setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_0); aryShader[1].setAutoMapLocations(true); aryShader[1].setAutoMapBindings(true); aryShader[1].setEnvInputVulkanRulesRelaxed(); aryShader[1].setGlobalUniformBlockName("DefaultUniformBlock_1"); aryShader[1].setResourceSetBinding(aryBindingSet[1]); aryShader[1].parse(&glslang::DefaultTBuiltInResource, 100, true, EShMsgDefault);
program.addShader(&aryShader[0]); program.addShader(&aryShader[1]); program.link(EShMsgDefault);
unsigned int stage = 0; while (!program.getIntermediate((EShLanguage)stage) && stage < EShLangCount) { stage++; } glslang::TIntermediate* firstIntermediate = program.getIntermediate((EShLanguage)stage);
glslang::TDefaultGlslIoResolver resolver(*firstIntermediate); glslang::TGlslIoMapper ioMapper; bool bMapIO = program.mapIO(&resolver, &ioMapper);
std::array<std::vector<uint32_t>, 2> spirvs; glslang::GlslangToSpv(*program.getIntermediate(EShLangVertex), spirvs[0], nullptr, nullptr); glslang::GlslangToSpv(*program.getIntermediate(EShLangFragment), spirvs[1], nullptr, nullptr);`
Have any change in this problem ? @mbechard Sorry,I didn't mean to urge.
Sorry, no chance to look at it yet. I have a list of a few things I want to look at soon in GLSLang
@lance-loong are you sure your example exhibits the problem? I just tried your code and DefaultUniformBlock_0 is correctly using set 0 and DefaultUniformBlock_1 is correctly using set 1 in the outputted SPIR-V:
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 39
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 9 11 20 37 38
Source ESSL 310
Name 4 "main"
Name 9 "v_texcoord"
Name 11 "a_position"
Name 18 "gl_PerVertex"
MemberName 18(gl_PerVertex) 0 "gl_Position"
MemberName 18(gl_PerVertex) 1 "gl_PointSize"
Name 20 ""
Name 24 "DefaultUniformBlock_0"
MemberName 24(DefaultUniformBlock_0) 0 "u_float"
Name 26 ""
Name 37 "gl_VertexIndex"
Name 38 "gl_InstanceIndex"
Decorate 9(v_texcoord) RelaxedPrecision
Decorate 9(v_texcoord) Location 0
Decorate 11(a_position) RelaxedPrecision
Decorate 11(a_position) Location 0
Decorate 12 RelaxedPrecision
Decorate 14 RelaxedPrecision
Decorate 15 RelaxedPrecision
Decorate 16 RelaxedPrecision
MemberDecorate 18(gl_PerVertex) 0 BuiltIn Position
MemberDecorate 18(gl_PerVertex) 1 BuiltIn PointSize
Decorate 18(gl_PerVertex) Block
Decorate 23 RelaxedPrecision
MemberDecorate 24(DefaultUniformBlock_0) 0 RelaxedPrecision
MemberDecorate 24(DefaultUniformBlock_0) 0 Offset 0
Decorate 24(DefaultUniformBlock_0) Block
Decorate 26 DescriptorSet 0
Decorate 26 Binding 0
Decorate 29 RelaxedPrecision
Decorate 31 RelaxedPrecision
Decorate 32 RelaxedPrecision
Decorate 33 RelaxedPrecision
Decorate 37(gl_VertexIndex) BuiltIn VertexIndex
Decorate 38(gl_InstanceIndex) BuiltIn InstanceIndex
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 2
8: TypePointer Output 7(fvec2)
9(v_texcoord): 8(ptr) Variable Output
10: TypePointer Input 7(fvec2)
11(a_position): 10(ptr) Variable Input
13: 6(float) Constant 1056964608
17: TypeVector 6(float) 4
18(gl_PerVertex): TypeStruct 17(fvec4) 6(float)
19: TypePointer Output 18(gl_PerVertex)
20: 19(ptr) Variable Output
21: TypeInt 32 1
22: 21(int) Constant 0
24(DefaultUniformBlock_0): TypeStruct 6(float)
25: TypePointer Uniform 24(DefaultUniformBlock_0)
26: 25(ptr) Variable Uniform
27: TypePointer Uniform 6(float)
30: 6(float) Constant 1065353216
34: TypePointer Output 17(fvec4)
36: TypePointer Input 21(int)
37(gl_VertexIndex): 36(ptr) Variable Input
38(gl_InstanceIndex): 36(ptr) Variable Input
4(main): 2 Function None 3
5: Label
12: 7(fvec2) Load 11(a_position)
14: 7(fvec2) VectorTimesScalar 12 13
15: 7(fvec2) CompositeConstruct 13 13
16: 7(fvec2) FAdd 14 15
Store 9(v_texcoord) 16
23: 7(fvec2) Load 11(a_position)
28: 27(ptr) AccessChain 26 22
29: 6(float) Load 28
31: 6(float) CompositeExtract 23 0
32: 6(float) CompositeExtract 23 1
33: 17(fvec4) CompositeConstruct 31 32 29 30
35: 34(ptr) AccessChain 20 22
Store 35 33
Return
FunctionEnd
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 34
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9 17
ExecutionMode 4 OriginUpperLeft
Source ESSL 310
Name 4 "main"
Name 9 "outFragColor"
Name 13 "sTexture"
Name 17 "v_texcoord"
Name 22 "DefaultUniformBlock_1"
MemberName 22(DefaultUniformBlock_1) 0 "u_float"
Name 24 ""
Decorate 9(outFragColor) RelaxedPrecision
Decorate 9(outFragColor) Location 0
Decorate 13(sTexture) RelaxedPrecision
Decorate 13(sTexture) DescriptorSet 1
Decorate 13(sTexture) Binding 0
Decorate 14 RelaxedPrecision
Decorate 17(v_texcoord) RelaxedPrecision
Decorate 17(v_texcoord) Location 0
Decorate 18 RelaxedPrecision
Decorate 19 RelaxedPrecision
Decorate 21 RelaxedPrecision
MemberDecorate 22(DefaultUniformBlock_1) 0 RelaxedPrecision
MemberDecorate 22(DefaultUniformBlock_1) 0 Offset 0
Decorate 22(DefaultUniformBlock_1) Block
Decorate 24 DescriptorSet 1
Decorate 24 Binding 1
Decorate 29 RelaxedPrecision
Decorate 30 RelaxedPrecision
Decorate 31 RelaxedPrecision
Decorate 32 RelaxedPrecision
Decorate 33 RelaxedPrecision
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Output 7(fvec4)
9(outFragColor): 8(ptr) Variable Output
10: TypeImage 6(float) 2D sampled format:Unknown
11: TypeSampledImage 10
12: TypePointer UniformConstant 11
13(sTexture): 12(ptr) Variable UniformConstant
15: TypeVector 6(float) 2
16: TypePointer Input 15(fvec2)
17(v_texcoord): 16(ptr) Variable Input
20: TypeVector 6(float) 3
22(DefaultUniformBlock_1): TypeStruct 6(float)
23: TypePointer Uniform 22(DefaultUniformBlock_1)
24: 23(ptr) Variable Uniform
25: TypeInt 32 1
26: 25(int) Constant 0
27: TypePointer Uniform 6(float)
4(main): 2 Function None 3
5: Label
14: 11 Load 13(sTexture)
18: 15(fvec2) Load 17(v_texcoord)
19: 7(fvec4) ImageSampleImplicitLod 14 18
21: 20(fvec3) VectorShuffle 19 19 0 1 2
28: 27(ptr) AccessChain 24 26
29: 6(float) Load 28
30: 6(float) CompositeExtract 21 0
31: 6(float) CompositeExtract 21 1
32: 6(float) CompositeExtract 21 2
33: 7(fvec4) CompositeConstruct 30 31 32 29
Store 9(outFragColor) 33
Return
FunctionEnd
@mbechard Why is there no problem with your!!!
Are you used "TGlslIoMapper"?you can try this shader again.
#version 310 es
precision mediump float;
#define attribute in
#define varying out
attribute vec2 aPos;
attribute vec2 aUV;
attribute vec4 aColor;
uniform mat4 projectionMatrix;
varying vec4 Color;
varying vec2 UV;
void main()
{
Color = aColor;
UV = aUV;
gl_Position = projectionMatrix * vec4(aPos, 0, 1);
}
#version 310 es
precision mediump float;
#define gl_FragColor outFragColor
layout(location = 0) out vec4 gl_FragColor;
#define varying in
uniform sampler2D sTexture;
varying vec4 Color;
varying vec2 UV;
void main()
{
gl_FragColor = Color * texture(sTexture, UV.st).a;
}
I'm using the code you pasted. Can you paste the human readable SPIR-V you get from the original example? For the new example you pasted, it actually crashes for me during the GlslangToSpv() conversion, but that occurs even if I remove the mapIO() work, so that's a different bug.
Of corse.Oh I found a different code.I'm using same ‘setGlobalUniformBlockName’ name.sorry,this is my problem.
aryShader[0].setGlobalUniformBlockName("globalUniformBlockName");
aryShader[1].setGlobalUniformBlockName("globalUniformBlockName");
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 43
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 9 11 15 17 21 31 41 42
Source ESSL 310
Name 4 "main"
Name 9 "Color"
Name 11 "aColor"
Name 15 "UV"
Name 17 "aUV"
Name 19 "gl_PerVertex"
MemberName 19(gl_PerVertex) 0 "gl_Position"
MemberName 19(gl_PerVertex) 1 "gl_PointSize"
Name 21 ""
Name 25 "globalUniformBlockName"
MemberName 25(globalUniformBlockName) 0 "projectionMatrix"
Name 27 ""
Name 31 "aPos"
Name 41 "gl_VertexID"
Name 42 "gl_InstanceID"
Decorate 9(Color) RelaxedPrecision
Decorate 9(Color) Location 0
Decorate 11(aColor) RelaxedPrecision
Decorate 11(aColor) Location 2
Decorate 12 RelaxedPrecision
Decorate 15(UV) RelaxedPrecision
Decorate 15(UV) Location 1
Decorate 17(aUV) RelaxedPrecision
Decorate 17(aUV) Location 1
Decorate 18 RelaxedPrecision
MemberDecorate 19(gl_PerVertex) 0 BuiltIn Position
MemberDecorate 19(gl_PerVertex) 1 BuiltIn PointSize
Decorate 19(gl_PerVertex) Block
MemberDecorate 25(globalUniformBlockName) 0 ColMajor
MemberDecorate 25(globalUniformBlockName) 0 RelaxedPrecision
MemberDecorate 25(globalUniformBlockName) 0 Offset 0
MemberDecorate 25(globalUniformBlockName) 0 MatrixStride 16
Decorate 25(globalUniformBlockName) Block
Decorate 27 DescriptorSet 1
Decorate 27 Binding 0
Decorate 30 RelaxedPrecision
Decorate 31(aPos) RelaxedPrecision
Decorate 31(aPos) Location 0
Decorate 32 RelaxedPrecision
Decorate 35 RelaxedPrecision
Decorate 36 RelaxedPrecision
Decorate 37 RelaxedPrecision
Decorate 38 RelaxedPrecision
Decorate 41(gl_VertexID) BuiltIn VertexIndex
Decorate 42(gl_InstanceID) BuiltIn InstanceIndex
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(aColor): 10(ptr) Variable Input
13: TypeVector 6(float) 2
14: TypePointer Output 13(fvec2)
15(UV): 14(ptr) Variable Output
16: TypePointer Input 13(fvec2)
17(aUV): 16(ptr) Variable Input
19(gl_PerVertex): TypeStruct 7(fvec4) 6(float)
20: TypePointer Output 19(gl_PerVertex)
21: 20(ptr) Variable Output
22: TypeInt 32 1
23: 22(int) Constant 0
24: TypeMatrix 7(fvec4) 4
25(globalUniformBlockName): TypeStruct 24
26: TypePointer Uniform 25(globalUniformBlockName)
27: 26(ptr) Variable Uniform
28: TypePointer Uniform 24
31(aPos): 16(ptr) Variable Input
33: 6(float) Constant 0
34: 6(float) Constant 1065353216
40: TypePointer Input 22(int)
41(gl_VertexID): 40(ptr) Variable Input
42(gl_InstanceID): 40(ptr) Variable Input
4(main): 2 Function None 3
5: Label
12: 7(fvec4) Load 11(aColor)
Store 9(Color) 12
18: 13(fvec2) Load 17(aUV)
Store 15(UV) 18
29: 28(ptr) AccessChain 27 23
30: 24 Load 29
32: 13(fvec2) Load 31(aPos)
35: 6(float) CompositeExtract 32 0
36: 6(float) CompositeExtract 32 1
37: 7(fvec4) CompositeConstruct 35 36 33 34
38: 7(fvec4) MatrixTimesVector 30 37
39: 8(ptr) AccessChain 21 23
Store 39 38
Return
FunctionEnd
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 27
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9 11 20
ExecutionMode 4 OriginUpperLeft
Source ESSL 310
Name 4 "main"
Name 9 "outFragColor"
Name 11 "Color"
Name 16 "sTexture"
Name 20 "UV"
Decorate 9(outFragColor) RelaxedPrecision
Decorate 9(outFragColor) Location 0
Decorate 11(Color) RelaxedPrecision
Decorate 11(Color) Location 0
Decorate 12 RelaxedPrecision
Decorate 16(sTexture) RelaxedPrecision
Decorate 16(sTexture) DescriptorSet 1
Decorate 16(sTexture) Binding 0
Decorate 17 RelaxedPrecision
Decorate 20(UV) RelaxedPrecision
Decorate 20(UV) Location 1
Decorate 21 RelaxedPrecision
Decorate 22 RelaxedPrecision
Decorate 25 RelaxedPrecision
Decorate 26 RelaxedPrecision
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Output 7(fvec4)
9(outFragColor): 8(ptr) Variable Output
10: TypePointer Input 7(fvec4)
11(Color): 10(ptr) Variable Input
13: TypeImage 6(float) 2D sampled format:Unknown
14: TypeSampledImage 13
15: TypePointer UniformConstant 14
16(sTexture): 15(ptr) Variable UniformConstant
18: TypeVector 6(float) 2
19: TypePointer Input 18(fvec2)
20(UV): 19(ptr) Variable Input
4(main): 2 Function None 3
5: Label
12: 7(fvec4) Load 11(Color)
17: 14 Load 16(sTexture)
21: 18(fvec2) Load 20(UV)
22: 7(fvec4) ImageSampleImplicitLod 17 21
25: 6(float) CompositeExtract 22 3
26: 7(fvec4) VectorTimesScalar 12 25
Store 9(outFragColor) 26
Return
FunctionEnd
If I'm understanding the issue correctly, the problem is that globalUniformBlockName
in the vertex shader is ending up on set 1, correct? Offhand this isn't necessarily wrong since if globalUniformBlockName
was used in the fragment shader, it would be correct for them to both end up at the same set/binding, since the blocks end being the same across the shader interface.
If you want to have different blocks and sets in different shaders, you should use different names.
Yes,I know. but i used diffrence setResourceSetBinding.I think this rule is high priority.
I think even more correctly this should result in an error, since trying to remap the same block to two sets/bindings isn't really correct.
Do some requirements treat the global uniform on shaders at different stages as independent blocks?
If they have different names then I think they can be independent between stages (not sure if this workflow is well tested). However if they have the same name they will be merged together since you can't have different blocks with the same name declared in a program
Yes,you are right in es 1.0.but I can use different sets in Different vulkan-shader of same name. So.I wrote different "setResourceSetBinding" in my program.I think this right.
oh interesting, can you point me to the spec what allows for that?
hhhhhhh,sorry.this is my problem.I corrected.
@lance5 Is there still any issue here that needs to be investigated, or can we close this?
I'm going to close this for now, feel free to reopen this issue or open a new one if you think there is still a problem that needs to be fixed.