Skip to content

Commit

Permalink
fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Jan 18, 2025
1 parent 55db8ab commit f4b3709
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 123 deletions.
31 changes: 14 additions & 17 deletions WickedEngine/wiGraphicsDevice_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,12 +1360,11 @@ namespace dx12_internal

virtual ~Resource_DX12()
{
allocationhandler->destroylocker.lock();
std::scoped_lock lck(allocationhandler->destroylocker);
uint64_t framecount = allocationhandler->framecount;
if (allocation) allocationhandler->destroyer_allocations.push_back(std::make_pair(allocation, framecount));
if (resource) allocationhandler->destroyer_resources.push_back(std::make_pair(resource, framecount));
destroy_subresources();
allocationhandler->destroylocker.unlock();
}
};
struct Texture_DX12 : public Resource_DX12
Expand All @@ -1379,9 +1378,8 @@ namespace dx12_internal

~Texture_DX12() override
{
allocationhandler->destroylocker.lock();
std::scoped_lock lck(allocationhandler->destroylocker);
uint64_t framecount = allocationhandler->framecount;
allocationhandler->destroylocker.unlock();

rtv.destroy();
dsv.destroy();
Expand All @@ -1402,10 +1400,8 @@ namespace dx12_internal

~Sampler_DX12()
{
allocationhandler->destroylocker.lock();
std::scoped_lock lck(allocationhandler->destroylocker);
uint64_t framecount = allocationhandler->framecount;
allocationhandler->destroylocker.unlock();

descriptor.destroy();
}
};
Expand All @@ -1416,10 +1412,9 @@ namespace dx12_internal

~QueryHeap_DX12()
{
allocationhandler->destroylocker.lock();
std::scoped_lock lck(allocationhandler->destroylocker);
uint64_t framecount = allocationhandler->framecount;
if (heap) allocationhandler->destroyer_queryheaps.push_back(std::make_pair(heap, framecount));
allocationhandler->destroylocker.unlock();
}
};
struct PipelineState_DX12
Expand Down Expand Up @@ -1468,11 +1463,10 @@ namespace dx12_internal

~PipelineState_DX12()
{
allocationhandler->destroylocker.lock();
std::scoped_lock lck(allocationhandler->destroylocker);
uint64_t framecount = allocationhandler->framecount;
if (resource) allocationhandler->destroyer_pipelines.push_back(std::make_pair(resource, framecount));
if (rootSignature) allocationhandler->destroyer_rootSignatures.push_back(std::make_pair(rootSignature, framecount));
allocationhandler->destroylocker.unlock();
}
};
struct BVH_DX12 : public Resource_DX12
Expand All @@ -1497,10 +1491,9 @@ namespace dx12_internal

~RTPipelineState_DX12()
{
allocationhandler->destroylocker.lock();
std::scoped_lock lck(allocationhandler->destroylocker);
uint64_t framecount = allocationhandler->framecount;
if (resource) allocationhandler->destroyer_stateobjects.push_back(std::make_pair(resource, framecount));
allocationhandler->destroylocker.unlock();
}
};
struct SwapChain_DX12
Expand All @@ -1519,13 +1512,12 @@ namespace dx12_internal

~SwapChain_DX12()
{
allocationhandler->destroylocker.lock();
std::scoped_lock lck(allocationhandler->destroylocker);
uint64_t framecount = allocationhandler->framecount;
for (auto& x : backBuffers)
{
allocationhandler->destroyer_resources.push_back(std::make_pair(x, framecount));
}
allocationhandler->destroylocker.unlock();
for (auto& x : backbufferRTV)
{
allocationhandler->descriptors_rtv.free(x);
Expand Down Expand Up @@ -1554,11 +1546,10 @@ namespace dx12_internal

~VideoDecoder_DX12()
{
allocationhandler->destroylocker.lock();
std::scoped_lock lck(allocationhandler->destroylocker);
uint64_t framecount = allocationhandler->framecount;
allocationhandler->destroyer_video_decoder_heaps.push_back(std::make_pair(decoder_heap, framecount));
allocationhandler->destroyer_video_decoders.push_back(std::make_pair(decoder, framecount));
allocationhandler->destroylocker.unlock();
}
};

Expand Down Expand Up @@ -3278,6 +3269,7 @@ std::mutex queue_locker;

// D3D12MA ValidateAllocateMemoryParameters requires this, wasn't always true on Xbox:
allocationInfo.SizeInBytes = AlignTo(allocationInfo.SizeInBytes, (UINT64)D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT);
allocationInfo.Alignment = std::max(allocationInfo.Alignment, (UINT64)D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT);

if (resource_heap_tier >= D3D12_RESOURCE_HEAP_TIER_2)
{
Expand Down Expand Up @@ -3609,6 +3601,7 @@ std::mutex queue_locker;

// D3D12MA ValidateAllocateMemoryParameters requires this, wasn't always true on Xbox:
allocationInfo.SizeInBytes = AlignTo(allocationInfo.SizeInBytes, (UINT64)D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT);
allocationInfo.Alignment = std::max(allocationInfo.Alignment, (UINT64)D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT);

if (resource_heap_tier >= D3D12_RESOURCE_HEAP_TIER_2)
{
Expand Down Expand Up @@ -5787,6 +5780,10 @@ std::mutex queue_locker;

void GraphicsDevice_DX12::SparseUpdate(QUEUE_TYPE queue, const SparseUpdateCommand* commands, uint32_t command_count)
{
#ifdef PLATFORM_XBOX
queue = QUEUE_GRAPHICS; // looks like non-graphics queue is a problem for sparse update on xbox (TODO: investigate)
#endif // PLATFORM_XBOX

CommandQueue& q = queues[queue];

thread_local wi::vector<D3D12_TILED_RESOURCE_COORDINATE> tiled_resource_coordinates;
Expand Down
137 changes: 33 additions & 104 deletions WickedEngine/wiGraphicsDevice_DX12.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,131 +546,60 @@ namespace wi::graphics
// Deferred destroy of resources that the GPU is already finished with:
void Update(uint64_t FRAMECOUNT, uint32_t BUFFERCOUNT)
{
destroylocker.lock();
std::scoped_lock lck(destroylocker);
framecount = FRAMECOUNT;
while (!destroyer_allocations.empty())
while (!destroyer_allocations.empty() && destroyer_allocations.front().second + BUFFERCOUNT < FRAMECOUNT)
{
if (destroyer_allocations.front().second + BUFFERCOUNT < FRAMECOUNT)
{
destroyer_allocations.pop_front();
// comptr auto delete
}
else
{
break;
}
destroyer_allocations.pop_front();
// comptr auto delete
}
while (!destroyer_resources.empty())
while (!destroyer_resources.empty() && destroyer_resources.front().second + BUFFERCOUNT < FRAMECOUNT)
{
if (destroyer_resources.front().second + BUFFERCOUNT < FRAMECOUNT)
{
destroyer_resources.pop_front();
// comptr auto delete
}
else
{
break;
}
destroyer_resources.pop_front();
// comptr auto delete
}
while (!destroyer_queryheaps.empty())
while (!destroyer_queryheaps.empty() && destroyer_queryheaps.front().second + BUFFERCOUNT < FRAMECOUNT)
{
if (destroyer_queryheaps.front().second + BUFFERCOUNT < FRAMECOUNT)
{
destroyer_queryheaps.pop_front();
// comptr auto delete
}
else
{
break;
}
destroyer_queryheaps.pop_front();
// comptr auto delete
}
while (!destroyer_pipelines.empty())
while (!destroyer_pipelines.empty() && destroyer_pipelines.front().second + BUFFERCOUNT < FRAMECOUNT)
{
if (destroyer_pipelines.front().second + BUFFERCOUNT < FRAMECOUNT)
{
destroyer_pipelines.pop_front();
// comptr auto delete
}
else
{
break;
}
destroyer_pipelines.pop_front();
// comptr auto delete
}
while (!destroyer_rootSignatures.empty())
while (!destroyer_rootSignatures.empty() && destroyer_rootSignatures.front().second + BUFFERCOUNT < FRAMECOUNT)
{
if (destroyer_rootSignatures.front().second + BUFFERCOUNT < FRAMECOUNT)
{
destroyer_rootSignatures.pop_front();
// comptr auto delete
}
else
{
break;
}
destroyer_rootSignatures.pop_front();
// comptr auto delete
}
while (!destroyer_stateobjects.empty())
while (!destroyer_stateobjects.empty() && destroyer_stateobjects.front().second + BUFFERCOUNT < FRAMECOUNT)
{
if (destroyer_stateobjects.front().second + BUFFERCOUNT < FRAMECOUNT)
{
destroyer_stateobjects.pop_front();
// comptr auto delete
}
else
{
break;
}
destroyer_stateobjects.pop_front();
// comptr auto delete
}
while (!destroyer_video_decoder_heaps.empty())
while (!destroyer_video_decoder_heaps.empty() && destroyer_video_decoder_heaps.front().second + BUFFERCOUNT < FRAMECOUNT)
{
if (destroyer_video_decoder_heaps.front().second + BUFFERCOUNT < FRAMECOUNT)
{
destroyer_video_decoder_heaps.pop_front();
// comptr auto delete
}
else
{
break;
}
destroyer_video_decoder_heaps.pop_front();
// comptr auto delete
}
while (!destroyer_video_decoders.empty())
while (!destroyer_video_decoders.empty() && destroyer_video_decoders.front().second + BUFFERCOUNT < FRAMECOUNT)
{
if (destroyer_video_decoders.front().second + BUFFERCOUNT < FRAMECOUNT)
{
destroyer_video_decoders.pop_front();
// comptr auto delete
}
else
{
break;
}
destroyer_video_decoders.pop_front();
// comptr auto delete
}
while (!destroyer_bindless_res.empty())
while (!destroyer_bindless_res.empty() && destroyer_bindless_res.front().second + BUFFERCOUNT < FRAMECOUNT)
{
if (destroyer_bindless_res.front().second + BUFFERCOUNT < FRAMECOUNT)
{
int index = destroyer_bindless_res.front().first;
destroyer_bindless_res.pop_front();
free_bindless_res.push_back(index);
}
else
{
break;
}
int index = destroyer_bindless_res.front().first;
destroyer_bindless_res.pop_front();
free_bindless_res.push_back(index);
}
while (!destroyer_bindless_sam.empty())
while (!destroyer_bindless_sam.empty() && destroyer_bindless_sam.front().second + BUFFERCOUNT < FRAMECOUNT)
{
if (destroyer_bindless_sam.front().second + BUFFERCOUNT < FRAMECOUNT)
{
int index = destroyer_bindless_sam.front().first;
destroyer_bindless_sam.pop_front();
free_bindless_sam.push_back(index);
}
else
{
break;
}
int index = destroyer_bindless_sam.front().first;
destroyer_bindless_sam.pop_front();
free_bindless_sam.push_back(index);
}
destroylocker.unlock();
}
};
std::shared_ptr<AllocationHandler> allocationhandler;
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace wi::scene
desc.usage = Usage::READBACK;
desc.bind_flags = BindFlag::NONE;
desc.misc_flags = ResourceMiscFlag::NONE;
for (int i = 0; i < arraysize(materialUploadBuffer); ++i)
for (int i = 0; i < arraysize(textureStreamingFeedbackBuffer_readback); ++i)
{
device->CreateBuffer(&desc, nullptr, &textureStreamingFeedbackBuffer_readback[i]);
device->SetName(&textureStreamingFeedbackBuffer_readback[i], "Scene::textureStreamingFeedbackBuffer_readback");
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 71;
// minor bug fixes, alterations, refactors, updates
const int revision = 658;
const int revision = 659;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down

0 comments on commit f4b3709

Please sign in to comment.