Skip to content

Commit

Permalink
Make descriptor sets support bindless
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 21, 2024
1 parent 72be90c commit 4b1eafb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ void kope_d3d12_command_list_set_descriptor_table(kope_g5_command_list *list, ui
table_index += 1;
}

if (set->bindless_descriptor_count > 0) {
D3D12_GPU_DESCRIPTOR_HANDLE gpu_descriptor = list->d3d12.device->descriptor_heap->GetGPUDescriptorHandleForHeapStart();
gpu_descriptor.ptr += set->bindless_descriptor_allocation.offset * list->d3d12.device->cbv_srv_uav_increment;
if (list->d3d12.compute_pipe != NULL || list->d3d12.ray_pipe != NULL) {
list->d3d12.list->SetComputeRootDescriptorTable(table_index, gpu_descriptor);
}
else {
list->d3d12.list->SetGraphicsRootDescriptorTable(table_index, gpu_descriptor);
}
table_index += 1;
}

if (set->sampler_count > 0) {
D3D12_GPU_DESCRIPTOR_HANDLE gpu_descriptor = list->d3d12.device->sampler_heap->GetGPUDescriptorHandleForHeapStart();
gpu_descriptor.ptr += set->sampler_allocation.offset * list->d3d12.device->sampler_increment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ void kope_d3d12_descriptor_set_set_bvh_view_srv(kope_g5_device *device, kope_d3d
device->d3d12.device->CreateShaderResourceView(nullptr, &desc, descriptor_handle);
}

void kope_d3d12_descriptor_set_set_texture_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, const kope_g5_texture_view *texture_view,
uint32_t index) {
void kope_d3d12_descriptor_set_set_texture_view_srv(kope_g5_device *device, uint32_t offset, const kope_g5_texture_view *texture_view) {
D3D12_SHADER_RESOURCE_VIEW_DESC desc = {};
desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
Expand All @@ -66,7 +65,7 @@ void kope_d3d12_descriptor_set_set_texture_view_srv(kope_g5_device *device, kope
desc.Texture2D.ResourceMinLODClamp = 0.0f;

D3D12_CPU_DESCRIPTOR_HANDLE descriptor_handle = device->d3d12.descriptor_heap->GetCPUDescriptorHandleForHeapStart();
descriptor_handle.ptr += (set->descriptor_allocation.offset + index) * device->d3d12.cbv_srv_uav_increment;
descriptor_handle.ptr += offset * device->d3d12.cbv_srv_uav_increment;
device->d3d12.device->CreateShaderResourceView(texture_view->texture->d3d12.resource, &desc, descriptor_handle);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ extern "C" {
void kope_d3d12_descriptor_set_set_buffer_view_cbv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_buffer *buffer, uint32_t index);
void kope_d3d12_descriptor_set_set_buffer_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_buffer *buffer, uint32_t index);
void kope_d3d12_descriptor_set_set_bvh_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_raytracing_hierarchy *bvh, uint32_t index);
void kope_d3d12_descriptor_set_set_texture_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, const kope_g5_texture_view *texture_view,
uint32_t index);
void kope_d3d12_descriptor_set_set_texture_view_srv(kope_g5_device *device, uint32_t offset, const kope_g5_texture_view *texture_view);
void kope_d3d12_descriptor_set_set_texture_array_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, const kope_g5_texture_view *texture_view,
uint32_t index);
void kope_d3d12_descriptor_set_set_texture_cube_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, const kope_g5_texture_view *texture_view,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ typedef struct kope_d3d12_descriptor_set {

size_t dynamic_descriptor_count;

oa_allocation_t bindless_descriptor_allocation;
size_t bindless_descriptor_count;

oa_allocation_t sampler_allocation;
size_t sampler_count;
} kope_d3d12_descriptor_set;
Expand Down
10 changes: 8 additions & 2 deletions Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_comm
kope_d3d12_buffer_access access = list->d3d12.queued_buffer_accesses[buffer_access_index];
kope_g5_buffer *buffer = access.buffer;

assert(buffer->d3d12.ranges_count < KOPE_D3D12_MAX_BUFFER_RANGES);
buffer->d3d12.ranges[buffer->d3d12.ranges_count].execution_index = device->d3d12.execution_index;
buffer->d3d12.ranges[buffer->d3d12.ranges_count].offset = access.offset;
buffer->d3d12.ranges[buffer->d3d12.ranges_count].size = access.size;
Expand Down Expand Up @@ -618,15 +619,20 @@ void kope_d3d12_device_wait_until_idle(kope_g5_device *device) {
wait_for_fence(device, device->d3d12.execution_fence, device->d3d12.execution_event, device->d3d12.execution_index - 1);
}

void kope_d3d12_device_create_descriptor_set(kope_g5_device *device, uint32_t descriptor_count, uint32_t dynamic_descriptor_count, uint32_t sampler_count,
kope_d3d12_descriptor_set *set) {
void kope_d3d12_device_create_descriptor_set(kope_g5_device *device, uint32_t descriptor_count, uint32_t dynamic_descriptor_count,
uint32_t bindless_descriptor_count, uint32_t sampler_count, kope_d3d12_descriptor_set *set) {
if (descriptor_count > 0) {
oa_allocate(&device->d3d12.descriptor_heap_allocator, descriptor_count, &set->descriptor_allocation);
}
set->descriptor_count = descriptor_count;

set->dynamic_descriptor_count = dynamic_descriptor_count;

if (bindless_descriptor_count > 0) {
oa_allocate(&device->d3d12.descriptor_heap_allocator, bindless_descriptor_count, &set->bindless_descriptor_allocation);
}
set->bindless_descriptor_count = bindless_descriptor_count;

if (sampler_count > 0) {
oa_allocate(&device->d3d12.sampler_heap_allocator, sampler_count, &set->sampler_allocation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void kope_d3d12_device_create_command_list(kope_g5_device *device, kope_g5_comma

void kope_d3d12_device_create_texture(kope_g5_device *device, const kope_g5_texture_parameters *parameters, kope_g5_texture *texture);

void kope_d3d12_device_create_descriptor_set(kope_g5_device *device, uint32_t descriptor_count, uint32_t dynamic_descriptor_count, uint32_t sampler_count,
kope_d3d12_descriptor_set *set);
void kope_d3d12_device_create_descriptor_set(kope_g5_device *device, uint32_t descriptor_count, uint32_t dynamic_descriptor_count,
uint32_t bindless_descriptor_count, uint32_t sampler_count, kope_d3d12_descriptor_set *set);

void kope_d3d12_device_create_sampler(kope_g5_device *device, const kope_g5_sampler_parameters *parameters, kope_g5_sampler *sampler);

Expand Down

0 comments on commit 4b1eafb

Please sign in to comment.