Vulkan NonUniformResourceIndex in Vulkan glsl

Recommended Posts

Posted (edited)

I need to index into a texture array using indices which are not dynamically uniform. This works fine on NVIDIA chips but you can see the artifacts on AMD due to the wavefront problem. This means, a lot of pixel invocations get the wrong index value. I know you fix this by using NonUniformResourceIndex in hlsl. Is there an equivalent for Vulkan glsl?

This is the shader code for reference. As you can see, index is an arbitrary value for each pixel and is not dynamically uniform. I fix this for hlsl by using NonUniformResourceIndex(index)

layout(set = 0, binding = 0) uniform sampler textureSampler;
layout(set = 0, binding = 1) uniform texture2D albedoMaps[256];

layout(location = 0) out vec4 oColor;

void main()
{
uint index = calculate_arbitrary_texture_index();
vec2 texCoord = calculate_texcoord();
vec4 albedo = texture(sampler2D(albedoMaps[index], textureSampler), texCoord);

oColor = albedo;
}

Thank you

Edited by mark_braga

Share on other sites

I'm not a Vulkan guy, but I Googled it and came across this information. It should set you on the right path:

Quote

shaderSampledImageArrayDynamicIndexing indicates whether arrays of samplers or sampled images can be indexed by dynamically uniform integer expressions in shader code. If this feature is not enabled, resources with a descriptor type of VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, orVK_DESCRIPTOR_TYPE_SAMPLED_IMAGE must be indexed only by constant integral expressions when aggregated into arrays in shader code. This also indicates whether shader modules can declare theSampledImageArrayDynamicIndexing capability.

Chances are this bool is true for NVIDIA and false for AMD?

Share on other sites
Posted (edited)

Vulkan doesn't have this intrinsic.

You'll have to do by hand what the compiler does for you when shaderSampledImageArrayDynamicIndexing is set to False:

uint NonUniformResourceIndex( uint textureIdx )
{
while (true)
{

if (currentIdx == textureIdx)
return currentIdx;
}

return 0; //Execution should never land here
}

Cheers

Matias

Edited by Matias Goldberg

Create an account

Register a new account

• Forum Statistics

• Total Topics
628366
• Total Posts
2982274
• Similar Content

• By dwatt
I am trying to get vulkan on android working and have run into a big issue. I don't see any validation layers available. I have tried linking their libraries into mine but still no layers. I have tried compiling it into a library of my own but the headers for it are all over the place. Unfortunately , google's examples and tutorials are out of date and don't work for me. Any idea what I have to do to get those layers to work?

• Hi, New here.
I need some help. My fiance and I like to play this mobile game online that goes by real time. Her and I are always working but when we have free time we like to play this game. We don't always got time throughout the day to Queue Buildings, troops, Upgrades....etc....
I was told to look into DLL Injection and OpenGL/DirectX Hooking. Is this true? Is this what I need to learn?
How do I read the Android files, or modify the files, or get the in-game tags/variables for the game I want?
Any assistance on this would be most appreciated. I been everywhere and seems no one knows or is to lazy to help me out. It would be nice to have assistance for once. I don't know what I need to learn.
So links of topics I need to learn within the comment section would be SOOOOO.....Helpful. Anything to just get me started.
Thanks,
Dejay Hextrix

• It seems like nobody really knows what is the correct behavior after window minimizes in Vulkan.
I have looked at most of the examples (Sascha Willems, GPUOpen,...) and all of them crash after the window minimize event with the error VK_ERROR_OUT_OF_DATE either with an assertion during acquire image or after calling present. This is because we have to recreate the swap chain.
I tried this but then Vulkan expects you to provide a swap chain with extents { 0, 0, 0, 0 }, but now if you try to set the viewport or create new image views with extents { 0, 0, 0, 0 }, Vulkan expects you to provide non-zero values. So now I am confused.
Should we just do nothing after a window minimize event? No rendering, update, ...?
• By HD86
As far as I know, the size of XMMATRIX must be 64 bytes, which is way too big to be returned by a function. However, DirectXMath functions do return this struct. I suppose this has something to do with the SIMD optimization. Should I return this huge struct from my own functions or should I pass it by a reference or pointer?
This question will look silly to you if you know how SIMD works, but I don't.
• By lubbe75
I am looking for some example projects and tutorials using sharpDX, in particular DX12 examples using sharpDX. I have only found a few. Among them the porting of Microsoft's D3D12 Hello World examples (https://github.com/RobyDX/SharpDX_D3D12HelloWorld), and Johan Falk's tutorials (http://www.johanfalk.eu/).
For instance, I would like to see an example how to use multisampling, and debugging using sharpDX DX12.
Let me know if you have any useful examples.
Thanks!

• 10
• 9
• 13
• 24
• 11