Skip to content

Commit 686e3a0

Browse files
authored
Merge branch 'baldurk:v1.x' into v1.x
2 parents fd2eeaf + 86585b6 commit 686e3a0

File tree

8 files changed

+74
-10
lines changed

8 files changed

+74
-10
lines changed

renderdoc/driver/d3d12/d3d12_pixelhistory.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -642,16 +642,19 @@ struct D3D12PixelHistoryCallback : public D3D12ActionCallback
642642

643643
// Copy into a buffer, but treat the footprint as the same format as the target image
644644
uint32_t elementSize = GetByteSize(0, 0, 0, p.copyFormat, 0);
645+
// Use Offset to get to the nearest 16KB
646+
UINT64 footprintOffset = (offset >> 14) << 14;
647+
UINT64 offsetRemaider = offset - footprintOffset;
648+
UINT dstX = (UINT)(offsetRemaider / elementSize);
645649

646650
dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
647651
dst.pResource = m_CallbackInfo.dstBuffer;
648-
dst.PlacedFootprint.Offset = 0;
649-
dst.PlacedFootprint.Footprint.Width =
650-
(UINT)m_CallbackInfo.dstBuffer->GetDesc().Width / elementSize;
652+
dst.PlacedFootprint.Offset = footprintOffset;
653+
dst.PlacedFootprint.Footprint.Width = dstX + 1;
651654
dst.PlacedFootprint.Footprint.Height = 1;
652655
dst.PlacedFootprint.Footprint.Depth = 1;
653656
dst.PlacedFootprint.Footprint.Format = p.copyFormat;
654-
dst.PlacedFootprint.Footprint.RowPitch = (UINT)m_CallbackInfo.dstBuffer->GetDesc().Width;
657+
dst.PlacedFootprint.Footprint.RowPitch = dst.PlacedFootprint.Footprint.Width * elementSize;
655658

656659
D3D12_BOX srcBox = {};
657660
srcBox.left = p.x;
@@ -661,10 +664,8 @@ struct D3D12PixelHistoryCallback : public D3D12ActionCallback
661664
srcBox.front = 0;
662665
srcBox.back = 1;
663666

664-
// We need to apply the offset here (measured in number of elements) rather than using
665-
// PlacedFootprint.Offset (measured in bytes) because the latter must be a multiple of 512
666667
RDCASSERT((offset % elementSize) == 0);
667-
cmd->CopyTextureRegion(&dst, (UINT)(offset / elementSize), 0, 0, &src, &srcBox);
668+
cmd->CopyTextureRegion(&dst, dstX, 0, 0, &src, &srcBox);
668669

669670
std::swap(barrier.Transition.StateBefore, barrier.Transition.StateAfter);
670671
cmd->ResourceBarrier(1, &barrier);

renderdoc/driver/d3d12/d3d12_postvs.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -2206,11 +2206,13 @@ void D3D12Replay::InitPostMSBuffers(uint32_t eventId)
22062206
ID3D12RootSignature *annotatedSig = NULL;
22072207

22082208
{
2209-
ID3DBlob *root = m_pDevice->GetShaderCache()->MakeRootSig(modsig);
2209+
ID3DBlob *blob = m_pDevice->GetShaderCache()->MakeRootSig(modsig);
22102210
HRESULT hr =
2211-
m_pDevice->CreateRootSignature(0, root->GetBufferPointer(), root->GetBufferSize(),
2211+
m_pDevice->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(),
22122212
__uuidof(ID3D12RootSignature), (void **)&annotatedSig);
22132213

2214+
SAFE_RELEASE(blob);
2215+
22142216
if(annotatedSig == NULL || FAILED(hr))
22152217
{
22162218
ret.ampout.status = ret.meshout.status = StringFormat::Fmt(

renderdoc/driver/d3d12/d3d12_shader_feedback.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1336,9 +1336,12 @@ bool D3D12Replay::FetchShaderFeedback(uint32_t eventId)
13361336

13371337
if(annotatedSig == NULL || FAILED(hr))
13381338
{
1339+
SAFE_RELEASE(root);
13391340
RDCERR("Couldn't create feedback modified root signature: %s", ToStr(hr).c_str());
13401341
return false;
13411342
}
1343+
1344+
SAFE_RELEASE(root);
13421345
}
13431346

13441347
ID3D12PipelineState *annotatedPipe = NULL;

renderdoc/driver/shaders/dxbc/dxbc_container.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,20 @@ void DXBCContainer::ReplaceChunk(bytebuf &ByteCode, uint32_t fourcc, const byte
743743
return;
744744
}
745745
}
746+
747+
uint32_t newOffs = uint32_t(ByteCode.size() + sizeof(uint32_t));
748+
ByteCode.insert(sizeof(FileHeader) + header->numChunks * sizeof(uint32_t), (byte *)&newOffs,
749+
sizeof(newOffs));
750+
751+
for(uint32_t chunkIdx = 0; chunkIdx < header->numChunks; chunkIdx++)
752+
chunkOffsets[chunkIdx] += sizeof(uint32_t);
753+
754+
ByteCode.append(replacement, size);
755+
756+
header->numChunks++;
757+
header->fileLength = (uint32_t)ByteCode.size();
758+
759+
HashContainer(ByteCode.data(), ByteCode.size());
746760
}
747761

748762
const byte *DXBCContainer::FindChunk(const bytebuf &ByteCode, uint32_t fourcc, size_t &size)

renderdoc/driver/shaders/dxil/dxil_bytecode_editor.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,6 @@ void ProgramEditor::SetNumThreads(uint32_t dim[3])
18181818

18191819
if(*headerSize >= headerSizeVer2)
18201820
{
1821-
cur += headerSizeVer0;
18221821
cur += headerSizeVer1;
18231822
memcpy(cur, dim, sizeof(uint32_t) * 3);
18241823
}

renderdoc/driver/vulkan/vk_debug.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,9 @@ void VulkanDebugManager::InitReadbackBuffer(VkDeviceSize sz)
25702570
m_ReadbackWindow.Create(m_pDriver, dev, AlignUp(sz, (VkDeviceSize)4096), 1,
25712571
GPUBuffer::eGPUBufferReadback);
25722572

2573+
m_pDriver->GetResourceManager()->SetInternalResource(GetResID(m_ReadbackWindow.buf));
2574+
m_pDriver->GetResourceManager()->SetInternalResource(GetResID(m_ReadbackWindow.mem));
2575+
25732576
RDCLOG("Allocating readback window of %llu bytes", m_ReadbackWindow.sz);
25742577

25752578
VkResult vkr = ObjDisp(dev)->MapMemory(Unwrap(dev), Unwrap(m_ReadbackWindow.mem), 0,

util/test/demos/d3d12/d3d12_pixel_history.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ float4 main(v2f vertIn, uint primId : SV_PrimitiveID, uint sampleId : SV_SampleI
217217
{Vec3f(-0.7f, 0.5f, 0.33f), Vec4f(1.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)},
218218
{Vec3f(-0.6f, 0.3f, 0.33f), Vec4f(1.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)},
219219
{Vec3f(-0.8f, 0.3f, 0.33f), Vec4f(1.0f, 1.0f, 0.0f, 1.0f), Vec2f(1.0f, 0.0f)},
220+
// 1000 draws of 1 triangle
221+
{Vec3f(-0.7f, 0.0f, 0.33f), Vec4f(0.5f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)},
222+
{Vec3f(-0.8f, 0.2f, 0.33f), Vec4f(0.5f, 1.0f, 0.0f, 1.0f), Vec2f(1.0f, 0.0f)},
223+
{Vec3f(-0.6f, 0.2f, 0.33f), Vec4f(0.5f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)},
224+
// 1000 instances of 1 triangle
225+
{Vec3f(-0.7f, 0.6f, 0.33f), Vec4f(1.0f, 0.5f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)},
226+
{Vec3f(-0.8f, 0.8f, 0.33f), Vec4f(1.0f, 0.5f, 0.0f, 1.0f), Vec2f(1.0f, 0.0f)},
227+
{Vec3f(-0.6f, 0.8f, 0.33f), Vec4f(1.0f, 0.5f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)},
220228
};
221229

222230
ID3D12ResourcePtr vb = MakeBuffer().Data(VBData);
@@ -608,6 +616,17 @@ float4 main(v2f vertIn, uint primId : SV_PrimitiveID, uint sampleId : SV_SampleI
608616
cmd->OMSetDepthBounds(0.4f, 0.6f);
609617
cmd->DrawInstanced(3, 1, 66, 0);
610618

619+
pushMarker(cmd, "Stress Test");
620+
pushMarker(cmd, "Lots of Drawcalls");
621+
setMarker(cmd, "1000 Draws");
622+
cmd->SetPipelineState(pass.depthWritePipe);
623+
for(int d = 0; d < 1000; ++d)
624+
cmd->DrawInstanced(3, 1, 72, 0);
625+
popMarker(cmd);
626+
setMarker(cmd, "1000 Instances");
627+
cmd->DrawInstanced(3, 1000, 75, 0);
628+
popMarker(cmd);
629+
611630
// Add a marker so we can easily locate this draw
612631
setMarker(cmd, "Test Begin");
613632

util/test/tests/D3D12/D3D12_Pixel_History.py

+23
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def primary_test(self, begin_name: str):
9696
depth_16bit_test_eid = self.find_action("Depth 16-bit Test", begin_renderpass_eid).next.eventId
9797
depth_bounds_prep_eid = self.find_action("Depth Bounds Prep", begin_renderpass_eid).next.eventId
9898
depth_bounds_clip_eid = self.find_action("Depth Bounds Clip", begin_renderpass_eid).next.eventId
99+
one_thousand_instances_action = self.find_action("1000 Instances", begin_renderpass_eid)
99100

100101
# For pixel 110, 100, inside the red triangle with stencil value 0x55
101102
x, y = 110, 100
@@ -274,6 +275,28 @@ def primary_test(self, begin_name: str):
274275
self.check_events(events, modifs, False)
275276
self.check_pixel_value(tex, x, y, get_post_mod_color(modifs[-1]), sub=sub, cast=rt.typeCast)
276277

278+
# For pixel 60, 130 inside the light green triangle which is 1000 draws of 1 instance of 1 triangle
279+
rdtest.log.print("Testing Lots of Drawcalls")
280+
self.controller.SetFrameEvent(one_thousand_instances_action.eventId, True)
281+
x, y = 60, 130
282+
rdtest.log.print("Testing pixel {}, {}".format(x, y))
283+
modifs: List[rd.PixelModification] = self.controller.PixelHistory(tex, x, y, sub, rt.typeCast)
284+
self.check_pixel_value(tex, x, y, get_post_mod_color(modifs[-1]), sub=sub, cast=rt.typeCast)
285+
countEvents = 1 + 1000
286+
self.check(len(modifs) == countEvents, "Expected {} events, got {}".format(countEvents, len(modifs)))
287+
self.check_modifs_consistent(modifs)
288+
289+
# For pixel 60, 50 inside the orange triangle which is 1 draws of 1000 instances of 1 triangle
290+
rdtest.log.print("Testing Lots of Instances")
291+
self.controller.SetFrameEvent(one_thousand_instances_action.next.eventId, True)
292+
x, y = 60, 50
293+
rdtest.log.print("Testing pixel {}, {}".format(x, y))
294+
modifs: List[rd.PixelModification] = self.controller.PixelHistory(tex, x, y, sub, rt.typeCast)
295+
self.check_pixel_value(tex, x, y, get_post_mod_color(modifs[-1]), sub=sub, cast=rt.typeCast)
296+
countEvents = 1 + 255
297+
self.check(len(modifs) == countEvents, "Expected {} events, got {}".format(countEvents, len(modifs)))
298+
self.check_modifs_consistent(modifs)
299+
277300
def multisampled_image_test(self, pass_name: str):
278301
begin_pass_action = self.find_action(pass_name)
279302
if begin_pass_action is None:

0 commit comments

Comments
 (0)