From 00777e8474b31013d025749b7da3105ce5d840b4 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Thu, 15 Feb 2024 13:30:59 +0000 Subject: [PATCH] D3D12 Pixel History force event info structures to be 48 byte aligned This is to ensure buffer offsets are always a multiple of 16 & 12 bytes 12 byte alignment is required to support copying R32G32B32 pixels --- renderdoc/driver/d3d12/d3d12_pixelhistory.cpp | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp b/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp index 1d143274d..d9eb43c31 100644 --- a/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp +++ b/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp @@ -171,7 +171,7 @@ struct D3D12EventInfo uint8_t dsWithoutShaderDiscard[8]; uint8_t padding[8]; uint8_t dsWithShaderDiscard[8]; - uint8_t padding1[8]; + uint8_t padding1[24]; }; struct D3D12PerFragmentInfo @@ -626,8 +626,8 @@ protected: uint32_t elementSize = GetByteSize(0, 0, 0, p.copyFormat, 0); // Use Offset to get to the nearest 16KB UINT64 footprintOffset = (offset >> 14) << 14; - UINT64 offsetRemaider = offset - footprintOffset; - UINT dstX = (UINT)(offsetRemaider / elementSize); + UINT64 offsetRemainder = offset - footprintOffset; + UINT dstX = (UINT)(offsetRemainder / elementSize); dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; dst.pResource = m_CallbackInfo.dstBuffer; @@ -648,8 +648,11 @@ protected: srcBox.front = 0; srcBox.back = 1; - RDCASSERT((offset % elementSize) == 0); - cmd->CopyTextureRegion(&dst, dstX, 0, 0, &src, &srcBox); + if(offsetRemainder % elementSize == 0) + cmd->CopyTextureRegion(&dst, dstX, 0, 0, &src, &srcBox); + else + RDCERR("OffsetRemainder %zu is not a multiple of elementSize %u", offsetRemainder, + elementSize); std::swap(barrier.Transition.StateBefore, barrier.Transition.StateAfter); cmd->ResourceBarrier(1, &barrier); @@ -3027,6 +3030,22 @@ rdcarray D3D12Replay::PixelHistory(rdcarray event { rdcarray history; + RDCCOMPILE_ASSERT(sizeof(D3D12EventInfo) % 16 == 0, "D3D12EventInfo not multiple of 16-bytes"); + RDCCOMPILE_ASSERT(sizeof(D3D12EventInfo) % 12 == 0, "D3D12EventInfo not multiple of 12-bytes"); + + RDCCOMPILE_ASSERT(offsetof(D3D12EventInfo, premod) % 16 == 0, + "D3D12EventInfo::premod not aligned to 16-bytes"); + RDCCOMPILE_ASSERT(offsetof(D3D12EventInfo, premod) % 12 == 0, + "D3D12EventInfo::premod not aligned to 12-bytes"); + RDCCOMPILE_ASSERT(offsetof(D3D12EventInfo, postmod) % 16 == 0, + "D3D12EventInfo::postmod not aligned to 16-bytes"); + RDCCOMPILE_ASSERT(offsetof(D3D12EventInfo, postmod) % 12 == 0, + "D3D12EventInfo::postmod not aligned to 12-bytes"); + RDCCOMPILE_ASSERT(offsetof(D3D12EventInfo, dsWithoutShaderDiscard) % 16 == 0, + "D3D12EventInfo::dsWithoutShaderDiscard not aligned to 16-bytes"); + RDCCOMPILE_ASSERT(offsetof(D3D12EventInfo, dsWithShaderDiscard) % 16 == 0, + "D3D12EventInfo::dsWithShaderDiscard not aligned to 16-bytes"); + if(events.empty()) return history;