Discard render targets before first use.

This commit is contained in:
Skyth
2024-10-20 15:11:15 +03:00
parent cc16abe484
commit ecc1098ddc
7 changed files with 29 additions and 3 deletions

View File

@@ -1947,6 +1947,11 @@ namespace RT64 {
d3d->BuildRaytracingAccelerationStructure(&buildDesc, 0, nullptr);
}
void D3D12CommandList::discardTexture(const RenderTexture* texture) {
const D3D12Texture* interfaceTexture = static_cast<const D3D12Texture*>(texture);
d3d->DiscardResource(interfaceTexture->d3d, nullptr);
}
void D3D12CommandList::checkDescriptorHeaps() {
if (!descriptorHeapsSet) {
ID3D12DescriptorHeap *descriptorHeaps[] = { device->viewHeapAllocator->shaderHeap, device->samplerHeapAllocator->shaderHeap };

View File

@@ -192,6 +192,7 @@ namespace RT64 {
void resolveTextureRegion(const RenderTexture *dstTexture, uint32_t dstX, uint32_t dstY, const RenderTexture *srcTexture, const RenderRect *srcRect) override;
void buildBottomLevelAS(const RenderAccelerationStructure *dstAccelerationStructure, RenderBufferReference scratchBuffer, const RenderBottomLevelASBuildInfo &buildInfo) override;
void buildTopLevelAS(const RenderAccelerationStructure *dstAccelerationStructure, RenderBufferReference scratchBuffer, RenderBufferReference instancesBuffer, const RenderTopLevelASBuildInfo &buildInfo) override;
void discardTexture(const RenderTexture* texture) override;
void checkDescriptorHeaps();
void notifyDescriptorHeapWasChangedExternally();
void checkTopology();

View File

@@ -138,7 +138,8 @@ namespace RT64 {
virtual void resolveTextureRegion(const RenderTexture *dstTexture, uint32_t dstX, uint32_t dstY, const RenderTexture *srcTexture, const RenderRect *srcRect = nullptr) = 0;
virtual void buildBottomLevelAS(const RenderAccelerationStructure *dstAccelerationStructure, RenderBufferReference scratchBuffer, const RenderBottomLevelASBuildInfo &buildInfo) = 0;
virtual void buildTopLevelAS(const RenderAccelerationStructure *dstAccelerationStructure, RenderBufferReference scratchBuffer, RenderBufferReference instancesBuffer, const RenderTopLevelASBuildInfo &buildInfo) = 0;
virtual void discardTexture(const RenderTexture* texture) = 0; // D3D12 only.
// Concrete implementation shortcuts.
inline void barriers(RenderBarrierStages stages, const RenderBufferBarrier &barrier) {
barriers(stages, &barrier, 1, nullptr, 0);

View File

@@ -3088,6 +3088,10 @@ namespace RT64 {
vkCmdBuildAccelerationStructuresKHR(vk, 1, &buildGeometryInfo, &buildRangeInfoPtr);
}
void VulkanCommandList::discardTexture(const RenderTexture* texture) {
// Not required in Vulkan.
}
void VulkanCommandList::checkActiveRenderPass() {
assert(targetFramebuffer != nullptr);

View File

@@ -295,6 +295,7 @@ namespace RT64 {
void resolveTextureRegion(const RenderTexture *dstTexture, uint32_t dstX, uint32_t dstY, const RenderTexture *srcTexture, const RenderRect *srcRect) override;
void buildBottomLevelAS(const RenderAccelerationStructure *dstAccelerationStructure, RenderBufferReference scratchBuffer, const RenderBottomLevelASBuildInfo &buildInfo) override;
void buildTopLevelAS(const RenderAccelerationStructure *dstAccelerationStructure, RenderBufferReference scratchBuffer, RenderBufferReference instancesBuffer, const RenderTopLevelASBuildInfo &buildInfo) override;
void discardTexture(const RenderTexture* texture) override;
void checkActiveRenderPass();
void endActiveRenderPass();
void setDescriptorSet(VkPipelineBindPoint bindPoint, const VulkanPipelineLayout *pipelineLayout, const RenderDescriptorSet *descriptorSet, uint32_t setIndex);

View File

@@ -1105,8 +1105,9 @@ static GuestSurface* CreateSurface(uint32_t width, uint32_t height, uint32_t for
surface->height = height;
surface->format = desc.format;
surface->sampleCount = desc.multisampling.sampleCount;
surface->pendingDiscard = true;
if (multiSample != 0 && desc.format == RenderFormat::D32_FLOAT)
if (desc.multisampling.sampleCount != RenderSampleCount::COUNT_1 && desc.format == RenderFormat::D32_FLOAT)
{
RenderTextureViewDesc viewDesc;
viewDesc.dimension = RenderTextureViewDimension::TEXTURE_2D;
@@ -1296,6 +1297,18 @@ static void FlushFramebuffer()
FlushBarriers();
if (g_renderTarget != nullptr && g_renderTarget->pendingDiscard)
{
commandList->discardTexture(g_renderTarget->textureHolder.get());
g_renderTarget->pendingDiscard = false;
}
if (g_depthStencil != nullptr && g_depthStencil->pendingDiscard)
{
commandList->discardTexture(g_depthStencil->textureHolder.get());
g_depthStencil->pendingDiscard = false;
}
if (g_dirtyStates.renderTargetAndDepthStencil)
{
GuestSurface* framebufferContainer = nullptr;

View File

@@ -150,9 +150,10 @@ struct GuestSurface : GuestResource
uint32_t height = 0;
RenderFormat format = RenderFormat::UNKNOWN;
ankerl::unordered_dense::map<const RenderTexture*, std::unique_ptr<RenderFramebuffer>> framebuffers;
bool pendingBarrier = true;
RenderSampleCounts sampleCount = RenderSampleCount::COUNT_1;
uint32_t descriptorIndex = 0;
bool pendingBarrier = true;
bool pendingDiscard = false;
};
enum GuestDeclType