Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPIR-V dynamic indexing capabilities not generated in all cases #2056

Open
rg3igalia opened this issue Jan 10, 2020 · 5 comments
Open

SPIR-V dynamic indexing capabilities not generated in all cases #2056

rg3igalia opened this issue Jan 10, 2020 · 5 comments

Comments

@rg3igalia
Copy link
Contributor

There is a set of tests in VK-GL-CTS that use dynamically uniform indexes when accessing arrays of descriptors of different types, like uniform buffers, storage buffers, storage texel buffers, etc.

These tests check for the corresponding feature to be available and enabled in the device, as you can see here:

https://github.com/KhronosGroup/VK-GL-CTS/blob/d99a765d38d35deeb3f27cf30d9d6fe4f183510e/external/vulkancts/modules/vulkan/binding_model/vktBindingDescriptorSetRandomTests.cpp#L218

If dynamic indexing is supported and the index type is "DEPENDENT", for example, these tests generate code like the following one:

#version 450 core
#extension GL_EXT_nonuniform_qualifier : enable
layout(r32i, set = 0, binding = 0) uniform iimage2D simage0_0;
layout(set = 1, binding = 0) uniform ubodef1_0 { int val; } ubo1_0[5];
layout(set = 1, binding = 2) uniform ubodef1_2 { int val; } ubo1_2[3];
layout(set = 3, binding = 6) uniform ubodef3_6 { int val; } ubo3_6[1];
layout(set = 7, binding = 2) uniform ubodef7_2 { int val; } ubo7_2[2];
layout(set = 7, binding = 7) uniform ubodef7_7 { int val; } ubo7_7[1];
layout(local_size_x = 1, local_size_y = 1) in;
void main()
{
  int accum = 0, temp;
  temp = ubo1_0[accum + 0].val; 
  accum = temp - 1;
  temp = ubo1_0[accum + 1].val; 
  accum = temp - 2;
  temp = ubo1_0[accum + 2].val; 
  accum = temp - 3;
  temp = ubo1_0[accum + 4].val; 
  accum = temp - 5;
  temp = ubo1_2[accum + 0].val; 
  accum = temp - 6;
  temp = ubo1_2[accum + 1].val; 
  accum = temp - 7;
  temp = ubo1_2[accum + 2].val; 
  accum = temp - 8;
  temp = ubo3_6[accum + 0].val; 
  accum = temp - 9;
  temp = ubo7_2[accum + 0].val; 
  accum = temp - 10;
  temp = ubo7_2[accum + 1].val; 
  accum = temp - 11;
  temp = ubo7_7[accum + 0].val; 
  accum = temp - 12;
  ivec4 color = (accum != 0) ? ivec4(0,0,0,0) : ivec4(1,0,0,1);
  imageStore(simage0_0, ivec2(gl_GlobalInvocationID.xy), color); 
}

However, when this specific GLSL shader is compiled to SPIR-V, the output does not declare the UniformBufferArrayDynamicIndexing capability, which I believe needs to be declared for the generated code to work (NB: vendors are still passing these tests, so it's probably not critical). The same problem is also happening with other DynamicIndexing capabilities.

@johnkslang
Copy link
Member

Yes, I see these are not generated, apparently since the beginning. They are supposed to be needed for devices that can't support them, but if everything is supporting them, that may call into question their necessity.

For background, I see this in the 3.2 ES GLSL spec:

All indices used to index a shader storage block array must be constant integral expressions. A uniform block array can only be indexed with a dynamically uniform integral expression, otherwise results are undefined.

So, it seems like some device should have trouble.

@rg3igalia
Copy link
Contributor Author

I'd guess devices supporting non constant indices will "handle the situation" no matter if the capability is requested by the shader or not, so checking for the feature being available from Vulkan is enough to make sure that type of constructions can be used (i.e. devices not supporting non constant indices will have those feature bits set to false). But, from the point of view of SPIR-V and GLSL, which may be used without Vulkan, requesting that capability could be important for devices not supporting these features so they can error out at some point.

@null77
Copy link
Contributor

null77 commented Mar 6, 2020

This might be an issue for ANGLE on Android when we support devices that don't have this feature enabled.

@Rua
Copy link

Rua commented May 3, 2021

What is the current status on this issue?

@greg-lunarg
Copy link
Contributor

I see priority for this as medium since it is not preventing valid Vulkan code from running. Does anyone disagree?

As such, I don't anticipate working on this in the very near term.

I am not aware of anyone actively working on this People are invited to contribute a fix. Please put a comment on this issue if you start work to prevent duplicate effort.

rdb added a commit to panda3d/panda3d that referenced this issue Jan 24, 2023
We unfortunately can't rely on glslang to set the required capability, see KhronosGroup/glslang#2056 - therefore we have no choice but to just check for it ourselves
lachbr pushed a commit to toontownretro/panda that referenced this issue Jun 15, 2023
We unfortunately can't rely on glslang to set the required capability, see KhronosGroup/glslang#2056 - therefore we have no choice but to just check for it ourselves
lachbr pushed a commit to lachbr/panda3d that referenced this issue Jun 16, 2023
We unfortunately can't rely on glslang to set the required capability, see KhronosGroup/glslang#2056 - therefore we have no choice but to just check for it ourselves
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants