upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/vk_bc_zero_init_test.cpp
diff options
context:
space:
mode:
authortahffo68hk-hash <tahffo68hk@gmail.com>2026-11-24 14:58:19 +0800
committertahffo68hk-hash <tahffo68hk@gmail.com>2026-11-24 14:58:19 +0800
commit1d4310bc71ed62a86156a26950ff96fe560ccbf2 (patch)
treecdaef35960043d5386b1a7741a57432f5d742ad0 /runtime/test/vk_bc_zero_init_test.cpp
parent8f481cf16f261c7f37458aeb45e8f4e19994146d (diff)
vulkan_replay: enforce 4-byte vkCmdFillBuffer alignment in zero_compressed_image
Diffstat (limited to 'runtime/test/vk_bc_zero_init_test.cpp')
-rw-r--r--runtime/test/vk_bc_zero_init_test.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/runtime/test/vk_bc_zero_init_test.cpp b/runtime/test/vk_bc_zero_init_test.cpp
index 6edc36fcb..495a4b92d 100644
--- a/runtime/test/vk_bc_zero_init_test.cpp
+++ b/runtime/test/vk_bc_zero_init_test.cpp
@@ -380,6 +380,86 @@ int main() {
380 VulkanQueue q(ctx, d.queue, d.family); 380 VulkanQueue q(ctx, d.queue, d.family);
381 EXPECT(q.ok()); 381 EXPECT(q.ok());
382 EXPECT(run_d3d220_cases(d, ctx, q, poison_buf, up_buf, up_ptr, rb_buf, rb_ptr, "copy_scratch") == 0); 382 EXPECT(run_d3d220_cases(d, ctx, q, poison_buf, up_buf, up_ptr, rb_buf, rb_ptr, "copy_scratch") == 0);
383
384 // Copy-only queue zero-init of odd-sized 1B (R8_UNORM 3x3 = 9B) and 2B (R16_UNORM 3x1 = 6B) color images
385 // via copy_scratch: must round vkCmdFillBuffer size/offset to 4 bytes (VUID-vkCmdFillBuffer-dstOffset-00024
386 // / -size-00028) and zero all texels on real GPU hardware.
387 {
388 VulkanQueue copy_q(ctx, d.queue, d.family, VulkanQueue::QueueKind::copy);
389 EXPECT(copy_q.ok());
390
391 struct SmallFormatCase {
392 const char* name;
393 VkFormat format;
394 std::uint32_t width, height, bpp;
395 };
396 const SmallFormatCase small_cases[] = {
397 {"R8_UNORM 3x3", VK_FORMAT_R8_UNORM, 3, 3, 1},
398 {"R16_UNORM 3x1", VK_FORMAT_R16_UNORM, 3, 1, 2},
399 };
400 for (const auto& sc : small_cases) {
401 OwnedImage img;
402 EXPECT(create_image(d, sc.format, sc.width, sc.height, 1, poison_buf, img));
403 EXPECT(img.poisoned);
404 ResourceBinding rb{};
405 rb.image = img.image;
406 rb.format = sc.format;
407 rb.aspects = VK_IMAGE_ASPECT_COLOR_BIT;
408 rb.width = sc.width; rb.height = sc.height;
409 rb.mip_levels = 1; rb.array_layers = 1; rb.depth = 1; rb.samples = 1;
410 ctx.add_resource(30, rb, VK_IMAGE_LAYOUT_UNDEFINED);
411 std::memset(rb_ptr, 0xCD, 1024);
412
413 CommandList list;
414 EXPECT(list.transition({30, all_subresources, d3d12_state::copy_dest, d3d12_state::copy_source}));
415 const CopyLocation src_loc{30, false, 0, 0, 0, 0, 0, 0};
416 const CopyLocation dst_loc{2, true, 0, 0, sc.width, sc.height, 1, 256};
417 EXPECT(list.copy_texture({dst_loc, 0, 0, 0, src_loc, false, {}}));
418 EXPECT(list.close());
419 const CommandList* ptr = &list;
420 EXPECT(copy_q.execute({&ptr, 1}) == ReplayResult::success);
421 EXPECT(copy_q.idle());
422
423 const auto* out = static_cast<const std::uint8_t*>(rb_ptr);
424 for (std::uint32_t y = 0; y < sc.height; ++y)
425 for (std::uint32_t x = 0; x < sc.width * sc.bpp; ++x)
426 EXPECT(out[y * 256 + x] == 0x00);
427 ctx.remove_resource(30);
428 std::printf("copy-queue zero-init (%s via copy_scratch): ok\n", sc.name);
429 }
430 }
431 }
432
433 // Direct ReplayFunctions check: verify vkCmdFillBuffer dstOffset and size are 4-byte aligned even for
434 // odd-sized 1B/2B color images and unaligned scratch offsets (VUID-vkCmdFillBuffer-dstOffset-00024 / -size-00028).
435 {
436 static VkDeviceSize last_fill_off = 1, last_fill_size = 1;
437 static std::uint32_t fill_calls = 0;
438 ReplayFunctions mock{};
439 mock.pipeline_barrier = [](VkCommandBuffer, VkPipelineStageFlags, VkPipelineStageFlags, VkDependencyFlags,
440 std::uint32_t, const VkMemoryBarrier*, std::uint32_t, const VkBufferMemoryBarrier*,
441 std::uint32_t, const VkImageMemoryBarrier*) {};
442 mock.copy_buffer_to_image = [](VkCommandBuffer, VkBuffer, VkImage, VkImageLayout, std::uint32_t,
443 const VkBufferImageCopy*) {};
444 mock.fill_buffer = [](VkCommandBuffer, VkBuffer, VkDeviceSize off, VkDeviceSize size, std::uint32_t) {
445 last_fill_off = off;
446 last_fill_size = size;
447 ++fill_calls;
448 };
449 mock.copy_scratch = [](std::uint64_t, VkBuffer& buf, VkDeviceSize& off) {
450 buf = reinterpret_cast<VkBuffer>(std::uintptr_t(0x1234));
451 off = 2; // deliberately non-4-byte-aligned
452 return true;
453 };
454 ResourceBinding r8{};
455 r8.image = reinterpret_cast<VkImage>(std::uintptr_t(0x5678));
456 r8.format = VK_FORMAT_R8_UNORM;
457 r8.aspects = VK_IMAGE_ASPECT_COLOR_BIT;
458 r8.width = 3; r8.height = 3; r8.mip_levels = 1; r8.array_layers = 1; r8.depth = 1; r8.samples = 1;
459 fill_calls = 0;
460 EXPECT(detail::zero_compressed_image(mock, VK_NULL_HANDLE, r8, {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
461 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL));
462 EXPECT(fill_calls == 1 && (last_fill_off % 4) == 0 && (last_fill_size % 4) == 0 && last_fill_size >= 8);
383 } 463 }
384 464
385 EXPECT(d.validation_errors() == 0); 465 EXPECT(d.validation_errors() == 0);