summaryrefslogtreecommitdiffstats
path: root/tools/gfx/d3d12
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-10-13 14:07:26 -0700
committerGitHub <noreply@github.com>2022-10-13 14:07:26 -0700
commit09054f7ae00aad0458de465a7f0b780a91c694dd (patch)
tree776f50b5ebe51ae7088d6990eaa5f6d84d8a6c2a /tools/gfx/d3d12
parentafa9f4b2786c92e72a563f316e074f62770630cb (diff)
Make `optimalClearValue` optional in `ITextureResource::Desc` (#2450)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tools/gfx/d3d12')
-rw-r--r--tools/gfx/d3d12/d3d12-device.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/tools/gfx/d3d12/d3d12-device.cpp b/tools/gfx/d3d12/d3d12-device.cpp
index 2d9780b0f..dbc2a18d9 100644
--- a/tools/gfx/d3d12/d3d12-device.cpp
+++ b/tools/gfx/d3d12/d3d12-device.cpp
@@ -941,7 +941,7 @@ Result DeviceImpl::createTextureResource(
flags |= D3D12_HEAP_FLAG_SHARED;
D3D12_CLEAR_VALUE clearValue;
- D3D12_CLEAR_VALUE* clearValuePtr = &clearValue;
+ D3D12_CLEAR_VALUE* clearValuePtr = nullptr;
if ((resourceDesc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET |
D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) == 0)
{
@@ -952,9 +952,13 @@ Result DeviceImpl::createTextureResource(
clearValuePtr = nullptr;
}
clearValue.Format = resourceDesc.Format;
- memcpy(clearValue.Color, &descIn.optimalClearValue.color, sizeof(clearValue.Color));
- clearValue.DepthStencil.Depth = descIn.optimalClearValue.depthStencil.depth;
- clearValue.DepthStencil.Stencil = descIn.optimalClearValue.depthStencil.stencil;
+ if (descIn.optimalClearValue)
+ {
+ memcpy(clearValue.Color, &descIn.optimalClearValue->color, sizeof(clearValue.Color));
+ clearValue.DepthStencil.Depth = descIn.optimalClearValue->depthStencil.depth;
+ clearValue.DepthStencil.Stencil = descIn.optimalClearValue->depthStencil.stencil;
+ clearValuePtr = &clearValue;
+ }
SLANG_RETURN_ON_FAIL(texture->m_resource.initCommitted(
m_device,
heapProps,
@@ -1633,8 +1637,11 @@ Result DeviceImpl::createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffe
static_cast<TextureResourceImpl*>(
static_cast<ResourceViewImpl*>(desc.renderTargetViews[i])->m_resource.Ptr())
->getDesc()
- ->optimalClearValue.color;
- memcpy(&framebuffer->renderTargetClearValues[i], &clearValue, sizeof(ColorClearValue));
+ ->optimalClearValue;
+ if (clearValue)
+ {
+ memcpy(&framebuffer->renderTargetClearValues[i], &clearValue->color, sizeof(ColorClearValue));
+ }
}
else
{
@@ -1644,11 +1651,15 @@ Result DeviceImpl::createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffe
framebuffer->depthStencilView = static_cast<ResourceViewImpl*>(desc.depthStencilView);
if (desc.depthStencilView)
{
- framebuffer->depthStencilClearValue =
- static_cast<TextureResourceImpl*>(
- static_cast<ResourceViewImpl*>(desc.depthStencilView)->m_resource.Ptr())
+ auto clearValue = static_cast<TextureResourceImpl*>(
+ static_cast<ResourceViewImpl*>(desc.depthStencilView)->m_resource.Ptr())
->getDesc()
- ->optimalClearValue.depthStencil;
+ ->optimalClearValue;
+
+ if (clearValue)
+ {
+ framebuffer->depthStencilClearValue = clearValue->depthStencil;
+ }
framebuffer->depthStencilDescriptor =
static_cast<ResourceViewImpl*>(desc.depthStencilView)->m_descriptor.cpuHandle;
}