Skip to content

Commit

Permalink
use committed resource in Accel to avoid potential driver bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellGengYF committed Sep 26, 2024
1 parent 02acc3d commit fecdc45
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/backends/dx/Resource/BottomAccel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ size_t BottomAccel::PreProcessStates(
accelBuffer = vstd::create_unique(new DefaultBuffer(
device,
CalcAlign(bottomLevelPrebuildInfo.ResultDataMaxSizeInBytes, 65536),
device->defaultAllocator.get(),
nullptr,
D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE,
false,
"blas-accel-buffer"));
Expand Down Expand Up @@ -164,7 +164,7 @@ bool BottomAccel::CheckAccel(
auto newAccelBuffer = vstd::create_unique(new DefaultBuffer(
device,
CalcAlign(compactSize, 65536),
device->defaultAllocator.get(),
nullptr,
D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE,
false,
"blas-accel-buffer"));
Expand Down
19 changes: 11 additions & 8 deletions src/backends/dx/Resource/TopAccel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ bool TopAccel::GenerateNewBuffer(
char const *name,
ResourceStateTracker &tracker,
CommandBufferBuilder &builder,
vstd::unique_ptr<DefaultBuffer> &oldBuffer, size_t newSize, bool needCopy, D3D12_RESOURCE_STATES state) {
vstd::unique_ptr<DefaultBuffer> &oldBuffer, size_t newSize, bool needCopy, D3D12_RESOURCE_STATES state,
GpuAllocator *allocator) {
if (!oldBuffer) {
newSize = CalcAlign(newSize, 65536);
oldBuffer = vstd::create_unique(new DefaultBuffer(
device,
newSize,
device->defaultAllocator.get(),
allocator,
state,
false,
name));
Expand All @@ -79,7 +80,7 @@ bool TopAccel::GenerateNewBuffer(
auto newBuffer = new DefaultBuffer(
device,
newSize,
device->defaultAllocator.get(),
allocator,
state);
if (needCopy) {
tracker.RecordState(
Expand Down Expand Up @@ -125,7 +126,7 @@ void TopAccel::PreProcessInst(
size_t instanceByteCount = size * sizeof(D3D12_RAYTRACING_INSTANCE_DESC);
if (GenerateNewBuffer(
"tlas-instance-buffer",
tracker, builder, instBuffer, instanceByteCount, true, tracker.ReadState(ResourceReadUsage::AccelBuildSrc))) {
tracker, builder, instBuffer, instanceByteCount, true, tracker.ReadState(ResourceReadUsage::AccelBuildSrc), device->defaultAllocator.get())) {
input.InstanceDescs = instBuffer->GetAddress();
}
}
Expand Down Expand Up @@ -232,11 +233,11 @@ size_t TopAccel::PreProcess(
size_t instanceByteCount = size * sizeof(D3D12_RAYTRACING_INSTANCE_DESC);
if (GenerateNewBuffer(
"tlas-instance-buffer",
tracker, builder, instBuffer, instanceByteCount, true, tracker.ReadState(ResourceReadUsage::AccelBuildSrc))) {
tracker, builder, instBuffer, instanceByteCount, true, tracker.ReadState(ResourceReadUsage::AccelBuildSrc), device->defaultAllocator.get())) {
input.InstanceDescs = instBuffer->GetAddress();
}
device->device->GetRaytracingAccelerationStructurePrebuildInfo(&input, &topLevelPrebuildInfo);
if (GenerateNewBuffer("tlas-accel-buffer", tracker, builder, accelBuffer, topLevelPrebuildInfo.ResultDataMaxSizeInBytes, false, D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE)) {
if (GenerateNewBuffer("tlas-accel-buffer", tracker, builder, accelBuffer, topLevelPrebuildInfo.ResultDataMaxSizeInBytes, false, D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE, nullptr)) {
update = false;
topLevelBuildDesc.DestAccelerationStructureData = accelBuffer->GetAddress();
}
Expand Down Expand Up @@ -347,8 +348,10 @@ bool TopAccel::CheckAccel(
auto newAccelBuffer = vstd::create_unique(new DefaultBuffer(
device,
CalcAlign(compactSize, 65536),
device->defaultAllocator.get(),
D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE));
nullptr,
D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE,
false,
"tlas-accel-buffer"));

builder.GetCB()->CmdList()->CopyRaytracingAccelerationStructure(
newAccelBuffer->GetAddress(),
Expand Down
3 changes: 2 additions & 1 deletion src/backends/dx/Resource/TopAccel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class TopAccel : public Resource {
char const *name,
ResourceStateTracker &tracker,
CommandBufferBuilder &builder,
vstd::unique_ptr<DefaultBuffer> &oldBuffer, size_t newSize, bool needCopy, D3D12_RESOURCE_STATES state);
vstd::unique_ptr<DefaultBuffer> &oldBuffer, size_t newSize, bool needCopy, D3D12_RESOURCE_STATES state,
GpuAllocator* allocator);
void InitSetDesc(vstd::span<AccelBuildCommand::Modification const> const &modifications);
void ProcessSetDesc();
void ProcessSetMap();
Expand Down

0 comments on commit fecdc45

Please sign in to comment.