Can someone please explain DescriptorHandle for Bindless Descriptor Access #8610
Replies: 4 comments
-
|
uniform Texture2D textures[]; // Approach A They are fundamentally different:
How Handles Actually WorkCPU Side - Create Global Heap (One Time Setup)// DX12 Example
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {
.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
.NumDescriptors = 1000000, // Million descriptors!
.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE
};
device->CreateDescriptorHeap(&heapDesc, &globalHeap);
// Put textures into the heap
for (int i = 0; i < numTextures; i++) {
device->CreateShaderResourceView(
textures[i],
nullptr,
globalHeap->GetCPUDescriptorHandleForHeapStart()
+ i * heapIncrement
);
}CPU Side - Create Handle Buffer (Per-Frame/Material)GPU Side - Shader Accesses HandleSlang - Backend Code GenerationNote:
|
Beta Was this translation helpful? Give feedback.
-
|
@szihs Ah thank you so much for this explanation. So... in the Vulkan case, (I'm not familiar with DirectX), when you do: The 'textureHandles' would be something like a storage buffer bound to a descriptor set, containing a list of indices. You use materialID to index into textureHandle, and that just gives another integer (or two or whatever). Then, with this integer you index into what you call the DescriptorHeap, which in DirectX is something I don't understand, but in Vulkan is just simply this:
So ^^^ that is basically the equivalent of the 'descriptor heap'. Ahh thank you for explaining it. The DescriptorHandle is just an integer (or two), which is bound as a storage buffer in Vulkan. Now that I know that DescriptorHandle is just an integer bound to a storage buffer, I think I'll skip it and just use my own integers. Why in the Slang backend code did you write: Why set = 10? Also, I never understood how in Slang documentation binding descriptor sets is recommended to be done automatically, not manually by specifying the set and binding, but just letting Slang select the descriptor set. This is because in your host-side code you still have to bind particular descriptor sets, and at least in Vulkan the sequence of them is important, so like if you have descriptor sets 1, 2, 3, 4 bound, and you then bind another descriptor set at 2, then 3 and 4 are invalid and need to be set again. What I'm saying is that descriptor sets, at least in Vulkan, are very specific and the programmer has to know exactly which ones need to be bound, I can't understand how automatic deduction of descriptor set binding numbers is possible or a good idea. |
Beta Was this translation helpful? Give feedback.
-
|
@szihs Hmm, I know that in the documentation here it explains that DescriptorHandle is just an integer (or two), but it might be good to explain that: Is just a buffer (either storage or uniform) of integers that you set from the host side. And also that the "Descriptor Heap" in something like Vulkan is just:
or |
Beta Was this translation helpful? Give feedback.
-
|
The
You can also query the assigned bindings using Slang's reflection API to know what to bind on the host side. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've read through the documentation about 4 times and I still don't understand what it does or how it's used. Please someone help and explain?
In GLSL to use bindless with Vulkan I'd do:
layout(set = 1, binding = 2) uniform texture2D textures[];And in Slang I can do:
[[vk::binding(2,1)]] Texture2D textures[];or
layout(set = 1, binding = 2) Texture2D textures[];This is a descriptor array bound to a certain descriptor set, that I bind manually in Vulkan API on the host-side.
OK, now we have:
DescriptorHandle<T>And the example shows this:
What I want to know is, leaving out the explicit binding, this:
uniform StructuredBuffer<DescriptorHandle<Texture2D>> textures;What is the relation between this and simply:
uniform Texture2D textures[];A StructuredBuffer as a uniform is basically equivalent to:
uniform T name[]???
And then what is the difference between:
uniform StructuredBuffer<DescriptorHandle<Texture2D>> my_array;and
uniform Textured2D my_array[];?
In uniform Texture2D my_array[]; I bind an array of texture descriptors to that uniform and what I am indexing in that array are 'Descriptors' which have been bound. I understand DescriptorHandle is an id (two integers), but how are they supposed to be set? Am I supposed to bind a buffer of integers instead of an array of image descriptors?
Beta Was this translation helpful? Give feedback.
All reactions