Skip to content

Commit 0efca93

Browse files
committed
Use non-uniform indexing to access textures
1 parent 0c71320 commit 0efca93

7 files changed

Lines changed: 8 additions & 3 deletions

File tree

samples/extensions/descriptor_heap/descriptor_heap.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ DescriptorHeap::DescriptorHeap()
2626
add_device_extension(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2727
add_device_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
2828
add_device_extension(VK_EXT_DESCRIPTOR_HEAP_EXTENSION_NAME);
29+
add_device_extension(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME);
2930
}
3031

3132
DescriptorHeap::~DescriptorHeap()
@@ -73,6 +74,8 @@ void DescriptorHeap::request_gpu_features(vkb::core::PhysicalDeviceC &gpu)
7374

7475
// We need to enable the descriptor heap feature to make use of them
7576
REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceDescriptorHeapFeaturesEXT, descriptorHeap);
77+
// The way we index inside the shader also requires use of non-uniform indexing
78+
REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceDescriptorIndexingFeaturesEXT, shaderSampledImageArrayNonUniformIndexing);
7679

7780
if (gpu.get_features().samplerAnisotropy)
7881
{

shaders/descriptor_heap/glsl/cube.frag

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19+
#extension GL_EXT_nonuniform_qualifier : require
20+
1921
layout (set = 1, binding = 0) uniform texture2D textureImage[2];
2022
layout (set = 2, binding = 0) uniform sampler textureSampler[2];
2123

@@ -31,5 +33,5 @@ layout (location = 0) out vec4 outFragColor;
3133

3234
void main()
3335
{
34-
outFragColor = texture(sampler2D(textureImage[inInstanceIndex], textureSampler[pushConsts.samplerIndex]), inUV);
36+
outFragColor = texture(sampler2D(textureImage[nonuniformEXT(inInstanceIndex)], textureSampler[pushConsts.samplerIndex]), inUV);
3537
}
132 Bytes
Binary file not shown.

shaders/descriptor_heap/hlsl/cube.frag.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ struct PushConsts
3636

3737
float4 main(VSOutput input) : SV_TARGET0
3838
{
39-
return textureImage[input.InstanceIndex].Sample(textureSampler[pushConsts.samplerIndex], input.UV);
39+
return textureImage[NonUniformResourceIndex(input.InstanceIndex)].Sample(textureSampler[pushConsts.samplerIndex], input.UV);
4040
}
112 Bytes
Binary file not shown.

shaders/descriptor_heap/slang/cube.frag.slang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ struct VSOutput
2828
[shader("fragment")]
2929
float4 main(VSOutput input, uniform int samplerIndex, uniform int frameIndex)
3030
{
31-
return textureImage[input.InstanceIndex].Sample(textureSampler[samplerIndex], input.UV);
31+
return textureImage[NonUniformResourceIndex(input.InstanceIndex)].Sample(textureSampler[samplerIndex], input.UV);
3232
}
64 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)