Skip to content

Commit

Permalink
Fix the bvh
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 16, 2024
1 parent 8009020 commit a83e0c8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ void kope_d3d12_command_list_prepare_raytracing_volume(kope_g5_command_list *lis
build_desc.ScratchAccelerationStructureData = volume->d3d12.scratch_buffer.d3d12.resource->GetGPUVirtualAddress();

list->d3d12.list->BuildRaytracingAccelerationStructure(&build_desc, 0, nullptr);

D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
barrier.UAV.pResource = volume->d3d12.acceleration_structure.d3d12.resource;

list->d3d12.list->ResourceBarrier(1, &barrier);
}

void kope_d3d12_command_list_prepare_raytracing_hierarchy(kope_g5_command_list *list, kope_g5_raytracing_hierarchy *hierarchy) {
Expand All @@ -259,6 +265,12 @@ void kope_d3d12_command_list_prepare_raytracing_hierarchy(kope_g5_command_list *
build_desc.ScratchAccelerationStructureData = hierarchy->d3d12.scratch_buffer.d3d12.resource->GetGPUVirtualAddress();

list->d3d12.list->BuildRaytracingAccelerationStructure(&build_desc, 0, nullptr);

D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
barrier.UAV.pResource = hierarchy->d3d12.acceleration_structure.d3d12.resource;

list->d3d12.list->ResourceBarrier(1, &barrier);
}

void kope_d3d12_command_list_set_ray_pipeline(kope_g5_command_list *list, kope_d3d12_ray_pipeline *pipeline) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ void kope_d3d12_descriptor_set_set_buffer_view_srv(kope_g5_device *device, kope_
device->d3d12.device->CreateShaderResourceView(buffer->d3d12.resource, &desc, descriptor_handle);
}

void kope_d3d12_descriptor_set_set_bvh_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_buffer *buffer, uint32_t index) {
D3D12_SHADER_RESOURCE_VIEW_DESC desc = {};
desc.ViewDimension = D3D12_SRV_DIMENSION_RAYTRACING_ACCELERATION_STRUCTURE;
desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
desc.Format = DXGI_FORMAT_UNKNOWN;
desc.RaytracingAccelerationStructure.Location = buffer->d3d12.resource->GetGPUVirtualAddress();

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;
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, kope_g5_texture *texture, uint32_t index) {
D3D12_SHADER_RESOURCE_VIEW_DESC desc = {};
desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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_buffer *buffer, uint32_t index);
void kope_d3d12_descriptor_set_set_texture_view_srv(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_texture *texture, uint32_t index);
void kope_d3d12_descriptor_set_set_texture_view_uav(kope_g5_device *device, kope_d3d12_descriptor_set *set, kope_g5_texture *texture, 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);
Expand Down
11 changes: 8 additions & 3 deletions Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,15 @@ void kope_d3d12_device_create_buffer(kope_g5_device *device, const kope_g5_buffe
heapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
}

D3D12_RESOURCE_DESC resourceDesc;
D3D12_RESOURCE_DESC resourceDesc = {};
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
resourceDesc.Alignment = 0;
resourceDesc.Width = align_pow2((int)parameters->size, 256); // 256 required for CBVs
if ((parameters->usage_flags & KOPE_G5_BUFFER_USAGE_RAYTRACING_VOLUME) != 0 || (parameters->usage_flags & KOPE_G5_BUFFER_USAGE_READ_WRITE) != 0) {
resourceDesc.Width = parameters->size;
}
else {
resourceDesc.Width = align_pow2((int)parameters->size, 256); // 256 required for CBVs
}
resourceDesc.Height = 1;
resourceDesc.DepthOrArraySize = 1;
resourceDesc.MipLevels = 1;
Expand All @@ -227,7 +232,7 @@ void kope_d3d12_device_create_buffer(kope_g5_device *device, const kope_g5_buffe

if ((parameters->usage_flags & KOPE_G5_BUFFER_USAGE_RAYTRACING_VOLUME) != 0) {
buffer->d3d12.resource_state = D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE;
resourceDesc.Flags |= D3D12_RESOURCE_FLAG_RAYTRACING_ACCELERATION_STRUCTURE;
resourceDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
}

kinc_microsoft_affirm(device->d3d12.device->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDesc,
Expand Down

0 comments on commit a83e0c8

Please sign in to comment.