Skip to content

Commit

Permalink
Allocate descriptor space for dynamic offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 9, 2024
1 parent a6e4464 commit ab3632c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,30 @@ void kope_d3d12_command_list_set_descriptor_table(kope_g5_command_list *list, ui
}

if (set->dynamic_descriptor_count > 0) {
uint32_t offset = list->d3d12.dynamic_descriptor_allocations[list->d3d12.current_allocator_index].offset +
list->d3d12.dynamic_descriptor_offsets[list->d3d12.current_allocator_index];

for (uint32_t descriptor_index = 0; descriptor_index < set->dynamic_descriptor_count; ++descriptor_index) {
D3D12_CONSTANT_BUFFER_VIEW_DESC desc = {};
// desc.BufferLocation = buffer->d3d12.resource->GetGPUVirtualAddress() + dynamic_offsets[descriptor_index];
// desc.SizeInBytes = align_pow2((int)buffer->d3d12.size, 256);

D3D12_CPU_DESCRIPTOR_HANDLE descriptor_handle = list->d3d12.device->descriptor_heap->GetCPUDescriptorHandleForHeapStart();
descriptor_handle.ptr += (offset + descriptor_index) * list->d3d12.device->cbv_srv_uav_increment;
list->d3d12.device->device->CreateConstantBufferView(&desc, descriptor_handle);
}

D3D12_GPU_DESCRIPTOR_HANDLE gpu_descriptor = list->d3d12.device->descriptor_heap->GetGPUDescriptorHandleForHeapStart();
/*gpu_descriptor.ptr += set->descriptor_allocation.offset * list->d3d12.device->cbv_srv_uav_increment;
gpu_descriptor.ptr += 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);
list->d3d12.list->SetComputeRootDescriptorTable(table_index, gpu_descriptor);
}
else {
list->d3d12.list->SetGraphicsRootDescriptorTable(table_index, gpu_descriptor);
}*/
list->d3d12.list->SetGraphicsRootDescriptorTable(table_index, gpu_descriptor);
}

list->d3d12.dynamic_descriptor_offsets[list->d3d12.current_allocator_index] += (uint32_t)set->dynamic_descriptor_count;

table_index += 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "d3d12mini.h"

#include <kope/util/offalloc/offalloc.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -20,6 +22,8 @@ struct ID3D12Fence;
// allocators. Increasing this value exchanges more memory against potentially less wait-times (depending on actual command-list usage).
#define KOPE_D3D12_COMMAND_LIST_ALLOCATOR_COUNT 3

#define KOPE_D3D12_COMMAND_LIST_DYNAMIC_DESCRIPTORS_COUNT 64

#define KOPE_D3D12_COMMAND_LIST_MAX_QUEUED_BUFFER_ACCESSES 256

typedef struct kope_d3d12_buffer_access {
Expand All @@ -33,6 +37,8 @@ typedef struct kope_d3d12_command_list {

struct ID3D12CommandAllocator *allocator[KOPE_D3D12_COMMAND_LIST_ALLOCATOR_COUNT];
uint64_t allocator_execution_index[KOPE_D3D12_COMMAND_LIST_ALLOCATOR_COUNT];
oa_allocation_t dynamic_descriptor_allocations[KOPE_D3D12_COMMAND_LIST_ALLOCATOR_COUNT];
uint32_t dynamic_descriptor_offsets[KOPE_D3D12_COMMAND_LIST_ALLOCATOR_COUNT];
uint8_t current_allocator_index;

struct ID3D12GraphicsCommandList4 *list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ void kope_d3d12_device_create_command_list(kope_g5_device *device, kope_g5_comma
for (int i = 0; i < KOPE_D3D12_COMMAND_LIST_ALLOCATOR_COUNT; ++i) {
kinc_microsoft_affirm(device->d3d12.device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_GRAPHICS_PPV_ARGS(&list->d3d12.allocator[i])));
list->d3d12.allocator_execution_index[i] = 0;

oa_allocate(&device->d3d12.descriptor_heap_allocator, KOPE_D3D12_COMMAND_LIST_DYNAMIC_DESCRIPTORS_COUNT,
&list->d3d12.dynamic_descriptor_allocations[i]);
list->d3d12.dynamic_descriptor_offsets[i] = 0;
}

list->d3d12.current_allocator_index = 0;
Expand Down

0 comments on commit ab3632c

Please sign in to comment.