From b332c6d2854cbeedfe4381437d33e6468d26f300 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 18:30:24 +0100 Subject: [PATCH 1/9] fix: index buffer view SizeInBytes bounds the index fetch; reads outside the view are 0 --- runtime/src/vulkan_replay.h | 30 +++++++++++++++++++++++------ runtime/test/d3d12_draw_test.cpp | 33 ++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index 2fef87194..b216be590 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h @@ -1233,6 +1233,7 @@ struct PreparedDraw { VkDeviceSize index_size = 0; // the bytes of the index buffer view inside its buffer; 0 with no index buffer VkIndexType index_type = VK_INDEX_TYPE_UINT16; QuadIndexExpansion quad_indices; // an indexed quad list: the triangle indices its draw binds instead + std::uint32_t index_first = 0; // firstIndex to draw with: the draw's, or 0 on the zero page (see prepare) VkExtent2D area{}; std::uint32_t layers = 1; // the fewest layers any bound attachment view has // The draw is dropped at emit: its pipeline, a vertex buffer or its index buffer could not be resolved (see @@ -1255,6 +1256,7 @@ struct PreparedDraw { index_size = 0; index_type = VK_INDEX_TYPE_UINT16; quad_indices = {}; + index_first = 0; area = {}; layers = 1; } @@ -2511,11 +2513,15 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct if (draw.index.format == 57) p.index_type = VK_INDEX_TYPE_UINT16; else if (draw.index.format == 42) p.index_type = VK_INDEX_TYPE_UINT32; else if (draw.index.va) return unsupported_at(__LINE__); - if (!draw.index.va) { // no index buffer: every index reads 0 - if (!vk.zero_buffer) return unresolved_at(__LINE__); - p.index_buffer = vk.zero_buffer; - p.index_offset = vk.zero_offset; - } else { + p.index_first = draw.first; + // Index fetches outside the view read 0 in D3D12, but vkCmdBindIndexBuffer binds to the end of the buffer + // (the layer's device does not enable VK_KHR_maintenance5 for a bind size). So the view's size decides + // here: a draw wholly inside binds the buffer, one wholly outside binds the zero page, and one that + // straddles the end is refused rather than reading bytes the view does not cover. + const std::uint64_t index_bytes = p.index_type == VK_INDEX_TYPE_UINT32 ? 4 : 2; + std::uint64_t view_indices = 0; + bool resolved = false; + if (draw.index.va) { std::uint64_t size = draw.index.size; if (!vk.buffer_at(draw.index.va, size, p.index_buffer, p.index_offset)) { size = draw.index.size; @@ -2529,6 +2535,18 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct } } p.index_size = size; + view_indices = size / index_bytes; // size is the view's, cut at the buffer's end + resolved = true; + } + const std::uint64_t last = std::uint64_t(draw.first) + draw.count; // one past the last index fetched + if (resolved && draw.count > 0 && last > view_indices && draw.first < view_indices) + return unsupported_at(__LINE__); + if (!resolved || (draw.count > 0 && draw.first >= view_indices)) { // every index reads 0 + if (!vk.zero_buffer) return unresolved_at(__LINE__); + if (resolved && std::uint64_t(draw.count) * index_bytes > vk.zero_size) return unsupported_at(__LINE__); + p.index_buffer = vk.zero_buffer; + p.index_offset = vk.zero_offset; + p.index_first = 0; } } return ReplayResult::success; @@ -4924,7 +4942,7 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_ } } else if (draw->indexed) { vk.bind_index_buffer(command_buffer, d.index_buffer, d.index_offset, d.index_type); - vk.draw_indexed(command_buffer, draw->count, draw->instances, draw->first, draw->base_vertex, + vk.draw_indexed(command_buffer, draw->count, draw->instances, d.index_first, draw->base_vertex, draw->first_instance); } else { vk.draw(command_buffer, draw->count, draw->instances, draw->first, draw->first_instance); diff --git a/runtime/test/d3d12_draw_test.cpp b/runtime/test/d3d12_draw_test.cpp index d10716158..ac9c53b7b 100644 --- a/runtime/test/d3d12_draw_test.cpp +++ b/runtime/test/d3d12_draw_test.cpp @@ -131,6 +131,8 @@ int main(int argc, char** argv) { constexpr UINT size = 64; std::vector pixels(size * 256), second_pixels(size * 256), logic_pixels(size * 256); std::vector strip16_pixels(size * 256), strip32_pixels(size * 256), strip_nocut_pixels(size * 256); + // Index buffer view size: a fetch past SizeInBytes reads index 0 (view_out), one inside the view reads the data. + std::vector view_out_pixels(size * 256), view_in_pixels(size * 256), view_straddle_pixels(size * 256); std::vector msaa_full_pixels(size * 256), msaa_half_pixels(size * 256); bool ran_msaa = false; std::vector step2_pixels(size * 256), step1_pixels(size * 256); @@ -636,6 +638,10 @@ int main(int argc, char** argv) { std::memcpy(static_cast(up_ptr) + 1280, strip_idx16, sizeof(strip_idx16)); std::memcpy(static_cast(up_ptr) + 1536, strip_idx32, sizeof(strip_idx32)); std::memcpy(static_cast(up_ptr) + 1792, strip_nocut, sizeof(strip_nocut)); + // Four indices of the top-left quad, then the same four again: the second half is the data a draw would + // read if the view's end were ignored. + const std::uint16_t view_idx[8] = {0, 1, 2, 3, 0, 1, 2, 3}; + std::memcpy(static_cast(up_ptr) + 3072, view_idx, sizeof(view_idx)); upload->Unmap(0, nullptr); auto strip_desc = pso_desc; @@ -654,11 +660,20 @@ int main(int argc, char** argv) { D3D12_INDEX_BUFFER_VIEW ibv; UINT index_count; std::vector* out; + UINT first = 0; // StartIndexLocation + leonida::ReplayResult want = leonida::ReplayResult::success; }; const StripPass strip_passes[] = { {strip16_pso.p, {upload_va + 1280, sizeof(strip_idx16), DXGI_FORMAT_R16_UINT}, 9, &strip16_pixels}, {strip32_pso.p, {upload_va + 1536, sizeof(strip_idx32), DXGI_FORMAT_R32_UINT}, 9, &strip32_pixels}, {strip_off_pso.p, {upload_va + 1792, sizeof(strip_nocut), DXGI_FORMAT_R16_UINT}, 8, &strip_nocut_pixels}, + // View of 4 indices, draw of indices 4..7: all outside the view, so all read 0 (a degenerate strip). + {strip_off_pso.p, {upload_va + 3072, 8, DXGI_FORMAT_R16_UINT}, 4, &view_out_pixels, 4}, + // Negative control: the view covers the 8 indices, the same draw reads the quad. + {strip_off_pso.p, {upload_va + 3072, 16, DXGI_FORMAT_R16_UINT}, 4, &view_in_pixels, 4}, + // Indices 2..5 cross the view's end: refused, nothing is read outside the view. + {strip_off_pso.p, {upload_va + 3072, 8, DXGI_FORMAT_R16_UINT}, 4, &view_straddle_pixels, 2, + leonida::ReplayResult::unsupported}, }; UINT64 strip_fence = 10; for (const auto& sp : strip_passes) { @@ -674,15 +689,15 @@ int main(int argc, char** argv) { list->OMSetRenderTargets(1, &rtv, FALSE, nullptr); list->SetGraphicsRoot32BitConstants(0, 2, origin, 0); list->SetGraphicsRootConstantBufferView(1, upload_va + 512); - list->DrawIndexedInstanced(sp.index_count, 1, 0, 0, 0); + list->DrawIndexedInstanced(sp.index_count, 1, sp.first, 0, 0); list->ResourceBarrier(1, &to_copy); list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); EXPECT(list->Close() == S_OK); queue->ExecuteCommandLists(1, lists); - EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success); ++strip_fence; EXPECT(SUCCEEDED(queue->Signal(fence.p, strip_fence)) && SUCCEEDED(fence->SetEventOnCompletion(strip_fence, nullptr))); + EXPECT(rt::d3d12::last_execute_result(queue.p) == sp.want); std::memcpy(sp.out->data(), mapped, sp.out->size()); } } @@ -1325,6 +1340,20 @@ int main(int argc, char** argv) { } EXPECT(!mismatches); EXPECT(nocut_bl_red > 0); + // Index buffer view size: past the view's end every fetch reads 0 (nothing drawn), inside it the data is read. + UINT view_out_red = 0, view_in_tl_red = 0; + for (UINT row = 0; row < size; ++row) { + for (UINT col = 0; col < size; ++col) { + const std::uint8_t* out = view_out_pixels.data() + row * 256 + col * 4; + const std::uint8_t* in = view_in_pixels.data() + row * 256 + col * 4; + if (out[0] == 255) ++view_out_red; + if (row < size / 2 && col < size / 2 && in[0] == 255 && in[2] == 0) ++view_in_tl_red; + } + } + EXPECT(view_out_red == 0); + EXPECT(view_in_tl_red == (size / 2) * (size / 2)); + std::printf("index view size: draw past the view painted %u red pixels (want 0); view covering the draw painted " + "%u of %u top-left pixels\n", view_out_red, view_in_tl_red, (size / 2) * (size / 2)); std::printf("strip cut (0xFFFF & 0xFFFFFFFF): 4096/4096 pixels matched each (no-cut negative control painted %u " "bridge pixels in bottom-left)\n", nocut_bl_red); From f86e68120ab366c8940123a221fcc1713ce9f2e7 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 18:33:45 +0100 Subject: [PATCH 2/9] fix: a draw that crosses the index view's end reads index 0 past it, from a staged copy --- runtime/src/vulkan_replay.h | 61 ++++++++++++++++++++++++++------ runtime/test/d3d12_draw_test.cpp | 12 +++++-- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index b216be590..1be3e91d7 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h @@ -1233,7 +1233,15 @@ struct PreparedDraw { VkDeviceSize index_size = 0; // the bytes of the index buffer view inside its buffer; 0 with no index buffer VkIndexType index_type = VK_INDEX_TYPE_UINT16; QuadIndexExpansion quad_indices; // an indexed quad list: the triangle indices its draw binds instead - std::uint32_t index_first = 0; // firstIndex to draw with: the draw's, or 0 on the zero page (see prepare) + std::uint32_t index_first = 0; // firstIndex to draw with: the draw's, or 0 on the zero page or a staged copy + // A draw that reads past the index view's end binds a scratch copy of the indices it fetches instead: the + // in-view part copied from the buffer, the rest zero. fill_bytes 0: no copy. + struct IndexStage { + VkBuffer scratch = VK_NULL_HANDLE; + VkDeviceSize scratch_offset = 0, fill_bytes = 0; + VkBuffer source = VK_NULL_HANDLE; + VkDeviceSize source_offset = 0, copy_bytes = 0; + } index_stage; VkExtent2D area{}; std::uint32_t layers = 1; // the fewest layers any bound attachment view has // The draw is dropped at emit: its pipeline, a vertex buffer or its index buffer could not be resolved (see @@ -1257,6 +1265,7 @@ struct PreparedDraw { index_type = VK_INDEX_TYPE_UINT16; quad_indices = {}; index_first = 0; + index_stage = {}; area = {}; layers = 1; } @@ -2514,13 +2523,12 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct else if (draw.index.format == 42) p.index_type = VK_INDEX_TYPE_UINT32; else if (draw.index.va) return unsupported_at(__LINE__); p.index_first = draw.first; - // Index fetches outside the view read 0 in D3D12, but vkCmdBindIndexBuffer binds to the end of the buffer - // (the layer's device does not enable VK_KHR_maintenance5 for a bind size). So the view's size decides - // here: a draw wholly inside binds the buffer, one wholly outside binds the zero page, and one that - // straddles the end is refused rather than reading bytes the view does not cover. + // Index fetches outside the view read 0 in D3D12, but vkCmdBindIndexBuffer binds to the end of the buffer (the + // layer's device does not enable VK_KHR_maintenance5 for a bind size). A draw wholly inside the view binds + // the buffer. One that reads past the view's end binds the zero page when every index is outside, else a + // scratch copy of the indices it fetches (in-view part copied, the rest zero), so no byte past the view is read. const std::uint64_t index_bytes = p.index_type == VK_INDEX_TYPE_UINT32 ? 4 : 2; std::uint64_t view_indices = 0; - bool resolved = false; if (draw.index.va) { std::uint64_t size = draw.index.size; if (!vk.buffer_at(draw.index.va, size, p.index_buffer, p.index_offset)) { @@ -2536,17 +2544,33 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct } p.index_size = size; view_indices = size / index_bytes; // size is the view's, cut at the buffer's end - resolved = true; } const std::uint64_t last = std::uint64_t(draw.first) + draw.count; // one past the last index fetched - if (resolved && draw.count > 0 && last > view_indices && draw.first < view_indices) - return unsupported_at(__LINE__); - if (!resolved || (draw.count > 0 && draw.first >= view_indices)) { // every index reads 0 + if (!draw.index.va) { if (!vk.zero_buffer) return unresolved_at(__LINE__); - if (resolved && std::uint64_t(draw.count) * index_bytes > vk.zero_size) return unsupported_at(__LINE__); p.index_buffer = vk.zero_buffer; p.index_offset = vk.zero_offset; p.index_first = 0; + } else if (draw.count > 0 && last > view_indices) { + const std::uint64_t inside = draw.first < view_indices ? view_indices - draw.first : 0; + const std::uint64_t bytes = std::uint64_t(draw.count) * index_bytes; + if (inside == 0 && vk.zero_buffer && bytes <= vk.zero_size) { + p.index_buffer = vk.zero_buffer; + p.index_offset = vk.zero_offset; + p.index_first = 0; + } else { + if (!vk.copy_scratch || !vk.fill_buffer || !vk.copy_buffer) return ReplayResult::unsupported; + const std::uint64_t fill = (bytes + 3) & ~std::uint64_t(3); // vkCmdFillBuffer: multiples of 4 + VkBuffer scratch = VK_NULL_HANDLE; + VkDeviceSize offset = 0; + if (!vk.copy_scratch(fill + 4, scratch, offset)) return ReplayResult::unsupported; + offset = (offset + 3) & ~VkDeviceSize(3); // also a multiple of the index size + p.index_stage = {scratch, offset, fill, p.index_buffer, + p.index_offset + VkDeviceSize(draw.first) * index_bytes, inside * index_bytes}; + p.index_buffer = scratch; + p.index_offset = offset; + p.index_first = 0; + } } } return ReplayResult::success; @@ -4836,6 +4860,21 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_ const GraphicsPipeline& graphics = *d.graphics; if (d.depth.id && (graphics.depth_aspects & VK_IMAGE_ASPECT_DEPTH_BIT)) rendering.pDepthAttachment = &depth; if (d.depth.id && (graphics.depth_aspects & VK_IMAGE_ASPECT_STENCIL_BIT)) rendering.pStencilAttachment = &depth; + if (d.index_stage.fill_bytes) { + const auto& stage = d.index_stage; + constexpr VkAccessFlags transfer_rw = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT; + detail::memory_barrier(vk, command_buffer, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + transfer_rw, VK_PIPELINE_STAGE_TRANSFER_BIT); + vk.fill_buffer(command_buffer, stage.scratch, stage.scratch_offset, stage.fill_bytes, 0); + if (stage.copy_bytes) { + detail::memory_barrier(vk, command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + transfer_rw, VK_PIPELINE_STAGE_TRANSFER_BIT); + const VkBufferCopy region{stage.source_offset, stage.scratch_offset, stage.copy_bytes}; + vk.copy_buffer(command_buffer, stage.source, stage.scratch, 1, ®ion); + } + detail::memory_barrier(vk, command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_INDEX_READ_BIT, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT); + } vk.begin_rendering(command_buffer, &rendering); ShaderUserData data{}; diff --git a/runtime/test/d3d12_draw_test.cpp b/runtime/test/d3d12_draw_test.cpp index ac9c53b7b..772ff9577 100644 --- a/runtime/test/d3d12_draw_test.cpp +++ b/runtime/test/d3d12_draw_test.cpp @@ -671,9 +671,10 @@ int main(int argc, char** argv) { {strip_off_pso.p, {upload_va + 3072, 8, DXGI_FORMAT_R16_UINT}, 4, &view_out_pixels, 4}, // Negative control: the view covers the 8 indices, the same draw reads the quad. {strip_off_pso.p, {upload_va + 3072, 16, DXGI_FORMAT_R16_UINT}, 4, &view_in_pixels, 4}, - // Indices 2..5 cross the view's end: refused, nothing is read outside the view. - {strip_off_pso.p, {upload_va + 3072, 8, DXGI_FORMAT_R16_UINT}, 4, &view_straddle_pixels, 2, - leonida::ReplayResult::unsupported}, + // Indices 2..5 cross the view's end: 2 and 3 are read, 4 and 5 are outside and read 0, so the strip is + // (2, 3, 0, 0): one triangle (2, 3, 0) of the top-left quad. Without the cut the buffer's 0, 1 would + // give (2, 3, 0, 1), the whole quad. + {strip_off_pso.p, {upload_va + 3072, 8, DXGI_FORMAT_R16_UINT}, 4, &view_straddle_pixels, 2}, }; UINT64 strip_fence = 10; for (const auto& sp : strip_passes) { @@ -1351,6 +1352,11 @@ int main(int argc, char** argv) { } } EXPECT(view_out_red == 0); + // Straddling draw: the strip is (2, 3, 0, 0), the lower-left half of the quad; the buffer's own 0, 1 would also + // paint the upper-right half. + const auto straddle_px = [&](UINT col, UINT row) { return view_straddle_pixels.data() + row * 256 + col * 4; }; + EXPECT(straddle_px(4, 28)[0] == 255 && straddle_px(4, 28)[2] == 0); // lower-left corner of the quad: drawn + EXPECT(straddle_px(28, 4)[0] == 0 && straddle_px(28, 4)[2] == 255); // upper-right corner: blue EXPECT(view_in_tl_red == (size / 2) * (size / 2)); std::printf("index view size: draw past the view painted %u red pixels (want 0); view covering the draw painted " "%u of %u top-left pixels\n", view_out_red, view_in_tl_red, (size / 2) * (size / 2)); From 369b3265995ae3668410e5ffc99cedbb1d123740 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 18:35:20 +0100 Subject: [PATCH 3/9] fix: scratch buffers allow index-buffer use for the staged index copy --- runtime/src/vulkan_scratch.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/src/vulkan_scratch.h b/runtime/src/vulkan_scratch.h index 753701e1c..ac790b1a5 100644 --- a/runtime/src/vulkan_scratch.h +++ b/runtime/src/vulkan_scratch.h @@ -161,7 +161,9 @@ class ScratchBuffers { bool make_chunk(std::uint64_t size, Chunk& out) { VkBufferCreateInfo info{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; info.size = size; - info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | extra_usage_; + // INDEX_BUFFER: a draw that reads past its index view's end binds a staged copy (vulkan_replay.h, prepare). + info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | + VK_BUFFER_USAGE_INDEX_BUFFER_BIT | extra_usage_; // A retired chunk can be reused by a submission on a different queue family. share_across_queue_families(info, families_); if (vk_.vkCreateBuffer(device_, &info, nullptr, &out.buffer) != VK_SUCCESS) return false; From b86163a92f293712167f613381803b62560ac0b5 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 18:50:30 +0100 Subject: [PATCH 4/9] fix: bound null index views to zero page --- runtime/src/vulkan_replay.h | 7 +---- runtime/test/d3d12_draw_test.cpp | 49 +++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index 1be3e91d7..5d84b428c 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h @@ -2546,12 +2546,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct view_indices = size / index_bytes; // size is the view's, cut at the buffer's end } const std::uint64_t last = std::uint64_t(draw.first) + draw.count; // one past the last index fetched - if (!draw.index.va) { - if (!vk.zero_buffer) return unresolved_at(__LINE__); - p.index_buffer = vk.zero_buffer; - p.index_offset = vk.zero_offset; - p.index_first = 0; - } else if (draw.count > 0 && last > view_indices) { + if (!draw.index.va || (draw.count > 0 && last > view_indices)) { const std::uint64_t inside = draw.first < view_indices ? view_indices - draw.first : 0; const std::uint64_t bytes = std::uint64_t(draw.count) * index_bytes; if (inside == 0 && vk.zero_buffer && bytes <= vk.zero_size) { diff --git a/runtime/test/d3d12_draw_test.cpp b/runtime/test/d3d12_draw_test.cpp index 772ff9577..51f098ccc 100644 --- a/runtime/test/d3d12_draw_test.cpp +++ b/runtime/test/d3d12_draw_test.cpp @@ -133,6 +133,7 @@ int main(int argc, char** argv) { std::vector strip16_pixels(size * 256), strip32_pixels(size * 256), strip_nocut_pixels(size * 256); // Index buffer view size: a fetch past SizeInBytes reads index 0 (view_out), one inside the view reads the data. std::vector view_out_pixels(size * 256), view_in_pixels(size * 256), view_straddle_pixels(size * 256); + std::vector null_ib_pixels(size * 256), zero_ib_pixels(size * 256), live_ib_pixels(size * 256); std::vector msaa_full_pixels(size * 256), msaa_half_pixels(size * 256); bool ran_msaa = false; std::vector step2_pixels(size * 256), step1_pixels(size * 256); @@ -173,6 +174,30 @@ int main(int argc, char** argv) { reinterpret_cast(&device.p), /*console_lists=*/false))); rt::d3d12::set_device_outer(inner, device.p); + // First arena allocation follows the 64 KiB zero page. A broken null-IBV bind can fetch these indices. + constexpr UINT large_index_count = 40000; + const D3D12_HEAP_PROPERTIES index_upload_heap{D3D12_HEAP_TYPE_UPLOAD}; + const D3D12_HEAP_PROPERTIES index_default_heap{D3D12_HEAP_TYPE_DEFAULT}; + const auto large_index_desc = buffer_desc(large_index_count * sizeof(std::uint16_t)); + Ref live_indices, index_upload, zero_indices; + EXPECT(SUCCEEDED(device->CreateCommittedResource(&index_default_heap, D3D12_HEAP_FLAG_NONE, &large_index_desc, + D3D12_RESOURCE_STATE_COPY_DEST, nullptr, + IID_PPV_ARGS(&live_indices.p)))); + EXPECT(live_indices->GetGPUVirtualAddress() == 64 * 1024); + EXPECT(SUCCEEDED(device->CreateCommittedResource(&index_upload_heap, D3D12_HEAP_FLAG_NONE, &large_index_desc, + D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, + IID_PPV_ARGS(&index_upload.p)))); + EXPECT(SUCCEEDED(device->CreateCommittedResource(&index_upload_heap, D3D12_HEAP_FLAG_NONE, &large_index_desc, + D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, + IID_PPV_ARGS(&zero_indices.p)))); + void* index_data = nullptr; + EXPECT(SUCCEEDED(index_upload->Map(0, nullptr, &index_data))); + for (UINT i = 0; i < large_index_count; ++i) static_cast(index_data)[i] = i % 4; + index_upload->Unmap(0, nullptr); + EXPECT(SUCCEEDED(zero_indices->Map(0, nullptr, &index_data))); + std::memset(index_data, 0, large_index_count * sizeof(std::uint16_t)); + zero_indices->Unmap(0, nullptr); + // Root signature: [0] two constants (s0, s1: offset), [1] a root CBV (s2:s3: tint). D3D12_ROOT_PARAMETER params[2] = {}; params[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; @@ -408,6 +433,10 @@ int main(int argc, char** argv) { EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence.p)))); // Upload the vertices, prepare the target. + list->CopyBufferRegion(live_indices.p, 0, index_upload.p, 0, large_index_count * sizeof(std::uint16_t)); + const auto indices_ready = transition(live_indices.p, D3D12_RESOURCE_STATE_COPY_DEST, + D3D12_RESOURCE_STATE_INDEX_BUFFER); + list->ResourceBarrier(1, &indices_ready); list->CopyBufferRegion(vertex_buffer.p, 0, upload.p, 0, sizeof(vertices)); D3D12_RESOURCE_BARRIER barriers[2] = { transition(vertex_buffer.p, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER), @@ -662,6 +691,7 @@ int main(int argc, char** argv) { std::vector* out; UINT first = 0; // StartIndexLocation leonida::ReplayResult want = leonida::ReplayResult::success; + bool bind_index = true; }; const StripPass strip_passes[] = { {strip16_pso.p, {upload_va + 1280, sizeof(strip_idx16), DXGI_FORMAT_R16_UINT}, 9, &strip16_pixels}, @@ -675,6 +705,11 @@ int main(int argc, char** argv) { // (2, 3, 0, 0): one triangle (2, 3, 0) of the top-left quad. Without the cut the buffer's 0, 1 would // give (2, 3, 0, 1), the whole quad. {strip_off_pso.p, {upload_va + 3072, 8, DXGI_FORMAT_R16_UINT}, 4, &view_straddle_pixels, 2}, + {strip_off_pso.p, {}, large_index_count, &null_ib_pixels, 0, leonida::ReplayResult::success, false}, + {strip_off_pso.p, {zero_indices->GetGPUVirtualAddress(), large_index_count * 2, DXGI_FORMAT_R16_UINT}, + large_index_count, &zero_ib_pixels}, + {strip_off_pso.p, {live_indices->GetGPUVirtualAddress(), large_index_count * 2, DXGI_FORMAT_R16_UINT}, + large_index_count, &live_ib_pixels}, }; UINT64 strip_fence = 10; for (const auto& sp : strip_passes) { @@ -684,7 +719,7 @@ int main(int argc, char** argv) { list->SetGraphicsRootSignature(root.p); list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); list->IASetVertexBuffers(0, 1, &strip_vbv); - list->IASetIndexBuffer(&sp.ibv); + if (sp.bind_index) list->IASetIndexBuffer(&sp.ibv); list->RSSetViewports(1, &viewport); list->RSSetScissorRects(1, &scissor); list->OMSetRenderTargets(1, &rtv, FALSE, nullptr); @@ -1352,6 +1387,18 @@ int main(int argc, char** argv) { } } EXPECT(view_out_red == 0); + UINT null_red = 0, zero_red = 0, live_red = 0; + for (UINT row = 0; row < size; ++row) { + for (UINT col = 0; col < size; ++col) { + const UINT offset = row * 256 + col * 4; + null_red += null_ib_pixels[offset] == 255; + zero_red += zero_ib_pixels[offset] == 255; + live_red += live_ib_pixels[offset] == 255; + } + } + EXPECT(null_red == 0 && zero_red == 0 && live_red > 0); + std::printf("40000 indices: null view %u red, zero view %u red, live view %u red\n", + null_red, zero_red, live_red); // Straddling draw: the strip is (2, 3, 0, 0), the lower-left half of the quad; the buffer's own 0, 1 would also // paint the upper-right half. const auto straddle_px = [&](UINT col, UINT row) { return view_straddle_pixels.data() + row * 256 + col * 4; }; From 0ee8064a74a2d62d349885177494be1f259c86e2 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 18:56:08 +0100 Subject: [PATCH 5/9] test: the null index view test releases its buffers before the device proxy reference check --- runtime/test/d3d12_draw_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/test/d3d12_draw_test.cpp b/runtime/test/d3d12_draw_test.cpp index 51f098ccc..6d103ad41 100644 --- a/runtime/test/d3d12_draw_test.cpp +++ b/runtime/test/d3d12_draw_test.cpp @@ -1284,7 +1284,8 @@ int main(int argc, char** argv) { list->OMSetRenderTargets(9, &rtv, TRUE, nullptr); EXPECT(list->Close() == E_INVALIDARG); - for (auto* r : {&vertex_buffer, &upload, &readback, &target, &uint_target}) r->reset(); + for (auto* r : {&vertex_buffer, &upload, &readback, &target, &uint_target, &live_indices, &index_upload, &zero_indices}) + r->reset(); for (auto* p : {&mrt, &instanced, &refused, &unfed, &xor_pso, &fullscreen}) p->reset(); pso.reset(); root.reset(); From ce7ade93f8a2078add9ba0f77b5196057c8e1d03 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Tue, 24 Nov 2026 00:35:54 +0100 Subject: [PATCH 6/9] test: replay_index_view_test covers the index view bounds in prepare_draw without a GPU --- runtime/CMakeLists.txt | 7 ++ runtime/test/replay_index_view_test.cpp | 134 ++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 runtime/test/replay_index_view_test.cpp diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 2763e9d1b..dad7266f9 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -3985,6 +3985,13 @@ if(TARGET Vulkan::Headers) target_compile_definitions(replay_copy_offset_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) endif() add_test(NAME replay_copy_offset COMMAND replay_copy_offset_test) + # An indexed draw's index buffer view size bounds the index fetch: past the view reads 0 (no GPU). + add_executable(replay_index_view_test test/replay_index_view_test.cpp) + target_link_libraries(replay_index_view_test PRIVATE Vulkan::Headers) + if(WIN32) + target_compile_definitions(replay_index_view_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) + endif() + add_test(NAME replay_index_view COMMAND replay_index_view_test) # KHR CopyRaytracingAccelerationStructure (CLONE, COMPACT) and COMPACTED_SIZE postbuild (no GPU). add_executable(replay_khr_as_copy_postbuild_test test/replay_khr_as_copy_postbuild_test.cpp) target_link_libraries(replay_khr_as_copy_postbuild_test PRIVATE Vulkan::Headers) diff --git a/runtime/test/replay_index_view_test.cpp b/runtime/test/replay_index_view_test.cpp new file mode 100644 index 000000000..8cd5fe9e0 --- /dev/null +++ b/runtime/test/replay_index_view_test.cpp @@ -0,0 +1,134 @@ +// An indexed draw's index buffer view SizeInBytes bounds the index fetch (D3D12: a fetch past the view reads 0). +// prepare_draw decides, from the view and the draw's StartIndexLocation/IndexCount, whether to bind the buffer, the +// zero page, or a staged copy that holds only the in-view indices. No Vulkan loader, GPU or game data. +#include "../src/vulkan_replay.h" + +#include +#include + +namespace { + +void dummy() {} + +template +T stub() { + return reinterpret_cast(&dummy); +} + +template +T handle(std::uintptr_t n) { + return reinterpret_cast(n); +} + +int failures = 0; +void expect(bool ok, const char* what) { + if (!ok) { + std::fprintf(stderr, "FAIL: %s\n", what); + ++failures; + } +} + +constexpr std::uint64_t ib_va = 0x10000; +constexpr std::uint32_t dxgi_r16_uint = 57; + +} // namespace + +int main() { + using namespace leonida; + using detail::PreparedDraw; + + const VkBuffer index_buffer = handle(0x1111); + const VkBuffer zero_buffer = handle(0x2222); + const VkBuffer scratch_buffer = handle(0x3333); + + GraphicsPipeline pipeline; + pipeline.pipeline = handle(0x4444); + + ReplayFunctions vk{}; + vk.begin_rendering = stub(); + vk.end_rendering = stub(); + vk.copy_buffer = stub(); + vk.fill_buffer = stub(); + vk.bind_pipeline = stub(); + vk.push_constants = stub(); + vk.bind_vertex_buffers2 = stub(); + vk.bind_index_buffer = stub(); + vk.set_viewport = stub(); + vk.set_scissor = stub(); + vk.set_primitive_topology = stub(); + vk.set_primitive_restart_enable = stub(); + vk.set_stencil_reference = stub(); + vk.set_blend_constants = stub(); + vk.draw = stub(); + vk.draw_indexed = stub(); + vk.graphics_pipeline = [&](std::uintptr_t) { return &pipeline; }; + vk.image_view = [](const ResourceBinding&, const VkImageSubresourceRange&) { return VkImageView(VK_NULL_HANDLE); }; + // The index buffer is 8 indices (16 bytes) of the arena; a view is cut at the buffer's end. + vk.buffer_at = [&](std::uint64_t va, std::uint64_t& size, VkBuffer& buffer, VkDeviceSize& offset) { + if (va != ib_va) return false; + size = std::min(size, 16); + buffer = index_buffer; + offset = 0; + return true; + }; + vk.zero_buffer = zero_buffer; + vk.zero_offset = 0; + vk.zero_size = 64; + vk.copy_scratch = [&](VkDeviceSize, VkBuffer& buffer, VkDeviceSize& offset) { + buffer = scratch_buffer; + offset = 0; + return true; + }; + const auto no_resource = [](auto) -> const ResourceBinding* { return nullptr; }; + + const auto prepare = [&](std::uint64_t va, std::uint32_t view_bytes, std::uint32_t first, std::uint32_t count, + PreparedDraw& p) { + Draw draw; + draw.indexed = true; + draw.index = {va, view_bytes, dxgi_r16_uint}; + draw.first = first; + draw.count = count; + draw.instances = 1; + return detail::prepare_draw(draw, no_resource, vk, p); + }; + + { // View of 4 indices, draw of indices 0..3: wholly inside, the buffer is bound as it is. + PreparedDraw p; + expect(prepare(ib_va, 8, 0, 4, p) == ReplayResult::success, "inside: success"); + expect(p.index_buffer == index_buffer && p.index_first == 0 && p.index_stage.fill_bytes == 0, + "inside: the buffer is bound, no staging"); + } + { // View of 4 indices, draw of indices 4..7: all outside, every index reads 0, from the zero page. + PreparedDraw p; + expect(prepare(ib_va, 8, 4, 4, p) == ReplayResult::success, "outside: success"); + expect(p.index_buffer == zero_buffer && p.index_first == 0 && p.index_stage.fill_bytes == 0, + "outside: the zero page is bound, not the buffer's second half"); + } + { // View of 4 indices, draw of indices 2..5: 2 and 3 are read, 4 and 5 read 0. + PreparedDraw p; + expect(prepare(ib_va, 8, 2, 4, p) == ReplayResult::success, "straddle: success"); + expect(p.index_buffer == scratch_buffer && p.index_first == 0, "straddle: a staged copy is bound"); + expect(p.index_stage.source == index_buffer && p.index_stage.source_offset == 4 && + p.index_stage.copy_bytes == 4, + "straddle: only the 2 in-view indices (4 bytes at byte 4) are copied"); + } + { // No index buffer bound: every index reads 0. + PreparedDraw p; + expect(prepare(0, 0, 0, 16, p) == ReplayResult::success, "null view: success"); + expect(p.index_buffer == zero_buffer && p.index_first == 0 && p.index_stage.fill_bytes == 0, + "null view: the zero page is bound"); + } + { // No index buffer bound, a draw larger than the zero page: staged zeros, never the arena after the page. + PreparedDraw p; + expect(prepare(0, 0, 0, 100, p) == ReplayResult::success, "null view, large draw: success"); + expect(p.index_buffer == scratch_buffer && p.index_stage.copy_bytes == 0 && p.index_stage.fill_bytes >= 200, + "null view, large draw: a zeroed scratch covers the whole draw"); + } + + if (failures) { + std::fprintf(stderr, "replay_index_view_test: FAILED (%d failures)\n", failures); + return 1; + } + std::printf("replay_index_view_test: all passed\n"); + return 0; +} From 26f1f58f0564f5c5703c78c6299218a03f15212b Mon Sep 17 00:00:00 2001 From: TimIdle <339155848+TimIdle@users.noreply.github.com> Date: Wed, 25 Nov 2026 10:30:18 +0800 Subject: [PATCH 7/9] test: the first arena allocation follows the zero page and the quad index table main now puts a 256 KiB table of quad-list indices (kQuadIndexCount 32-bit indices) right after the 64 KiB zero page, so the first committed buffer of the null index view check starts at 320 KiB, not 64 KiB. Only the expected address changes. Co-Authored-By: Claude Opus 5.5 --- runtime/test/d3d12_draw_test.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/test/d3d12_draw_test.cpp b/runtime/test/d3d12_draw_test.cpp index 6d103ad41..be65d1208 100644 --- a/runtime/test/d3d12_draw_test.cpp +++ b/runtime/test/d3d12_draw_test.cpp @@ -174,7 +174,8 @@ int main(int argc, char** argv) { reinterpret_cast(&device.p), /*console_lists=*/false))); rt::d3d12::set_device_outer(inner, device.p); - // First arena allocation follows the 64 KiB zero page. A broken null-IBV bind can fetch these indices. + // First arena allocation follows the 64 KiB zero page and the 256 KiB quad index table (64 Ki 32-bit + // indices) after it. A broken null-IBV bind can fetch these indices. constexpr UINT large_index_count = 40000; const D3D12_HEAP_PROPERTIES index_upload_heap{D3D12_HEAP_TYPE_UPLOAD}; const D3D12_HEAP_PROPERTIES index_default_heap{D3D12_HEAP_TYPE_DEFAULT}; @@ -183,7 +184,7 @@ int main(int argc, char** argv) { EXPECT(SUCCEEDED(device->CreateCommittedResource(&index_default_heap, D3D12_HEAP_FLAG_NONE, &large_index_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&live_indices.p)))); - EXPECT(live_indices->GetGPUVirtualAddress() == 64 * 1024); + EXPECT(live_indices->GetGPUVirtualAddress() == 64 * 1024 + 64 * 1024 * sizeof(std::uint32_t)); EXPECT(SUCCEEDED(device->CreateCommittedResource(&index_upload_heap, D3D12_HEAP_FLAG_NONE, &large_index_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&index_upload.p)))); From 21c7bc80650f32960e31adb1784dfd8a6364e6d3 Mon Sep 17 00:00:00 2001 From: TimIdle <339155848+TimIdle@users.noreply.github.com> Date: Wed, 25 Nov 2026 14:41:17 +0800 Subject: [PATCH 8/9] fix: an indexed quad list keeps main's expansion pass instead of a staged index copy main's prepare_quad_indices already reads only the index view and zero-fills the rest, from p.index_buffer, p.index_size and draw.first. A staged copy would rebase the indices to 0 under it. replay_index_view_test covers a quad list that straddles the view and one with no index buffer. Co-Authored-By: Claude Opus 5.5 --- runtime/src/vulkan_replay.h | 13 ++++++++++--- runtime/test/replay_index_view_test.cpp | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index 5d84b428c..a1bd35ebe 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h @@ -2527,6 +2527,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct // layer's device does not enable VK_KHR_maintenance5 for a bind size). A draw wholly inside the view binds // the buffer. One that reads past the view's end binds the zero page when every index is outside, else a // scratch copy of the indices it fetches (in-view part copied, the rest zero), so no byte past the view is read. + // An indexed quad list is left to its expansion pass, which reads only the view (prepare_quad_indices). const std::uint64_t index_bytes = p.index_type == VK_INDEX_TYPE_UINT32 ? 4 : 2; std::uint64_t view_indices = 0; if (draw.index.va) { @@ -2546,7 +2547,13 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct view_indices = size / index_bytes; // size is the view's, cut at the buffer's end } const std::uint64_t last = std::uint64_t(draw.first) + draw.count; // one past the last index fetched - if (!draw.index.va || (draw.count > 0 && last > view_indices)) { + if (draw.topology == topology_quad_list) { + if (!draw.index.va) { // no index buffer: every index reads 0 + if (!vk.zero_buffer) return unresolved_at(__LINE__); + p.index_buffer = vk.zero_buffer; + p.index_offset = vk.zero_offset; + } + } else if (!draw.index.va || (draw.count > 0 && last > view_indices)) { const std::uint64_t inside = draw.first < view_indices ? view_indices - draw.first : 0; const std::uint64_t bytes = std::uint64_t(draw.count) * index_bytes; if (inside == 0 && vk.zero_buffer && bytes <= vk.zero_size) { @@ -2554,11 +2561,11 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct p.index_offset = vk.zero_offset; p.index_first = 0; } else { - if (!vk.copy_scratch || !vk.fill_buffer || !vk.copy_buffer) return ReplayResult::unsupported; + if (!vk.copy_scratch || !vk.fill_buffer || !vk.copy_buffer) return unsupported_at(__LINE__); const std::uint64_t fill = (bytes + 3) & ~std::uint64_t(3); // vkCmdFillBuffer: multiples of 4 VkBuffer scratch = VK_NULL_HANDLE; VkDeviceSize offset = 0; - if (!vk.copy_scratch(fill + 4, scratch, offset)) return ReplayResult::unsupported; + if (!vk.copy_scratch(fill + 4, scratch, offset)) return unsupported_at(__LINE__); offset = (offset + 3) & ~VkDeviceSize(3); // also a multiple of the index size p.index_stage = {scratch, offset, fill, p.index_buffer, p.index_offset + VkDeviceSize(draw.first) * index_bytes, inside * index_bytes}; diff --git a/runtime/test/replay_index_view_test.cpp b/runtime/test/replay_index_view_test.cpp index 8cd5fe9e0..879d34790 100644 --- a/runtime/test/replay_index_view_test.cpp +++ b/runtime/test/replay_index_view_test.cpp @@ -82,9 +82,10 @@ int main() { const auto no_resource = [](auto) -> const ResourceBinding* { return nullptr; }; const auto prepare = [&](std::uint64_t va, std::uint32_t view_bytes, std::uint32_t first, std::uint32_t count, - PreparedDraw& p) { + PreparedDraw& p, std::uint32_t topology = 0) { Draw draw; draw.indexed = true; + draw.topology = topology; draw.index = {va, view_bytes, dxgi_r16_uint}; draw.first = first; draw.count = count; @@ -125,6 +126,19 @@ int main() { "null view, large draw: a zeroed scratch covers the whole draw"); } + { // An indexed quad list of indices 2..9 over a view of 4: its expansion pass reads only the view + // (prepare_quad_indices), so the buffer and the view's size stay as they are and nothing is staged. + PreparedDraw p; + expect(prepare(ib_va, 8, 2, 8, p, topology_quad_list) == ReplayResult::success, "quad straddle: success"); + expect(p.index_buffer == index_buffer && p.index_size == 8 && p.index_stage.fill_bytes == 0, + "quad straddle: the buffer and view size go to the expansion pass, no staging"); + } + { // An indexed quad list with no index buffer: the zero page, as main binds it. + PreparedDraw p; + expect(prepare(0, 0, 0, 8, p, topology_quad_list) == ReplayResult::success, "quad null view: success"); + expect(p.index_buffer == zero_buffer && p.index_stage.fill_bytes == 0, "quad null view: the zero page is bound"); + } + if (failures) { std::fprintf(stderr, "replay_index_view_test: FAILED (%d failures)\n", failures); return 1; From b403c27e177666507762a20ed3563341454a0084 Mon Sep 17 00:00:00 2001 From: TimIdle <339155848+TimIdle@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:03:54 +0800 Subject: [PATCH 9/9] fix: the device asks scratch for index-buffer use, and the draw test follows main's quad index table main gives ScratchBuffers an extra_usage set by its creator and vulkan_scratch_test checks that a chunk carries only what was asked. The staged index copy now asks for INDEX_BUFFER there, on every GPU, instead of in vulkan_scratch.h. The first arena allocation follows the 64 KiB zero page and main's quad index table of 16 Ki quads of 6 indices. Co-Authored-By: Claude Opus 5.5 --- runtime/shims/d3d12_vulkan_device.cpp | 5 ++++- runtime/src/vulkan_scratch.h | 4 +--- runtime/test/d3d12_draw_test.cpp | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 12494d201..33c489eab 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -9841,7 +9841,10 @@ class Device final [this, index_scratch](const VkMemoryRequirements& requirements) { return state_.allocate(requirements, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, nullptr, index_scratch); }, - index_scratch ? VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT : 0, state_.families); + // INDEX_BUFFER on every GPU: a draw that reads past its index view's end binds a staged copy + // (vulkan_replay.h, prepare_draw). + VK_BUFFER_USAGE_INDEX_BUFFER_BIT | (index_scratch ? VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT : 0), + state_.families); if (info.buffer_device_address && info.physical && info.get_instance_proc) { if (const auto get_props = reinterpret_cast( info.get_instance_proc(info.instance, "vkGetPhysicalDeviceProperties"))) { diff --git a/runtime/src/vulkan_scratch.h b/runtime/src/vulkan_scratch.h index ac790b1a5..753701e1c 100644 --- a/runtime/src/vulkan_scratch.h +++ b/runtime/src/vulkan_scratch.h @@ -161,9 +161,7 @@ class ScratchBuffers { bool make_chunk(std::uint64_t size, Chunk& out) { VkBufferCreateInfo info{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; info.size = size; - // INDEX_BUFFER: a draw that reads past its index view's end binds a staged copy (vulkan_replay.h, prepare). - info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | - VK_BUFFER_USAGE_INDEX_BUFFER_BIT | extra_usage_; + info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | extra_usage_; // A retired chunk can be reused by a submission on a different queue family. share_across_queue_families(info, families_); if (vk_.vkCreateBuffer(device_, &info, nullptr, &out.buffer) != VK_SUCCESS) return false; diff --git a/runtime/test/d3d12_draw_test.cpp b/runtime/test/d3d12_draw_test.cpp index be65d1208..8957d74c1 100644 --- a/runtime/test/d3d12_draw_test.cpp +++ b/runtime/test/d3d12_draw_test.cpp @@ -184,7 +184,8 @@ int main(int argc, char** argv) { EXPECT(SUCCEEDED(device->CreateCommittedResource(&index_default_heap, D3D12_HEAP_FLAG_NONE, &large_index_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&live_indices.p)))); - EXPECT(live_indices->GetGPUVirtualAddress() == 64 * 1024 + 64 * 1024 * sizeof(std::uint32_t)); + // The first allocation follows the 64 KiB zero page and the quad index table (16 Ki quads of 6 indices). + EXPECT(live_indices->GetGPUVirtualAddress() == 64 * 1024 + 16 * 1024 * 6 * sizeof(std::uint32_t)); EXPECT(SUCCEEDED(device->CreateCommittedResource(&index_upload_heap, D3D12_HEAP_FLAG_NONE, &large_index_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&index_upload.p))));