Skip to content

Commit

Permalink
Fix buffer range checks
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 12, 2024
1 parent a4886d5 commit 55b4318
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void kope_d3d12_command_list_draw_indexed(kope_g5_command_list *list, uint32_t i
}

void kope_d3d12_command_list_set_descriptor_table(kope_g5_command_list *list, uint32_t table_index, kope_d3d12_descriptor_set *set,
kope_g5_buffer **dynamic_buffers, uint32_t *dynamic_offsets) {
kope_g5_buffer **dynamic_buffers, uint32_t *dynamic_offsets, uint32_t *dynamic_sizes) {
if (set->descriptor_count > 0) {
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;
Expand All @@ -249,7 +249,7 @@ void kope_d3d12_command_list_set_descriptor_table(kope_g5_command_list *list, ui
for (uint32_t descriptor_index = 0; descriptor_index < set->dynamic_descriptor_count; ++descriptor_index) {
D3D12_CONSTANT_BUFFER_VIEW_DESC desc = {};
desc.BufferLocation = dynamic_buffers[descriptor_index]->d3d12.resource->GetGPUVirtualAddress() + dynamic_offsets[descriptor_index];
desc.SizeInBytes = (UINT)dynamic_buffers[descriptor_index]->d3d12.size - dynamic_offsets[descriptor_index];
desc.SizeInBytes = (UINT)dynamic_sizes[descriptor_index];

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;
Expand Down Expand Up @@ -760,11 +760,11 @@ void kope_d3d12_command_list_compute_indirect(kope_g5_command_list *list, kope_g
list->d3d12.list->ExecuteIndirect(list->d3d12.compute_pipe->compute_command_signature, 1, indirect_buffer->d3d12.resource, indirect_offset, NULL, 0);
}

void kope_d3d12_command_list_queue_buffer_access(kope_g5_command_list *list, kope_g5_buffer *buffer) {
void kope_d3d12_command_list_queue_buffer_access(kope_g5_command_list *list, kope_g5_buffer *buffer, uint32_t offset, uint32_t size) {
kope_d3d12_buffer_access access;
access.buffer = buffer;
access.offset = 0;
access.size = UINT64_MAX;
access.offset = offset;
access.size = size;

list->d3d12.queued_buffer_accesses[list->d3d12.queued_buffer_accesses_count] = access;
list->d3d12.queued_buffer_accesses_count += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void kope_d3d12_command_list_draw_indexed(kope_g5_command_list *list, uint32_t i
uint32_t first_instance);

void kope_d3d12_command_list_set_descriptor_table(kope_g5_command_list *list, uint32_t table_index, kope_d3d12_descriptor_set *set,
kope_g5_buffer **dynamic_buffers, uint32_t *dynamic_offsets);
kope_g5_buffer **dynamic_buffers, uint32_t *dynamic_offsets, uint32_t *dynamic_sizes);

void kope_d3d12_command_list_set_root_constants(kope_g5_command_list *list, uint32_t table_index, const void *data, size_t data_size);

Expand Down Expand Up @@ -99,7 +99,7 @@ void kope_d3d12_command_list_draw_indexed_indirect(kope_g5_command_list *list, k

void kope_d3d12_command_list_compute_indirect(kope_g5_command_list *list, kope_g5_buffer *indirect_buffer, uint64_t indirect_offset);

void kope_d3d12_command_list_queue_buffer_access(kope_g5_command_list *list, kope_g5_buffer *buffer);
void kope_d3d12_command_list_queue_buffer_access(kope_g5_command_list *list, kope_g5_buffer *buffer, uint32_t offset, uint32_t size);

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void kope_d3d12_descriptor_set_set_sampler(kope_g5_device *device, kope_d3d12_de
device->d3d12.device->CopyDescriptorsSimple(1, dst_handle, src_handle, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
}

void kope_d3d12_descriptor_set_prepare_cbv_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer) {
void kope_d3d12_descriptor_set_prepare_cbv_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer, uint32_t offset, uint32_t size) {
if (buffer->d3d12.resource_state != D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER && buffer->d3d12.resource_state != D3D12_RESOURCE_STATE_GENERIC_READ) {
D3D12_RESOURCE_BARRIER barrier;
barrier.Transition.pResource = buffer->d3d12.resource;
Expand All @@ -161,7 +161,7 @@ void kope_d3d12_descriptor_set_prepare_cbv_buffer(kope_g5_command_list *list, ko
}

if (buffer->d3d12.cpu_read || buffer->d3d12.cpu_write) {
kope_d3d12_command_list_queue_buffer_access(list, buffer);
kope_d3d12_command_list_queue_buffer_access(list, buffer, offset, size);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void kope_d3d12_descriptor_set_set_texture_view_uav(kope_g5_device *device, kope
uint32_t index);
void kope_d3d12_descriptor_set_set_sampler(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_sampler *sampler, uint32_t index);

void kope_d3d12_descriptor_set_prepare_cbv_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer);
void kope_d3d12_descriptor_set_prepare_cbv_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer, uint32_t offset, uint32_t size);
void kope_d3d12_descriptor_set_prepare_srv_texture(kope_g5_command_list *list, const kope_g5_texture_view *texture_view);
void kope_d3d12_descriptor_set_prepare_uav_texture(kope_g5_command_list *list, const kope_g5_texture_view *texture_view);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_comm
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;
buffer->d3d12.ranges_count += 1;
}
list->d3d12.queued_buffer_accesses_count = 0;

Expand Down

0 comments on commit 55b4318

Please sign in to comment.