diff options
| author | lumenpearson <139921639+lumenpearson@users.noreply.github.com> | 2026-11-22 23:25:25 +0300 |
|---|---|---|
| committer | lumenpearson <139921639+lumenpearson@users.noreply.github.com> | 2026-11-22 23:25:25 +0300 |
| commit | f324bfbc71f0eabf9515bcd7c8b7c9e4b89448bf (patch) | |
| tree | 2db4ae6fd5412abbbc3e1894f8bc7ed88c8ae514 /runtime/test | |
| parent | 18380c6d2baf1422109b369860a6e8be5e185b05 (diff) | |
| parent | f847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff) | |
Merge upstream main into SHADER-537
Diffstat (limited to 'runtime/test')
74 files changed, 9458 insertions, 313 deletions
diff --git a/runtime/test/bvh_builder_test.cpp b/runtime/test/bvh_builder_test.cpp index a730f190a..16e5db4d8 100644 --- a/runtime/test/bvh_builder_test.cpp +++ b/runtime/test/bvh_builder_test.cpp | |||
| @@ -154,6 +154,9 @@ int filter(EXCEPTION_POINTERS* e, Call* c) { | |||
| 154 | using Ctor = void* (*)(void* self, void* device, bool flag); | 154 | using Ctor = void* (*)(void* self, void* device, bool flag); |
| 155 | using Dtor = void (*)(void* self); | 155 | using Dtor = void (*)(void* self); |
| 156 | 156 | ||
| 157 | // Each guard returns a copy of `c`, not `c` itself: with `return c;` the local becomes the named return value, and | ||
| 158 | // clang-cl 19 and 20 crash (exit 139, in recoverAddrOfEscapedLocal) generating the __except filter that writes it, | ||
| 159 | // which stops the Linux cross-build (runtime/cmake/clang-cl-xwin.cmake). MSVC is fine either way. | ||
| 157 | Call guarded_ctor(Ctor fn, void* self, void* device, bool flag) { | 160 | Call guarded_ctor(Ctor fn, void* self, void* device, bool flag) { |
| 158 | Call c; | 161 | Call c; |
| 159 | __try { | 162 | __try { |
| @@ -161,7 +164,7 @@ Call guarded_ctor(Ctor fn, void* self, void* device, bool flag) { | |||
| 161 | } __except (filter(GetExceptionInformation(), &c)) { | 164 | } __except (filter(GetExceptionInformation(), &c)) { |
| 162 | c.faulted = true; | 165 | c.faulted = true; |
| 163 | } | 166 | } |
| 164 | return c; | 167 | return Call(c); |
| 165 | } | 168 | } |
| 166 | 169 | ||
| 167 | Call guarded_dtor(Dtor fn, void* self) { | 170 | Call guarded_dtor(Dtor fn, void* self) { |
| @@ -171,7 +174,7 @@ Call guarded_dtor(Dtor fn, void* self) { | |||
| 171 | } __except (filter(GetExceptionInformation(), &c)) { | 174 | } __except (filter(GetExceptionInformation(), &c)) { |
| 172 | c.faulted = true; | 175 | c.faulted = true; |
| 173 | } | 176 | } |
| 174 | return c; | 177 | return Call(c); |
| 175 | } | 178 | } |
| 176 | 179 | ||
| 177 | // main's loader (#95) maps, sets up TLS and runs DllMain, but doesn't register the image's x64 unwind tables yet | 180 | // main's loader (#95) maps, sets up TLS and runs DllMain, but doesn't register the image's x64 unwind tables yet |
| @@ -342,6 +345,40 @@ std::string container_shape(const void* bytecode, size_t length) { | |||
| 342 | return out; | 345 | return out; |
| 343 | } | 346 | } |
| 344 | 347 | ||
| 348 | // The module a container belongs to: the file name (without ".pdb") in its ILDN part, a DXIL debug-name record | ||
| 349 | // (u16 flags, u16 name length, then the PDB path). Empty when there is no such part. The module names are the ones | ||
| 350 | // listed in docs/embedded_shaders.md section 3. | ||
| 351 | std::string container_module(const void* bytecode, size_t length) { | ||
| 352 | const auto* b = static_cast<const uint8_t*>(bytecode); | ||
| 353 | auto u32 = [&](size_t o) { | ||
| 354 | uint32_t v = 0; | ||
| 355 | if (o + 4 <= length) std::memcpy(&v, b + o, 4); | ||
| 356 | return v; | ||
| 357 | }; | ||
| 358 | if (!b || length < 32 || std::memcmp(b, "DXBC", 4) != 0) return {}; | ||
| 359 | const uint32_t parts = u32(28); | ||
| 360 | for (uint32_t i = 0; i < parts && 32 + 4 * size_t(i) + 4 <= length; ++i) { | ||
| 361 | const size_t off = u32(32 + 4 * size_t(i)); | ||
| 362 | if (off + 8 > length || std::memcmp(b + off, "ILDN", 4) != 0) continue; | ||
| 363 | const size_t size = u32(off + 4), data = off + 8; | ||
| 364 | if (size < 5 || data + size > length) return {}; | ||
| 365 | std::string path(reinterpret_cast<const char*>(b + data + 4), size - 4); | ||
| 366 | path.resize(std::strlen(path.c_str())); | ||
| 367 | const size_t slash = path.find_last_of("\\/"); | ||
| 368 | std::string name = slash == std::string::npos ? path : path.substr(slash + 1); | ||
| 369 | if (name.size() > 4 && name.compare(name.size() - 4, 4, ".pdb") == 0) name.resize(name.size() - 4); | ||
| 370 | return name; | ||
| 371 | } | ||
| 372 | return {}; | ||
| 373 | } | ||
| 374 | |||
| 375 | // Every container the constructor has passed to slot 62 so far, to find one that is passed twice (RT-182). The bytes | ||
| 376 | // are compared, not a hash, and nothing is printed from them. | ||
| 377 | std::vector<std::vector<uint8_t>> g_seen_containers; | ||
| 378 | std::vector<std::string> g_seen_modules; | ||
| 379 | int g_repeat_first = 0, g_repeat_second = 0; // creation numbers (1-based) of the first repeat found, 0 = none | ||
| 380 | int g_repeats = 0; | ||
| 381 | |||
| 345 | // LEONIDA_BVH_DXIL=1: what each shader uses, from dxcompiler.dll's disassembly in memory: the distinct dx.op names | 382 | // LEONIDA_BVH_DXIL=1: what each shader uses, from dxcompiler.dll's disassembly in memory: the distinct dx.op names |
| 346 | // with call counts, and a few type/feature markers. Also dxil.dll's validator verdict. Names and counts only; the | 383 | // with call counts, and a few type/feature markers. Also dxil.dll's validator verdict. Names and counts only; the |
| 347 | // disassembly is not printed or written. The DLLs come from PATH or the Windows SDK, loaded at run time. | 384 | // disassembly is not printed or written. The DLLs come from PATH or the Windows SDK, loaded at run time. |
| @@ -459,6 +496,27 @@ uint64_t WINAPI record_slot62(void* self, uint64_t a1, uint64_t a2, uint64_t a3, | |||
| 459 | if (desc) { | 496 | if (desc) { |
| 460 | std::printf(" slot62 #%d container: %s\n", n + 1, | 497 | std::printf(" slot62 #%d container: %s\n", n + 1, |
| 461 | container_shape(desc->CS.pShaderBytecode, desc->CS.BytecodeLength).c_str()); | 498 | container_shape(desc->CS.pShaderBytecode, desc->CS.BytecodeLength).c_str()); |
| 499 | const std::string module = container_module(desc->CS.pShaderBytecode, desc->CS.BytecodeLength); | ||
| 500 | std::printf(" slot62 #%d module: %s\n", n + 1, module.empty() ? "(no ILDN part)" : module.c_str()); | ||
| 501 | const auto* bytes = static_cast<const uint8_t*>(desc->CS.pShaderBytecode); | ||
| 502 | std::vector<uint8_t> copy(bytes, bytes + desc->CS.BytecodeLength); | ||
| 503 | int same_as = 0; | ||
| 504 | for (size_t i = 0; i < g_seen_containers.size(); ++i) | ||
| 505 | if (g_seen_containers[i] == copy) { | ||
| 506 | same_as = static_cast<int>(i) + 1; | ||
| 507 | break; | ||
| 508 | } | ||
| 509 | if (same_as) { | ||
| 510 | std::printf(" slot62 #%d is byte-identical to #%d (module %s)\n", n + 1, same_as, | ||
| 511 | g_seen_modules[same_as - 1].c_str()); | ||
| 512 | if (!g_repeats) { | ||
| 513 | g_repeat_first = same_as; | ||
| 514 | g_repeat_second = n + 1; | ||
| 515 | } | ||
| 516 | ++g_repeats; | ||
| 517 | } | ||
| 518 | g_seen_containers.push_back(std::move(copy)); | ||
| 519 | g_seen_modules.push_back(module); | ||
| 462 | if (env("LEONIDA_BVH_DXIL") == "1") | 520 | if (env("LEONIDA_BVH_DXIL") == "1") |
| 463 | std::printf(" slot62 #%d uses: %s\n", n + 1, dxil_usage(desc->CS.pShaderBytecode, desc->CS.BytecodeLength).c_str()); | 521 | std::printf(" slot62 #%d uses: %s\n", n + 1, dxil_usage(desc->CS.pShaderBytecode, desc->CS.BytecodeLength).c_str()); |
| 464 | } | 522 | } |
| @@ -627,6 +685,16 @@ int main() { | |||
| 627 | note("slot 62 (Xbox CreateComputePipelineState) calls: " + std::to_string(rt::d3d12_xs::device_slot_hits(62)) + | 685 | note("slot 62 (Xbox CreateComputePipelineState) calls: " + std::to_string(rt::d3d12_xs::device_slot_hits(62)) + |
| 628 | (g_slot62_logged ? ", succeeded " + std::to_string(g_slot62_ok) + ", failed " + std::to_string(g_slot62_failed) | 686 | (g_slot62_logged ? ", succeeded " + std::to_string(g_slot62_ok) + ", failed " + std::to_string(g_slot62_failed) |
| 629 | : std::string())); | 687 | : std::string())); |
| 688 | if (g_slot62_logged) { | ||
| 689 | note("slot 62 creations: " + std::to_string(g_slot62_logged) + ", distinct containers: " + | ||
| 690 | std::to_string(g_slot62_logged - g_repeats) + ", repeated creations: " + std::to_string(g_repeats)); | ||
| 691 | if (g_repeats) { | ||
| 692 | note("first repeat: creation #" + std::to_string(g_repeat_second) + " passes the same container as #" + | ||
| 693 | std::to_string(g_repeat_first) + ", module " + g_seen_modules[g_repeat_first - 1]); | ||
| 694 | check(g_seen_modules[g_repeat_first - 1] == g_seen_modules[g_repeat_second - 1], | ||
| 695 | "the repeated container names the same module both times"); | ||
| 696 | } | ||
| 697 | } | ||
| 630 | note("OutputDebugString calls: " + std::to_string(g_debug_strings) + ", TerminateProcess calls: " + | 698 | note("OutputDebugString calls: " + std::to_string(g_debug_strings) + ", TerminateProcess calls: " + |
| 631 | std::to_string(g_terminate_calls)); | 699 | std::to_string(g_terminate_calls)); |
| 632 | check(!c.faulted || c.code == kTerminateCalled, "constructor returns or gives up through TerminateProcess, no fault"); | 700 | check(!c.faulted || c.code == kTerminateCalled, "constructor returns or gives up through TerminateProcess, no fault"); |
diff --git a/runtime/test/check_startup_cmdline.cmake b/runtime/test/check_startup_cmdline.cmake new file mode 100644 index 000000000..7d4d803aa --- /dev/null +++ b/runtime/test/check_startup_cmdline.cmake | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | foreach(mode args no_args fail_init) | ||
| 2 | set(args) | ||
| 3 | if(mode STREQUAL "args") | ||
| 4 | set(args hello "two words") | ||
| 5 | elseif(mode STREQUAL "fail_init") | ||
| 6 | set(args fail-init) | ||
| 7 | endif() | ||
| 8 | execute_process( | ||
| 9 | COMMAND ${RUNNER} "${LOADER}" --run "${GUEST}" -- ${args} | ||
| 10 | TIMEOUT 90 | ||
| 11 | RESULT_VARIABLE code OUTPUT_VARIABLE output ERROR_VARIABLE error) | ||
| 12 | if(mode STREQUAL "fail_init") | ||
| 13 | if(NOT code STREQUAL "1" OR NOT error MATCHES "DllMain returned FALSE" OR output MATCHES "running ") | ||
| 14 | message(FATAL_ERROR "Failed attach returned ${code}\n${output}\n${error}") | ||
| 15 | endif() | ||
| 16 | elseif(NOT code STREQUAL "0" OR NOT output MATCHES "tiny_startup_cmdline: PASS" | ||
| 17 | OR NOT output MATCHES "game exited with code 0") | ||
| 18 | message(FATAL_ERROR "Startup command line (${mode}) returned ${code}\n${output}\n${error}") | ||
| 19 | endif() | ||
| 20 | endforeach() | ||
diff --git a/runtime/test/check_vk_pipeline_cli.cmake b/runtime/test/check_vk_pipeline_cli.cmake index 58c3eb8b1..cec400b6d 100644 --- a/runtime/test/check_vk_pipeline_cli.cmake +++ b/runtime/test/check_vk_pipeline_cli.cmake | |||
| @@ -42,4 +42,18 @@ foreach(bytes -1 1.5 4294967296) | |||
| 42 | if(NOT code STREQUAL "2" OR NOT log MATCHES "at byte [0-9]+") | 42 | if(NOT code STREQUAL "2" OR NOT log MATCHES "at byte [0-9]+") |
| 43 | message(FATAL_ERROR "lds_bytes=${bytes}: expected a malformed index, got ${code}\n${log}") | 43 | message(FATAL_ERROR "lds_bytes=${bytes}: expected a malformed index, got ${code}\n${log}") |
| 44 | endif() | 44 | endif() |
| 45 | |||
| 46 | file(WRITE "${TEST_DIR}/index.json" "{\"example\":{\"stage\":\"cs\",\"push_constant_bytes\":${bytes}}}\n") | ||
| 47 | execute_process(COMMAND ${RUNNER} "${TOOL}" "${TEST_DIR}" | ||
| 48 | RESULT_VARIABLE code OUTPUT_VARIABLE log ERROR_VARIABLE log TIMEOUT 5) | ||
| 49 | if(NOT code STREQUAL "2" OR NOT log MATCHES "at byte [0-9]+") | ||
| 50 | message(FATAL_ERROR "push_constant_bytes=${bytes}: expected a malformed index, got ${code}\n${log}") | ||
| 51 | endif() | ||
| 52 | |||
| 53 | file(WRITE "${TEST_DIR}/index.json" "{\"example\":{\"stage\":\"cs\",\"pc_tail\":{\"set\":1,\"binding\":0,\"bytes\":${bytes}}}}\n") | ||
| 54 | execute_process(COMMAND ${RUNNER} "${TOOL}" "${TEST_DIR}" | ||
| 55 | RESULT_VARIABLE code OUTPUT_VARIABLE log ERROR_VARIABLE log TIMEOUT 5) | ||
| 56 | if(NOT code STREQUAL "2" OR NOT log MATCHES "at byte [0-9]+") | ||
| 57 | message(FATAL_ERROR "pc_tail.bytes=${bytes}: expected a malformed index, got ${code}\n${log}") | ||
| 58 | endif() | ||
| 45 | endforeach() | 59 | endforeach() |
diff --git a/runtime/test/d3d12_com_test.cpp b/runtime/test/d3d12_com_test.cpp index 5f30d83b5..caeb70323 100644 --- a/runtime/test/d3d12_com_test.cpp +++ b/runtime/test/d3d12_com_test.cpp | |||
| @@ -29,6 +29,11 @@ struct Ref { | |||
| 29 | 29 | ||
| 30 | } // namespace | 30 | } // namespace |
| 31 | 31 | ||
| 32 | static_assert(std::is_move_constructible_v<leonida::Draw>); | ||
| 33 | static_assert(std::is_move_assignable_v<leonida::Draw>); | ||
| 34 | static_assert(sizeof(leonida::Draw::render_targets) == sizeof(leonida::TargetView) * 8); | ||
| 35 | static_assert(sizeof(leonida::Draw::vertex_buffers) == sizeof(leonida::VertexBufferView) * 32); | ||
| 36 | |||
| 32 | int main(int argc, char** argv) { | 37 | int main(int argc, char** argv) { |
| 33 | if (argc == 2 && std::strcmp(argv[1], "--trace-d3d12") == 0) rt::d3d12_trace::set_enabled(true); | 38 | if (argc == 2 && std::strcmp(argv[1], "--trace-d3d12") == 0) rt::d3d12_trace::set_enabled(true); |
| 34 | else if (argc != 1) return 2; | 39 | else if (argc != 1) return 2; |
diff --git a/runtime/test/d3d12_compute_test.cpp b/runtime/test/d3d12_compute_test.cpp index 8aa5611f2..8f22c447b 100644 --- a/runtime/test/d3d12_compute_test.cpp +++ b/runtime/test/d3d12_compute_test.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | // arguments they were recorded with, and the results copied to a readback buffer. | 8 | // arguments they were recorded with, and the results copied to a readback buffer. |
| 9 | // The shader (test/glsl/cs_user_data.comp) is written to the translator's push-constant and address contract. | 9 | // The shader (test/glsl/cs_user_data.comp) is written to the translator's push-constant and address contract. |
| 10 | // No game data. Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. | 10 | // No game data. Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. |
| 11 | #include "shader_fixture_path.h" | ||
| 11 | #include "vk_test_device.h" | 12 | #include "vk_test_device.h" |
| 12 | #include "../shims/d3d12_com.h" | 13 | #include "../shims/d3d12_com.h" |
| 13 | #include "../src/gfx10_descriptors.h" | 14 | #include "../src/gfx10_descriptors.h" |
| @@ -269,7 +270,7 @@ int main() { | |||
| 269 | EXPECT(leonida::fssm_program(container) == fssm); | 270 | EXPECT(leonida::fssm_program(container) == fssm); |
| 270 | const auto library = std::filesystem::temp_directory_path() / "leonida_compute_test"; | 271 | const auto library = std::filesystem::temp_directory_path() / "leonida_compute_test"; |
| 271 | std::filesystem::create_directories(library); | 272 | std::filesystem::create_directories(library); |
| 272 | std::filesystem::copy_file(LEONIDA_TEST_CS_SPV, library / "cs_user_data.spv", | 273 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_CS_SPV), library / "cs_user_data.spv", |
| 273 | std::filesystem::copy_options::overwrite_existing); | 274 | std::filesystem::copy_options::overwrite_existing); |
| 274 | { | 275 | { |
| 275 | std::ofstream index(library / "index.json", std::ios::binary); | 276 | std::ofstream index(library / "index.json", std::ios::binary); |
diff --git a/runtime/test/d3d12_copy_compare.h b/runtime/test/d3d12_copy_compare.h index 3d4281a17..49583f1b5 100644 --- a/runtime/test/d3d12_copy_compare.h +++ b/runtime/test/d3d12_copy_compare.h | |||
| @@ -508,7 +508,6 @@ struct MixCase { | |||
| 508 | bool has_box; | 508 | bool has_box; |
| 509 | D3D12_BOX box; | 509 | D3D12_BOX box; |
| 510 | UINT dx, dy; | 510 | UINT dx, dy; |
| 511 | bool bc_gap; // block-compressed: the host copies whole blocks, the layer cannot (known difference) | ||
| 512 | }; | 511 | }; |
| 513 | 512 | ||
| 514 | // Copies one subresource of A into one of D (both prefilled), reads D back. `out.error` is set when the list was | 513 | // Copies one subresource of A into one of D (both prefilled), reads D back. `out.error` is set when the list was |
| @@ -702,19 +701,24 @@ inline int compare_copies(ID3D12Device* ours, bool bc_supported) { | |||
| 702 | both("buffers", [&](Run& r, Outcome& o) { run_buffers(r, o); }); | 701 | both("buffers", [&](Run& r, Outcome& o) { run_buffers(r, o); }); |
| 703 | 702 | ||
| 704 | // Different mips of one texture. Both sides must refuse what does not fit; what the host copies the layer must | 703 | // Different mips of one texture. Both sides must refuse what does not fit; what the host copies the layer must |
| 705 | // copy the same, except block-compressed copies of sizes that are no block multiple (known difference). | 704 | // copy the same. A block-compressed copy whose mip edge falls inside a block on one side only is staged through |
| 705 | // transfer scratch by the layer (vulkan_replay.h, prepare_texture_copy). | ||
| 706 | constexpr D3D12_BOX no_box{}; | 706 | constexpr D3D12_BOX no_box{}; |
| 707 | const MixCase mixes[] = { | 707 | const MixCase mixes[] = { |
| 708 | {"mip 0 box 12x12 into mip 1", 0, 1, true, {0, 0, 0, 12, 12, 1}, 0, 0, false}, | 708 | {"mip 0 box 12x12 into mip 1", 0, 1, true, {0, 0, 0, 12, 12, 1}, 0, 0}, |
| 709 | {"mip 1 into mip 0 at 8,8", 1, 0, false, no_box, 8, 8, false}, | 709 | {"mip 1 into mip 0 at 8,8", 1, 0, false, no_box, 8, 8}, |
| 710 | {"mip 1 box 4..12 into mip 0", 1, 0, true, {4, 4, 0, 12, 12, 1}, 0, 0, false}, | 710 | {"mip 1 box 4..12 into mip 0", 1, 0, true, {4, 4, 0, 12, 12, 1}, 0, 0}, |
| 711 | {"mip 0 box 8x8 into the 6x6 mip 2", 0, 2, true, {0, 0, 0, 8, 8, 1}, 0, 0, true}, | 711 | {"mip 0 box 8x8 into the 6x6 mip 2", 0, 2, true, {0, 0, 0, 8, 8, 1}, 0, 0}, |
| 712 | {"mip 2 (6x6) into mip 0 at 4,4", 2, 0, false, no_box, 4, 4, true}, | 712 | {"mip 2 (6x6) into mip 0 at 4,4", 2, 0, false, no_box, 4, 4}, |
| 713 | {"mip 2 (6x6) into mip 1", 2, 1, false, no_box, 0, 0, true}, | 713 | {"mip 2 (6x6) into mip 1", 2, 1, false, no_box, 0, 0}, |
| 714 | {"mip 0 box 4x4 into the 3x3 mip 3", 0, 3, true, {0, 0, 0, 4, 4, 1}, 0, 0, true}, | 714 | {"mip 0 box 4x4 into the 3x3 mip 3", 0, 3, true, {0, 0, 0, 4, 4, 1}, 0, 0}, |
| 715 | {"mip 0 box 16x16 into the 3x3 mip 3 (does not fit)", 0, 3, true, {0, 0, 0, 16, 16, 1}, 0, 0, false}, | 715 | // The source's mip edge inside the block: the box 4..8 of the 6x6 mip 2 (2x2 texels) into the 3x3 mip 3. |
| 716 | {"mip 0 box 16x16 into the 6x6 mip 2 (does not fit)", 0, 2, true, {0, 0, 0, 16, 16, 1}, 0, 0, false}, | 716 | {"mip 2 (6x6) box 4..8 into the 3x3 mip 3", 2, 3, true, {4, 4, 0, 8, 8, 1}, 0, 0}, |
| 717 | {"mip 1 into mip 0 at 16,16 (does not fit)", 1, 0, false, no_box, 16, 16, false}, | 717 | // Both mip edges inside one block, at an offset: the 3x3 mip 3 into the 6x6 mip 2 at 4,4 (2x2 texels land). |
| 718 | {"mip 3 (3x3) into mip 2 at 4,4", 3, 2, false, no_box, 4, 4}, | ||
| 719 | {"mip 0 box 16x16 into the 3x3 mip 3 (does not fit)", 0, 3, true, {0, 0, 0, 16, 16, 1}, 0, 0}, | ||
| 720 | {"mip 0 box 16x16 into the 6x6 mip 2 (does not fit)", 0, 2, true, {0, 0, 0, 16, 16, 1}, 0, 0}, | ||
| 721 | {"mip 1 into mip 0 at 16,16 (does not fit)", 1, 0, false, no_box, 16, 16}, | ||
| 718 | }; | 722 | }; |
| 719 | Run ours_run, host_run; // one queue each for every mixed-mip case | 723 | Run ours_run, host_run; // one queue each for every mixed-mip case |
| 720 | const bool ours_ok = ours_run.init(ours, true), host_ok = host_run.init(host.p, false); | 724 | const bool ours_ok = ours_run.init(ours, true), host_ok = host_run.init(host.p, false); |
| @@ -738,14 +742,10 @@ inline int compare_copies(ID3D12Device* ours, bool bc_supported) { | |||
| 738 | std::fprintf(stderr, "copy case %s: the HOST run failed (%s); fix the case\n", name.c_str(), b.error.c_str()); | 742 | std::fprintf(stderr, "copy case %s: the HOST run failed (%s); fix the case\n", name.c_str(), b.error.c_str()); |
| 739 | ++bad; | 743 | ++bad; |
| 740 | } else if (host_run.refused != ours_run.refused) { | 744 | } else if (host_run.refused != ours_run.refused) { |
| 741 | if (!host_run.refused && bc && mc.bc_gap) { | 745 | std::fprintf(stderr, "copy case %s: the host %s the copy, the layer %s it (%s)\n", name.c_str(), |
| 742 | std::printf("copy case %s: known difference: the host copies whole blocks, the layer refuses it\n", name.c_str()); | 746 | host_run.refused ? "refuses" : "does", ours_run.refused ? "refuses" : "does", |
| 743 | } else { | 747 | ours_run.refused ? a.error.c_str() : "accepted"); |
| 744 | std::fprintf(stderr, "copy case %s: the host %s the copy, the layer %s it (%s)\n", name.c_str(), | 748 | ++bad; |
| 745 | host_run.refused ? "refuses" : "does", ours_run.refused ? "refuses" : "does", | ||
| 746 | ours_run.refused ? a.error.c_str() : "accepted"); | ||
| 747 | ++bad; | ||
| 748 | } | ||
| 749 | } else if (!host_run.refused) { | 749 | } else if (!host_run.refused) { |
| 750 | const int r = compare(name.c_str(), a, b); | 750 | const int r = compare(name.c_str(), a, b); |
| 751 | bad += r; | 751 | bad += r; |
diff --git a/runtime/test/d3d12_debug_markers_test.cpp b/runtime/test/d3d12_debug_markers_test.cpp index 4bc502aca..1be8fffed 100644 --- a/runtime/test/d3d12_debug_markers_test.cpp +++ b/runtime/test/d3d12_debug_markers_test.cpp | |||
| @@ -214,22 +214,29 @@ int check_private_data(ID3D12Object* object, const char* what) { | |||
| 214 | EXPECT(size == sizeof(value)); | 214 | EXPECT(size == sizeof(value)); |
| 215 | read = 0; | 215 | read = 0; |
| 216 | EXPECT(object->GetPrivateData(kKey, &size, &read) == S_OK && size == sizeof(value) && read == value); | 216 | EXPECT(object->GetPrivateData(kKey, &size, &read) == S_OK && size == sizeof(value) && read == value); |
| 217 | EXPECT(object->SetPrivateData(kKey, 4, nullptr) == E_INVALIDARG); | 217 | // Null data removes the entry whatever the size: S_OK, then S_FALSE once there is none (the host runtime's |
| 218 | // answers, d3d12_private_data_test). | ||
| 219 | EXPECT(object->SetPrivateData(kKey, 4, nullptr) == S_OK); | ||
| 220 | EXPECT(object->GetPrivateData(kKey, &size, nullptr) == DXGI_ERROR_NOT_FOUND && size == 0); | ||
| 221 | EXPECT(object->SetPrivateData(kKey, 4, nullptr) == S_FALSE); | ||
| 218 | EXPECT(object->SetPrivateDataInterface(kKey, &counted) == S_OK && counted.refs == 2); | 222 | EXPECT(object->SetPrivateDataInterface(kKey, &counted) == S_OK && counted.refs == 2); |
| 219 | EXPECT(object->SetPrivateDataInterface(kKey, &counted) == S_OK && counted.refs == 2); // same one again | 223 | EXPECT(object->SetPrivateDataInterface(kKey, &counted) == S_OK && counted.refs == 2); // same one again |
| 224 | // A null interface releases the one held and stays as a pointer-sized entry that reads back as null. | ||
| 220 | EXPECT(object->SetPrivateDataInterface(kKey, nullptr) == S_OK && counted.refs == 1); | 225 | EXPECT(object->SetPrivateDataInterface(kKey, nullptr) == S_OK && counted.refs == 1); |
| 221 | size = 99; | 226 | size = 99; |
| 227 | EXPECT(object->GetPrivateData(kKey, &size, nullptr) == S_OK && size == sizeof(IUnknown*)); | ||
| 228 | got = &counted; | ||
| 229 | EXPECT(object->GetPrivateData(kKey, &size, &got) == S_OK && got == nullptr && counted.refs == 1); | ||
| 230 | EXPECT(object->SetPrivateData(kKey, 0, nullptr) == S_OK); | ||
| 222 | EXPECT(object->GetPrivateData(kKey, &size, nullptr) == DXGI_ERROR_NOT_FOUND && size == 0); | 231 | EXPECT(object->GetPrivateData(kKey, &size, nullptr) == DXGI_ERROR_NOT_FOUND && size == 0); |
| 223 | 232 | ||
| 224 | // SetName is readable as WKPDID_D3DDebugObjectNameW, terminator included. | 233 | // SetName is not readable through GetPrivateData, as on the host runtime: WKPDID_D3DDebugObjectNameW stays |
| 234 | // missing. A null name (which the host faults on) clears it. | ||
| 225 | const wchar_t name[] = L"leonida object"; | 235 | const wchar_t name[] = L"leonida object"; |
| 226 | EXPECT(object->SetName(name) == S_OK); | 236 | EXPECT(object->SetName(name) == S_OK); |
| 227 | wchar_t stored[32] = {}; | 237 | size = 0; |
| 228 | size = sizeof(stored); | 238 | EXPECT(object->GetPrivateData(kDebugObjectNameW, &size, nullptr) == DXGI_ERROR_NOT_FOUND && size == 0); |
| 229 | EXPECT(object->GetPrivateData(kDebugObjectNameW, &size, stored) == S_OK); | ||
| 230 | EXPECT(size == sizeof(name) && std::wcscmp(stored, name) == 0); | ||
| 231 | EXPECT(object->SetName(nullptr) == S_OK); | 239 | EXPECT(object->SetName(nullptr) == S_OK); |
| 232 | EXPECT(object->GetPrivateData(kDebugObjectNameW, &size, nullptr) == DXGI_ERROR_NOT_FOUND); | ||
| 233 | 240 | ||
| 234 | // Left set: released when the object dies (checked for a fence below). | 241 | // Left set: released when the object dies (checked for a fence below). |
| 235 | EXPECT(object->SetPrivateDataInterface(kOtherKey, nullptr) == S_OK); | 242 | EXPECT(object->SetPrivateDataInterface(kOtherKey, nullptr) == S_OK); |
diff --git a/runtime/test/d3d12_descriptor_test.cpp b/runtime/test/d3d12_descriptor_test.cpp index f2a33c4f2..9db94da9a 100644 --- a/runtime/test/d3d12_descriptor_test.cpp +++ b/runtime/test/d3d12_descriptor_test.cpp | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | // and binds the device's set (rt::d3d12::bindless_set). Without glslangValidator the GPU readbacks are skipped. | 21 | // and binds the device's set (rt::d3d12::bindless_set). Without glslangValidator the GPU readbacks are skipped. |
| 22 | // No game data. | 22 | // No game data. |
| 23 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. | 23 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. |
| 24 | #include "shader_fixture_path.h" | ||
| 24 | #include "vk_test_device.h" | 25 | #include "vk_test_device.h" |
| 25 | #include "../shims/d3d12_com.h" | 26 | #include "../shims/d3d12_com.h" |
| 26 | #include "../shims/d3d12_xs_device.h" | 27 | #include "../shims/d3d12_xs_device.h" |
| @@ -102,7 +103,7 @@ struct SampleKeys { | |||
| 102 | }; | 103 | }; |
| 103 | 104 | ||
| 104 | VkShaderModule load_shader(vktest::Device& d, const char* path) { | 105 | VkShaderModule load_shader(vktest::Device& d, const char* path) { |
| 105 | std::ifstream file(path, std::ios::binary | std::ios::ate); | 106 | std::ifstream file(vktest::shader_fixture_path(path), std::ios::binary | std::ios::ate); |
| 106 | if (!file) return VK_NULL_HANDLE; | 107 | if (!file) return VK_NULL_HANDLE; |
| 107 | std::vector<std::uint32_t> code(std::size_t(file.tellg()) / 4); | 108 | std::vector<std::uint32_t> code(std::size_t(file.tellg()) / 4); |
| 108 | file.seekg(0); | 109 | file.seekg(0); |
diff --git a/runtime/test/d3d12_draw_test.cpp b/runtime/test/d3d12_draw_test.cpp index b108fa8ec..216534cd4 100644 --- a/runtime/test/d3d12_draw_test.cpp +++ b/runtime/test/d3d12_draw_test.cpp | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | // B8G8R8X8 has no alpha, so destination alpha reads 1 there, as on WARP and AMD's D3D12 driver. | 12 | // B8G8R8X8 has no alpha, so destination alpha reads 1 there, as on WARP and AMD's D3D12 driver. |
| 13 | // The shaders are GLSL written to the translator's contract (test/glsl/vs_draw.vert, ps_draw.frag). No game data. | 13 | // The shaders are GLSL written to the translator's contract (test/glsl/vs_draw.vert, ps_draw.frag). No game data. |
| 14 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. | 14 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. |
| 15 | #include "shader_fixture_path.h" | ||
| 15 | #include "vk_test_device.h" | 16 | #include "vk_test_device.h" |
| 16 | #include "d3d12_test_shaders.h" | 17 | #include "d3d12_test_shaders.h" |
| 17 | #include "../shims/d3d12_com.h" | 18 | #include "../shims/d3d12_com.h" |
| @@ -69,11 +70,11 @@ int main() { | |||
| 69 | const auto vs_int_container = shader_container(vs_int_program); | 70 | const auto vs_int_container = shader_container(vs_int_program); |
| 70 | const auto library = std::filesystem::temp_directory_path() / "leonida_draw_test"; | 71 | const auto library = std::filesystem::temp_directory_path() / "leonida_draw_test"; |
| 71 | std::filesystem::create_directories(library); | 72 | std::filesystem::create_directories(library); |
| 72 | std::filesystem::copy_file(LEONIDA_TEST_VS_SPV, library / "vs_draw.spv", std::filesystem::copy_options::overwrite_existing); | 73 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_VS_SPV), library / "vs_draw.spv", std::filesystem::copy_options::overwrite_existing); |
| 73 | std::filesystem::copy_file(LEONIDA_TEST_PS_SPV, library / "ps_draw.spv", std::filesystem::copy_options::overwrite_existing); | 74 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_PS_SPV), library / "ps_draw.spv", std::filesystem::copy_options::overwrite_existing); |
| 74 | std::filesystem::copy_file(LEONIDA_TEST_VS_FULLSCREEN_SPV, library / "vs_fullscreen.spv", | 75 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_VS_FULLSCREEN_SPV), library / "vs_fullscreen.spv", |
| 75 | std::filesystem::copy_options::overwrite_existing); | 76 | std::filesystem::copy_options::overwrite_existing); |
| 76 | std::filesystem::copy_file(LEONIDA_TEST_VS_INT_SPV, library / "vs_draw_int.spv", | 77 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_VS_INT_SPV), library / "vs_draw_int.spv", |
| 77 | std::filesystem::copy_options::overwrite_existing); | 78 | std::filesystem::copy_options::overwrite_existing); |
| 78 | { | 79 | { |
| 79 | std::ofstream index(library / "index.json", std::ios::binary); | 80 | std::ofstream index(library / "index.json", std::ios::binary); |
diff --git a/runtime/test/d3d12_f16_halves_test.cpp b/runtime/test/d3d12_f16_halves_test.cpp new file mode 100644 index 000000000..c2f194e31 --- /dev/null +++ b/runtime/test/d3d12_f16_halves_test.cpp | |||
| @@ -0,0 +1,367 @@ | |||
| 1 | // End-to-end Vulkan GPU test for per-pipeline `--f16-interp-fallback` linking (SHADER-378). | ||
| 2 | // | ||
| 3 | // Exercises two graphics PSOs through ID3D12Device::CreateGraphicsPipelineState on a real Vulkan 1.3 GPU, without | ||
| 4 | // needing glslangValidator, llvm-mc or game files (both SPIR-V 1.5 modules are built directly in memory): | ||
| 5 | // 1. A 16-param VS (param0..param15, static f16_halves only for param0..param6) writes packed f16 pairs into | ||
| 6 | // param7: .x = packHalf2x16(0.25, 0.75) = 0x3A003400, .y = packHalf2x16(0.5, 1.0) = 0x3C003800. | ||
| 7 | // PS #1 reads raw attr0..attr14 plus attr7's decoded f16 halves at Locations 20 & 21 (which collide with VS's | ||
| 8 | // static param4 halves at 20 & 21). `link_f16_halves` demotes VS's unneeded static halves to Private, | ||
| 9 | // synthesizes UnpackHalf2x16 for param7 at Locations 20 & 21, and the GPU renders RGBA (64, 191, 128, 255). | ||
| 10 | // 2. PS #2 reads raw attr0..attr13 plus attr7's decoded f16 halves at Locations 14 & 15 (colliding with VS's raw | ||
| 11 | // param14 & param15). `link_f16_halves` relocates BOTH PS and VS halves to Locations 28 & 29 and renders the | ||
| 12 | // exact same RGBA (64, 191, 128, 255). | ||
| 13 | // Skips (77) when no usable Vulkan 1.3 device is present. No game data. | ||
| 14 | #include "vk_test_device.h" | ||
| 15 | #include "d3d12_test_shaders.h" | ||
| 16 | #include "../shims/d3d12_com.h" | ||
| 17 | #include "../shims/d3d12_xs_device.h" | ||
| 18 | #include "../src/shader_library.h" | ||
| 19 | #include "../src/spirv_f16_halves.h" | ||
| 20 | |||
| 21 | #include <cmath> | ||
| 22 | #include <cstdint> | ||
| 23 | #include <cstdio> | ||
| 24 | #include <filesystem> | ||
| 25 | #include <fstream> | ||
| 26 | #include <map> | ||
| 27 | #include <vector> | ||
| 28 | |||
| 29 | #define EXPECT(cond) do { \ | ||
| 30 | if (!(cond)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #cond); return 1; } \ | ||
| 31 | } while (0) | ||
| 32 | |||
| 33 | using namespace d3d12test; | ||
| 34 | using namespace leonida::spirv_detail; | ||
| 35 | using XboxHeapHandleFn = std::uint64_t(WINAPI*)(void* heap); // heap slot 9: handle in RAX | ||
| 36 | |||
| 37 | namespace { | ||
| 38 | |||
| 39 | void put_inst(std::vector<std::uint32_t>& w, std::uint16_t op, std::initializer_list<std::uint32_t> args) { | ||
| 40 | w.push_back((std::uint32_t(1 + args.size()) << 16) | op); | ||
| 41 | for (std::uint32_t a : args) w.push_back(a); | ||
| 42 | } | ||
| 43 | |||
| 44 | void put_inst_vec(std::vector<std::uint32_t>& w, std::uint16_t op, const std::vector<std::uint32_t>& args) { | ||
| 45 | w.push_back((std::uint32_t(1 + args.size()) << 16) | op); | ||
| 46 | w.insert(w.end(), args.begin(), args.end()); | ||
| 47 | } | ||
| 48 | |||
| 49 | void write_spv(const std::filesystem::path& path, const std::vector<std::uint32_t>& words) { | ||
| 50 | std::ofstream f(path, std::ios::binary | std::ios::trunc); | ||
| 51 | f.write(reinterpret_cast<const char*>(words.data()), std::streamsize(words.size() * 4)); | ||
| 52 | } | ||
| 53 | |||
| 54 | // Fullscreen triangle VS (from VertexIndex 0,1,2) exporting 16 raw params (0..15) + static f16_halves for 0..6. | ||
| 55 | // param7 carries packed f16 bits: .x = 0x3A003400 (lo=0.25, hi=0.75), .y = 0x3C003800 (lo=0.5, hi=1.0). | ||
| 56 | std::vector<std::uint32_t> make_16param_vs() { | ||
| 57 | // Fixed IDs: | ||
| 58 | // 1=%void, 2=%fn, 3=%float, 4=%v4float, 5=%int, 6=%ptr_in_int, 7=%ptr_out_v4 | ||
| 59 | // 8=%vid_var, 9=%pos_var, 10=%null_v4 | ||
| 60 | // 11=%f_m1(-1.0), 12=%f_3(3.0), 13=%f_0(0.0), 14=%f_1(1.0) | ||
| 61 | // 15=%c_p0(-1,-1,0,1), 16=%c_p1(3,-1,0,1), 17=%c_p2(-1,3,0,1) | ||
| 62 | // 18=%i_0, 19=%i_1, 20=%bool | ||
| 63 | // 21=%f_pack_x (bitcast 0x3A003400), 22=%f_pack_y (bitcast 0x3C003800), 23=%v_param7 | ||
| 64 | // 24=%main, 25=%entry | ||
| 65 | // 26=%vid, 27=%is0, 28=%is1, 29=%p12, 30=%pos | ||
| 66 | // 31..46 = raw param0..param15 Output vars | ||
| 67 | // 47..60 = static f16_halves for param0..param6 (14 Output vars: 28,29, 26,27, ..., 16,17) | ||
| 68 | constexpr std::uint32_t kBound = 61; | ||
| 69 | std::vector<std::uint32_t> w = {kSpirvMagic, 0x00010500u, 0, kBound, 0}; | ||
| 70 | put_inst(w, kOpCapability, {1}); // Shader | ||
| 71 | put_inst(w, kOpMemoryModel, {0, 1}); // Logical GLSL450 | ||
| 72 | std::vector<std::uint32_t> ep = {kExecModelVertex, 24, 0x6e69616du, 0x00000000u, 8, 9}; | ||
| 73 | for (std::uint32_t id = 31; id <= 60; ++id) ep.push_back(id); | ||
| 74 | put_inst_vec(w, kOpEntryPoint, ep); | ||
| 75 | |||
| 76 | put_inst(w, kOpDecorate, {8, 11, 42}); // BuiltIn VertexIndex | ||
| 77 | put_inst(w, kOpDecorate, {9, 11, 0}); // BuiltIn Position | ||
| 78 | for (std::uint32_t p = 0; p < 16; ++p) put_inst(w, kOpDecorate, {31 + p, kDecorationLocation, p}); | ||
| 79 | for (std::uint32_t n = 0; n <= 6; ++n) { | ||
| 80 | put_inst(w, kOpDecorate, {47 + 2 * n, kDecorationLocation, 28 - 2 * n}); | ||
| 81 | put_inst(w, kOpDecorate, {48 + 2 * n, kDecorationLocation, 29 - 2 * n}); | ||
| 82 | } | ||
| 83 | |||
| 84 | put_inst(w, 19, {1}); // OpTypeVoid | ||
| 85 | put_inst(w, 33, {2, 1}); // OpTypeFunction %void | ||
| 86 | put_inst(w, kOpTypeFloat, {3, 32}); | ||
| 87 | put_inst(w, kOpTypeVector, {4, 3, 4}); | ||
| 88 | put_inst(w, kOpTypeInt, {5, 32, 1}); // %int | ||
| 89 | put_inst(w, kOpTypePointer, {6, kStorageInput, 5}); | ||
| 90 | put_inst(w, kOpTypePointer, {7, kStorageOutput, 4}); | ||
| 91 | put_inst(w, 20, {20}); // OpTypeBool | ||
| 92 | |||
| 93 | put_inst(w, kOpConstantNull, {4, 10}); | ||
| 94 | put_inst(w, 43, {3, 11, 0xbf800000u}); // -1.0f | ||
| 95 | put_inst(w, 43, {3, 12, 0x40400000u}); // 3.0f | ||
| 96 | put_inst(w, 43, {3, 13, 0x00000000u}); // 0.0f | ||
| 97 | put_inst(w, 43, {3, 14, 0x3f800000u}); // 1.0f | ||
| 98 | put_inst(w, 44, {4, 15, 11, 11, 13, 14}); // (-1, -1, 0, 1) | ||
| 99 | put_inst(w, 44, {4, 16, 12, 11, 13, 14}); // ( 3, -1, 0, 1) | ||
| 100 | put_inst(w, 44, {4, 17, 11, 12, 13, 14}); // (-1, 3, 0, 1) | ||
| 101 | put_inst(w, 43, {5, 18, 0u}); | ||
| 102 | put_inst(w, 43, {5, 19, 1u}); | ||
| 103 | put_inst(w, 43, {3, 21, 0x3a003400u}); // packHalf2x16(0.25, 0.75) as raw f32 bits | ||
| 104 | put_inst(w, 43, {3, 22, 0x3c003800u}); // packHalf2x16(0.50, 1.00) as raw f32 bits | ||
| 105 | put_inst(w, 44, {4, 23, 21, 22, 13, 14}); | ||
| 106 | |||
| 107 | put_inst(w, kOpVariable, {6, 8, kStorageInput}); | ||
| 108 | put_inst(w, kOpVariable, {7, 9, kStorageOutput}); | ||
| 109 | for (std::uint32_t id = 31; id <= 60; ++id) put_inst(w, kOpVariable, {7, id, kStorageOutput}); | ||
| 110 | |||
| 111 | put_inst(w, kOpFunction, {1, 24, 0, 2}); | ||
| 112 | put_inst(w, 248, {25}); // OpLabel | ||
| 113 | put_inst(w, kOpLoad, {5, 26, 8}); // %vid | ||
| 114 | put_inst(w, 170, {20, 27, 26, 18}); // OpIEqual %vid 0 | ||
| 115 | put_inst(w, 170, {20, 28, 26, 19}); // OpIEqual %vid 1 | ||
| 116 | put_inst(w, 169, {4, 29, 28, 16, 17}); // OpSelect %is1 %p1 %p2 | ||
| 117 | put_inst(w, 169, {4, 30, 27, 15, 29}); // OpSelect %is0 %p0 %p12 | ||
| 118 | put_inst(w, kOpStore, {9, 30}); | ||
| 119 | for (std::uint32_t p = 0; p < 16; ++p) put_inst(w, kOpStore, {31 + p, p == 7 ? 23u : 10u}); | ||
| 120 | for (std::uint32_t id = 47; id <= 60; ++id) put_inst(w, kOpStore, {id, 10}); | ||
| 121 | put_inst(w, kOpReturn, {}); | ||
| 122 | put_inst(w, kOpFunctionEnd, {}); | ||
| 123 | return w; | ||
| 124 | } | ||
| 125 | |||
| 126 | // Fragment shader reading `num_raw` raw inputs (Location 0..num_raw-1) plus decoded halves of param7 at | ||
| 127 | // `lo_loc` and `hi_loc`, writing vec4(lo.x, hi.x, lo.y, hi.y) to MRT 0. | ||
| 128 | std::vector<std::uint32_t> make_f16_ps(std::uint32_t num_raw, std::uint32_t lo_loc, std::uint32_t hi_loc) { | ||
| 129 | // 1=%void, 2=%fn, 3=%float, 4=%v4float, 5=%ptr_in_v4, 6=%ptr_out_v4, 7=%out0, 8=%in_lo, 9=%in_hi, | ||
| 130 | // 10=%main, 11=%entry, 12=%vlo, 13=%vhi, 14=%lox, 15=%hix, 16=%loy, 17=%hiy, 18=%rgba, | ||
| 131 | // 19.. = raw inputs 0..num_raw-1 | ||
| 132 | const std::uint32_t bound = 19 + num_raw; | ||
| 133 | std::vector<std::uint32_t> w = {kSpirvMagic, 0x00010500u, 0, bound, 0}; | ||
| 134 | put_inst(w, kOpCapability, {1}); | ||
| 135 | put_inst(w, kOpMemoryModel, {0, 1}); | ||
| 136 | std::vector<std::uint32_t> ep = {kExecModelFragment, 10, 0x6e69616du, 0x00000000u, 7, 8, 9}; | ||
| 137 | for (std::uint32_t i = 0; i < num_raw; ++i) ep.push_back(19 + i); | ||
| 138 | put_inst_vec(w, kOpEntryPoint, ep); | ||
| 139 | put_inst(w, kOpExecutionMode, {10, 7}); // OriginUpperLeft | ||
| 140 | |||
| 141 | put_inst(w, kOpDecorate, {7, kDecorationLocation, 0}); | ||
| 142 | put_inst(w, kOpDecorate, {8, kDecorationLocation, lo_loc}); | ||
| 143 | put_inst(w, kOpDecorate, {9, kDecorationLocation, hi_loc}); | ||
| 144 | for (std::uint32_t i = 0; i < num_raw; ++i) put_inst(w, kOpDecorate, {19 + i, kDecorationLocation, i}); | ||
| 145 | |||
| 146 | put_inst(w, 19, {1}); | ||
| 147 | put_inst(w, 33, {2, 1}); | ||
| 148 | put_inst(w, kOpTypeFloat, {3, 32}); | ||
| 149 | put_inst(w, kOpTypeVector, {4, 3, 4}); | ||
| 150 | put_inst(w, kOpTypePointer, {5, kStorageInput, 4}); | ||
| 151 | put_inst(w, kOpTypePointer, {6, kStorageOutput, 4}); | ||
| 152 | |||
| 153 | put_inst(w, kOpVariable, {6, 7, kStorageOutput}); | ||
| 154 | put_inst(w, kOpVariable, {5, 8, kStorageInput}); | ||
| 155 | put_inst(w, kOpVariable, {5, 9, kStorageInput}); | ||
| 156 | for (std::uint32_t i = 0; i < num_raw; ++i) put_inst(w, kOpVariable, {5, 19 + i, kStorageInput}); | ||
| 157 | |||
| 158 | put_inst(w, kOpFunction, {1, 10, 0, 2}); | ||
| 159 | put_inst(w, 248, {11}); | ||
| 160 | put_inst(w, kOpLoad, {4, 12, 8}); | ||
| 161 | put_inst(w, kOpLoad, {4, 13, 9}); | ||
| 162 | put_inst(w, kOpCompositeExtract, {3, 14, 12, 0}); // lo.x = 0.25 | ||
| 163 | put_inst(w, kOpCompositeExtract, {3, 15, 13, 0}); // hi.x = 0.75 | ||
| 164 | put_inst(w, kOpCompositeExtract, {3, 16, 12, 1}); // lo.y = 0.50 | ||
| 165 | put_inst(w, kOpCompositeExtract, {3, 17, 13, 1}); // hi.y = 1.00 | ||
| 166 | put_inst(w, kOpCompositeConstruct, {4, 18, 14, 15, 16, 17}); | ||
| 167 | put_inst(w, kOpStore, {7, 18}); | ||
| 168 | put_inst(w, kOpReturn, {}); | ||
| 169 | put_inst(w, kOpFunctionEnd, {}); | ||
| 170 | return w; | ||
| 171 | } | ||
| 172 | |||
| 173 | } // namespace | ||
| 174 | |||
| 175 | int main() { | ||
| 176 | vktest::Device d; | ||
| 177 | const auto status = d.initialize(); | ||
| 178 | if (status == vktest::DeviceStatus::unavailable) { | ||
| 179 | std::fprintf(stderr, "SKIP: no usable Vulkan 1.3 device\n"); | ||
| 180 | return 77; | ||
| 181 | } | ||
| 182 | EXPECT(status == vktest::DeviceStatus::ready); | ||
| 183 | |||
| 184 | const auto vs_prog = fssm_program({0x56530378, 0xbf810000}); | ||
| 185 | const auto ps1_prog = fssm_program({0x50530378, 0x00000001}); | ||
| 186 | const auto ps2_prog = fssm_program({0x50530378, 0x00000002}); | ||
| 187 | const auto vs_c = shader_container(vs_prog); | ||
| 188 | const auto ps1_c = shader_container(ps1_prog); | ||
| 189 | const auto ps2_c = shader_container(ps2_prog); | ||
| 190 | |||
| 191 | const auto lib_dir = std::filesystem::temp_directory_path() / "leonida_f16_halves_gpu_test"; | ||
| 192 | std::filesystem::create_directories(lib_dir); | ||
| 193 | write_spv(lib_dir / "vs_16p.spv", make_16param_vs()); | ||
| 194 | write_spv(lib_dir / "ps_packed.spv", make_f16_ps(15, 20, 21)); | ||
| 195 | write_spv(lib_dir / "ps_reloc.spv", make_f16_ps(14, 14, 15)); | ||
| 196 | { | ||
| 197 | std::ofstream idx(lib_dir / "index.json", std::ios::binary | std::ios::trunc); | ||
| 198 | idx << "{\"vs_16p\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_prog) | ||
| 199 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"input_signature\": [], " | ||
| 200 | "\"f16_halves\": {\"0\": [28, 29], \"1\": [26, 27], \"2\": [24, 25], \"3\": [22, 23], " | ||
| 201 | "\"4\": [20, 21], \"5\": [18, 19], \"6\": [16, 17]}},\n" | ||
| 202 | " \"ps_packed\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << leonida::sha256_hex(ps1_prog) | ||
| 203 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"outputs\": [0], " | ||
| 204 | "\"f16_halves\": {\"7\": [20, 21]}},\n" | ||
| 205 | " \"ps_reloc\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << leonida::sha256_hex(ps2_prog) | ||
| 206 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"outputs\": [0], " | ||
| 207 | "\"f16_halves\": {\"7\": [14, 15]}}}"; | ||
| 208 | } | ||
| 209 | |||
| 210 | rt::d3d12::VulkanDeviceInfo info{}; | ||
| 211 | info.get_instance_proc = d.instance_proc; | ||
| 212 | info.instance = d.instance; | ||
| 213 | info.physical = d.physical; | ||
| 214 | info.device = d.device; | ||
| 215 | info.queue = d.queue; | ||
| 216 | info.queue_family = d.family; | ||
| 217 | info.buffer_device_address = true; | ||
| 218 | info.subgroup = d.subgroup; | ||
| 219 | info.shader_dir = lib_dir.string(); | ||
| 220 | |||
| 221 | ID3D12Device* inner = nullptr; | ||
| 222 | EXPECT(SUCCEEDED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&inner)))); | ||
| 223 | Ref<ID3D12Device> device; | ||
| 224 | EXPECT(SUCCEEDED(rt::d3d12_xs::create_device_proxy(inner, __uuidof(ID3D12Device), | ||
| 225 | reinterpret_cast<void**>(&device.p)))); | ||
| 226 | rt::d3d12::set_device_outer(inner, device.p); | ||
| 227 | |||
| 228 | D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{}; | ||
| 229 | root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0; | ||
| 230 | const auto root_blob = serialize_root_signature(root_desc); | ||
| 231 | EXPECT(!root_blob.empty()); | ||
| 232 | Ref<ID3D12RootSignature> root; | ||
| 233 | EXPECT(SUCCEEDED(device->CreateRootSignature(0, root_blob.data(), root_blob.size(), IID_PPV_ARGS(&root.p)))); | ||
| 234 | |||
| 235 | D3D12_COMMAND_QUEUE_DESC qd{}; | ||
| 236 | qd.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; | ||
| 237 | Ref<ID3D12CommandQueue> queue; | ||
| 238 | EXPECT(SUCCEEDED(device->CreateCommandQueue(&qd, IID_PPV_ARGS(&queue.p)))); | ||
| 239 | Ref<ID3D12CommandAllocator> alloc; | ||
| 240 | EXPECT(SUCCEEDED(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&alloc.p)))); | ||
| 241 | Ref<ID3D12GraphicsCommandList> list; | ||
| 242 | EXPECT(SUCCEEDED(device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, alloc.p, nullptr, | ||
| 243 | IID_PPV_ARGS(&list.p)))); | ||
| 244 | EXPECT(SUCCEEDED(list->Close())); | ||
| 245 | |||
| 246 | Ref<ID3D12Fence> fence; | ||
| 247 | EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence.p)))); | ||
| 248 | |||
| 249 | constexpr UINT kSize = 16; | ||
| 250 | D3D12_HEAP_PROPERTIES default_hp{}; | ||
| 251 | default_hp.Type = D3D12_HEAP_TYPE_DEFAULT; | ||
| 252 | D3D12_RESOURCE_DESC rt_desc{}; | ||
| 253 | rt_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; | ||
| 254 | rt_desc.Width = kSize; | ||
| 255 | rt_desc.Height = kSize; | ||
| 256 | rt_desc.DepthOrArraySize = 1; | ||
| 257 | rt_desc.MipLevels = 1; | ||
| 258 | rt_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| 259 | rt_desc.SampleDesc.Count = 1; | ||
| 260 | rt_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; | ||
| 261 | Ref<ID3D12Resource> rt_res; | ||
| 262 | EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_hp, D3D12_HEAP_FLAG_NONE, &rt_desc, | ||
| 263 | D3D12_RESOURCE_STATE_RENDER_TARGET, nullptr, | ||
| 264 | IID_PPV_ARGS(&rt_res.p)))); | ||
| 265 | |||
| 266 | D3D12_DESCRIPTOR_HEAP_DESC rtv_hd{}; | ||
| 267 | rtv_hd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; | ||
| 268 | rtv_hd.NumDescriptors = 1; | ||
| 269 | Ref<ID3D12DescriptorHeap> rtv_heap; | ||
| 270 | EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&rtv_hd, IID_PPV_ARGS(&rtv_heap.p)))); | ||
| 271 | const D3D12_CPU_DESCRIPTOR_HANDLE rtv_h{ | ||
| 272 | SIZE_T(reinterpret_cast<XboxHeapHandleFn>(slot(rtv_heap.p, 9))(rtv_heap.p))}; | ||
| 273 | device->CreateRenderTargetView(rt_res.p, nullptr, rtv_h); | ||
| 274 | |||
| 275 | D3D12_HEAP_PROPERTIES rb_hp{}; | ||
| 276 | rb_hp.Type = D3D12_HEAP_TYPE_READBACK; | ||
| 277 | D3D12_RESOURCE_DESC rb_desc{}; | ||
| 278 | rb_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; | ||
| 279 | rb_desc.Width = kSize * 256; | ||
| 280 | rb_desc.Height = 1; | ||
| 281 | rb_desc.DepthOrArraySize = 1; | ||
| 282 | rb_desc.MipLevels = 1; | ||
| 283 | rb_desc.SampleDesc.Count = 1; | ||
| 284 | rb_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; | ||
| 285 | Ref<ID3D12Resource> rb_res; | ||
| 286 | EXPECT(SUCCEEDED(device->CreateCommittedResource(&rb_hp, D3D12_HEAP_FLAG_NONE, &rb_desc, | ||
| 287 | D3D12_RESOURCE_STATE_COPY_DEST, nullptr, | ||
| 288 | IID_PPV_ARGS(&rb_res.p)))); | ||
| 289 | |||
| 290 | UINT64 fence_val = 0; | ||
| 291 | const auto run_case = [&](const char* label, const std::vector<std::uint8_t>& ps_container) -> bool { | ||
| 292 | D3D12_GRAPHICS_PIPELINE_STATE_DESC pd{}; | ||
| 293 | pd.pRootSignature = root.p; | ||
| 294 | pd.VS = {vs_c.data(), vs_c.size()}; | ||
| 295 | pd.PS = {ps_container.data(), ps_container.size()}; | ||
| 296 | pd.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL; | ||
| 297 | pd.SampleMask = 0xffffffffu; | ||
| 298 | pd.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID; | ||
| 299 | pd.RasterizerState.CullMode = D3D12_CULL_MODE_NONE; | ||
| 300 | pd.RasterizerState.DepthClipEnable = TRUE; | ||
| 301 | pd.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; | ||
| 302 | pd.NumRenderTargets = 1; | ||
| 303 | pd.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| 304 | pd.SampleDesc.Count = 1; | ||
| 305 | |||
| 306 | Ref<ID3D12PipelineState> pso; | ||
| 307 | if (FAILED(device->CreateGraphicsPipelineState(&pd, IID_PPV_ARGS(&pso.p))) || !pso.p) { | ||
| 308 | std::fprintf(stderr, "%s: CreateGraphicsPipelineState failed\n", label); | ||
| 309 | return false; | ||
| 310 | } | ||
| 311 | if (FAILED(alloc->Reset()) || FAILED(list->Reset(alloc.p, pso.p))) return false; | ||
| 312 | const float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | ||
| 313 | list->ClearRenderTargetView(rtv_h, clear_col, 0, nullptr); | ||
| 314 | list->OMSetRenderTargets(1, &rtv_h, FALSE, nullptr); | ||
| 315 | const D3D12_VIEWPORT vp = {0.0f, 0.0f, float(kSize), float(kSize), 0.0f, 1.0f}; | ||
| 316 | const D3D12_RECT sc = {0, 0, LONG(kSize), LONG(kSize)}; | ||
| 317 | list->RSSetViewports(1, &vp); | ||
| 318 | list->RSSetScissorRects(1, &sc); | ||
| 319 | list->SetGraphicsRootSignature(root.p); | ||
| 320 | list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); | ||
| 321 | list->DrawInstanced(3, 1, 0, 0); | ||
| 322 | |||
| 323 | D3D12_RESOURCE_BARRIER to_copy{}; | ||
| 324 | to_copy.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; | ||
| 325 | to_copy.Transition = {rt_res.p, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, | ||
| 326 | D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE}; | ||
| 327 | list->ResourceBarrier(1, &to_copy); | ||
| 328 | D3D12_TEXTURE_COPY_LOCATION dst{}; | ||
| 329 | dst.pResource = rb_res.p; | ||
| 330 | dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; | ||
| 331 | dst.PlacedFootprint.Footprint = {DXGI_FORMAT_R8G8B8A8_UNORM, kSize, kSize, 1, 256}; | ||
| 332 | D3D12_TEXTURE_COPY_LOCATION src{}; | ||
| 333 | src.pResource = rt_res.p; | ||
| 334 | src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; | ||
| 335 | list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); | ||
| 336 | D3D12_RESOURCE_BARRIER to_rt = to_copy; | ||
| 337 | to_rt.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_SOURCE; | ||
| 338 | to_rt.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET; | ||
| 339 | list->ResourceBarrier(1, &to_rt); | ||
| 340 | if (FAILED(list->Close())) return false; | ||
| 341 | |||
| 342 | ID3D12CommandList* cl = list.p; | ||
| 343 | queue->ExecuteCommandLists(1, &cl); | ||
| 344 | ++fence_val; | ||
| 345 | if (FAILED(queue->Signal(fence.p, fence_val))) return false; | ||
| 346 | if (FAILED(fence->SetEventOnCompletion(fence_val, nullptr))) return false; | ||
| 347 | |||
| 348 | void* mapped = nullptr; | ||
| 349 | const D3D12_RANGE read_range = {0, kSize * 256}; | ||
| 350 | if (FAILED(rb_res->Map(0, &read_range, &mapped)) || !mapped) return false; | ||
| 351 | const auto* px = static_cast<const std::uint8_t*>(mapped) + (kSize / 2) * 256 + (kSize / 2) * 4; | ||
| 352 | const int r = px[0], g = px[1], b = px[2], a = px[3]; | ||
| 353 | rb_res->Unmap(0, nullptr); | ||
| 354 | // Expected: (0.25, 0.75, 0.50, 1.00) -> (64, 191, 128, 255) within +-1 LSB of UNORM rounding. | ||
| 355 | const bool ok = std::abs(r - 64) <= 1 && std::abs(g - 191) <= 1 && std::abs(b - 128) <= 1 && a == 255; | ||
| 356 | if (!ok) { | ||
| 357 | std::fprintf(stderr, "%s: pixel=(%d,%d,%d,%d), expected~(64,191,128,255)\n", label, r, g, b, a); | ||
| 358 | } else { | ||
| 359 | std::printf("%s: rendered pixel=(%d,%d,%d,%d) OK\n", label, r, g, b, a); | ||
| 360 | } | ||
| 361 | return ok; | ||
| 362 | }; | ||
| 363 | |||
| 364 | EXPECT(run_case("ps_packed (synth param7 + demote static halves)", ps1_c)); | ||
| 365 | EXPECT(run_case("ps_reloc (relocate colliding PS + VS halves to 28,29)", ps2_c)); | ||
| 366 | return 0; | ||
| 367 | } | ||
diff --git a/runtime/test/d3d12_fence_timing_test.cpp b/runtime/test/d3d12_fence_timing_test.cpp index 49eef01df..f5e067dfb 100644 --- a/runtime/test/d3d12_fence_timing_test.cpp +++ b/runtime/test/d3d12_fence_timing_test.cpp | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <cstdint> | 16 | #include <cstdint> |
| 17 | #include <cstring> | 17 | #include <cstring> |
| 18 | #include <thread> | 18 | #include <thread> |
| 19 | #include <utility> | ||
| 19 | #include <vector> | 20 | #include <vector> |
| 20 | 21 | ||
| 21 | #define EXPECT(condition) do { \ | 22 | #define EXPECT(condition) do { \ |
| @@ -197,7 +198,9 @@ int check_custom_heap_properties(ID3D12Device* device) { | |||
| 197 | } | 198 | } |
| 198 | } | 199 | } |
| 199 | const D3D12_HEAP_PROPERTIES custom = device->GetCustomHeapProperties(0, D3D12_HEAP_TYPE_CUSTOM); | 200 | const D3D12_HEAP_PROPERTIES custom = device->GetCustomHeapProperties(0, D3D12_HEAP_TYPE_CUSTOM); |
| 200 | EXPECT(custom.Type == D3D12_HEAP_TYPE(0) && custom.CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_UNKNOWN); | 201 | EXPECT(custom.Type == D3D12_HEAP_TYPE(0) && custom.CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_UNKNOWN && |
| 202 | custom.MemoryPoolPreference == D3D12_MEMORY_POOL_UNKNOWN && custom.CreationNodeMask == 1 && | ||
| 203 | custom.VisibleNodeMask == 1); | ||
| 201 | 204 | ||
| 202 | // The host runtime on a NUMA adapter (the answer the layer gives in D3D12_FEATURE_ARCHITECTURE) must agree. | 205 | // The host runtime on a NUMA adapter (the answer the layer gives in D3D12_FEATURE_ARCHITECTURE) must agree. |
| 203 | Ref<ID3D12Device> host; | 206 | Ref<ID3D12Device> host; |
| @@ -221,7 +224,23 @@ int check_custom_heap_properties(ID3D12Device* device) { | |||
| 221 | return 1; | 224 | return 1; |
| 222 | } | 225 | } |
| 223 | } | 226 | } |
| 224 | std::printf("GetCustomHeapProperties: DEFAULT, UPLOAD and READBACK match the host runtime\n"); | 227 | // What has no custom equivalent: an all-zero description with node 0 in both masks on the host runtime. |
| 228 | const std::pair<UINT, D3D12_HEAP_TYPE> invalid[] = { | ||
| 229 | {0, D3D12_HEAP_TYPE_CUSTOM}, {1, D3D12_HEAP_TYPE_CUSTOM}, {0, D3D12_HEAP_TYPE(99)}, | ||
| 230 | {2, D3D12_HEAP_TYPE_UPLOAD}}; | ||
| 231 | for (const auto& [node_mask, type] : invalid) { | ||
| 232 | const D3D12_HEAP_PROPERTIES ours = device->GetCustomHeapProperties(node_mask, type); | ||
| 233 | const D3D12_HEAP_PROPERTIES theirs = host->GetCustomHeapProperties(node_mask, type); | ||
| 234 | if (std::memcmp(&ours, &theirs, sizeof(ours)) != 0) { | ||
| 235 | std::fprintf(stderr, "node mask %u, heap type %d: ours %d/%d/%d/%u/%u, host %d/%d/%d/%u/%u\n", node_mask, | ||
| 236 | type, ours.Type, ours.CPUPageProperty, ours.MemoryPoolPreference, ours.CreationNodeMask, | ||
| 237 | ours.VisibleNodeMask, theirs.Type, theirs.CPUPageProperty, theirs.MemoryPoolPreference, | ||
| 238 | theirs.CreationNodeMask, theirs.VisibleNodeMask); | ||
| 239 | return 1; | ||
| 240 | } | ||
| 241 | } | ||
| 242 | std::printf("GetCustomHeapProperties: DEFAULT, UPLOAD, READBACK, CUSTOM, an unknown type and node mask 2 match " | ||
| 243 | "the host runtime\n"); | ||
| 225 | return 0; | 244 | return 0; |
| 226 | } | 245 | } |
| 227 | 246 | ||
diff --git a/runtime/test/d3d12_fspx_compute_test.cpp b/runtime/test/d3d12_fspx_compute_test.cpp index d919345f5..607af18e4 100644 --- a/runtime/test/d3d12_fspx_compute_test.cpp +++ b/runtime/test/d3d12_fspx_compute_test.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | // refused with E_INVALIDARG, as bytecode without a program is today. | 9 | // refused with E_INVALIDARG, as bytecode without a program is today. |
| 10 | // The shader (test/glsl/cs_user_data.comp) stands in for a translated one. No game data. Set LEONIDA_VK_VALIDATION=1 | 10 | // The shader (test/glsl/cs_user_data.comp) stands in for a translated one. No game data. Set LEONIDA_VK_VALIDATION=1 |
| 11 | // to run under VK_LAYER_KHRONOS_validation. | 11 | // to run under VK_LAYER_KHRONOS_validation. |
| 12 | #include "shader_fixture_path.h" | ||
| 12 | #include "vk_test_device.h" | 13 | #include "vk_test_device.h" |
| 13 | #include "../shims/d3d12_com.h" | 14 | #include "../shims/d3d12_com.h" |
| 14 | #include "../src/shader_library.h" | 15 | #include "../src/shader_library.h" |
| @@ -165,12 +166,12 @@ int main() { | |||
| 165 | const auto library = std::filesystem::temp_directory_path() / "leonida_fspx_compute_test"; | 166 | const auto library = std::filesystem::temp_directory_path() / "leonida_fspx_compute_test"; |
| 166 | std::filesystem::remove_all(library); | 167 | std::filesystem::remove_all(library); |
| 167 | std::filesystem::create_directories(library / "fspx"); | 168 | std::filesystem::create_directories(library / "fspx"); |
| 168 | std::filesystem::copy_file(LEONIDA_TEST_CS_SPV, library / "fspx" / "cs_user_data.spv"); | 169 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_CS_SPV), library / "fspx" / "cs_user_data.spv"); |
| 169 | std::filesystem::copy_file(LEONIDA_TEST_CS_SPV, library / "fspx" / "cs_user_data_b.spv"); | 170 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_CS_SPV), library / "fspx" / "cs_user_data_b.spv"); |
| 170 | // The review case on #1911: program C in two containers whose kind-0 entries differ, translated to two | 171 | // The review case on #1911: program C in two containers whose kind-0 entries differ, translated to two |
| 171 | // different modules (the second has another generator word in its header, still a valid module). | 172 | // different modules (the second has another generator word in its header, still a valid module). |
| 172 | const auto code_c = kind6(9100); | 173 | const auto code_c = kind6(9100); |
| 173 | std::filesystem::copy_file(LEONIDA_TEST_CS_SPV, library / "fspx" / "cs_c_state1.spv"); | 174 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_CS_SPV), library / "fspx" / "cs_c_state1.spv"); |
| 174 | { | 175 | { |
| 175 | std::ifstream in(LEONIDA_TEST_CS_SPV, std::ios::binary); | 176 | std::ifstream in(LEONIDA_TEST_CS_SPV, std::ios::binary); |
| 176 | std::vector<char> words((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>()); | 177 | std::vector<char> words((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>()); |
diff --git a/runtime/test/d3d12_geometry_test.cpp b/runtime/test/d3d12_geometry_test.cpp new file mode 100644 index 000000000..dcfb82bc1 --- /dev/null +++ b/runtime/test/d3d12_geometry_test.cpp | |||
| @@ -0,0 +1,267 @@ | |||
| 1 | // Geometry shaders through the Xbox-ABI proxy over the Vulkan device. A VS+GS+PS pipeline whose GS | ||
| 2 | // (test/glsl/gs_double.geom, with a translated GS's interface: triangles in, a triangle strip out) emits every | ||
| 3 | // triangle twice, the second copy one clip-space unit to the right. On a 64x64 target cleared blue: | ||
| 4 | // - the GS pipeline draws the quad in the top-left quadrant, red: the GS's copy fills the top-right one too; | ||
| 5 | // - a pipeline without a GS draws the same quad moved to the bottom-left quadrant, green: no copy, so the | ||
| 6 | // bottom-right quadrant stays blue. | ||
| 7 | // The PS entry asks for a 32-wide subgroup, so with a GS the third stage's required-size struct is filled too (the | ||
| 8 | // recipe keeps one per stage; a two-entry array overflowed here, found by @0xTehuti on #2109). | ||
| 9 | // Also refused: a GS pipeline whose topology type is not the GS's input primitive (lines: E_INVALIDARG). Skipped where | ||
| 10 | // the GPU lacks geometryShader. Shaders: test/glsl/vs_draw.vert, gs_double.geom, ps_draw.frag. No game data. | ||
| 11 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. | ||
| 12 | #include "vk_test_device.h" | ||
| 13 | #include "d3d12_test_shaders.h" | ||
| 14 | #include "../shims/d3d12_com.h" | ||
| 15 | #include "../shims/d3d12_xs_device.h" | ||
| 16 | #include "../src/shader_library.h" | ||
| 17 | |||
| 18 | #include <array> | ||
| 19 | #include <cstring> | ||
| 20 | |||
| 21 | #if !defined(LEONIDA_TEST_VS_SPV) || !defined(LEONIDA_TEST_GS_SPV) || !defined(LEONIDA_TEST_PS_SPV) | ||
| 22 | #error "LEONIDA_TEST_VS_SPV, LEONIDA_TEST_GS_SPV and LEONIDA_TEST_PS_SPV must name the compiled test shaders" | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #define EXPECT(condition) do { \ | ||
| 26 | if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ | ||
| 27 | } while (0) | ||
| 28 | |||
| 29 | using namespace d3d12test; | ||
| 30 | using XboxHeapHandleFn = std::uint64_t(WINAPI*)(void* heap); // heap slot 9: handle in RAX | ||
| 31 | |||
| 32 | namespace { | ||
| 33 | |||
| 34 | struct Vertex { | ||
| 35 | float x, y; | ||
| 36 | std::uint8_t r, g, b, a; | ||
| 37 | }; | ||
| 38 | |||
| 39 | } // namespace | ||
| 40 | |||
| 41 | int main() { | ||
| 42 | vktest::Device d; | ||
| 43 | EXPECT(d.create()); | ||
| 44 | if (!d.enabled.geometryShader) { | ||
| 45 | std::printf("SKIP: no geometryShader on this GPU\n"); | ||
| 46 | return 77; // ctest's SKIP_RETURN_CODE | ||
| 47 | } | ||
| 48 | |||
| 49 | const auto vs_program = fssm_program({0x56530001, 0xbf810000}); | ||
| 50 | const auto gs_program = fssm_program({0x47530001, 0xbf810000}); | ||
| 51 | const auto ps_program = fssm_program({0x50530001, 0xbf810000}); | ||
| 52 | const auto vs_container = shader_container(vs_program), gs_container = shader_container(gs_program), | ||
| 53 | ps_container = shader_container(ps_program); | ||
| 54 | const auto library = std::filesystem::temp_directory_path() / "leonida_geometry_test"; | ||
| 55 | std::filesystem::create_directories(library); | ||
| 56 | std::filesystem::copy_file(LEONIDA_TEST_VS_SPV, library / "vs_draw.spv", std::filesystem::copy_options::overwrite_existing); | ||
| 57 | std::filesystem::copy_file(LEONIDA_TEST_GS_SPV, library / "gs_double.spv", | ||
| 58 | std::filesystem::copy_options::overwrite_existing); | ||
| 59 | std::filesystem::copy_file(LEONIDA_TEST_PS_SPV, library / "ps_draw.spv", std::filesystem::copy_options::overwrite_existing); | ||
| 60 | { | ||
| 61 | std::ofstream index(library / "index.json", std::ios::binary); | ||
| 62 | index << "{\"vs_draw\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_program) | ||
| 63 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"input_signature\": [" | ||
| 64 | "{\"semantic\": \"COLOR\", \"semantic_index\": 0, \"register\": 0, \"mask\": 15, \"rw_mask\": 15, " | ||
| 65 | "\"system_value\": 0, \"component_type\": \"float\"}, " | ||
| 66 | "{\"semantic\": \"POSITION\", \"semantic_index\": 0, \"register\": 1, \"mask\": 3, \"rw_mask\": 3, " | ||
| 67 | "\"system_value\": 0, \"component_type\": \"float\"}]},\n" | ||
| 68 | " \"gs_double\": {\"stage\": \"gs\", \"fssm_sha256\": \"" << leonida::sha256_hex(gs_program) | ||
| 69 | << "\", \"bindings\": [], \"push_constant_bytes\": 144},\n" | ||
| 70 | " \"ps_draw\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << leonida::sha256_hex(ps_program) | ||
| 71 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"outputs\": [0], \"subgroup_size\": 32}}"; | ||
| 72 | } | ||
| 73 | |||
| 74 | constexpr UINT size = 64; | ||
| 75 | std::vector<std::uint8_t> pixels(size * 256); | ||
| 76 | { | ||
| 77 | rt::d3d12::VulkanDeviceInfo info{}; | ||
| 78 | info.get_instance_proc = d.instance_proc; | ||
| 79 | info.instance = d.instance; | ||
| 80 | info.physical = d.physical; | ||
| 81 | info.device = d.device; | ||
| 82 | info.queue = d.queue; | ||
| 83 | info.queue_family = d.family; | ||
| 84 | info.buffer_device_address = true; | ||
| 85 | info.features = d.enabled; | ||
| 86 | info.subgroup = d.subgroup; | ||
| 87 | info.shader_dir = library.string(); | ||
| 88 | ID3D12Device* inner = nullptr; | ||
| 89 | EXPECT(SUCCEEDED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&inner)))); | ||
| 90 | Ref<ID3D12Device> device; | ||
| 91 | EXPECT(SUCCEEDED(rt::d3d12_xs::create_device_proxy(inner, __uuidof(ID3D12Device), | ||
| 92 | reinterpret_cast<void**>(&device.p)))); | ||
| 93 | rt::d3d12::set_device_outer(inner, device.p); | ||
| 94 | |||
| 95 | D3D12_ROOT_PARAMETER params[2] = {}; | ||
| 96 | params[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; | ||
| 97 | params[0].Constants = {0, 0, 2}; | ||
| 98 | params[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; | ||
| 99 | params[1].Descriptor = {1, 0}; | ||
| 100 | D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{}; | ||
| 101 | root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0; | ||
| 102 | root_desc.Desc_1_0 = {2, params, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT}; | ||
| 103 | const auto root_blob = serialize_root_signature(root_desc); | ||
| 104 | EXPECT(!root_blob.empty()); | ||
| 105 | Ref<ID3D12RootSignature> root; | ||
| 106 | EXPECT(SUCCEEDED(device->CreateRootSignature(0, root_blob.data(), root_blob.size(), IID_PPV_ARGS(&root.p)))); | ||
| 107 | |||
| 108 | const D3D12_INPUT_ELEMENT_DESC elements[2] = { | ||
| 109 | {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, | ||
| 110 | {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D12_APPEND_ALIGNED_ELEMENT, | ||
| 111 | D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}}; | ||
| 112 | D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc{}; | ||
| 113 | pso_desc.pRootSignature = root.p; | ||
| 114 | pso_desc.VS = {vs_container.data(), vs_container.size()}; | ||
| 115 | pso_desc.PS = {ps_container.data(), ps_container.size()}; | ||
| 116 | pso_desc.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL; | ||
| 117 | pso_desc.SampleMask = 0xffffffff; | ||
| 118 | pso_desc.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID; | ||
| 119 | pso_desc.RasterizerState.CullMode = D3D12_CULL_MODE_NONE; | ||
| 120 | pso_desc.RasterizerState.DepthClipEnable = TRUE; | ||
| 121 | pso_desc.InputLayout = {elements, 2}; | ||
| 122 | pso_desc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; | ||
| 123 | pso_desc.NumRenderTargets = 1; | ||
| 124 | pso_desc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| 125 | pso_desc.SampleDesc.Count = 1; | ||
| 126 | Ref<ID3D12PipelineState> plain, doubled, lines; | ||
| 127 | EXPECT(SUCCEEDED(device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&plain.p)))); | ||
| 128 | pso_desc.GS = {gs_container.data(), gs_container.size()}; | ||
| 129 | EXPECT(SUCCEEDED(device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&doubled.p)))); | ||
| 130 | pso_desc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE; // not the GS's input primitive | ||
| 131 | EXPECT(device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&lines.p)) == E_INVALIDARG && !lines.p); | ||
| 132 | |||
| 133 | // The d3d12_draw_test quad in the top-left quadrant; root constants move it. | ||
| 134 | const Vertex vertices[4] = { | ||
| 135 | {-1, 1, 255, 0, 0, 255}, {0, 1, 255, 0, 0, 255}, {-1, 0, 255, 0, 0, 255}, {0, 0, 255, 0, 0, 255}}; | ||
| 136 | const std::uint16_t indices[6] = {0, 1, 2, 2, 1, 3}; | ||
| 137 | const float tints[2][3] = {{1, 0, 1}, {0, 1, 0}}; // red stays red; then green | ||
| 138 | |||
| 139 | const D3D12_HEAP_PROPERTIES default_heap{D3D12_HEAP_TYPE_DEFAULT}; | ||
| 140 | const D3D12_HEAP_PROPERTIES upload_heap{D3D12_HEAP_TYPE_UPLOAD}; | ||
| 141 | const D3D12_HEAP_PROPERTIES readback_heap{D3D12_HEAP_TYPE_READBACK}; | ||
| 142 | Ref<ID3D12Resource> upload, readback, target; | ||
| 143 | const auto upload_desc = buffer_desc(4096); | ||
| 144 | EXPECT(SUCCEEDED(device->CreateCommittedResource(&upload_heap, D3D12_HEAP_FLAG_NONE, &upload_desc, | ||
| 145 | D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, | ||
| 146 | IID_PPV_ARGS(&upload.p)))); | ||
| 147 | const auto readback_desc = buffer_desc(size * 256); | ||
| 148 | EXPECT(SUCCEEDED(device->CreateCommittedResource(&readback_heap, D3D12_HEAP_FLAG_NONE, &readback_desc, | ||
| 149 | D3D12_RESOURCE_STATE_COPY_DEST, nullptr, | ||
| 150 | IID_PPV_ARGS(&readback.p)))); | ||
| 151 | D3D12_RESOURCE_DESC rt_desc{}; | ||
| 152 | rt_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; | ||
| 153 | rt_desc.Width = rt_desc.Height = size; | ||
| 154 | rt_desc.DepthOrArraySize = 1; | ||
| 155 | rt_desc.MipLevels = 1; | ||
| 156 | rt_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| 157 | rt_desc.SampleDesc.Count = 1; | ||
| 158 | rt_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; | ||
| 159 | EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &rt_desc, | ||
| 160 | D3D12_RESOURCE_STATE_RENDER_TARGET, nullptr, | ||
| 161 | IID_PPV_ARGS(&target.p)))); | ||
| 162 | std::uint8_t* up = nullptr; | ||
| 163 | EXPECT(SUCCEEDED(upload->Map(0, nullptr, reinterpret_cast<void**>(&up)))); | ||
| 164 | std::memcpy(up, vertices, sizeof(vertices)); | ||
| 165 | std::memcpy(up + 256, indices, sizeof(indices)); | ||
| 166 | std::memcpy(up + 512, tints[0], sizeof(tints[0])); | ||
| 167 | std::memcpy(up + 768, tints[1], sizeof(tints[1])); | ||
| 168 | const D3D12_GPU_VIRTUAL_ADDRESS upload_va = upload->GetGPUVirtualAddress(); | ||
| 169 | |||
| 170 | const D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1, D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0}; | ||
| 171 | Ref<ID3D12DescriptorHeap> rtv_heap; | ||
| 172 | EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&rtv_heap.p)))); | ||
| 173 | const D3D12_CPU_DESCRIPTOR_HANDLE rtv{ | ||
| 174 | SIZE_T(reinterpret_cast<XboxHeapHandleFn>(slot(rtv_heap.p, 9))(rtv_heap.p))}; | ||
| 175 | device->CreateRenderTargetView(target.p, nullptr, rtv); | ||
| 176 | |||
| 177 | D3D12_COMMAND_QUEUE_DESC queue_desc{}; | ||
| 178 | Ref<ID3D12CommandQueue> queue; | ||
| 179 | Ref<ID3D12CommandAllocator> allocator; | ||
| 180 | Ref<ID3D12GraphicsCommandList> list; | ||
| 181 | Ref<ID3D12Fence> fence; | ||
| 182 | EXPECT(SUCCEEDED(device->CreateCommandQueue(&queue_desc, IID_PPV_ARGS(&queue.p)))); | ||
| 183 | EXPECT(SUCCEEDED(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator.p)))); | ||
| 184 | EXPECT(SUCCEEDED(device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, allocator.p, doubled.p, | ||
| 185 | IID_PPV_ARGS(&list.p)))); | ||
| 186 | EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence.p)))); | ||
| 187 | |||
| 188 | const FLOAT blue[4] = {0, 0, 1, 1}; | ||
| 189 | list->ClearRenderTargetView(rtv, blue, 0, nullptr); | ||
| 190 | list->SetGraphicsRootSignature(root.p); | ||
| 191 | list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); | ||
| 192 | const D3D12_VERTEX_BUFFER_VIEW vbv{upload_va, sizeof(vertices), sizeof(Vertex)}; | ||
| 193 | list->IASetVertexBuffers(0, 1, &vbv); | ||
| 194 | const D3D12_INDEX_BUFFER_VIEW ibv{upload_va + 256, sizeof(indices), DXGI_FORMAT_R16_UINT}; | ||
| 195 | list->IASetIndexBuffer(&ibv); | ||
| 196 | const D3D12_VIEWPORT viewport{0, 0, float(size), float(size), 0, 1}; | ||
| 197 | const D3D12_RECT scissor{0, 0, LONG(size), LONG(size)}; | ||
| 198 | list->RSSetViewports(1, &viewport); | ||
| 199 | list->RSSetScissorRects(1, &scissor); | ||
| 200 | list->OMSetRenderTargets(1, &rtv, FALSE, nullptr); | ||
| 201 | const float top_left[2] = {0, 0}, bottom_left[2] = {0, -1}; | ||
| 202 | list->SetGraphicsRootConstantBufferView(1, upload_va + 512); // red | ||
| 203 | list->SetGraphicsRoot32BitConstants(0, 2, top_left, 0); | ||
| 204 | list->DrawIndexedInstanced(6, 1, 0, 0, 0); // GS: top-left and its copy top-right | ||
| 205 | list->SetPipelineState(plain.p); | ||
| 206 | list->SetGraphicsRootConstantBufferView(1, upload_va + 768); // green | ||
| 207 | list->SetGraphicsRoot32BitConstants(0, 2, bottom_left, 0); | ||
| 208 | list->DrawIndexedInstanced(6, 1, 0, 0, 0); // no GS: bottom-left only | ||
| 209 | |||
| 210 | D3D12_RESOURCE_BARRIER to_copy = transition(target.p, D3D12_RESOURCE_STATE_RENDER_TARGET, | ||
| 211 | D3D12_RESOURCE_STATE_COPY_SOURCE); | ||
| 212 | list->ResourceBarrier(1, &to_copy); | ||
| 213 | D3D12_TEXTURE_COPY_LOCATION dst{}; | ||
| 214 | dst.pResource = readback.p; | ||
| 215 | dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; | ||
| 216 | dst.PlacedFootprint = {0, {DXGI_FORMAT_R8G8B8A8_UNORM, size, size, 1, 256}}; | ||
| 217 | D3D12_TEXTURE_COPY_LOCATION src{}; | ||
| 218 | src.pResource = target.p; | ||
| 219 | src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; | ||
| 220 | list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); | ||
| 221 | EXPECT(list->Close() == S_OK); | ||
| 222 | ID3D12CommandList* lists[] = {list.p}; | ||
| 223 | queue->ExecuteCommandLists(1, lists); | ||
| 224 | EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success); | ||
| 225 | EXPECT(SUCCEEDED(queue->Signal(fence.p, 1))); | ||
| 226 | EXPECT(SUCCEEDED(fence->SetEventOnCompletion(1, nullptr))); | ||
| 227 | void* mapped = nullptr; | ||
| 228 | EXPECT(SUCCEEDED(readback->Map(0, nullptr, &mapped))); | ||
| 229 | std::memcpy(pixels.data(), mapped, pixels.size()); | ||
| 230 | |||
| 231 | for (auto* r : {&upload, &readback, &target}) r->reset(); | ||
| 232 | plain.reset(); | ||
| 233 | doubled.reset(); | ||
| 234 | root.reset(); | ||
| 235 | rtv_heap.reset(); | ||
| 236 | list.reset(); | ||
| 237 | allocator.reset(); | ||
| 238 | queue.reset(); | ||
| 239 | fence.reset(); | ||
| 240 | EXPECT(rt::d3d12_xs::device_proxy_ref_count(device.p) == 1); | ||
| 241 | } | ||
| 242 | std::filesystem::remove_all(library); | ||
| 243 | |||
| 244 | unsigned mismatches = 0; | ||
| 245 | for (UINT row = 0; row < size; ++row) { | ||
| 246 | for (UINT col = 0; col < size; ++col) { | ||
| 247 | const bool top = row < size / 2, left = col < size / 2; | ||
| 248 | const std::array<std::uint8_t, 4> want = top ? std::array<std::uint8_t, 4>{255, 0, 0, 255} | ||
| 249 | : left ? std::array<std::uint8_t, 4>{0, 255, 0, 255} | ||
| 250 | : std::array<std::uint8_t, 4>{0, 0, 255, 255}; | ||
| 251 | const std::uint8_t* got = pixels.data() + row * 256 + col * 4; | ||
| 252 | if (std::equal(want.begin(), want.end(), got)) continue; | ||
| 253 | if (mismatches++ < 6) | ||
| 254 | std::fprintf(stderr, "pixel (%u, %u): got %u,%u,%u,%u want %u,%u,%u,%u\n", col, row, got[0], got[1], | ||
| 255 | got[2], got[3], want[0], want[1], want[2], want[3]); | ||
| 256 | } | ||
| 257 | } | ||
| 258 | EXPECT(!mismatches); | ||
| 259 | if (d.validation_errors()) { | ||
| 260 | std::fprintf(stderr, "%u validation errors\n", d.validation_errors()); | ||
| 261 | return 1; | ||
| 262 | } | ||
| 263 | std::printf("geometry: a VS+GS+PS pipeline drew its quad and the GS's copy (top half red), a pipeline without a " | ||
| 264 | "GS only the quad (bottom-left green), all %u pixels matched; a GS with a line topology refused\n", | ||
| 265 | size * size); | ||
| 266 | return 0; | ||
| 267 | } | ||
diff --git a/runtime/test/d3d12_msaa_draw_test.cpp b/runtime/test/d3d12_msaa_draw_test.cpp index 8b8aa06e1..2c87e880c 100644 --- a/runtime/test/d3d12_msaa_draw_test.cpp +++ b/runtime/test/d3d12_msaa_draw_test.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | // and 3 samples are E_INVALIDARG. A 4x PSO drawing into a single-sampled target fails the list at execute | 10 | // and 3 samples are E_INVALIDARG. A 4x PSO drawing into a single-sampled target fails the list at execute |
| 11 | // (invalid_subresource) instead of reaching the driver. Shaders: test/glsl/vs_draw.vert, ps_draw.frag. No game data. | 11 | // (invalid_subresource) instead of reaching the driver. Shaders: test/glsl/vs_draw.vert, ps_draw.frag. No game data. |
| 12 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. | 12 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. |
| 13 | #include "shader_fixture_path.h" | ||
| 13 | #include "vk_test_device.h" | 14 | #include "vk_test_device.h" |
| 14 | #include "d3d12_test_shaders.h" | 15 | #include "d3d12_test_shaders.h" |
| 15 | #include "../shims/d3d12_com.h" | 16 | #include "../shims/d3d12_com.h" |
| @@ -53,8 +54,8 @@ int main() { | |||
| 53 | const auto vs_container = shader_container(vs_program), ps_container = shader_container(ps_program); | 54 | const auto vs_container = shader_container(vs_program), ps_container = shader_container(ps_program); |
| 54 | const auto library = std::filesystem::temp_directory_path() / "leonida_msaa_draw_test"; | 55 | const auto library = std::filesystem::temp_directory_path() / "leonida_msaa_draw_test"; |
| 55 | std::filesystem::create_directories(library); | 56 | std::filesystem::create_directories(library); |
| 56 | std::filesystem::copy_file(LEONIDA_TEST_VS_SPV, library / "vs_draw.spv", std::filesystem::copy_options::overwrite_existing); | 57 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_VS_SPV), library / "vs_draw.spv", std::filesystem::copy_options::overwrite_existing); |
| 57 | std::filesystem::copy_file(LEONIDA_TEST_PS_SPV, library / "ps_draw.spv", std::filesystem::copy_options::overwrite_existing); | 58 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_PS_SPV), library / "ps_draw.spv", std::filesystem::copy_options::overwrite_existing); |
| 58 | { | 59 | { |
| 59 | std::ofstream index(library / "index.json", std::ios::binary); | 60 | std::ofstream index(library / "index.json", std::ios::binary); |
| 60 | index << "{\"vs_draw\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_program) | 61 | index << "{\"vs_draw\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_program) |
| @@ -131,7 +132,7 @@ int main() { | |||
| 131 | EXPECT(device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&three.p)) == E_INVALIDARG && !three.p); | 132 | EXPECT(device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&three.p)) == E_INVALIDARG && !three.p); |
| 132 | pso_desc.SampleDesc = {samples, 1}; // past NumQualityLevels (1): D3D12 returns E_INVALIDARG | 133 | pso_desc.SampleDesc = {samples, 1}; // past NumQualityLevels (1): D3D12 returns E_INVALIDARG |
| 133 | EXPECT(device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&three.p)) == E_INVALIDARG && !three.p); | 134 | EXPECT(device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&three.p)) == E_INVALIDARG && !three.p); |
| 134 | pso_desc.SampleDesc = {samples, UINT(D3D12_STANDARD_MULTISAMPLE_PATTERN)}; // accepted natively | 135 | pso_desc.SampleDesc = {samples, UINT(DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN)}; // accepted natively |
| 135 | EXPECT(SUCCEEDED(device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&three.p)))); | 136 | EXPECT(SUCCEEDED(device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&three.p)))); |
| 136 | three.reset(); | 137 | three.reset(); |
| 137 | 138 | ||
diff --git a/runtime/test/d3d12_pipeline_library_test.cpp b/runtime/test/d3d12_pipeline_library_test.cpp index cd7b411e5..5643c0d73 100644 --- a/runtime/test/d3d12_pipeline_library_test.cpp +++ b/runtime/test/d3d12_pipeline_library_test.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | // - GetSerializedSize + Serialize round-trip into a second CreatePipelineLibrary; | 8 | // - GetSerializedSize + Serialize round-trip into a second CreatePipelineLibrary; |
| 9 | // - GPU execution of both loaded compute and loaded graphics PSOs under LEONIDA_VK_VALIDATION=1. | 9 | // - GPU execution of both loaded compute and loaded graphics PSOs under LEONIDA_VK_VALIDATION=1. |
| 10 | // No game data. | 10 | // No game data. |
| 11 | #include "shader_fixture_path.h" | ||
| 11 | #include "vk_test_device.h" | 12 | #include "vk_test_device.h" |
| 12 | #include "d3d12_test_shaders.h" | 13 | #include "d3d12_test_shaders.h" |
| 13 | #include "../shims/d3d12_com.h" | 14 | #include "../shims/d3d12_com.h" |
| @@ -69,11 +70,11 @@ int main() { | |||
| 69 | 70 | ||
| 70 | const auto lib_dir = std::filesystem::temp_directory_path() / "leonida_pipeline_library_test"; | 71 | const auto lib_dir = std::filesystem::temp_directory_path() / "leonida_pipeline_library_test"; |
| 71 | std::filesystem::create_directories(lib_dir); | 72 | std::filesystem::create_directories(lib_dir); |
| 72 | std::filesystem::copy_file(LEONIDA_TEST_CS_SPV, lib_dir / "cs.spv", | 73 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_CS_SPV), lib_dir / "cs.spv", |
| 73 | std::filesystem::copy_options::overwrite_existing); | 74 | std::filesystem::copy_options::overwrite_existing); |
| 74 | std::filesystem::copy_file(LEONIDA_TEST_VS_SPV, lib_dir / "vs.spv", | 75 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_VS_SPV), lib_dir / "vs.spv", |
| 75 | std::filesystem::copy_options::overwrite_existing); | 76 | std::filesystem::copy_options::overwrite_existing); |
| 76 | std::filesystem::copy_file(LEONIDA_TEST_PS_SPV, lib_dir / "ps.spv", | 77 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_PS_SPV), lib_dir / "ps.spv", |
| 77 | std::filesystem::copy_options::overwrite_existing); | 78 | std::filesystem::copy_options::overwrite_existing); |
| 78 | { | 79 | { |
| 79 | std::ofstream idx(lib_dir / "index.json", std::ios::binary); | 80 | std::ofstream idx(lib_dir / "index.json", std::ios::binary); |
diff --git a/runtime/test/d3d12_present_test.cpp b/runtime/test/d3d12_present_test.cpp index 44c7f4624..c3a0f4d39 100644 --- a/runtime/test/d3d12_present_test.cpp +++ b/runtime/test/d3d12_present_test.cpp | |||
| @@ -3,8 +3,9 @@ | |||
| 3 | // moves the back buffer PRESENT -> RENDER_TARGET, clears it, moves it back, executes, presents and signals a fence. | 3 | // moves the back buffer PRESENT -> RENDER_TARGET, clears it, moves it back, executes, presents and signals a fence. |
| 4 | // The window is then resized, which recreates the swapchain and scales the blit. The presented images are copied | 4 | // The window is then resized, which recreates the swapchain and scales the blit. The presented images are copied |
| 5 | // back (the presenter's capture) and must hold the clear colour at the swapchain's size. Last, the colour on screen | 5 | // back (the presenter's capture) and must hold the clear colour at the swapchain's size. Last, the colour on screen |
| 6 | // is read back with GDI when the window is in front, the display is in SDR and GDI can read the screen (skipped | 6 | // is read back with GDI on native Windows when the window is in front, the display is in SDR and GDI can read the |
| 7 | // otherwise, e.g. in HDR, on a locked desktop or under Wine's macOS driver). No shaders or game data. | 7 | // screen. Under Wine, rootless XWayland can return black for desktop reads, so the swapchain checks confirm the |
| 8 | // colour there. No shaders or game data. | ||
| 8 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation; any validation error fails the test. | 9 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation; any validation error fails the test. |
| 9 | #include "vk_test_device.h" | 10 | #include "vk_test_device.h" |
| 10 | #include "../shims/d3d12_com.h" | 11 | #include "../shims/d3d12_com.h" |
| @@ -461,13 +462,16 @@ int main() { | |||
| 461 | "(%u real out-of-date presents)\n", | 462 | "(%u real out-of-date presents)\n", |
| 462 | real_out_of_date); | 463 | real_out_of_date); |
| 463 | 464 | ||
| 464 | // What reached the screen: the centre of the client area, if the window is in front. This needs GDI to read | 465 | // Wine's desktop GDI read can return black even when the compositor presents the right colour. |
| 465 | // the screen, which not every window system gives it: under Wine's macOS driver the screen DC reads nothing | 466 | // The swapchain checks above also cover Wine drivers that cannot read the desktop at all. |
| 466 | // (GetPixel returns CLR_INVALID even for a pixel GDI itself painted), so there the swapchain checks above are | 467 | const bool wine = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "wine_get_version") != nullptr; |
| 467 | // what confirms the colour. | 468 | if (!wine) { |
| 468 | Sleep(200); | 469 | Sleep(200); |
| 469 | pump(); | 470 | pump(); |
| 470 | if (GetForegroundWindow() == window && !IsIconic(window)) { | 471 | } |
| 472 | if (wine) { | ||
| 473 | std::printf("Wine: on-screen colour check skipped after swapchain readback\n"); | ||
| 474 | } else if (GetForegroundWindow() == window && !IsIconic(window)) { | ||
| 471 | if (is_hdr_monitor(window)) { | 475 | if (is_hdr_monitor(window)) { |
| 472 | std::printf("the monitor is in HDR mode: on-screen colour check skipped\n"); | 476 | std::printf("the monitor is in HDR mode: on-screen colour check skipped\n"); |
| 473 | } else { | 477 | } else { |
diff --git a/runtime/test/d3d12_private_data_test.cpp b/runtime/test/d3d12_private_data_test.cpp new file mode 100644 index 000000000..4c1848a9c --- /dev/null +++ b/runtime/test/d3d12_private_data_test.cpp | |||
| @@ -0,0 +1,346 @@ | |||
| 1 | // ID3D12Object private data on the Vulkan-backed device, compared with the host PC runtime: GetPrivateData, | ||
| 2 | // SetPrivateData, SetPrivateDataInterface and SetName (runtime/shims/d3d12_com_object.h, D3D-24). The same script | ||
| 3 | // runs on the device and on a fence, a committed buffer, a command allocator and a descriptor heap of each device, | ||
| 4 | // and records every HRESULT, every size the call writes back, the bytes it reads and the reference count of an | ||
| 5 | // interface the object holds. The two records must be the same, step by step. No shaders or game data. Skips (77) | ||
| 6 | // without a Vulkan GPU; without a host D3D12 device only the layer's own record is printed. Set | ||
| 7 | // LEONIDA_D3D49_VERBOSE=1 to print every step. | ||
| 8 | #include "vk_test_device.h" | ||
| 9 | #include "../shims/d3d12_com.h" | ||
| 10 | |||
| 11 | #include <cstdint> | ||
| 12 | #include <cstdio> | ||
| 13 | #include <cstring> | ||
| 14 | #include <string> | ||
| 15 | #include <vector> | ||
| 16 | |||
| 17 | #define EXPECT(condition) do { \ | ||
| 18 | if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ | ||
| 19 | } while (0) | ||
| 20 | |||
| 21 | namespace { | ||
| 22 | |||
| 23 | template<class T> | ||
| 24 | struct Ref { | ||
| 25 | T* p = nullptr; | ||
| 26 | ~Ref() { reset(); } | ||
| 27 | void reset() { | ||
| 28 | if (p) p->Release(); | ||
| 29 | p = nullptr; | ||
| 30 | } | ||
| 31 | T* operator->() const { return p; } | ||
| 32 | }; | ||
| 33 | |||
| 34 | // An interface for SetPrivateDataInterface that counts its references, the same object type on both devices. | ||
| 35 | class Counted final : public IUnknown { | ||
| 36 | public: | ||
| 37 | HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** out) override { | ||
| 38 | if (!out) return E_POINTER; | ||
| 39 | if (riid == __uuidof(IUnknown)) { | ||
| 40 | *out = this; | ||
| 41 | AddRef(); | ||
| 42 | return S_OK; | ||
| 43 | } | ||
| 44 | *out = nullptr; | ||
| 45 | return E_NOINTERFACE; | ||
| 46 | } | ||
| 47 | ULONG STDMETHODCALLTYPE AddRef() override { return ++refs; } | ||
| 48 | ULONG STDMETHODCALLTYPE Release() override { return --refs; } // lives on the stack; never deleted | ||
| 49 | ULONG refs = 1; | ||
| 50 | }; | ||
| 51 | |||
| 52 | // WKPDID_D3DDebugObjectName / ...NameW (d3dcommon.h), spelled out so nothing needs dxguid.lib. | ||
| 53 | constexpr GUID kName{0x429b8c22, 0x9188, 0x4b0c, {0x87, 0x42, 0xac, 0xb0, 0xbf, 0x85, 0xc2, 0x00}}; | ||
| 54 | constexpr GUID kNameW{0x4cca5fd8, 0x921f, 0x42c8, {0x85, 0x99, 0xd2, 0x86, 0x6a, 0x3e, 0x5f, 0x7e}}; | ||
| 55 | |||
| 56 | // A key of its own for each step, so no step sees another's entry. | ||
| 57 | GUID key(unsigned step) { return GUID{0x5eed0000u + step, 0x1d3d, 0x4c12, {0x9a, 0x41, 0x77, 0x10, 0x2b, 0x6c, 0x00, 0x01}}; } | ||
| 58 | |||
| 59 | struct Record { | ||
| 60 | std::vector<std::string> names; | ||
| 61 | std::vector<std::uint64_t> values; | ||
| 62 | void add(const std::string& name, std::uint64_t value) { | ||
| 63 | names.push_back(name); | ||
| 64 | values.push_back(value); | ||
| 65 | } | ||
| 66 | }; | ||
| 67 | |||
| 68 | // A call the host may fault on is recorded as this value instead of crashing the test. | ||
| 69 | constexpr std::uint64_t kFaulted = 0xC0000005; | ||
| 70 | |||
| 71 | HRESULT get_guarded(ID3D12Object* o, REFGUID guid, UINT* size, void* data) { | ||
| 72 | __try { | ||
| 73 | return o->GetPrivateData(guid, size, data); | ||
| 74 | } __except (EXCEPTION_EXECUTE_HANDLER) { | ||
| 75 | return HRESULT(kFaulted); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | HRESULT set_guarded(ID3D12Object* o, REFGUID guid, UINT size, const void* data) { | ||
| 80 | __try { | ||
| 81 | return o->SetPrivateData(guid, size, data); | ||
| 82 | } __except (EXCEPTION_EXECUTE_HANDLER) { | ||
| 83 | return HRESULT(kFaulted); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | HRESULT name_guarded(ID3D12Object* o, LPCWSTR name) { | ||
| 88 | __try { | ||
| 89 | return o->SetName(name); | ||
| 90 | } __except (EXCEPTION_EXECUTE_HANDLER) { | ||
| 91 | return HRESULT(kFaulted); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | // GetPrivateData with a buffer of `capacity` bytes (null when `with_buffer` is false), starting the size at | ||
| 96 | // `capacity`. Records the HRESULT, the size written back and the first 8 bytes of the buffer (filled with 0xCD). | ||
| 97 | void get(Record& r, const std::string& what, ID3D12Object* o, REFGUID guid, UINT capacity, bool with_buffer = true) { | ||
| 98 | std::uint8_t buffer[64]; | ||
| 99 | std::memset(buffer, 0xCD, sizeof(buffer)); | ||
| 100 | UINT size = capacity; | ||
| 101 | const HRESULT hr = get_guarded(o, guid, &size, with_buffer ? buffer : nullptr); | ||
| 102 | r.add(what + ": hr", std::uint32_t(hr)); | ||
| 103 | r.add(what + ": size", size); | ||
| 104 | std::uint64_t head = 0; | ||
| 105 | std::memcpy(&head, buffer, sizeof(head)); | ||
| 106 | if (with_buffer) r.add(what + ": bytes", head); | ||
| 107 | } | ||
| 108 | |||
| 109 | void script(Record& r, ID3D12Object* o) { | ||
| 110 | const std::uint8_t eight[8] = {1, 2, 3, 4, 5, 6, 7, 8}; | ||
| 111 | const std::uint8_t four[4] = {9, 10, 11, 12}; | ||
| 112 | unsigned step = 0; | ||
| 113 | |||
| 114 | // A key that was never set. | ||
| 115 | { | ||
| 116 | const GUID g = key(++step); | ||
| 117 | get(r, "missing, 16-byte buffer", o, g, 16); | ||
| 118 | get(r, "missing, size query", o, g, 16, false); | ||
| 119 | get(r, "missing, size 0", o, g, 0); | ||
| 120 | r.add("missing, null size: hr", std::uint32_t(get_guarded(o, g, nullptr, nullptr))); | ||
| 121 | } | ||
| 122 | // Eight bytes, read back with buffers of every size around them. | ||
| 123 | { | ||
| 124 | const GUID g = key(++step); | ||
| 125 | r.add("set 8 bytes: hr", std::uint32_t(set_guarded(o, g, 8, eight))); | ||
| 126 | get(r, "8 bytes, size query", o, g, 0, false); | ||
| 127 | get(r, "8 bytes, size query from 100", o, g, 100, false); | ||
| 128 | get(r, "8 bytes, 4-byte buffer", o, g, 4); | ||
| 129 | get(r, "8 bytes, 0-byte buffer", o, g, 0); | ||
| 130 | get(r, "8 bytes, 8-byte buffer", o, g, 8); | ||
| 131 | get(r, "8 bytes, 64-byte buffer", o, g, 64); | ||
| 132 | r.add("8 bytes, null size: hr", std::uint32_t(get_guarded(o, g, nullptr, nullptr))); | ||
| 133 | r.add("overwrite with 4 bytes: hr", std::uint32_t(set_guarded(o, g, 4, four))); | ||
| 134 | get(r, "after overwrite", o, g, 64); | ||
| 135 | } | ||
| 136 | // Removal: size 0, null data, or both. | ||
| 137 | { | ||
| 138 | const GUID g = key(++step); | ||
| 139 | set_guarded(o, g, 8, eight); | ||
| 140 | r.add("set 8 with null data: hr", std::uint32_t(set_guarded(o, g, 8, nullptr))); | ||
| 141 | get(r, "after 8 with null data", o, g, 64); | ||
| 142 | } | ||
| 143 | { | ||
| 144 | const GUID g = key(++step); | ||
| 145 | set_guarded(o, g, 8, eight); | ||
| 146 | r.add("set 0 bytes with data: hr", std::uint32_t(set_guarded(o, g, 0, eight))); | ||
| 147 | get(r, "after 0 bytes with data", o, g, 64); | ||
| 148 | } | ||
| 149 | { | ||
| 150 | const GUID g = key(++step); | ||
| 151 | set_guarded(o, g, 8, eight); | ||
| 152 | r.add("set 0 bytes, null data: hr", std::uint32_t(set_guarded(o, g, 0, nullptr))); | ||
| 153 | get(r, "after 0 bytes, null data", o, g, 64); | ||
| 154 | } | ||
| 155 | { | ||
| 156 | const GUID g = key(++step); | ||
| 157 | r.add("set 8 with null data on a missing key: hr", std::uint32_t(set_guarded(o, g, 8, nullptr))); | ||
| 158 | r.add("set 0 bytes on a missing key: hr", std::uint32_t(set_guarded(o, g, 0, nullptr))); | ||
| 159 | get(r, "missing key after removals", o, g, 64); | ||
| 160 | } | ||
| 161 | { | ||
| 162 | const GUID g = key(++step); | ||
| 163 | r.add("set 0 bytes with data on a missing key: hr", std::uint32_t(set_guarded(o, g, 0, eight))); | ||
| 164 | get(r, "after 0 bytes with data on a missing key", o, g, 64); | ||
| 165 | get(r, "after 0 bytes with data on a missing key, size query", o, g, 64, false); | ||
| 166 | r.add("then 0 bytes, null data: hr", std::uint32_t(set_guarded(o, g, 0, nullptr))); | ||
| 167 | get(r, "after removing the empty entry", o, g, 64); | ||
| 168 | } | ||
| 169 | { | ||
| 170 | const GUID g = key(++step); | ||
| 171 | r.add("null interface on a missing key: hr", std::uint32_t(o->SetPrivateDataInterface(g, nullptr))); | ||
| 172 | get(r, "after a null interface, 4-byte buffer", o, g, 4); | ||
| 173 | get(r, "after a null interface, 64-byte buffer", o, g, 64); | ||
| 174 | r.add("null interface again: hr", std::uint32_t(o->SetPrivateDataInterface(g, nullptr))); | ||
| 175 | r.add("remove the null interface: hr", std::uint32_t(set_guarded(o, g, 0, nullptr))); | ||
| 176 | get(r, "after removing the null interface", o, g, 64); | ||
| 177 | } | ||
| 178 | // An interface entry: the object's references to it, and what reading it gives. | ||
| 179 | { | ||
| 180 | const GUID g = key(++step); | ||
| 181 | Counted payload; | ||
| 182 | r.add("interface: set hr", std::uint32_t(o->SetPrivateDataInterface(g, &payload))); | ||
| 183 | r.add("interface: refs after set", payload.refs); | ||
| 184 | get(r, "interface, size query", o, g, 0, false); | ||
| 185 | r.add("interface, size query: refs", payload.refs); | ||
| 186 | get(r, "interface, 4-byte buffer", o, g, 4); | ||
| 187 | r.add("interface, 4-byte buffer: refs", payload.refs); | ||
| 188 | { | ||
| 189 | IUnknown* read = nullptr; | ||
| 190 | UINT size = sizeof(read); | ||
| 191 | const HRESULT hr = get_guarded(o, g, &size, &read); | ||
| 192 | r.add("interface, pointer-size buffer: hr", std::uint32_t(hr)); | ||
| 193 | r.add("interface, pointer-size buffer: size", size); | ||
| 194 | r.add("interface, pointer-size buffer: same object", read == &payload); | ||
| 195 | r.add("interface, pointer-size buffer: refs", payload.refs); | ||
| 196 | if (read == &payload) read->Release(); | ||
| 197 | } | ||
| 198 | r.add("interface: set again hr", std::uint32_t(o->SetPrivateDataInterface(g, &payload))); | ||
| 199 | r.add("interface: refs after setting again", payload.refs); | ||
| 200 | r.add("interface: bytes over it hr", std::uint32_t(set_guarded(o, g, 4, four))); | ||
| 201 | r.add("interface: refs after bytes over it", payload.refs); | ||
| 202 | get(r, "interface, then bytes", o, g, 64); | ||
| 203 | r.add("interface: set over bytes hr", std::uint32_t(o->SetPrivateDataInterface(g, &payload))); | ||
| 204 | r.add("interface: refs after set over bytes", payload.refs); | ||
| 205 | r.add("interface: null hr", std::uint32_t(o->SetPrivateDataInterface(g, nullptr))); | ||
| 206 | r.add("interface: refs after null", payload.refs); | ||
| 207 | get(r, "interface, after null", o, g, 64); | ||
| 208 | // Removed with SetPrivateData(0, null) instead. | ||
| 209 | o->SetPrivateDataInterface(g, &payload); | ||
| 210 | r.add("interface: removed with bytes hr", std::uint32_t(set_guarded(o, g, 0, nullptr))); | ||
| 211 | r.add("interface: refs after removal with bytes", payload.refs); | ||
| 212 | get(r, "interface, after removal with bytes", o, g, 64); | ||
| 213 | o->SetPrivateDataInterface(g, nullptr); | ||
| 214 | } | ||
| 215 | // SetName: where the name goes, and what an empty or null name does. | ||
| 216 | { | ||
| 217 | r.add("SetName abc: hr", std::uint32_t(name_guarded(o, L"abc"))); | ||
| 218 | get(r, "name W after abc", o, kNameW, 64); | ||
| 219 | get(r, "name A after abc", o, kName, 64); | ||
| 220 | r.add("SetName empty: hr", std::uint32_t(name_guarded(o, L""))); | ||
| 221 | get(r, "name W after empty", o, kNameW, 64); | ||
| 222 | get(r, "name A after empty", o, kName, 64); | ||
| 223 | r.add("SetName null: hr", std::uint32_t(name_guarded(o, nullptr))); | ||
| 224 | get(r, "name W after null", o, kNameW, 64); | ||
| 225 | get(r, "name A after null", o, kName, 64); | ||
| 226 | // A name set through the narrow key, and SetName after it. | ||
| 227 | const char narrow[] = "xyz"; | ||
| 228 | r.add("set narrow name: hr", std::uint32_t(set_guarded(o, kName, sizeof(narrow), narrow))); | ||
| 229 | get(r, "name W after narrow", o, kNameW, 64); | ||
| 230 | r.add("SetName def after narrow: hr", std::uint32_t(name_guarded(o, L"def"))); | ||
| 231 | get(r, "name A after def", o, kName, 64); | ||
| 232 | get(r, "name W after def", o, kNameW, 64); | ||
| 233 | set_guarded(o, kName, 0, nullptr); | ||
| 234 | name_guarded(o, nullptr); | ||
| 235 | } | ||
| 236 | } | ||
| 237 | |||
| 238 | // The objects the script runs on, made on `device`: the device itself and four children. | ||
| 239 | struct Objects { | ||
| 240 | Ref<ID3D12Fence> fence; | ||
| 241 | Ref<ID3D12Resource> buffer; | ||
| 242 | Ref<ID3D12CommandAllocator> allocator; | ||
| 243 | Ref<ID3D12DescriptorHeap> heap; | ||
| 244 | }; | ||
| 245 | |||
| 246 | bool make(ID3D12Device* device, Objects& o) { | ||
| 247 | D3D12_RESOURCE_DESC desc{}; | ||
| 248 | desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; | ||
| 249 | desc.Width = 256; | ||
| 250 | desc.Height = 1; | ||
| 251 | desc.DepthOrArraySize = 1; | ||
| 252 | desc.MipLevels = 1; | ||
| 253 | desc.SampleDesc.Count = 1; | ||
| 254 | desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; | ||
| 255 | const D3D12_HEAP_PROPERTIES upload{D3D12_HEAP_TYPE_UPLOAD}; | ||
| 256 | const D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 4}; | ||
| 257 | return SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&o.fence.p))) && | ||
| 258 | SUCCEEDED(device->CreateCommittedResource(&upload, D3D12_HEAP_FLAG_NONE, &desc, | ||
| 259 | D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, | ||
| 260 | IID_PPV_ARGS(&o.buffer.p))) && | ||
| 261 | SUCCEEDED(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&o.allocator.p))) && | ||
| 262 | SUCCEEDED(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&o.heap.p))); | ||
| 263 | } | ||
| 264 | |||
| 265 | // The records of every object of `device`, in a fixed order, each name prefixed with the object's kind. | ||
| 266 | bool record(ID3D12Device* device, Record& r) { | ||
| 267 | Objects o; | ||
| 268 | if (!make(device, o)) return false; | ||
| 269 | const struct { | ||
| 270 | const char* kind; | ||
| 271 | ID3D12Object* object; | ||
| 272 | } objects[] = {{"device", device}, {"fence", o.fence.p}, {"buffer", o.buffer.p}, | ||
| 273 | {"allocator", o.allocator.p}, {"descriptor heap", o.heap.p}}; | ||
| 274 | for (const auto& entry : objects) { | ||
| 275 | Record one; | ||
| 276 | script(one, entry.object); | ||
| 277 | for (std::size_t i = 0; i < one.names.size(); ++i) r.add(std::string(entry.kind) + ": " + one.names[i], one.values[i]); | ||
| 278 | } | ||
| 279 | // An object that dies holding an interface releases it. | ||
| 280 | Counted payload; | ||
| 281 | { | ||
| 282 | Ref<ID3D12Fence> fence; | ||
| 283 | if (FAILED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence.p)))) return false; | ||
| 284 | fence->SetPrivateDataInterface(key(100), &payload); | ||
| 285 | r.add("dying fence: refs while held", payload.refs); | ||
| 286 | } | ||
| 287 | r.add("dying fence: refs after release", payload.refs); | ||
| 288 | return true; | ||
| 289 | } | ||
| 290 | |||
| 291 | } // namespace | ||
| 292 | |||
| 293 | int main() { | ||
| 294 | vktest::Device d; | ||
| 295 | const auto device_status = d.initialize(); | ||
| 296 | if (device_status == vktest::DeviceStatus::unavailable) return 77; // no Vulkan GPU: ctest skips | ||
| 297 | if (device_status != vktest::DeviceStatus::ready) return 1; | ||
| 298 | const bool verbose = GetEnvironmentVariableA("LEONIDA_D3D49_VERBOSE", nullptr, 0) > 0; | ||
| 299 | { | ||
| 300 | rt::d3d12::VulkanDeviceInfo info{}; | ||
| 301 | info.get_instance_proc = d.instance_proc; | ||
| 302 | info.instance = d.instance; | ||
| 303 | info.physical = d.physical; | ||
| 304 | info.device = d.device; | ||
| 305 | info.queue = d.queue; | ||
| 306 | info.queue_family = d.family; | ||
| 307 | Ref<ID3D12Device> device; | ||
| 308 | EXPECT(SUCCEEDED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&device.p)))); | ||
| 309 | Record ours; | ||
| 310 | EXPECT(record(device.p, ours)); | ||
| 311 | |||
| 312 | const HMODULE d3d12 = LoadLibraryExA("d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); | ||
| 313 | const auto create_host = d3d12 ? reinterpret_cast<PFN_D3D12_CREATE_DEVICE>( | ||
| 314 | reinterpret_cast<void*>(GetProcAddress(d3d12, "D3D12CreateDevice"))) | ||
| 315 | : nullptr; | ||
| 316 | Ref<ID3D12Device> host; | ||
| 317 | if (!create_host || FAILED(create_host(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p)))) { | ||
| 318 | std::printf("private data: no host D3D12 device to compare with; %zu steps recorded, not compared\n", | ||
| 319 | ours.values.size()); | ||
| 320 | } else { | ||
| 321 | Record theirs; | ||
| 322 | EXPECT(record(host.p, theirs)); | ||
| 323 | EXPECT(theirs.names == ours.names); | ||
| 324 | int mismatches = 0, faulted = 0; | ||
| 325 | for (std::size_t i = 0; i < ours.values.size(); ++i) { | ||
| 326 | if (theirs.values[i] == kFaulted) { // SetName(nullptr): the host faults; the layer clears the name | ||
| 327 | std::printf("private data %s: the host faults, not compared (ours 0x%llx)\n", | ||
| 328 | ours.names[i].c_str(), static_cast<unsigned long long>(ours.values[i])); | ||
| 329 | ++faulted; | ||
| 330 | continue; | ||
| 331 | } | ||
| 332 | const bool same = ours.values[i] == theirs.values[i]; | ||
| 333 | if (verbose || !same) | ||
| 334 | std::printf("private data %s: ours 0x%llx host 0x%llx%s\n", ours.names[i].c_str(), | ||
| 335 | static_cast<unsigned long long>(ours.values[i]), | ||
| 336 | static_cast<unsigned long long>(theirs.values[i]), same ? "" : " MISMATCH"); | ||
| 337 | mismatches += !same; | ||
| 338 | } | ||
| 339 | std::printf("private data: %zu steps compared with the host (%d more the host faults on), %d mismatches\n", | ||
| 340 | ours.values.size() - faulted, faulted, mismatches); | ||
| 341 | EXPECT(mismatches == 0); | ||
| 342 | } | ||
| 343 | } | ||
| 344 | std::printf("d3d12_private_data_test: OK\n"); | ||
| 345 | return 0; | ||
| 346 | } | ||
diff --git a/runtime/test/d3d12_set0_compute_test.cpp b/runtime/test/d3d12_set0_compute_test.cpp index 69663d764..0b0646593 100644 --- a/runtime/test/d3d12_set0_compute_test.cpp +++ b/runtime/test/d3d12_set0_compute_test.cpp | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | // A device without the bindless set refuses the PSO. No game data: the program is two marker words and the module is | 15 | // A device without the bindless set refuses the PSO. No game data: the program is two marker words and the module is |
| 16 | // GLSL written to the translator's contract. | 16 | // GLSL written to the translator's contract. |
| 17 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation (0 errors required). | 17 | // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation (0 errors required). |
| 18 | #include "shader_fixture_path.h" | ||
| 18 | #include "vk_test_device.h" | 19 | #include "vk_test_device.h" |
| 19 | #include "d3d12_test_shaders.h" | 20 | #include "d3d12_test_shaders.h" |
| 20 | #include "../shims/d3d12_com.h" | 21 | #include "../shims/d3d12_com.h" |
| @@ -69,7 +70,7 @@ int main() { | |||
| 69 | const auto container = shader_container(program); | 70 | const auto container = shader_container(program); |
| 70 | const auto library = std::filesystem::temp_directory_path() / "leonida_set0_compute_test"; | 71 | const auto library = std::filesystem::temp_directory_path() / "leonida_set0_compute_test"; |
| 71 | std::filesystem::create_directories(library); | 72 | std::filesystem::create_directories(library); |
| 72 | std::filesystem::copy_file(LEONIDA_TEST_CS_SET0_SAMPLE_SPV, library / "cs_set0_sample.spv", | 73 | std::filesystem::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_CS_SET0_SAMPLE_SPV), library / "cs_set0_sample.spv", |
| 73 | std::filesystem::copy_options::overwrite_existing); | 74 | std::filesystem::copy_options::overwrite_existing); |
| 74 | { | 75 | { |
| 75 | std::ofstream index(library / "index.json", std::ios::binary); | 76 | std::ofstream index(library / "index.json", std::ios::binary); |
diff --git a/runtime/test/d3d12_state_map_test.cpp b/runtime/test/d3d12_state_map_test.cpp index 77ef6222d..58a649437 100644 --- a/runtime/test/d3d12_state_map_test.cpp +++ b/runtime/test/d3d12_state_map_test.cpp | |||
| @@ -227,6 +227,48 @@ int main() { | |||
| 227 | CHECK(!(vulkan_access(s::predication, false).access & VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT)); | 227 | CHECK(!(vulkan_access(s::predication, false).access & VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT)); |
| 228 | CHECK(!(vulkan_access(s::copy_dest, false, true).stages & VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT)); | 228 | CHECK(!(vulkan_access(s::copy_dest, false, true).stages & VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT)); |
| 229 | 229 | ||
| 230 | // Primitive topology: a D3D12_PRIMITIVE_TOPOLOGY value maps to a VkPrimitiveTopology, and strip topologies are | ||
| 231 | // the ones a primitive-restart index cuts. A wrong map draws the wrong primitive; a wrong strip classification | ||
| 232 | // restarts (or fails to restart) an indexed strip. The D3D12 values are the public D3D_PRIMITIVE_TOPOLOGY enum. | ||
| 233 | { | ||
| 234 | using detail::strip_topology; | ||
| 235 | using detail::vulkan_topology; | ||
| 236 | #ifdef _WIN32 | ||
| 237 | static_assert(D3D_PRIMITIVE_TOPOLOGY_POINTLIST == 1 && D3D_PRIMITIVE_TOPOLOGY_LINELIST == 2 && | ||
| 238 | D3D_PRIMITIVE_TOPOLOGY_LINESTRIP == 3 && D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST == 4 && | ||
| 239 | D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP == 5 && D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ == 10 && | ||
| 240 | D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ == 11 && D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ == 12 && | ||
| 241 | D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ == 13, | ||
| 242 | "D3D_PRIMITIVE_TOPOLOGY values the topology map is keyed on"); | ||
| 243 | #endif | ||
| 244 | struct TopoCase { | ||
| 245 | std::uint32_t d3d; | ||
| 246 | VkPrimitiveTopology vk; | ||
| 247 | bool strip; | ||
| 248 | }; | ||
| 249 | static constexpr TopoCase topos[] = { | ||
| 250 | {1, VK_PRIMITIVE_TOPOLOGY_POINT_LIST, false}, // POINTLIST | ||
| 251 | {2, VK_PRIMITIVE_TOPOLOGY_LINE_LIST, false}, // LINELIST | ||
| 252 | {3, VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, true}, // LINESTRIP | ||
| 253 | {5, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, true}, // TRIANGLESTRIP | ||
| 254 | {10, VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY, false}, // LINELIST_ADJ | ||
| 255 | {11, VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY, true}, // LINESTRIP_ADJ | ||
| 256 | {12, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY, false}, // TRIANGLELIST_ADJ | ||
| 257 | {13, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY, true}, // TRIANGLESTRIP_ADJ | ||
| 258 | }; | ||
| 259 | for (const auto& t : topos) { | ||
| 260 | CHECK(vulkan_topology(t.d3d) == t.vk); | ||
| 261 | CHECK(strip_topology(t.vk) == t.strip); | ||
| 262 | } | ||
| 263 | // TRIANGLELIST (4), UNDEFINED (0) and any unmapped value fall back to the triangle list, which is not a strip. | ||
| 264 | CHECK(vulkan_topology(4) == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST); | ||
| 265 | CHECK(vulkan_topology(0) == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST); | ||
| 266 | CHECK(vulkan_topology(99) == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST); | ||
| 267 | CHECK(!strip_topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)); | ||
| 268 | CHECK(!strip_topology(VK_PRIMITIVE_TOPOLOGY_LINE_LIST)); | ||
| 269 | CHECK(!strip_topology(VK_PRIMITIVE_TOPOLOGY_POINT_LIST)); | ||
| 270 | } | ||
| 271 | |||
| 230 | // Subresource indices: mip + layer * mips + plane * mips * layers. | 272 | // Subresource indices: mip + layer * mips + plane * mips * layers. |
| 231 | VkImageSubresourceRange range{}; | 273 | VkImageSubresourceRange range{}; |
| 232 | ResourceBinding color{}; | 274 | ResourceBinding color{}; |
| @@ -274,6 +316,62 @@ int main() { | |||
| 274 | CHECK(detail::prepare_texture_copy(copy, upload) == ReplayResult::invalid_copy); | 316 | CHECK(detail::prepare_texture_copy(copy, upload) == ReplayResult::invalid_copy); |
| 275 | CHECK(upload.buffer_image_copies.size() == 1); | 317 | CHECK(upload.buffer_image_copies.size() == 1); |
| 276 | 318 | ||
| 319 | // Block-compressed texture to texture between mips of a 24x24 BC1 texture (mips 24, 12, 6, 3, 1). The host | ||
| 320 | // copies whole blocks; where one vkCmdCopyImage extent cannot reach the edge of both mips, the copy is described | ||
| 321 | // as a read into transfer scratch and a write from it (offsets from the scratch's start; prepare allocates it). | ||
| 322 | { | ||
| 323 | ResourceBinding bc1 = color; | ||
| 324 | bc1.format = VK_FORMAT_BC1_RGBA_UNORM_BLOCK; | ||
| 325 | bc1.width = bc1.height = 24; | ||
| 326 | bc1.depth = 1; | ||
| 327 | bc1.mip_levels = 5; | ||
| 328 | bc1.array_layers = 1; | ||
| 329 | const auto bc_copy = [&](std::uint32_t dst_mip, std::uint32_t x, std::uint32_t y, std::uint32_t src_mip, | ||
| 330 | bool has_box, CopyBox box, detail::Prepared& p) { | ||
| 331 | p = {}; | ||
| 332 | p.binding = p.source = bc1; | ||
| 333 | CopyTexture c{}; | ||
| 334 | c.dst = {1, false, dst_mip, 0, 0, 0, 0, 0}; | ||
| 335 | c.src = {1, false, src_mip, 0, 0, 0, 0, 0}; | ||
| 336 | c.x = x; | ||
| 337 | c.y = y; | ||
| 338 | c.has_box = has_box; | ||
| 339 | c.box = box; | ||
| 340 | return detail::prepare_texture_copy(c, p); | ||
| 341 | }; | ||
| 342 | const auto extent_is = [](const VkExtent3D& e, std::uint32_t w, std::uint32_t h) { | ||
| 343 | return e.width == w && e.height == h && e.depth == 1; | ||
| 344 | }; | ||
| 345 | const auto staged = [](const detail::Prepared& p) { | ||
| 346 | return p.image_copies.empty() && p.staged_reads.size() == 1 && p.staged_writes.size() == 1; | ||
| 347 | }; | ||
| 348 | detail::Prepared p{}; | ||
| 349 | // Both edges reachable with one extent: a direct copy, nothing staged. | ||
| 350 | CHECK(bc_copy(1, 0, 0, 0, true, {0, 0, 0, 12, 12, 1}, p) == ReplayResult::success); | ||
| 351 | CHECK(p.image_copies.size() == 1 && p.staged_reads.empty() && extent_is(p.image_copies[0].extent, 12, 12)); | ||
| 352 | // A 4x4 box into the 3x3 mip 3: one block read 4x4 from mip 0 and written 3x3. | ||
| 353 | CHECK(bc_copy(3, 0, 0, 0, true, {0, 0, 0, 4, 4, 1}, p) == ReplayResult::success && staged(p)); | ||
| 354 | CHECK(p.staged_reads[0].bufferRowLength == 4 && p.staged_reads[0].bufferImageHeight == 4); | ||
| 355 | CHECK(p.staged_reads[0].imageSubresource.mipLevel == 0 && extent_is(p.staged_reads[0].imageExtent, 4, 4)); | ||
| 356 | CHECK(p.staged_writes[0].imageSubresource.mipLevel == 3 && extent_is(p.staged_writes[0].imageExtent, 3, 3)); | ||
| 357 | CHECK(p.staged_writes[0].bufferOffset == 0 && p.staged_writes[0].bufferRowLength == 4); | ||
| 358 | // The 6x6 mip 2 into the 12x12 mip 1: 2x2 blocks, read to the 6x6 edge, written as 8x8. | ||
| 359 | CHECK(bc_copy(1, 0, 0, 2, false, {}, p) == ReplayResult::success && staged(p)); | ||
| 360 | CHECK(p.staged_reads[0].bufferRowLength == 8 && extent_is(p.staged_reads[0].imageExtent, 6, 6) && | ||
| 361 | extent_is(p.staged_writes[0].imageExtent, 8, 8)); | ||
| 362 | // The 3x3 mip 3 into the 6x6 mip 2 at 4,4: read 3x3, written 2x2 at (4, 4). | ||
| 363 | CHECK(bc_copy(2, 4, 4, 3, false, {}, p) == ReplayResult::success && staged(p)); | ||
| 364 | CHECK(extent_is(p.staged_reads[0].imageExtent, 3, 3) && extent_is(p.staged_writes[0].imageExtent, 2, 2)); | ||
| 365 | CHECK(p.staged_writes[0].imageOffset.x == 4 && p.staged_writes[0].imageOffset.y == 4); | ||
| 366 | // The box 4..8 of the 6x6 mip 2 (its edge inside the block) into the 3x3 mip 3: read 2x2 at (4, 4). | ||
| 367 | CHECK(bc_copy(3, 0, 0, 2, true, {4, 4, 0, 8, 8, 1}, p) == ReplayResult::success && staged(p)); | ||
| 368 | CHECK(p.staged_reads[0].imageOffset.x == 4 && extent_is(p.staged_reads[0].imageExtent, 2, 2) && | ||
| 369 | extent_is(p.staged_writes[0].imageExtent, 3, 3)); | ||
| 370 | // What does not fit the destination's padded mip is refused, staged or not. | ||
| 371 | CHECK(bc_copy(3, 0, 0, 0, true, {0, 0, 0, 16, 16, 1}, p) == ReplayResult::invalid_copy); | ||
| 372 | CHECK(bc_copy(0, 16, 16, 1, false, {}, p) == ReplayResult::invalid_copy); | ||
| 373 | } | ||
| 374 | |||
| 277 | ResourceBinding depth_stencil = color; | 375 | ResourceBinding depth_stencil = color; |
| 278 | depth_stencil.aspects = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; | 376 | depth_stencil.aspects = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 279 | depth_stencil.mip_levels = 2; | 377 | depth_stencil.mip_levels = 2; |
| @@ -584,6 +682,10 @@ int main() { | |||
| 584 | CHECK(memory_type_order(memory, 0xF, host, local, 224395264) == (order{3, 1, 2})); // exactly fits | 682 | CHECK(memory_type_order(memory, 0xF, host, local, 224395264) == (order{3, 1, 2})); // exactly fits |
| 585 | CHECK(memory_type_order(memory, 0x7, host, local, 128 * mib) == (order{1, 2})); // type 3 not allowed | 683 | CHECK(memory_type_order(memory, 0x7, host, local, 128 * mib) == (order{1, 2})); // type 3 not allowed |
| 586 | CHECK(memory_type_order(memory, 0xF, 0, local, 1 * mib) == (order{0, 3, 1, 2})); | 684 | CHECK(memory_type_order(memory, 0xF, 0, local, 1 * mib) == (order{0, 3, 1, 2})); |
| 685 | // D3D-299: types 1 and 2 lack DEVICE_LOCAL; when preferred local fails, allocations fall back to them (host spill). | ||
| 686 | const order spill_order = memory_type_order(memory, 0xF, 0, local, 1 * mib); | ||
| 687 | CHECK((memory.memoryTypes[spill_order[2]].propertyFlags & local) == 0); | ||
| 688 | CHECK((memory.memoryTypes[spill_order[3]].propertyFlags & local) == 0); | ||
| 587 | CHECK(memory_type_order(memory, 0xF, host, local, 64ull << 30).empty()); // nothing that large | 689 | CHECK(memory_type_order(memory, 0xF, host, local, 64ull << 30).empty()); // nothing that large |
| 588 | memory.memoryHeaps[2].size = 24ull << 30; // Resizable BAR on | 690 | memory.memoryHeaps[2].size = 24ull << 30; // Resizable BAR on |
| 589 | CHECK(memory_type_order(memory, 0xF, host, local, 256 * mib) == (order{3, 1, 2})); | 691 | CHECK(memory_type_order(memory, 0xF, host, local, 256 * mib) == (order{3, 1, 2})); |
| @@ -610,6 +712,24 @@ int main() { | |||
| 610 | {VK_FORMAT_R32_UINT, 4, 1}, {VK_FORMAT_R8G8_UNORM, 2, 1}, | 712 | {VK_FORMAT_R32_UINT, 4, 1}, {VK_FORMAT_R8G8_UNORM, 2, 1}, |
| 611 | {VK_FORMAT_R16_SFLOAT, 2, 1}, {VK_FORMAT_R16_UNORM, 2, 1}, | 713 | {VK_FORMAT_R16_SFLOAT, 2, 1}, {VK_FORMAT_R16_UNORM, 2, 1}, |
| 612 | {VK_FORMAT_R8_UNORM, 1, 1}, | 714 | {VK_FORMAT_R8_UNORM, 1, 1}, |
| 715 | // Integer and additional packed formats the DXGI map also produces: each SINT/SNORM/UINT variant is the | ||
| 716 | // size of its UNORM/SFLOAT sibling, and the PACK16/PACK32 formats are 2 and 4 bytes. | ||
| 717 | {VK_FORMAT_R32G32B32A32_SINT, 16, 1}, | ||
| 718 | {VK_FORMAT_R16G16B16A16_SNORM, 8, 1}, {VK_FORMAT_R16G16B16A16_UINT, 8, 1}, | ||
| 719 | {VK_FORMAT_R16G16B16A16_SINT, 8, 1}, {VK_FORMAT_R32G32_UINT, 8, 1}, | ||
| 720 | {VK_FORMAT_R32G32_SINT, 8, 1}, | ||
| 721 | {VK_FORMAT_A2B10G10R10_UINT_PACK32, 4, 1}, {VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, 4, 1}, | ||
| 722 | {VK_FORMAT_R8G8B8A8_SNORM, 4, 1}, {VK_FORMAT_R8G8B8A8_SINT, 4, 1}, | ||
| 723 | {VK_FORMAT_R16G16_UNORM, 4, 1}, {VK_FORMAT_R16G16_SNORM, 4, 1}, | ||
| 724 | {VK_FORMAT_R16G16_UINT, 4, 1}, {VK_FORMAT_R16G16_SINT, 4, 1}, | ||
| 725 | {VK_FORMAT_R32_SINT, 4, 1}, | ||
| 726 | {VK_FORMAT_R5G6B5_UNORM_PACK16, 2, 1}, {VK_FORMAT_A1R5G5B5_UNORM_PACK16, 2, 1}, | ||
| 727 | {VK_FORMAT_A4R4G4B4_UNORM_PACK16, 2, 1}, {VK_FORMAT_R4G4B4A4_UNORM_PACK16, 2, 1}, | ||
| 728 | {VK_FORMAT_R8G8_SNORM, 2, 1}, {VK_FORMAT_R8G8_UINT, 2, 1}, | ||
| 729 | {VK_FORMAT_R8G8_SINT, 2, 1}, {VK_FORMAT_R16_SNORM, 2, 1}, | ||
| 730 | {VK_FORMAT_R16_UINT, 2, 1}, {VK_FORMAT_R16_SINT, 2, 1}, | ||
| 731 | {VK_FORMAT_R8_SNORM, 1, 1}, {VK_FORMAT_R8_UINT, 1, 1}, | ||
| 732 | {VK_FORMAT_R8_SINT, 1, 1}, | ||
| 613 | // Block-compressed: one 4x4 block is 8 bytes (BC1, BC4) or 16 bytes (BC2, BC3, BC5, BC6H, BC7). | 733 | // Block-compressed: one 4x4 block is 8 bytes (BC1, BC4) or 16 bytes (BC2, BC3, BC5, BC6H, BC7). |
| 614 | {VK_FORMAT_BC1_RGBA_UNORM_BLOCK, 8, 4}, {VK_FORMAT_BC1_RGBA_SRGB_BLOCK, 8, 4}, | 734 | {VK_FORMAT_BC1_RGBA_UNORM_BLOCK, 8, 4}, {VK_FORMAT_BC1_RGBA_SRGB_BLOCK, 8, 4}, |
| 615 | {VK_FORMAT_BC4_UNORM_BLOCK, 8, 4}, {VK_FORMAT_BC4_SNORM_BLOCK, 8, 4}, | 735 | {VK_FORMAT_BC4_UNORM_BLOCK, 8, 4}, {VK_FORMAT_BC4_SNORM_BLOCK, 8, 4}, |
diff --git a/runtime/test/d3d12_subresource_copy_test.cpp b/runtime/test/d3d12_subresource_copy_test.cpp new file mode 100644 index 000000000..17b6e179e --- /dev/null +++ b/runtime/test/d3d12_subresource_copy_test.cpp | |||
| @@ -0,0 +1,366 @@ | |||
| 1 | // ID3D12Resource::WriteToSubresource / ReadFromSubresource on the Vulkan-backed device, compared with the host PC | ||
| 2 | // runtime. The same script runs on both devices: textures in CPU-visible custom heaps (write-back and | ||
| 3 | // write-combine), a volume, an array, BC1 blocks, a buffer, an upload-heap buffer, a default-heap texture and a | ||
| 4 | // multisampled one, with whole and boxed copies, pitches too small or zero, boxes outside or empty or cutting a | ||
| 5 | // block, subresources past the last, and null pointers. Every HRESULT is recorded, and every read records a hash of | ||
| 6 | // its whole destination buffer (so bytes written outside the region count too). The two records must be the same, | ||
| 7 | // step by step. A step the host runtime faults on is reported and not compared. No shaders or game data. Skips (77) | ||
| 8 | // without a Vulkan GPU; without a host D3D12 device only the layer's own record is printed. Set | ||
| 9 | // LEONIDA_D3D49_VERBOSE=1 to print every step. | ||
| 10 | #include "vk_test_device.h" | ||
| 11 | #include "../shims/d3d12_com.h" | ||
| 12 | |||
| 13 | #include <cstdint> | ||
| 14 | #include <cstdio> | ||
| 15 | #include <cstring> | ||
| 16 | #include <string> | ||
| 17 | #include <vector> | ||
| 18 | |||
| 19 | #define EXPECT(condition) do { \ | ||
| 20 | if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ | ||
| 21 | } while (0) | ||
| 22 | |||
| 23 | namespace { | ||
| 24 | |||
| 25 | template<class T> | ||
| 26 | struct Ref { | ||
| 27 | T* p = nullptr; | ||
| 28 | ~Ref() { reset(); } | ||
| 29 | void reset() { | ||
| 30 | if (p) p->Release(); | ||
| 31 | p = nullptr; | ||
| 32 | } | ||
| 33 | T* operator->() const { return p; } | ||
| 34 | }; | ||
| 35 | |||
| 36 | constexpr std::uint64_t kFaulted = 0xFA017EDull; // the call raised an exception | ||
| 37 | constexpr std::uint64_t kMissing = 0x5C1F1Dull; // the resource couldn't be created on this device | ||
| 38 | constexpr std::size_t kBytes = 4096; | ||
| 39 | |||
| 40 | struct Resources { | ||
| 41 | ID3D12Resource* tex = nullptr; // 8x8 RGBA8, 2 mips, custom heap write-back L0 | ||
| 42 | ID3D12Resource* vol = nullptr; // 4x4x4 RGBA8 volume, same heap | ||
| 43 | ID3D12Resource* arr = nullptr; // 4x4 RGBA8, 2 layers | ||
| 44 | ID3D12Resource* bc1 = nullptr; // 8x8 BC1 | ||
| 45 | ID3D12Resource* wc = nullptr; // 4x4 RGBA8, custom heap write-combine L0 | ||
| 46 | ID3D12Resource* buffer = nullptr; // 4096-byte buffer, custom heap write-back L0 | ||
| 47 | ID3D12Resource* upload = nullptr; // 4096-byte buffer, upload heap | ||
| 48 | ID3D12Resource* gpu = nullptr; // 4x4 RGBA8, default heap | ||
| 49 | ID3D12Resource* msaa = nullptr; // 4x4 RGBA8 render target, 4 samples, default heap | ||
| 50 | std::uint8_t src[kBytes]; | ||
| 51 | std::uint8_t dst[kBytes]; | ||
| 52 | }; | ||
| 53 | |||
| 54 | using Call = HRESULT (*)(Resources&); | ||
| 55 | |||
| 56 | struct Step { | ||
| 57 | const char* name; | ||
| 58 | ID3D12Resource* Resources::*resource; | ||
| 59 | Call call; | ||
| 60 | bool read; // also record a hash of r.dst | ||
| 61 | }; | ||
| 62 | |||
| 63 | HRESULT guarded(Call call, Resources* r) { | ||
| 64 | __try { | ||
| 65 | return call(*r); | ||
| 66 | } __except (EXCEPTION_EXECUTE_HANDLER) { | ||
| 67 | return HRESULT(kFaulted); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | D3D12_BOX box(UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back) { | ||
| 72 | return D3D12_BOX{left, top, front, right, bottom, back}; | ||
| 73 | } | ||
| 74 | |||
| 75 | HRESULT write(ID3D12Resource* t, UINT sub, const D3D12_BOX* b, Resources& r, UINT row, UINT depth) { | ||
| 76 | return t->WriteToSubresource(sub, b, r.src, row, depth); | ||
| 77 | } | ||
| 78 | HRESULT read(ID3D12Resource* t, UINT sub, const D3D12_BOX* b, Resources& r, UINT row, UINT depth) { | ||
| 79 | std::memset(r.dst, 0xcd, kBytes); | ||
| 80 | return t->ReadFromSubresource(r.dst, row, depth, sub, b); | ||
| 81 | } | ||
| 82 | |||
| 83 | #define W(res, sub, B, row, depth) [](Resources& r) -> HRESULT { const D3D12_BOX b = B; return write(r.res, sub, &b, r, row, depth); } | ||
| 84 | #define WN(res, sub, row, depth) [](Resources& r) -> HRESULT { return write(r.res, sub, nullptr, r, row, depth); } | ||
| 85 | #define R(res, sub, B, row, depth) [](Resources& r) -> HRESULT { const D3D12_BOX b = B; return read(r.res, sub, &b, r, row, depth); } | ||
| 86 | #define RN(res, sub, row, depth) [](Resources& r) -> HRESULT { return read(r.res, sub, nullptr, r, row, depth); } | ||
| 87 | |||
| 88 | const Step kSteps[] = { | ||
| 89 | // Before any Map: D3D12 asks for the subresource to be mapped (with a null pointer) first. | ||
| 90 | {"tex: write before Map", &Resources::tex, WN(tex, 0, 32, 0), false}, | ||
| 91 | {"tex: read before Map", &Resources::tex, RN(tex, 0, 32, 0), true}, | ||
| 92 | {"buffer: write before Map", &Resources::buffer, WN(buffer, 0, 64, 0), false}, | ||
| 93 | // Map(sub, nullptr) on every texture subresource the script uses comes next (in run()). | ||
| 94 | {"tex: write mip 0 whole", &Resources::tex, WN(tex, 0, 32, 0), false}, | ||
| 95 | {"tex: write mip 1 whole", &Resources::tex, WN(tex, 1, 16, 0), false}, | ||
| 96 | {"tex: write subresource 2 (past the last)", &Resources::tex, WN(tex, 2, 32, 0), false}, | ||
| 97 | {"tex: write subresource 0xffffffff", &Resources::tex, WN(tex, 0xffffffffu, 32, 0), false}, | ||
| 98 | {"tex: write a 5x4 box at a 100-byte pitch", &Resources::tex, W(tex, 0, box(2, 1, 0, 7, 5, 1), 100, 0), false}, | ||
| 99 | {"tex: write a box past the right edge", &Resources::tex, W(tex, 0, box(0, 0, 0, 9, 1, 1), 100, 0), false}, | ||
| 100 | {"tex: write a box past the bottom edge", &Resources::tex, W(tex, 0, box(0, 0, 0, 1, 9, 1), 100, 0), false}, | ||
| 101 | {"tex: write a box with back 2", &Resources::tex, W(tex, 0, box(0, 0, 0, 1, 1, 2), 100, 0), false}, | ||
| 102 | {"tex: write a box with front 1, back 2", &Resources::tex, W(tex, 0, box(0, 0, 1, 1, 1, 2), 100, 0), false}, | ||
| 103 | {"tex: write an empty box (left == right)", &Resources::tex, W(tex, 0, box(2, 2, 0, 2, 3, 1), 100, 0), false}, | ||
| 104 | {"tex: write an empty box (top == bottom)", &Resources::tex, W(tex, 0, box(2, 2, 0, 3, 2, 1), 100, 0), false}, | ||
| 105 | {"tex: write an empty box (front == back)", &Resources::tex, W(tex, 0, box(2, 2, 0, 3, 3, 0), 100, 0), false}, | ||
| 106 | {"tex: write an inverted box", &Resources::tex, W(tex, 0, box(5, 0, 0, 3, 1, 1), 100, 0), false}, | ||
| 107 | {"tex: write an inverted box starting past the right edge", &Resources::tex, | ||
| 108 | W(tex, 0, box(9, 0, 0, 3, 1, 1), 100, 0), false}, | ||
| 109 | {"tex: write an empty box at the right edge", &Resources::tex, W(tex, 0, box(8, 0, 0, 8, 1, 1), 100, 0), false}, | ||
| 110 | {"tex: write an empty box past the right edge", &Resources::tex, W(tex, 0, box(9, 0, 0, 9, 1, 1), 100, 0), false}, | ||
| 111 | {"tex: write an empty box past the bottom edge", &Resources::tex, W(tex, 0, box(0, 9, 0, 1, 9, 1), 100, 0), false}, | ||
| 112 | {"tex: write an empty box in subresource 2", &Resources::tex, W(tex, 2, box(0, 0, 0, 0, 1, 1), 100, 0), false}, | ||
| 113 | {"tex: read mip 0 after the empty and inverted boxes", &Resources::tex, RN(tex, 0, 32, 0), true}, | ||
| 114 | {"tex: write a box of mip 1 past its edge", &Resources::tex, W(tex, 1, box(0, 0, 0, 5, 1, 1), 100, 0), false}, | ||
| 115 | {"tex: write null data", &Resources::tex, [](Resources& r) -> HRESULT { | ||
| 116 | return r.tex->WriteToSubresource(0, nullptr, nullptr, 32, 0); | ||
| 117 | }, false}, | ||
| 118 | {"tex: write rows 16 apart (32-byte rows)", &Resources::tex, WN(tex, 0, 16, 0), false}, | ||
| 119 | {"tex: write rows 31 apart", &Resources::tex, WN(tex, 0, 31, 0), false}, | ||
| 120 | {"tex: write rows 0 apart", &Resources::tex, WN(tex, 0, 0, 0), false}, | ||
| 121 | {"tex: write one row, pitch 0", &Resources::tex, W(tex, 0, box(0, 3, 0, 8, 4, 1), 0, 0), false}, | ||
| 122 | {"tex: write one row, pitch 4", &Resources::tex, W(tex, 0, box(0, 3, 0, 8, 4, 1), 4, 0), false}, | ||
| 123 | {"tex: write one texel, pitch 0", &Resources::tex, W(tex, 0, box(7, 7, 0, 8, 8, 1), 0, 0), false}, | ||
| 124 | {"tex: write mip 0, depth pitch 1", &Resources::tex, WN(tex, 0, 32, 1), false}, | ||
| 125 | {"tex: write mip 0 at a 48-byte pitch", &Resources::tex, WN(tex, 0, 48, 0), false}, | ||
| 126 | {"tex: read null data", &Resources::tex, [](Resources& r) -> HRESULT { | ||
| 127 | return r.tex->ReadFromSubresource(nullptr, 32, 0, 0, nullptr); | ||
| 128 | }, false}, | ||
| 129 | {"tex: read subresource 2", &Resources::tex, RN(tex, 2, 32, 0), true}, | ||
| 130 | {"tex: read a box past the right edge", &Resources::tex, R(tex, 0, box(0, 0, 0, 9, 1, 1), 64, 0), true}, | ||
| 131 | {"tex: read an empty box", &Resources::tex, R(tex, 0, box(2, 2, 0, 2, 3, 1), 64, 0), true}, | ||
| 132 | {"tex: read rows 16 apart [overlap]", &Resources::tex, RN(tex, 0, 16, 0), true}, | ||
| 133 | {"tex: read rows 0 apart [overlap]", &Resources::tex, RN(tex, 0, 0, 0), true}, | ||
| 134 | {"tex: read mip 0 whole at a 40-byte pitch", &Resources::tex, RN(tex, 0, 40, 0), true}, | ||
| 135 | {"tex: read mip 1 whole", &Resources::tex, RN(tex, 1, 16, 0), true}, | ||
| 136 | {"tex: read a 2x3 box of mip 1", &Resources::tex, R(tex, 1, box(1, 1, 0, 3, 4, 1), 8, 0), true}, | ||
| 137 | {"tex: read one row, pitch 0", &Resources::tex, R(tex, 0, box(0, 5, 0, 8, 6, 1), 0, 0), true}, | ||
| 138 | |||
| 139 | {"vol: write whole, rows 16 and slices 64 apart", &Resources::vol, WN(vol, 0, 16, 64), false}, | ||
| 140 | {"vol: write a 3x4x3 box, rows 12 and slices 64 apart", &Resources::vol, | ||
| 141 | W(vol, 0, box(1, 0, 1, 4, 4, 4), 12, 64), false}, | ||
| 142 | {"vol: write slices 32 apart (64-byte slices)", &Resources::vol, WN(vol, 0, 16, 32), false}, | ||
| 143 | {"vol: write slices 0 apart", &Resources::vol, WN(vol, 0, 16, 0), false}, | ||
| 144 | {"vol: write one slice, depth pitch 0", &Resources::vol, W(vol, 0, box(0, 0, 2, 4, 4, 3), 16, 0), false}, | ||
| 145 | {"vol: write a box with back 5", &Resources::vol, W(vol, 0, box(0, 0, 0, 4, 4, 5), 16, 64), false}, | ||
| 146 | {"vol: read whole, rows 20 and slices 96 apart", &Resources::vol, RN(vol, 0, 20, 96), true}, | ||
| 147 | {"vol: read slices 0 apart [overlap]", &Resources::vol, RN(vol, 0, 16, 0), true}, | ||
| 148 | |||
| 149 | {"arr: write layer 1", &Resources::arr, WN(arr, 1, 16, 0), false}, | ||
| 150 | {"arr: write subresource 2 (past the last)", &Resources::arr, WN(arr, 2, 16, 0), false}, | ||
| 151 | {"arr: write layer 0 with back 2", &Resources::arr, W(arr, 0, box(0, 0, 0, 4, 4, 2), 16, 64), false}, | ||
| 152 | {"arr: read layer 1", &Resources::arr, RN(arr, 1, 16, 0), true}, | ||
| 153 | {"arr: read layer 0", &Resources::arr, RN(arr, 0, 16, 0), true}, | ||
| 154 | |||
| 155 | {"bc1: write whole (2x2 blocks, rows 16 apart)", &Resources::bc1, WN(bc1, 0, 16, 0), false}, | ||
| 156 | {"bc1: write the bottom-right block", &Resources::bc1, W(bc1, 0, box(4, 4, 0, 8, 8, 1), 8, 0), false}, | ||
| 157 | {"bc1: write a box starting inside a block", &Resources::bc1, W(bc1, 0, box(2, 0, 0, 8, 4, 1), 16, 0), false}, | ||
| 158 | {"bc1: write a box ending inside a block", &Resources::bc1, W(bc1, 0, box(0, 0, 0, 6, 4, 1), 16, 0), false}, | ||
| 159 | {"bc1: write a box ending inside a block row", &Resources::bc1, W(bc1, 0, box(0, 0, 0, 4, 2, 1), 16, 0), false}, | ||
| 160 | {"bc1: write an empty box inside a block", &Resources::bc1, W(bc1, 0, box(2, 0, 0, 2, 4, 1), 16, 0), false}, | ||
| 161 | {"bc1: write an inverted box cutting blocks", &Resources::bc1, W(bc1, 0, box(6, 0, 0, 2, 4, 1), 16, 0), false}, | ||
| 162 | {"bc1: read whole after the empty boxes", &Resources::bc1, RN(bc1, 0, 32, 0), true}, | ||
| 163 | {"bc1: write rows 8 apart (16-byte block rows)", &Resources::bc1, WN(bc1, 0, 8, 0), false}, | ||
| 164 | {"bc1: write a block row, pitch 0", &Resources::bc1, W(bc1, 0, box(0, 4, 0, 8, 8, 1), 0, 0), false}, | ||
| 165 | {"bc1: read whole, rows 32 apart", &Resources::bc1, RN(bc1, 0, 32, 0), true}, | ||
| 166 | |||
| 167 | {"wc: write whole", &Resources::wc, WN(wc, 0, 16, 0), false}, | ||
| 168 | {"wc: read whole", &Resources::wc, RN(wc, 0, 16, 0), true}, | ||
| 169 | |||
| 170 | {"buffer: write", &Resources::buffer, WN(buffer, 0, 64, 0), false}, | ||
| 171 | {"buffer: write a 16-byte box", &Resources::buffer, W(buffer, 0, box(0, 0, 0, 16, 1, 1), 16, 0), false}, | ||
| 172 | {"buffer: read", &Resources::buffer, RN(buffer, 0, 64, 0), true}, | ||
| 173 | {"upload: write", &Resources::upload, WN(upload, 0, 64, 0), false}, | ||
| 174 | {"upload: read", &Resources::upload, RN(upload, 0, 64, 0), true}, | ||
| 175 | |||
| 176 | {"gpu: write (default heap)", &Resources::gpu, WN(gpu, 0, 16, 0), false}, | ||
| 177 | {"gpu: read (default heap)", &Resources::gpu, RN(gpu, 0, 16, 0), true}, | ||
| 178 | {"msaa: write (4 samples)", &Resources::msaa, WN(msaa, 0, 16, 0), false}, | ||
| 179 | {"msaa: read (4 samples)", &Resources::msaa, RN(msaa, 0, 16, 0), true}, | ||
| 180 | }; | ||
| 181 | constexpr std::size_t kBeforeMap = 3; // the first steps run before Map | ||
| 182 | |||
| 183 | #undef W | ||
| 184 | #undef WN | ||
| 185 | #undef R | ||
| 186 | #undef RN | ||
| 187 | |||
| 188 | std::uint64_t fnv(const std::uint8_t* p, std::size_t n) { | ||
| 189 | std::uint64_t h = 1469598103934665603ull; | ||
| 190 | for (std::size_t i = 0; i < n; ++i) h = (h ^ p[i]) * 1099511628211ull; | ||
| 191 | return h; | ||
| 192 | } | ||
| 193 | |||
| 194 | D3D12_RESOURCE_DESC texture(UINT width, UINT height, UINT16 depth, UINT16 mips, DXGI_FORMAT format, | ||
| 195 | D3D12_RESOURCE_DIMENSION dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D) { | ||
| 196 | D3D12_RESOURCE_DESC d{}; | ||
| 197 | d.Dimension = dimension; | ||
| 198 | d.Width = width; | ||
| 199 | d.Height = height; | ||
| 200 | d.DepthOrArraySize = depth; | ||
| 201 | d.MipLevels = mips; | ||
| 202 | d.Format = format; | ||
| 203 | d.SampleDesc.Count = 1; | ||
| 204 | return d; | ||
| 205 | } | ||
| 206 | |||
| 207 | D3D12_RESOURCE_DESC buffer(UINT64 bytes) { | ||
| 208 | D3D12_RESOURCE_DESC d{}; | ||
| 209 | d.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; | ||
| 210 | d.Width = bytes; | ||
| 211 | d.Height = 1; | ||
| 212 | d.DepthOrArraySize = 1; | ||
| 213 | d.MipLevels = 1; | ||
| 214 | d.SampleDesc.Count = 1; | ||
| 215 | d.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; | ||
| 216 | return d; | ||
| 217 | } | ||
| 218 | |||
| 219 | struct Record { | ||
| 220 | std::vector<std::string> names; | ||
| 221 | std::vector<std::uint64_t> values; | ||
| 222 | void add(const std::string& name, std::uint64_t value) { | ||
| 223 | names.push_back(name); | ||
| 224 | values.push_back(value); | ||
| 225 | } | ||
| 226 | }; | ||
| 227 | |||
| 228 | // Creates the resources on `device`, runs the script and records it. A resource the device refuses is recorded | ||
| 229 | // as missing, and its steps too. | ||
| 230 | bool run(ID3D12Device* device, bool bc, Record& out) { | ||
| 231 | const D3D12_HEAP_PROPERTIES write_back{D3D12_HEAP_TYPE_CUSTOM, D3D12_CPU_PAGE_PROPERTY_WRITE_BACK, | ||
| 232 | D3D12_MEMORY_POOL_L0}; | ||
| 233 | const D3D12_HEAP_PROPERTIES write_combine{D3D12_HEAP_TYPE_CUSTOM, D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE, | ||
| 234 | D3D12_MEMORY_POOL_L0}; | ||
| 235 | const D3D12_HEAP_PROPERTIES upload{D3D12_HEAP_TYPE_UPLOAD}; | ||
| 236 | const D3D12_HEAP_PROPERTIES gpu{D3D12_HEAP_TYPE_DEFAULT}; | ||
| 237 | static Resources r; // too big for the stack frame __try lives next to | ||
| 238 | std::memset(&r, 0, sizeof(r)); | ||
| 239 | for (std::size_t i = 0; i < kBytes; ++i) r.src[i] = std::uint8_t(i * 7 + (i >> 8) * 13 + 1); | ||
| 240 | const auto create = [&](const char* what, const D3D12_HEAP_PROPERTIES& heap, const D3D12_RESOURCE_DESC& desc, | ||
| 241 | D3D12_RESOURCE_STATES state, ID3D12Resource*& to) { | ||
| 242 | const HRESULT hr = device->CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &desc, state, nullptr, | ||
| 243 | IID_PPV_ARGS(&to)); | ||
| 244 | out.add(std::string("create ") + what, std::uint64_t(std::uint32_t(hr))); | ||
| 245 | if (FAILED(hr)) to = nullptr; | ||
| 246 | }; | ||
| 247 | create("tex", write_back, texture(8, 8, 1, 2, DXGI_FORMAT_R8G8B8A8_UNORM), D3D12_RESOURCE_STATE_COMMON, r.tex); | ||
| 248 | create("vol", write_back, texture(4, 4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_DIMENSION_TEXTURE3D), | ||
| 249 | D3D12_RESOURCE_STATE_COMMON, r.vol); | ||
| 250 | create("arr", write_back, texture(4, 4, 2, 1, DXGI_FORMAT_R8G8B8A8_UNORM), D3D12_RESOURCE_STATE_COMMON, r.arr); | ||
| 251 | if (bc) create("bc1", write_back, texture(8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM), D3D12_RESOURCE_STATE_COMMON, r.bc1); | ||
| 252 | create("wc", write_combine, texture(4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM), D3D12_RESOURCE_STATE_COMMON, r.wc); | ||
| 253 | create("buffer", write_back, buffer(kBytes), D3D12_RESOURCE_STATE_COMMON, r.buffer); | ||
| 254 | create("upload", upload, buffer(kBytes), D3D12_RESOURCE_STATE_GENERIC_READ, r.upload); | ||
| 255 | create("gpu", gpu, texture(4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM), D3D12_RESOURCE_STATE_COMMON, r.gpu); | ||
| 256 | auto ms = texture(4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM); | ||
| 257 | ms.SampleDesc.Count = 4; | ||
| 258 | ms.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; | ||
| 259 | create("msaa", gpu, ms, D3D12_RESOURCE_STATE_RENDER_TARGET, r.msaa); | ||
| 260 | |||
| 261 | const auto step = [&](const Step& s) { | ||
| 262 | if (!(r.*s.resource)) { | ||
| 263 | out.add(s.name, kMissing); | ||
| 264 | if (s.read) out.add(std::string(s.name) + " (bytes)", kMissing); | ||
| 265 | return; | ||
| 266 | } | ||
| 267 | const HRESULT hr = guarded(s.call, &r); | ||
| 268 | out.add(s.name, std::uint64_t(std::uint32_t(hr))); | ||
| 269 | if (s.read) out.add(std::string(s.name) + " (bytes)", hr == HRESULT(kFaulted) ? kFaulted : fnv(r.dst, kBytes)); | ||
| 270 | }; | ||
| 271 | for (std::size_t i = 0; i < kBeforeMap; ++i) step(kSteps[i]); | ||
| 272 | // Map with a null pointer, as D3D12 asks before a CPU copy: every texture subresource in a CPU-visible heap. | ||
| 273 | const struct { ID3D12Resource* res; UINT subs; } maps[] = {{r.tex, 2}, {r.vol, 1}, {r.arr, 2}, {r.bc1, 1}, | ||
| 274 | {r.wc, 1}, {r.buffer, 1}, {r.upload, 1}}; | ||
| 275 | for (const auto& m : maps) | ||
| 276 | for (UINT s = 0; m.res && s < m.subs; ++s) out.add("Map", std::uint64_t(std::uint32_t(m.res->Map(s, nullptr, nullptr)))); | ||
| 277 | for (std::size_t i = kBeforeMap; i < sizeof(kSteps) / sizeof(kSteps[0]); ++i) step(kSteps[i]); | ||
| 278 | for (const auto& m : maps) | ||
| 279 | for (UINT s = 0; m.res && s < m.subs; ++s) m.res->Unmap(s, nullptr); | ||
| 280 | for (ID3D12Resource* res : {r.tex, r.vol, r.arr, r.bc1, r.wc, r.buffer, r.upload, r.gpu, r.msaa}) | ||
| 281 | if (res) res->Release(); | ||
| 282 | return true; | ||
| 283 | } | ||
| 284 | |||
| 285 | } // namespace | ||
| 286 | |||
| 287 | int main() { | ||
| 288 | vktest::Device d; | ||
| 289 | const auto device_status = d.initialize(); | ||
| 290 | if (device_status == vktest::DeviceStatus::unavailable) return 77; // no Vulkan GPU: ctest skips | ||
| 291 | if (device_status != vktest::DeviceStatus::ready) return 1; | ||
| 292 | const bool verbose = GetEnvironmentVariableA("LEONIDA_D3D49_VERBOSE", nullptr, 0) > 0; | ||
| 293 | |||
| 294 | const HMODULE d3d12 = LoadLibraryExA("d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); | ||
| 295 | const auto create_host = d3d12 ? reinterpret_cast<PFN_D3D12_CREATE_DEVICE>( | ||
| 296 | reinterpret_cast<void*>(GetProcAddress(d3d12, "D3D12CreateDevice"))) | ||
| 297 | : nullptr; | ||
| 298 | Ref<ID3D12Device> host; | ||
| 299 | Record theirs; | ||
| 300 | if (create_host && SUCCEEDED(create_host(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p)))) | ||
| 301 | EXPECT(run(host.p, d.bc, theirs)); | ||
| 302 | |||
| 303 | // Once per copy path: on the host with VK_EXT_host_image_copy where the GPU has it, and through a staging submit | ||
| 304 | // (a second D3D12 device on the same Vulkan device, told the extension is off). | ||
| 305 | for (const bool host_copy : {true, false}) { | ||
| 306 | const char* path = host_copy ? "host image copy" : "staging copy"; | ||
| 307 | if (host_copy && !d.host_image_copy) { | ||
| 308 | std::printf("CPU copies (%s): no VK_EXT_host_image_copy, skipped\n", path); | ||
| 309 | continue; | ||
| 310 | } | ||
| 311 | rt::d3d12::VulkanDeviceInfo info{}; | ||
| 312 | info.get_instance_proc = d.instance_proc; | ||
| 313 | info.instance = d.instance; | ||
| 314 | info.physical = d.physical; | ||
| 315 | info.device = d.device; | ||
| 316 | info.queue = d.queue; | ||
| 317 | info.queue_family = d.family; | ||
| 318 | info.texture_compression_bc = d.bc; | ||
| 319 | info.host_image_copy = host_copy; | ||
| 320 | Ref<ID3D12Device> device; | ||
| 321 | EXPECT(SUCCEEDED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&device.p)))); | ||
| 322 | Record ours; | ||
| 323 | EXPECT(run(device.p, d.bc, ours)); | ||
| 324 | if (!host.p) { | ||
| 325 | std::printf("CPU copies (%s): no host D3D12 device to compare with; %zu steps recorded, not compared\n", | ||
| 326 | path, ours.values.size()); | ||
| 327 | continue; | ||
| 328 | } | ||
| 329 | EXPECT(theirs.names == ours.names); | ||
| 330 | int mismatches = 0, skipped = 0; | ||
| 331 | const auto show = [&](std::size_t i, const char* note) { | ||
| 332 | std::printf("CPU copies (%s) %s: ours 0x%llx host 0x%llx%s\n", path, ours.names[i].c_str(), | ||
| 333 | static_cast<unsigned long long>(ours.values[i]), | ||
| 334 | static_cast<unsigned long long>(theirs.values[i]), note); | ||
| 335 | }; | ||
| 336 | for (std::size_t i = 0; i < ours.values.size(); ++i) { | ||
| 337 | if (theirs.values[i] == kFaulted) { // null data: the host faults | ||
| 338 | show(i, " (the host faults; not compared)"); | ||
| 339 | ++skipped; | ||
| 340 | continue; | ||
| 341 | } | ||
| 342 | // A default-heap texture: the host refuses CPU copies there, the layer makes them and logs it | ||
| 343 | // (docs/d3d12_vulkan.md), on purpose. | ||
| 344 | if (ours.names[i].find("(default heap)") != std::string::npos) { | ||
| 345 | show(i, " (the layer copies on purpose; not compared)"); | ||
| 346 | ++skipped; | ||
| 347 | continue; | ||
| 348 | } | ||
| 349 | // A read whose rows or slices overlap in the destination: which bytes win is the order the driver | ||
| 350 | // copies texels in (tiled on an RTX 3060, not row by row), so only its HRESULT is compared. | ||
| 351 | if (ours.names[i].find("[overlap] (bytes)") != std::string::npos) { | ||
| 352 | if (verbose) show(i, " (the driver's copy order; not compared)"); | ||
| 353 | ++skipped; | ||
| 354 | continue; | ||
| 355 | } | ||
| 356 | const bool same = ours.values[i] == theirs.values[i]; | ||
| 357 | if (verbose || !same) show(i, same ? "" : " MISMATCH"); | ||
| 358 | mismatches += !same; | ||
| 359 | } | ||
| 360 | std::printf("CPU copies (%s): %zu steps compared with the host (%d more not compared), %d mismatches\n", path, | ||
| 361 | ours.values.size() - skipped, skipped, mismatches); | ||
| 362 | EXPECT(mismatches == 0); | ||
| 363 | } | ||
| 364 | std::printf("d3d12_subresource_copy_test: OK\n"); | ||
| 365 | return 0; | ||
| 366 | } | ||
diff --git a/runtime/test/d3d12_vulkan_device_test.cpp b/runtime/test/d3d12_vulkan_device_test.cpp index 6b7a399bf..ad98eca7b 100644 --- a/runtime/test/d3d12_vulkan_device_test.cpp +++ b/runtime/test/d3d12_vulkan_device_test.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | // under VK_LAYER_KHRONOS_validation; any validation error fails the test. | 10 | // under VK_LAYER_KHRONOS_validation; any validation error fails the test. |
| 11 | #include "vk_test_device.h" | 11 | #include "vk_test_device.h" |
| 12 | #include "../shims/d3d12_com.h" | 12 | #include "../shims/d3d12_com.h" |
| 13 | #include "../shims/d3d12_feature_compat.h" | ||
| 13 | #include "../shims/d3d12_xs_device.h" | 14 | #include "../shims/d3d12_xs_device.h" |
| 14 | #include "d3d12_copy_compare.h" // D3D-46: copies compared with the host runtime | 15 | #include "d3d12_copy_compare.h" // D3D-46: copies compared with the host runtime |
| 15 | #include "d3d12_depth24_compare.h" // D24 clears compared with the host runtime | 16 | #include "d3d12_depth24_compare.h" // D24 clears compared with the host runtime |
| @@ -252,15 +253,15 @@ int cpu_copies(ID3D12Device* device, bool bc, const char* path) { | |||
| 252 | EXPECT(bc1->WriteToSubresource(0, &cut, blocks, 16, 0) == E_INVALIDARG); | 253 | EXPECT(bc1->WriteToSubresource(0, &cut, blocks, 16, 0) == E_INVALIDARG); |
| 253 | } | 254 | } |
| 254 | 255 | ||
| 255 | // Calls D3D12 rejects. | 256 | // Calls D3D12 rejects, and two it doesn't: an empty box copies nothing, and pitches aren't checked (the host's |
| 257 | // answers, d3d12_subresource_copy_test). | ||
| 256 | const D3D12_BOX outside{0, 0, 0, 9, 1, 1}, empty{2, 2, 0, 2, 3, 1}; | 258 | const D3D12_BOX outside{0, 0, 0, 9, 1, 1}, empty{2, 2, 0, 2, 3, 1}; |
| 257 | EXPECT(tex->WriteToSubresource(0, &outside, src.data(), 100, 0) == E_INVALIDARG); | 259 | EXPECT(tex->WriteToSubresource(0, &outside, src.data(), 100, 0) == E_INVALIDARG); |
| 258 | EXPECT(tex->WriteToSubresource(0, &empty, src.data(), 100, 0) == E_INVALIDARG); | 260 | EXPECT(tex->WriteToSubresource(0, &empty, src.data(), 100, 0) == S_OK); |
| 259 | EXPECT(tex->WriteToSubresource(2, nullptr, src.data(), 100, 0) == E_INVALIDARG); // 2 mips, 1 layer | 261 | EXPECT(tex->WriteToSubresource(2, nullptr, src.data(), 100, 0) == E_INVALIDARG); // 2 mips, 1 layer |
| 260 | EXPECT(tex->WriteToSubresource(0, nullptr, nullptr, 32, 0) == E_INVALIDARG); | 262 | EXPECT(tex->WriteToSubresource(0, nullptr, nullptr, 32, 0) == E_INVALIDARG); |
| 261 | EXPECT(tex->ReadFromSubresource(nullptr, 32, 0, 0, nullptr) == E_INVALIDARG); | 263 | EXPECT(tex->ReadFromSubresource(nullptr, 32, 0, 0, nullptr) == E_INVALIDARG); |
| 262 | EXPECT(tex->WriteToSubresource(0, nullptr, src.data(), 16, 0) == E_INVALIDARG); // 32-byte rows 16 apart | 264 | EXPECT(vol->WriteToSubresource(0, nullptr, src.data(), 16, 32) == S_OK); // 64-byte slices 32 apart |
| 263 | EXPECT(vol->WriteToSubresource(0, nullptr, src.data(), 16, 32) == E_INVALIDARG); // 64-byte slices 32 apart | ||
| 264 | EXPECT(buffer->WriteToSubresource(0, nullptr, src.data(), 16, 0) == E_INVALIDARG); | 265 | EXPECT(buffer->WriteToSubresource(0, nullptr, src.data(), 16, 0) == E_INVALIDARG); |
| 265 | 266 | ||
| 266 | // A default-heap texture: D3D12 wants a CPU-visible heap, but the copy still works (and is logged). | 267 | // A default-heap texture: D3D12 wants a CPU-visible heap, but the copy still works (and is logged). |
| @@ -2034,11 +2035,24 @@ int new_format_round_trips(ID3D12Device* device, const rt::d3d12::VulkanDeviceIn | |||
| 2034 | continue; | 2035 | continue; |
| 2035 | } | 2036 | } |
| 2036 | if (host.p) { | 2037 | if (host.p) { |
| 2037 | Ref<ID3D12Resource> native; | 2038 | // A host runtime older than the format has nothing to match: A4B4G4R4_UNORM is not in Windows 10's D3D12, |
| 2038 | if (FAILED(host->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &desc, | 2039 | // which reports no 2D texture support for it and refuses it. Compare only where the host itself says it |
| 2039 | D3D12_RESOURCE_STATE_COPY_DEST, nullptr, | 2040 | // has the format, so a host that reports it and still refuses the texture fails as before. |
| 2040 | IID_PPV_ARGS(&native.p)))) | 2041 | D3D12_FEATURE_DATA_FORMAT_SUPPORT host_support{format}; |
| 2041 | fail(format, "the host refuses a texture the layer creates"); | 2042 | const bool host_has_format = |
| 2043 | SUCCEEDED(host->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &host_support, | ||
| 2044 | sizeof(host_support))) && | ||
| 2045 | (host_support.Support1 & D3D12_FORMAT_SUPPORT1_TEXTURE2D); | ||
| 2046 | if (!host_has_format) { | ||
| 2047 | std::printf("new format %d: the host runtime has no such 2D texture (e.g. Windows 10), " | ||
| 2048 | "host comparison skipped\n", int(format)); | ||
| 2049 | } else { | ||
| 2050 | Ref<ID3D12Resource> native; | ||
| 2051 | if (FAILED(host->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &desc, | ||
| 2052 | D3D12_RESOURCE_STATE_COPY_DEST, nullptr, | ||
| 2053 | IID_PPV_ARGS(&native.p)))) | ||
| 2054 | fail(format, "the host refuses a texture the layer creates"); | ||
| 2055 | } | ||
| 2042 | } | 2056 | } |
| 2043 | D3D12_PLACED_SUBRESOURCE_FOOTPRINT placed{}; | 2057 | D3D12_PLACED_SUBRESOURCE_FOOTPRINT placed{}; |
| 2044 | UINT rows = 0; | 2058 | UINT rows = 0; |
| @@ -2241,8 +2255,8 @@ int compare_feature_options(ID3D12Device* ours, const rt::d3d12::VulkanDeviceInf | |||
| 2241 | D3D12_FEATURE_DATA_CROSS_NODE cross_node{}; | 2255 | D3D12_FEATURE_DATA_CROSS_NODE cross_node{}; |
| 2242 | D3D12_FEATURE_DATA_DISPLAYABLE displayable{}; | 2256 | D3D12_FEATURE_DATA_DISPLAYABLE displayable{}; |
| 2243 | D3D12_FEATURE_DATA_PREDICATION predication{}; | 2257 | D3D12_FEATURE_DATA_PREDICATION predication{}; |
| 2244 | D3D12_FEATURE_DATA_APPLICATION_SPECIFIC_DRIVER_STATE driver_state{}; | 2258 | rt::d3d12::compat::FeatureSupportFlag driver_state{}; |
| 2245 | D3D12_FEATURE_DATA_BYTECODE_BYPASS_HASH_SUPPORTED bypass_hash{}; | 2259 | rt::d3d12::compat::FeatureSupportFlag bypass_hash{}; |
| 2246 | D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_SUPPORT prot_support{}; | 2260 | D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_SUPPORT prot_support{}; |
| 2247 | D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPE_COUNT prot_count{}; | 2261 | D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPE_COUNT prot_count{}; |
| 2248 | D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPES prot_types{}; | 2262 | D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPES prot_types{}; |
| @@ -2254,9 +2268,12 @@ int compare_feature_options(ID3D12Device* ours, const rt::d3d12::VulkanDeviceInf | |||
| 2254 | query_ours(std::pair{"CROSS_NODE", D3D12_FEATURE_CROSS_NODE}, cross_node); | 2268 | query_ours(std::pair{"CROSS_NODE", D3D12_FEATURE_CROSS_NODE}, cross_node); |
| 2255 | query_ours(std::pair{"DISPLAYABLE", D3D12_FEATURE_DISPLAYABLE}, displayable); | 2269 | query_ours(std::pair{"DISPLAYABLE", D3D12_FEATURE_DISPLAYABLE}, displayable); |
| 2256 | query_ours(std::pair{"PREDICATION", D3D12_FEATURE_PREDICATION}, predication); | 2270 | query_ours(std::pair{"PREDICATION", D3D12_FEATURE_PREDICATION}, predication); |
| 2257 | query_ours(std::pair{"APPLICATION_SPECIFIC_DRIVER_STATE", D3D12_FEATURE_APPLICATION_SPECIFIC_DRIVER_STATE}, | 2271 | query_ours(std::pair{"APPLICATION_SPECIFIC_DRIVER_STATE", |
| 2272 | rt::d3d12::compat::kFeatureApplicationSpecificDriverState}, | ||
| 2258 | driver_state); | 2273 | driver_state); |
| 2259 | query_ours(std::pair{"BYTECODE_BYPASS_HASH_SUPPORTED", D3D12_FEATURE_BYTECODE_BYPASS_HASH_SUPPORTED}, bypass_hash); | 2274 | query_ours(std::pair{"BYTECODE_BYPASS_HASH_SUPPORTED", |
| 2275 | rt::d3d12::compat::kFeatureBytecodeBypassHashSupported}, | ||
| 2276 | bypass_hash); | ||
| 2260 | query_ours_input(std::pair{"PROTECTED_RESOURCE_SESSION_SUPPORT", D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_SUPPORT}, | 2277 | query_ours_input(std::pair{"PROTECTED_RESOURCE_SESSION_SUPPORT", D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_SUPPORT}, |
| 2261 | D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_SUPPORT{0, {}}, prot_support); | 2278 | D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_SUPPORT{0, {}}, prot_support); |
| 2262 | query_ours_input( | 2279 | query_ours_input( |
| @@ -2648,11 +2665,13 @@ int compare_feature_options(ID3D12Device* ours, const rt::d3d12::VulkanDeviceInf | |||
| 2648 | [&](const char* n, const auto& a, const auto& b) { | 2665 | [&](const char* n, const auto& a, const auto& b) { |
| 2649 | check_bool(n, "Supported", a.Supported, b.Supported); | 2666 | check_bool(n, "Supported", a.Supported, b.Supported); |
| 2650 | }); | 2667 | }); |
| 2651 | compare_host("APPLICATION_SPECIFIC_DRIVER_STATE", D3D12_FEATURE_APPLICATION_SPECIFIC_DRIVER_STATE, driver_state, | 2668 | compare_host("APPLICATION_SPECIFIC_DRIVER_STATE", rt::d3d12::compat::kFeatureApplicationSpecificDriverState, |
| 2669 | driver_state, | ||
| 2652 | [&](const char* n, const auto& a, const auto& b) { | 2670 | [&](const char* n, const auto& a, const auto& b) { |
| 2653 | check_bool(n, "Supported", a.Supported, b.Supported); | 2671 | check_bool(n, "Supported", a.Supported, b.Supported); |
| 2654 | }); | 2672 | }); |
| 2655 | compare_host("BYTECODE_BYPASS_HASH_SUPPORTED", D3D12_FEATURE_BYTECODE_BYPASS_HASH_SUPPORTED, bypass_hash, | 2673 | compare_host("BYTECODE_BYPASS_HASH_SUPPORTED", rt::d3d12::compat::kFeatureBytecodeBypassHashSupported, |
| 2674 | bypass_hash, | ||
| 2656 | [&](const char* n, const auto& a, const auto& b) { | 2675 | [&](const char* n, const auto& a, const auto& b) { |
| 2657 | check_bool(n, "Supported", a.Supported, b.Supported); | 2676 | check_bool(n, "Supported", a.Supported, b.Supported); |
| 2658 | }); | 2677 | }); |
| @@ -2781,6 +2800,56 @@ HRESULT command_queue(ID3D12Device* device, D3D12_COMMAND_QUEUE_DESC desc) { | |||
| 2781 | return released(device->CreateCommandQueue(&desc, __uuidof(ID3D12CommandQueue), &out), &out); | 2800 | return released(device->CreateCommandQueue(&desc, __uuidof(ID3D12CommandQueue), &out), &out); |
| 2782 | } | 2801 | } |
| 2783 | 2802 | ||
| 2803 | HRESULT query_heap(ID3D12Device* device, D3D12_QUERY_HEAP_TYPE type, UINT count, UINT node_mask = 0, | ||
| 2804 | bool output = true) { | ||
| 2805 | const D3D12_QUERY_HEAP_DESC desc{type, count, node_mask}; | ||
| 2806 | void* out = nullptr; | ||
| 2807 | return released(device->CreateQueryHeap(&desc, __uuidof(ID3D12QueryHeap), output ? &out : nullptr), &out); | ||
| 2808 | } | ||
| 2809 | |||
| 2810 | // A root signature blob from the host's own serializer (version 1.0): empty, or one root CBV at b0, or one table of | ||
| 2811 | // unbounded SRVs from t0. Empty when d3d12.dll has no serializer, and both devices then get the same refusal. | ||
| 2812 | std::vector<std::uint8_t> root_signature_blob(int parameters) { | ||
| 2813 | using Serialize = HRESULT(WINAPI*)(const D3D12_ROOT_SIGNATURE_DESC*, D3D_ROOT_SIGNATURE_VERSION, ID3DBlob**, | ||
| 2814 | ID3DBlob**); | ||
| 2815 | static const auto serialize = reinterpret_cast<Serialize>(reinterpret_cast<void*>(GetProcAddress( | ||
| 2816 | LoadLibraryExA("d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32), "D3D12SerializeRootSignature"))); | ||
| 2817 | D3D12_ROOT_PARAMETER parameter{}; | ||
| 2818 | parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; | ||
| 2819 | const D3D12_DESCRIPTOR_RANGE range{D3D12_DESCRIPTOR_RANGE_TYPE_SRV, UINT_MAX, 0, 0, | ||
| 2820 | D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND}; | ||
| 2821 | if (parameters == 1) { | ||
| 2822 | parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; | ||
| 2823 | } else if (parameters == 2) { | ||
| 2824 | parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; | ||
| 2825 | parameter.DescriptorTable = {1, &range}; | ||
| 2826 | } | ||
| 2827 | const D3D12_ROOT_SIGNATURE_DESC desc{parameters ? 1u : 0u, parameters ? ¶meter : nullptr, 0, nullptr, | ||
| 2828 | D3D12_ROOT_SIGNATURE_FLAG_NONE}; | ||
| 2829 | ID3DBlob* blob = nullptr; | ||
| 2830 | ID3DBlob* error = nullptr; | ||
| 2831 | std::vector<std::uint8_t> bytes; | ||
| 2832 | if (serialize && SUCCEEDED(serialize(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, &error)) && blob) { | ||
| 2833 | const auto* first = static_cast<const std::uint8_t*>(blob->GetBufferPointer()); | ||
| 2834 | bytes.assign(first, first + blob->GetBufferSize()); | ||
| 2835 | } | ||
| 2836 | if (blob) blob->Release(); | ||
| 2837 | if (error) error->Release(); | ||
| 2838 | return bytes; | ||
| 2839 | } | ||
| 2840 | |||
| 2841 | // CreateRootSignature with `blob`, passed as `size` bytes (the blob's own size when 0; the vector is padded with | ||
| 2842 | // zeros when `size` is larger). | ||
| 2843 | HRESULT root_signature(ID3D12Device* device, std::vector<std::uint8_t> blob, SIZE_T size = 0, UINT node_mask = 0, | ||
| 2844 | bool output = true, REFIID riid = __uuidof(ID3D12RootSignature)) { | ||
| 2845 | if (!size) size = blob.size(); | ||
| 2846 | if (blob.size() < size) blob.resize(size); | ||
| 2847 | void* out = nullptr; | ||
| 2848 | return released(device->CreateRootSignature(node_mask, blob.empty() ? nullptr : blob.data(), size, riid, | ||
| 2849 | output ? &out : nullptr), | ||
| 2850 | &out); | ||
| 2851 | } | ||
| 2852 | |||
| 2784 | // CreateCommandSignature without a root signature. Each argument is only its type; a CONSTANT one sets one value. | 2853 | // CreateCommandSignature without a root signature. Each argument is only its type; a CONSTANT one sets one value. |
| 2785 | HRESULT command_signature(ID3D12Device* device, UINT stride, std::initializer_list<D3D12_INDIRECT_ARGUMENT_TYPE> types, | 2854 | HRESULT command_signature(ID3D12Device* device, UINT stride, std::initializer_list<D3D12_INDIRECT_ARGUMENT_TYPE> types, |
| 2786 | UINT node_mask = 0) { | 2855 | UINT node_mask = 0) { |
| @@ -2796,6 +2865,14 @@ HRESULT command_signature(ID3D12Device* device, UINT stride, std::initializer_li | |||
| 2796 | return released(device->CreateCommandSignature(&desc, nullptr, __uuidof(ID3D12CommandSignature), &out), &out); | 2865 | return released(device->CreateCommandSignature(&desc, nullptr, __uuidof(ID3D12CommandSignature), &out), &out); |
| 2797 | } | 2866 | } |
| 2798 | 2867 | ||
| 2868 | // CheckFeatureSupport(FORMAT_SUPPORT) for `value`: the HRESULT, or Support1 when it succeeds (Support2 holds what the | ||
| 2869 | // GPU can do, such as TILED, which the layer doesn't offer, so it isn't compared). | ||
| 2870 | HRESULT format_support1(ID3D12Device* device, UINT value) { | ||
| 2871 | D3D12_FEATURE_DATA_FORMAT_SUPPORT support{static_cast<DXGI_FORMAT>(value)}; | ||
| 2872 | const HRESULT hr = device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &support, sizeof(support)); | ||
| 2873 | return SUCCEEDED(hr) ? static_cast<HRESULT>(support.Support1) : hr; | ||
| 2874 | } | ||
| 2875 | |||
| 2799 | HRESULT fence(ID3D12Device* device, D3D12_FENCE_FLAGS flags, REFIID riid = __uuidof(ID3D12Fence)) { | 2876 | HRESULT fence(ID3D12Device* device, D3D12_FENCE_FLAGS flags, REFIID riid = __uuidof(ID3D12Fence)) { |
| 2800 | void* out = nullptr; | 2877 | void* out = nullptr; |
| 2801 | return released(device->CreateFence(0, flags, riid, &out), &out); | 2878 | return released(device->CreateFence(0, flags, riid, &out), &out); |
| @@ -2817,6 +2894,49 @@ HRESULT heap_create(ID3D12Device* device, D3D12_HEAP_DESC desc) { | |||
| 2817 | return released(device->CreateHeap(&desc, __uuidof(ID3D12Heap), &out), &out); | 2894 | return released(device->CreateHeap(&desc, __uuidof(ID3D12Heap), &out), &out); |
| 2818 | } | 2895 | } |
| 2819 | 2896 | ||
| 2897 | // CreatePlacedResource in a fresh heap of `heap` made on the same device. A heap the device refuses makes the case | ||
| 2898 | // itself wrong, so it answers E_UNEXPECTED on either side. | ||
| 2899 | struct PlacedArgs { | ||
| 2900 | D3D12_HEAP_DESC heap = heap_desc_of(0, {D3D12_HEAP_TYPE_DEFAULT}, D3D12_HEAP_FLAG_NONE, 1024 * 1024); | ||
| 2901 | UINT64 offset = 0; | ||
| 2902 | D3D12_RESOURCE_STATES state = D3D12_RESOURCE_STATE_COMMON; | ||
| 2903 | const D3D12_CLEAR_VALUE* clear = nullptr; | ||
| 2904 | bool output = true; | ||
| 2905 | const IID* riid = &__uuidof(ID3D12Resource); | ||
| 2906 | }; | ||
| 2907 | |||
| 2908 | HRESULT placed(ID3D12Device* device, const D3D12_RESOURCE_DESC* desc, const PlacedArgs& args = {}) { | ||
| 2909 | ID3D12Heap* heap = nullptr; | ||
| 2910 | if (FAILED(device->CreateHeap(&args.heap, IID_PPV_ARGS(&heap)))) return E_UNEXPECTED; | ||
| 2911 | void* out = nullptr; | ||
| 2912 | const HRESULT hr = device->CreatePlacedResource(heap, args.offset, desc, args.state, args.clear, *args.riid, | ||
| 2913 | args.output ? &out : nullptr); | ||
| 2914 | released(hr, &out); | ||
| 2915 | heap->Release(); | ||
| 2916 | return hr; | ||
| 2917 | } | ||
| 2918 | |||
| 2919 | HRESULT placed(ID3D12Device* device, D3D12_RESOURCE_DESC desc, const PlacedArgs& args = {}) { | ||
| 2920 | return placed(device, &desc, args); | ||
| 2921 | } | ||
| 2922 | |||
| 2923 | HRESULT reserved(ID3D12Device* device, const D3D12_RESOURCE_DESC* desc, | ||
| 2924 | D3D12_RESOURCE_STATES state = D3D12_RESOURCE_STATE_COMMON, const D3D12_CLEAR_VALUE* clear = nullptr, | ||
| 2925 | bool output = true, REFIID riid = __uuidof(ID3D12Resource)) { | ||
| 2926 | void* out = nullptr; | ||
| 2927 | return released(device->CreateReservedResource(desc, state, clear, riid, output ? &out : nullptr), &out); | ||
| 2928 | } | ||
| 2929 | |||
| 2930 | HRESULT reserved(ID3D12Device* device, D3D12_RESOURCE_DESC desc, | ||
| 2931 | D3D12_RESOURCE_STATES state = D3D12_RESOURCE_STATE_COMMON, const D3D12_CLEAR_VALUE* clear = nullptr) { | ||
| 2932 | return reserved(device, &desc, state, clear); | ||
| 2933 | } | ||
| 2934 | |||
| 2935 | D3D12_RESOURCE_DESC tiled(D3D12_RESOURCE_DESC desc) { | ||
| 2936 | desc.Layout = D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; | ||
| 2937 | return desc; | ||
| 2938 | } | ||
| 2939 | |||
| 2820 | // Map on a fresh committed resource; `range` is the read range, or null. | 2940 | // Map on a fresh committed resource; `range` is the read range, or null. |
| 2821 | HRESULT map(ID3D12Device* device, D3D12_HEAP_PROPERTIES heap, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES state, | 2941 | HRESULT map(ID3D12Device* device, D3D12_HEAP_PROPERTIES heap, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES state, |
| 2822 | UINT subresource, const D3D12_RANGE* range, bool want_pointer = true) { | 2942 | UINT subresource, const D3D12_RANGE* range, bool want_pointer = true) { |
| @@ -2843,6 +2963,15 @@ HRESULT call_guarded(InvalidCase call, ID3D12Device* device) { | |||
| 2843 | } | 2963 | } |
| 2844 | } | 2964 | } |
| 2845 | 2965 | ||
| 2966 | // The host accepts a UAV buffer in RAYTRACING_ACCELERATION_STRUCTURE state only where OPTIONS5 reports ray tracing | ||
| 2967 | // (an RTX does, an integrated Radeon without DXR refuses it: @aguedou-34 on #2462). The layer accepts it where it | ||
| 2968 | // has acceleration structures: the standalone device (XDXR or KHR), not the device main builds without them. | ||
| 2969 | bool host_ray_tracing(ID3D12Device* host) { | ||
| 2970 | D3D12_FEATURE_DATA_D3D12_OPTIONS5 o5{}; | ||
| 2971 | return SUCCEEDED(host->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &o5, sizeof(o5))) && | ||
| 2972 | o5.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED; | ||
| 2973 | } | ||
| 2974 | |||
| 2846 | int compare_invalid_arguments(ID3D12Device* ours) { | 2975 | int compare_invalid_arguments(ID3D12Device* ours) { |
| 2847 | Ref<ID3D12Device> host; | 2976 | Ref<ID3D12Device> host; |
| 2848 | if (!create_host_device(host)) return -1; | 2977 | if (!create_host_device(host)) return -1; |
| @@ -2880,6 +3009,104 @@ int compare_invalid_arguments(ID3D12Device* ours) { | |||
| 2880 | D3D12_RESOURCE_STATE_COMMON, nullptr, | 3009 | D3D12_RESOURCE_STATE_COMMON, nullptr, |
| 2881 | __uuidof(ID3D12Fence), &out), &out); | 3010 | __uuidof(ID3D12Fence), &out), &out); |
| 2882 | }}, | 3011 | }}, |
| 3012 | // CreateCommittedResource: the initial state. A buffer takes any bits but the acceleration-structure state | ||
| 3013 | // without UAV access; a texture takes GENERIC_READ, one write state alone (RENDER_TARGET, UNORDERED_ACCESS, | ||
| 3014 | // DEPTH_WRITE with their flag), or a mix of read states (DEPTH_READ with ALLOW_DEPTH_STENCIL, the shader | ||
| 3015 | // resource states without DENY_SHADER_RESOURCE), and never a buffer-only or undefined bit. | ||
| 3016 | {"committed: plain texture in RENDER_TARGET state", [](ID3D12Device* d) { | ||
| 3017 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), D3D12_RESOURCE_STATE_RENDER_TARGET); | ||
| 3018 | }}, | ||
| 3019 | {"committed: render target in RENDER_TARGET state", [](ID3D12Device* d) { | ||
| 3020 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET), | ||
| 3021 | D3D12_RESOURCE_STATE_RENDER_TARGET); | ||
| 3022 | }}, | ||
| 3023 | {"committed: plain texture in UNORDERED_ACCESS state", [](ID3D12Device* d) { | ||
| 3024 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS); | ||
| 3025 | }}, | ||
| 3026 | {"committed: UAV texture in UNORDERED_ACCESS state", [](ID3D12Device* d) { | ||
| 3027 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS), | ||
| 3028 | D3D12_RESOURCE_STATE_UNORDERED_ACCESS); | ||
| 3029 | }}, | ||
| 3030 | {"committed: plain texture in DEPTH_WRITE state", [](ID3D12Device* d) { | ||
| 3031 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), D3D12_RESOURCE_STATE_DEPTH_WRITE); | ||
| 3032 | }}, | ||
| 3033 | {"committed: plain texture in DEPTH_READ state", [](ID3D12Device* d) { | ||
| 3034 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), D3D12_RESOURCE_STATE_DEPTH_READ); | ||
| 3035 | }}, | ||
| 3036 | {"committed: depth texture in DEPTH_READ | PIXEL_SHADER_RESOURCE state", [](ID3D12Device* d) { | ||
| 3037 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, | ||
| 3038 | texture_desc(16, 16, DXGI_FORMAT_D32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL), | ||
| 3039 | D3D12_RESOURCE_STATE_DEPTH_READ | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); | ||
| 3040 | }}, | ||
| 3041 | {"committed: depth texture in DEPTH_WRITE | DEPTH_READ state", [](ID3D12Device* d) { | ||
| 3042 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, | ||
| 3043 | texture_desc(16, 16, DXGI_FORMAT_D32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL), | ||
| 3044 | D3D12_RESOURCE_STATE_DEPTH_WRITE | D3D12_RESOURCE_STATE_DEPTH_READ); | ||
| 3045 | }}, | ||
| 3046 | {"committed: depth texture without shader resource in PIXEL_SHADER_RESOURCE state", [](ID3D12Device* d) { | ||
| 3047 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, | ||
| 3048 | texture_desc(16, 16, DXGI_FORMAT_D32_FLOAT, | ||
| 3049 | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | | ||
| 3050 | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE), | ||
| 3051 | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); | ||
| 3052 | }}, | ||
| 3053 | {"committed: depth texture without shader resource in GENERIC_READ state", [](ID3D12Device* d) { | ||
| 3054 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, | ||
| 3055 | texture_desc(16, 16, DXGI_FORMAT_D32_FLOAT, | ||
| 3056 | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | | ||
| 3057 | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE), | ||
| 3058 | D3D12_RESOURCE_STATE_GENERIC_READ); | ||
| 3059 | }}, | ||
| 3060 | {"committed: texture in GENERIC_READ state", [](ID3D12Device* d) { | ||
| 3061 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), D3D12_RESOURCE_STATE_GENERIC_READ); | ||
| 3062 | }}, | ||
| 3063 | {"committed: texture in GENERIC_READ | COPY_DEST state", [](ID3D12Device* d) { | ||
| 3064 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), | ||
| 3065 | D3D12_RESOURCE_STATE_GENERIC_READ | D3D12_RESOURCE_STATE_COPY_DEST); | ||
| 3066 | }}, | ||
| 3067 | {"committed: texture in COPY_DEST | PIXEL_SHADER_RESOURCE state", [](ID3D12Device* d) { | ||
| 3068 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), | ||
| 3069 | D3D12_RESOURCE_STATE_COPY_DEST | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); | ||
| 3070 | }}, | ||
| 3071 | {"committed: texture in the three shader-read and copy-source states", [](ID3D12Device* d) { | ||
| 3072 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), | ||
| 3073 | D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_COPY_SOURCE); | ||
| 3074 | }}, | ||
| 3075 | {"committed: render target in RENDER_TARGET | PIXEL_SHADER_RESOURCE state", [](ID3D12Device* d) { | ||
| 3076 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET), | ||
| 3077 | D3D12_RESOURCE_STATE_RENDER_TARGET | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); | ||
| 3078 | }}, | ||
| 3079 | {"committed: texture in VERTEX_AND_CONSTANT_BUFFER state", [](ID3D12Device* d) { | ||
| 3080 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER); | ||
| 3081 | }}, | ||
| 3082 | {"committed: texture in INDEX_BUFFER | PIXEL_SHADER_RESOURCE state", [](ID3D12Device* d) { | ||
| 3083 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), | ||
| 3084 | D3D12_RESOURCE_STATE_INDEX_BUFFER | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); | ||
| 3085 | }}, | ||
| 3086 | {"committed: texture in state 0x80000000", [](ID3D12Device* d) { | ||
| 3087 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), D3D12_RESOURCE_STATES(0x80000000u)); | ||
| 3088 | }}, | ||
| 3089 | {"committed: texture in RESOLVE_DEST state", [](ID3D12Device* d) { | ||
| 3090 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, rgba8(), D3D12_RESOURCE_STATE_RESOLVE_DEST); | ||
| 3091 | }}, | ||
| 3092 | {"committed: buffer in state 0x80000000", [](ID3D12Device* d) { | ||
| 3093 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, buffer_desc(256), D3D12_RESOURCE_STATES(0x80000000u)); | ||
| 3094 | }}, | ||
| 3095 | {"committed: buffer in RENDER_TARGET | UNORDERED_ACCESS state", [](ID3D12Device* d) { | ||
| 3096 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, buffer_desc(256), | ||
| 3097 | D3D12_RESOURCE_STATE_RENDER_TARGET | D3D12_RESOURCE_STATE_UNORDERED_ACCESS); | ||
| 3098 | }}, | ||
| 3099 | {"committed: buffer in RAYTRACING_ACCELERATION_STRUCTURE state", [](ID3D12Device* d) { | ||
| 3100 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, buffer_desc(256), | ||
| 3101 | D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE); | ||
| 3102 | }}, | ||
| 3103 | // This device has no acceleration structures and refuses it, as a host without ray tracing does. | ||
| 3104 | {"committed: UAV buffer in RAYTRACING_ACCELERATION_STRUCTURE state", [](ID3D12Device* d) { | ||
| 3105 | auto desc = buffer_desc(256); | ||
| 3106 | desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; | ||
| 3107 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, desc, | ||
| 3108 | D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE); | ||
| 3109 | }, [](ID3D12Device* host) { return !host_ray_tracing(host); }}, | ||
| 2883 | // CreateCommittedResource: buffer descriptions. | 3110 | // CreateCommittedResource: buffer descriptions. |
| 2884 | {"committed: buffer width 0", [](ID3D12Device* d) { | 3111 | {"committed: buffer width 0", [](ID3D12Device* d) { |
| 2885 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, buffer_desc(0)); | 3112 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, buffer_desc(0)); |
| @@ -3512,6 +3739,94 @@ int compare_invalid_arguments(ID3D12Device* ours) { | |||
| 3512 | }}, | 3739 | }}, |
| 3513 | {"command queue: compute", [](ID3D12Device* d) { return command_queue(d, {D3D12_COMMAND_LIST_TYPE_COMPUTE}); }}, | 3740 | {"command queue: compute", [](ID3D12Device* d) { return command_queue(d, {D3D12_COMMAND_LIST_TYPE_COMPUTE}); }}, |
| 3514 | {"command queue: copy", [](ID3D12Device* d) { return command_queue(d, {D3D12_COMMAND_LIST_TYPE_COPY}); }}, | 3741 | {"command queue: copy", [](ID3D12Device* d) { return command_queue(d, {D3D12_COMMAND_LIST_TYPE_COPY}); }}, |
| 3742 | // CreateQueryHeap: the description is checked first (types past PIPELINE_STATISTICS1 are refused), then a | ||
| 3743 | // null output is E_UNEXPECTED. Known types this layer has no path for (stream output, video decode, mesh | ||
| 3744 | // statistics) are E_NOTIMPL here and not compared. | ||
| 3745 | {"query heap: occlusion", [](ID3D12Device* d) { return query_heap(d, D3D12_QUERY_HEAP_TYPE_OCCLUSION, 4); }}, | ||
| 3746 | {"query heap: timestamps", [](ID3D12Device* d) { return query_heap(d, D3D12_QUERY_HEAP_TYPE_TIMESTAMP, 4); }}, | ||
| 3747 | {"query heap: no queries", [](ID3D12Device* d) { return query_heap(d, D3D12_QUERY_HEAP_TYPE_OCCLUSION, 0); }}, | ||
| 3748 | {"query heap: type 8", [](ID3D12Device* d) { return query_heap(d, D3D12_QUERY_HEAP_TYPE(8), 1); }}, | ||
| 3749 | {"query heap: type 99", [](ID3D12Device* d) { return query_heap(d, D3D12_QUERY_HEAP_TYPE(99), 1); }}, | ||
| 3750 | {"query heap: type -1", [](ID3D12Device* d) { return query_heap(d, D3D12_QUERY_HEAP_TYPE(-1), 1); }}, | ||
| 3751 | {"query heap: node mask 1", [](ID3D12Device* d) { | ||
| 3752 | return query_heap(d, D3D12_QUERY_HEAP_TYPE_OCCLUSION, 1, 1); | ||
| 3753 | }}, | ||
| 3754 | {"query heap: node mask 2", [](ID3D12Device* d) { | ||
| 3755 | return query_heap(d, D3D12_QUERY_HEAP_TYPE_OCCLUSION, 1, 2); | ||
| 3756 | }}, | ||
| 3757 | {"query heap: null output", [](ID3D12Device* d) { | ||
| 3758 | return query_heap(d, D3D12_QUERY_HEAP_TYPE_OCCLUSION, 4, 0, false); | ||
| 3759 | }}, | ||
| 3760 | {"query heap: null output, no queries", [](ID3D12Device* d) { | ||
| 3761 | return query_heap(d, D3D12_QUERY_HEAP_TYPE_OCCLUSION, 0, 0, false); | ||
| 3762 | }}, | ||
| 3763 | {"query heap: null output, type 99", [](ID3D12Device* d) { | ||
| 3764 | return query_heap(d, D3D12_QUERY_HEAP_TYPE(99), 1, 0, false); | ||
| 3765 | }}, | ||
| 3766 | {"query heap: null output, node mask 2", [](ID3D12Device* d) { | ||
| 3767 | return query_heap(d, D3D12_QUERY_HEAP_TYPE_OCCLUSION, 1, 2, false); | ||
| 3768 | }}, | ||
| 3769 | {"query heap: wrong interface", [](ID3D12Device* d) { | ||
| 3770 | const D3D12_QUERY_HEAP_DESC desc{D3D12_QUERY_HEAP_TYPE_OCCLUSION, 1, 0}; | ||
| 3771 | void* out = nullptr; | ||
| 3772 | return released(d->CreateQueryHeap(&desc, __uuidof(ID3D12Fence), &out), &out); | ||
| 3773 | }}, | ||
| 3774 | // CreateRootSignature: a null output is S_FALSE whatever the blob; otherwise node 0 only, and the blob's | ||
| 3775 | // DXBC size must be the size passed. | ||
| 3776 | {"root signature: empty", [](ID3D12Device* d) { return root_signature(d, root_signature_blob(0)); }}, | ||
| 3777 | {"root signature: root CBV", [](ID3D12Device* d) { return root_signature(d, root_signature_blob(1)); }}, | ||
| 3778 | {"root signature: unbounded SRV table", [](ID3D12Device* d) { | ||
| 3779 | return root_signature(d, root_signature_blob(2)); | ||
| 3780 | }}, | ||
| 3781 | {"root signature: size 0", [](ID3D12Device* d) { | ||
| 3782 | void* out = nullptr; | ||
| 3783 | const auto blob = root_signature_blob(0); | ||
| 3784 | return released(d->CreateRootSignature(0, blob.data(), 0, __uuidof(ID3D12RootSignature), &out), &out); | ||
| 3785 | }}, | ||
| 3786 | {"root signature: one byte short", [](ID3D12Device* d) { | ||
| 3787 | const auto blob = root_signature_blob(0); | ||
| 3788 | return root_signature(d, blob, blob.size() - 1); | ||
| 3789 | }}, | ||
| 3790 | {"root signature: 4 bytes over", [](ID3D12Device* d) { | ||
| 3791 | const auto blob = root_signature_blob(1); | ||
| 3792 | return root_signature(d, blob, blob.size() + 4); | ||
| 3793 | }}, | ||
| 3794 | {"root signature: 16 bytes over", [](ID3D12Device* d) { | ||
| 3795 | const auto blob = root_signature_blob(0); | ||
| 3796 | return root_signature(d, blob, blob.size() + 16); | ||
| 3797 | }}, | ||
| 3798 | {"root signature: 64 zero bytes", [](ID3D12Device* d) { | ||
| 3799 | return root_signature(d, std::vector<std::uint8_t>(64, 0)); | ||
| 3800 | }}, | ||
| 3801 | {"root signature: null blob", [](ID3D12Device* d) { | ||
| 3802 | void* out = nullptr; | ||
| 3803 | return released(d->CreateRootSignature(0, nullptr, 64, __uuidof(ID3D12RootSignature), &out), &out); | ||
| 3804 | }}, | ||
| 3805 | {"root signature: node mask 1", [](ID3D12Device* d) { | ||
| 3806 | return root_signature(d, root_signature_blob(0), 0, 1); | ||
| 3807 | }}, | ||
| 3808 | {"root signature: node mask 2", [](ID3D12Device* d) { | ||
| 3809 | return root_signature(d, root_signature_blob(0), 0, 2); | ||
| 3810 | }}, | ||
| 3811 | {"root signature: node mask 0x80000000", [](ID3D12Device* d) { | ||
| 3812 | return root_signature(d, root_signature_blob(0), 0, 0x80000000u); | ||
| 3813 | }}, | ||
| 3814 | {"root signature: wrong interface", [](ID3D12Device* d) { | ||
| 3815 | return root_signature(d, root_signature_blob(0), 0, 0, true, __uuidof(ID3D12Fence)); | ||
| 3816 | }}, | ||
| 3817 | {"root signature: null output", [](ID3D12Device* d) { | ||
| 3818 | return root_signature(d, root_signature_blob(1), 0, 0, false); | ||
| 3819 | }}, | ||
| 3820 | {"root signature: null output, 64 zero bytes", [](ID3D12Device* d) { | ||
| 3821 | return root_signature(d, std::vector<std::uint8_t>(64, 0), 0, 0, false); | ||
| 3822 | }}, | ||
| 3823 | {"root signature: null output, node mask 2", [](ID3D12Device* d) { | ||
| 3824 | return root_signature(d, root_signature_blob(0), 0, 2, false); | ||
| 3825 | }}, | ||
| 3826 | {"root signature: null output, 16 bytes over", [](ID3D12Device* d) { | ||
| 3827 | const auto blob = root_signature_blob(0); | ||
| 3828 | return root_signature(d, blob, blob.size() + 16, 0, false); | ||
| 3829 | }}, | ||
| 3515 | {"command queue: high priority", [](ID3D12Device* d) { | 3830 | {"command queue: high priority", [](ID3D12Device* d) { |
| 3516 | return command_queue(d, {D3D12_COMMAND_LIST_TYPE_DIRECT, D3D12_COMMAND_QUEUE_PRIORITY_HIGH}); | 3831 | return command_queue(d, {D3D12_COMMAND_LIST_TYPE_DIRECT, D3D12_COMMAND_QUEUE_PRIORITY_HIGH}); |
| 3517 | }}, | 3832 | }}, |
| @@ -3594,6 +3909,19 @@ int compare_invalid_arguments(ID3D12Device* ours) { | |||
| 3594 | return command_queue(d, {D3D12_COMMAND_LIST_TYPE_DIRECT, 0, D3D12_COMMAND_QUEUE_FLAG_NONE, 1}); | 3909 | return command_queue(d, {D3D12_COMMAND_LIST_TYPE_DIRECT, 0, D3D12_COMMAND_QUEUE_FLAG_NONE, 1}); |
| 3595 | }}, | 3910 | }}, |
| 3596 | // CreateFence. | 3911 | // CreateFence. |
| 3912 | // FORMAT_SUPPORT for values the runtime's format table has no entry for (E_FAIL), and for UNKNOWN (a buffer | ||
| 3913 | // format: Support1 is compared, not Support2). | ||
| 3914 | {"format support: UNKNOWN", [](ID3D12Device* d) { return format_support1(d, DXGI_FORMAT_UNKNOWN); }}, | ||
| 3915 | {"format support: 116, the first unused value", [](ID3D12Device* d) { return format_support1(d, 0x74u); }}, | ||
| 3916 | {"format support: 129", [](ID3D12Device* d) { return format_support1(d, 0x81u); }}, | ||
| 3917 | {"format support: 130, P208", [](ID3D12Device* d) { return format_support1(d, 0x82u); }}, | ||
| 3918 | {"format support: 131, V208", [](ID3D12Device* d) { return format_support1(d, 0x83u); }}, | ||
| 3919 | {"format support: 132, V408", [](ID3D12Device* d) { return format_support1(d, 0x84u); }}, | ||
| 3920 | {"format support: 133", [](ID3D12Device* d) { return format_support1(d, 0x85u); }}, | ||
| 3921 | {"format support: 188", [](ID3D12Device* d) { return format_support1(d, 0xbcu); }}, | ||
| 3922 | {"format support: 192, past A4B4G4R4", [](ID3D12Device* d) { return format_support1(d, 0xc0u); }}, | ||
| 3923 | {"format support: 1000", [](ID3D12Device* d) { return format_support1(d, 0x3e8u); }}, | ||
| 3924 | {"format support: -1", [](ID3D12Device* d) { return format_support1(d, 0xffffffffu); }}, | ||
| 3597 | {"fence: null output", [](ID3D12Device* d) { | 3925 | {"fence: null output", [](ID3D12Device* d) { |
| 3598 | return d->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), nullptr); | 3926 | return d->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), nullptr); |
| 3599 | }}, | 3927 | }}, |
| @@ -3782,6 +4110,446 @@ int compare_heap_neighbours(ID3D12Device* ours) { | |||
| 3782 | return mismatches; | 4110 | return mismatches; |
| 3783 | } | 4111 | } |
| 3784 | 4112 | ||
| 4113 | // CreatePlacedResource and CreateReservedResource answer their arguments as the host runtime does: the placement | ||
| 4114 | // (offset, alignment, room in the heap), the heap's type and DENY flags against the resource, the description and | ||
| 4115 | // initial state rules CreateCommittedResource shares, and the output and interface. Run on a device with the GPU | ||
| 4116 | // address arena (without it every heap is E_NOTIMPL). Returns the number of mismatches, or -1 without a host. | ||
| 4117 | int compare_placed_reserved(ID3D12Device* ours) { | ||
| 4118 | Ref<ID3D12Device> host; | ||
| 4119 | if (!create_host_device(host)) return -1; | ||
| 4120 | struct Case { | ||
| 4121 | const char* name; | ||
| 4122 | InvalidCase call; | ||
| 4123 | bool (*comparable)(ID3D12Device*) = nullptr; | ||
| 4124 | }; | ||
| 4125 | static const Case cases[] = { | ||
| 4126 | // The standalone device has acceleration structures (XDXR, or KHR with LEONIDA_RT_AS=khr) and accepts a UAV | ||
| 4127 | // buffer in their state, as a host with ray tracing does. | ||
| 4128 | {"committed (standalone): UAV buffer in RAYTRACING_ACCELERATION_STRUCTURE state", [](ID3D12Device* d) { | ||
| 4129 | auto desc = buffer_desc(256); | ||
| 4130 | desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; | ||
| 4131 | return committed(d, {D3D12_HEAP_TYPE_DEFAULT}, desc, | ||
| 4132 | D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE); | ||
| 4133 | }, host_ray_tracing}, | ||
| 4134 | {"placed: UAV buffer in RAYTRACING_ACCELERATION_STRUCTURE state", [](ID3D12Device* d) { | ||
| 4135 | PlacedArgs a; | ||
| 4136 | a.state = D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE; | ||
| 4137 | auto desc = buffer_desc(64 * 1024); | ||
| 4138 | desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; | ||
| 4139 | return placed(d, desc, a); | ||
| 4140 | }, host_ray_tracing}, | ||
| 4141 | // CreatePlacedResource: arguments. | ||
| 4142 | {"placed: buffer at 0", [](ID3D12Device* d) { return placed(d, buffer_desc(64 * 1024)); }}, | ||
| 4143 | {"placed: null description", [](ID3D12Device* d) { return placed(d, nullptr); }}, | ||
| 4144 | {"placed: null heap", [](ID3D12Device* d) { | ||
| 4145 | const D3D12_RESOURCE_DESC desc = buffer_desc(64 * 1024); | ||
| 4146 | void* out = nullptr; | ||
| 4147 | return released(d->CreatePlacedResource(nullptr, 0, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, | ||
| 4148 | __uuidof(ID3D12Resource), &out), &out); | ||
| 4149 | }}, | ||
| 4150 | {"placed: null output (capability check)", [](ID3D12Device* d) { | ||
| 4151 | PlacedArgs a; | ||
| 4152 | a.output = false; | ||
| 4153 | return placed(d, buffer_desc(64 * 1024), a); | ||
| 4154 | }}, | ||
| 4155 | {"placed: null output, offset 4096", [](ID3D12Device* d) { | ||
| 4156 | PlacedArgs a; | ||
| 4157 | a.output = false; | ||
| 4158 | a.offset = 4096; | ||
| 4159 | return placed(d, buffer_desc(64 * 1024), a); | ||
| 4160 | }}, | ||
| 4161 | {"placed: null output, buffer height 2", [](ID3D12Device* d) { | ||
| 4162 | auto desc = buffer_desc(256); | ||
| 4163 | desc.Height = 2; | ||
| 4164 | PlacedArgs a; | ||
| 4165 | a.output = false; | ||
| 4166 | return placed(d, desc, a); | ||
| 4167 | }}, | ||
| 4168 | {"placed: null output, texture past the heap's end", [](ID3D12Device* d) { | ||
| 4169 | PlacedArgs a; | ||
| 4170 | a.output = false; | ||
| 4171 | a.offset = 1024 * 1024 - 64 * 1024; | ||
| 4172 | return placed(d, texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), a); | ||
| 4173 | }}, | ||
| 4174 | {"placed: wrong interface", [](ID3D12Device* d) { | ||
| 4175 | PlacedArgs a; | ||
| 4176 | a.riid = &__uuidof(ID3D12Fence); | ||
| 4177 | return placed(d, buffer_desc(64 * 1024), a); | ||
| 4178 | }}, | ||
| 4179 | // CreatePlacedResource: where the resource goes. | ||
| 4180 | {"placed: buffer at 64 KiB", [](ID3D12Device* d) { | ||
| 4181 | PlacedArgs a; | ||
| 4182 | a.offset = 64 * 1024; | ||
| 4183 | return placed(d, buffer_desc(64 * 1024), a); | ||
| 4184 | }}, | ||
| 4185 | {"placed: buffer at 4096", [](ID3D12Device* d) { | ||
| 4186 | PlacedArgs a; | ||
| 4187 | a.offset = 4096; | ||
| 4188 | return placed(d, buffer_desc(256), a); | ||
| 4189 | }}, | ||
| 4190 | {"placed: buffer filling the heap", [](ID3D12Device* d) { return placed(d, buffer_desc(1024 * 1024)); }}, | ||
| 4191 | {"placed: buffer one byte larger than the heap", [](ID3D12Device* d) { | ||
| 4192 | return placed(d, buffer_desc(1024 * 1024 + 1)); | ||
| 4193 | }}, | ||
| 4194 | {"placed: buffer past the heap's end", [](ID3D12Device* d) { | ||
| 4195 | PlacedArgs a; | ||
| 4196 | a.offset = 1024 * 1024 - 64 * 1024; | ||
| 4197 | return placed(d, buffer_desc(128 * 1024), a); | ||
| 4198 | }}, | ||
| 4199 | {"placed: buffer at the heap's end", [](ID3D12Device* d) { | ||
| 4200 | PlacedArgs a; | ||
| 4201 | a.offset = 1024 * 1024; | ||
| 4202 | return placed(d, buffer_desc(256), a); | ||
| 4203 | }}, | ||
| 4204 | {"placed: small texture at 4096 (4 KiB alignment)", [](ID3D12Device* d) { | ||
| 4205 | auto desc = texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE); | ||
| 4206 | desc.Alignment = D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT; | ||
| 4207 | PlacedArgs a; | ||
| 4208 | a.offset = 4096; | ||
| 4209 | return placed(d, desc, a); | ||
| 4210 | }}, | ||
| 4211 | {"placed: texture at 4096 (default alignment)", [](ID3D12Device* d) { | ||
| 4212 | PlacedArgs a; | ||
| 4213 | a.offset = 4096; | ||
| 4214 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), a); | ||
| 4215 | }}, | ||
| 4216 | {"placed: texture at 64 KiB", [](ID3D12Device* d) { | ||
| 4217 | PlacedArgs a; | ||
| 4218 | a.offset = 64 * 1024; | ||
| 4219 | return placed(d, texture_desc(64, 64, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), a); | ||
| 4220 | }}, | ||
| 4221 | {"placed: texture larger than the heap", [](ID3D12Device* d) { | ||
| 4222 | return placed(d, texture_desc(1024, 1024, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)); | ||
| 4223 | }}, | ||
| 4224 | {"placed: texture past the heap's end", [](ID3D12Device* d) { | ||
| 4225 | PlacedArgs a; | ||
| 4226 | a.offset = 1024 * 1024 - 64 * 1024; | ||
| 4227 | return placed(d, texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), a); | ||
| 4228 | }}, | ||
| 4229 | {"placed: MSAA texture at 64 KiB (4 MiB alignment)", [](ID3D12Device* d) { | ||
| 4230 | auto desc = texture_desc(64, 64, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET); | ||
| 4231 | desc.SampleDesc.Count = 4; | ||
| 4232 | PlacedArgs a; | ||
| 4233 | a.heap = heap_desc_of(D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT, {D3D12_HEAP_TYPE_DEFAULT}, | ||
| 4234 | D3D12_HEAP_FLAG_NONE, 8 * 1024 * 1024); | ||
| 4235 | a.offset = 64 * 1024; | ||
| 4236 | return placed(d, desc, a); | ||
| 4237 | }}, | ||
| 4238 | {"placed: MSAA texture in a 64 KiB-aligned heap", [](ID3D12Device* d) { | ||
| 4239 | auto desc = texture_desc(64, 64, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET); | ||
| 4240 | desc.SampleDesc.Count = 4; | ||
| 4241 | return placed(d, desc); | ||
| 4242 | }}, | ||
| 4243 | // CreatePlacedResource: the heap's type and DENY flags against the resource. | ||
| 4244 | {"placed: buffer in an ALLOW_ONLY_NON_RT_DS_TEXTURES heap", [](ID3D12Device* d) { | ||
| 4245 | PlacedArgs a; | ||
| 4246 | a.heap.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES; | ||
| 4247 | return placed(d, buffer_desc(256), a); | ||
| 4248 | }}, | ||
| 4249 | {"placed: texture in an ALLOW_ONLY_BUFFERS heap", [](ID3D12Device* d) { | ||
| 4250 | PlacedArgs a; | ||
| 4251 | a.heap.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS; | ||
| 4252 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), a); | ||
| 4253 | }}, | ||
| 4254 | {"placed: render target in an ALLOW_ONLY_NON_RT_DS_TEXTURES heap", [](ID3D12Device* d) { | ||
| 4255 | PlacedArgs a; | ||
| 4256 | a.heap.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES; | ||
| 4257 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, | ||
| 4258 | D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET), a); | ||
| 4259 | }}, | ||
| 4260 | {"placed: plain texture in an ALLOW_ONLY_RT_DS_TEXTURES heap", [](ID3D12Device* d) { | ||
| 4261 | PlacedArgs a; | ||
| 4262 | a.heap.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; | ||
| 4263 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), a); | ||
| 4264 | }}, | ||
| 4265 | {"placed: render target in an ALLOW_ONLY_RT_DS_TEXTURES heap", [](ID3D12Device* d) { | ||
| 4266 | PlacedArgs a; | ||
| 4267 | a.heap.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; | ||
| 4268 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, | ||
| 4269 | D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET), a); | ||
| 4270 | }}, | ||
| 4271 | {"placed: texture in an upload heap", [](ID3D12Device* d) { | ||
| 4272 | PlacedArgs a; | ||
| 4273 | a.heap.Properties.Type = D3D12_HEAP_TYPE_UPLOAD; | ||
| 4274 | a.state = D3D12_RESOURCE_STATE_GENERIC_READ; | ||
| 4275 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), a); | ||
| 4276 | }}, | ||
| 4277 | // CreatePlacedResource: the description rules CreateCommittedResource has. | ||
| 4278 | {"placed: buffer width 0", [](ID3D12Device* d) { return placed(d, buffer_desc(0)); }}, | ||
| 4279 | {"placed: buffer height 2", [](ID3D12Device* d) { | ||
| 4280 | auto desc = buffer_desc(256); | ||
| 4281 | desc.Height = 2; | ||
| 4282 | return placed(d, desc); | ||
| 4283 | }}, | ||
| 4284 | {"placed: buffer with 2 mips", [](ID3D12Device* d) { | ||
| 4285 | auto desc = buffer_desc(256); | ||
| 4286 | desc.MipLevels = 2; | ||
| 4287 | return placed(d, desc); | ||
| 4288 | }}, | ||
| 4289 | {"placed: buffer with a format", [](ID3D12Device* d) { | ||
| 4290 | auto desc = buffer_desc(256); | ||
| 4291 | desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| 4292 | return placed(d, desc); | ||
| 4293 | }}, | ||
| 4294 | {"placed: buffer with layout UNKNOWN", [](ID3D12Device* d) { | ||
| 4295 | auto desc = buffer_desc(256); | ||
| 4296 | desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; | ||
| 4297 | return placed(d, desc); | ||
| 4298 | }}, | ||
| 4299 | {"placed: buffer with 4 KiB alignment", [](ID3D12Device* d) { | ||
| 4300 | auto desc = buffer_desc(256); | ||
| 4301 | desc.Alignment = D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT; | ||
| 4302 | return placed(d, desc); | ||
| 4303 | }}, | ||
| 4304 | {"placed: buffer with ALLOW_DEPTH_STENCIL", [](ID3D12Device* d) { | ||
| 4305 | auto desc = buffer_desc(256); | ||
| 4306 | desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; | ||
| 4307 | return placed(d, desc); | ||
| 4308 | }}, | ||
| 4309 | {"placed: texture width 0", [](ID3D12Device* d) { | ||
| 4310 | return placed(d, texture_desc(0, 16, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)); | ||
| 4311 | }}, | ||
| 4312 | {"placed: texture with format UNKNOWN", [](ID3D12Device* d) { | ||
| 4313 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_UNKNOWN, D3D12_RESOURCE_FLAG_NONE)); | ||
| 4314 | }}, | ||
| 4315 | {"placed: texture with layout ROW_MAJOR", [](ID3D12Device* d) { | ||
| 4316 | auto desc = texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE); | ||
| 4317 | desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; | ||
| 4318 | return placed(d, desc); | ||
| 4319 | }}, | ||
| 4320 | {"placed: depth texture with ALLOW_UNORDERED_ACCESS", [](ID3D12Device* d) { | ||
| 4321 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_D32_FLOAT, | ||
| 4322 | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | | ||
| 4323 | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)); | ||
| 4324 | }}, | ||
| 4325 | // CreatePlacedResource: the initial state and the clear value. | ||
| 4326 | {"placed: upload buffer in GENERIC_READ", [](ID3D12Device* d) { | ||
| 4327 | PlacedArgs a; | ||
| 4328 | a.heap.Properties.Type = D3D12_HEAP_TYPE_UPLOAD; | ||
| 4329 | a.state = D3D12_RESOURCE_STATE_GENERIC_READ; | ||
| 4330 | return placed(d, buffer_desc(256), a); | ||
| 4331 | }}, | ||
| 4332 | {"placed: upload buffer in COPY_DEST", [](ID3D12Device* d) { | ||
| 4333 | PlacedArgs a; | ||
| 4334 | a.heap.Properties.Type = D3D12_HEAP_TYPE_UPLOAD; | ||
| 4335 | a.state = D3D12_RESOURCE_STATE_COPY_DEST; | ||
| 4336 | return placed(d, buffer_desc(256), a); | ||
| 4337 | }}, | ||
| 4338 | {"placed: upload buffer with ALLOW_UNORDERED_ACCESS", [](ID3D12Device* d) { | ||
| 4339 | auto desc = buffer_desc(256); | ||
| 4340 | desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; | ||
| 4341 | PlacedArgs a; | ||
| 4342 | a.heap.Properties.Type = D3D12_HEAP_TYPE_UPLOAD; | ||
| 4343 | a.state = D3D12_RESOURCE_STATE_GENERIC_READ; | ||
| 4344 | return placed(d, desc, a); | ||
| 4345 | }}, | ||
| 4346 | {"placed: readback buffer in COPY_DEST", [](ID3D12Device* d) { | ||
| 4347 | PlacedArgs a; | ||
| 4348 | a.heap.Properties.Type = D3D12_HEAP_TYPE_READBACK; | ||
| 4349 | a.state = D3D12_RESOURCE_STATE_COPY_DEST; | ||
| 4350 | return placed(d, buffer_desc(256), a); | ||
| 4351 | }}, | ||
| 4352 | {"placed: readback buffer in GENERIC_READ", [](ID3D12Device* d) { | ||
| 4353 | PlacedArgs a; | ||
| 4354 | a.heap.Properties.Type = D3D12_HEAP_TYPE_READBACK; | ||
| 4355 | a.state = D3D12_RESOURCE_STATE_GENERIC_READ; | ||
| 4356 | return placed(d, buffer_desc(256), a); | ||
| 4357 | }}, | ||
| 4358 | {"placed: default buffer in state 0x80000000", [](ID3D12Device* d) { | ||
| 4359 | PlacedArgs a; | ||
| 4360 | a.state = D3D12_RESOURCE_STATES(0x80000000u); | ||
| 4361 | return placed(d, buffer_desc(256), a); | ||
| 4362 | }}, | ||
| 4363 | {"placed: depth texture in DEPTH_WRITE", [](ID3D12Device* d) { | ||
| 4364 | PlacedArgs a; | ||
| 4365 | a.state = D3D12_RESOURCE_STATE_DEPTH_WRITE; | ||
| 4366 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_D32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL), | ||
| 4367 | a); | ||
| 4368 | }}, | ||
| 4369 | {"placed: plain texture in UNORDERED_ACCESS", [](ID3D12Device* d) { | ||
| 4370 | PlacedArgs a; | ||
| 4371 | a.state = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; | ||
| 4372 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), a); | ||
| 4373 | }}, | ||
| 4374 | {"placed: render target in RENDER_TARGET", [](ID3D12Device* d) { | ||
| 4375 | PlacedArgs a; | ||
| 4376 | a.state = D3D12_RESOURCE_STATE_RENDER_TARGET; | ||
| 4377 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, | ||
| 4378 | D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET), a); | ||
| 4379 | }}, | ||
| 4380 | {"placed: plain texture in RENDER_TARGET", [](ID3D12Device* d) { | ||
| 4381 | PlacedArgs a; | ||
| 4382 | a.state = D3D12_RESOURCE_STATE_RENDER_TARGET; | ||
| 4383 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), a); | ||
| 4384 | }}, | ||
| 4385 | {"placed: render target with a clear value", [](ID3D12Device* d) { | ||
| 4386 | static const D3D12_CLEAR_VALUE clear{DXGI_FORMAT_R8G8B8A8_UNORM, {0.f, 0.f, 0.f, 1.f}}; | ||
| 4387 | PlacedArgs a; | ||
| 4388 | a.clear = &clear; | ||
| 4389 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, | ||
| 4390 | D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET), a); | ||
| 4391 | }}, | ||
| 4392 | {"placed: plain texture with a clear value", [](ID3D12Device* d) { | ||
| 4393 | static const D3D12_CLEAR_VALUE clear{DXGI_FORMAT_R8G8B8A8_UNORM, {0.f, 0.f, 0.f, 1.f}}; | ||
| 4394 | PlacedArgs a; | ||
| 4395 | a.clear = &clear; | ||
| 4396 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), a); | ||
| 4397 | }}, | ||
| 4398 | {"placed: buffer with a clear value", [](ID3D12Device* d) { | ||
| 4399 | static const D3D12_CLEAR_VALUE clear{DXGI_FORMAT_R8G8B8A8_UNORM, {0.f, 0.f, 0.f, 1.f}}; | ||
| 4400 | PlacedArgs a; | ||
| 4401 | a.clear = &clear; | ||
| 4402 | return placed(d, buffer_desc(256), a); | ||
| 4403 | }}, | ||
| 4404 | {"placed: render target, clear value of another format", [](ID3D12Device* d) { | ||
| 4405 | static const D3D12_CLEAR_VALUE clear{DXGI_FORMAT_R16G16B16A16_FLOAT, {0.f, 0.f, 0.f, 1.f}}; | ||
| 4406 | PlacedArgs a; | ||
| 4407 | a.clear = &clear; | ||
| 4408 | return placed(d, texture_desc(16, 16, DXGI_FORMAT_R8G8B8A8_UNORM, | ||
| 4409 | D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET), a); | ||
| 4410 | }}, | ||
| 4411 | // CreateReservedResource. | ||
| 4412 | {"reserved: buffer", [](ID3D12Device* d) { return reserved(d, buffer_desc(64 * 1024)); }}, | ||
| 4413 | {"reserved: null description", [](ID3D12Device* d) { return reserved(d, nullptr); }}, | ||
| 4414 | {"reserved: null output (capability check)", [](ID3D12Device* d) { | ||
| 4415 | const auto desc = buffer_desc(64 * 1024); | ||
| 4416 | return reserved(d, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, false); | ||
| 4417 | }}, | ||
| 4418 | {"reserved: null output, buffer height 2", [](ID3D12Device* d) { | ||
| 4419 | auto desc = buffer_desc(64 * 1024); | ||
| 4420 | desc.Height = 2; | ||
| 4421 | return reserved(d, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, false); | ||
| 4422 | }}, | ||
| 4423 | {"reserved: null output, plain texture in RENDER_TARGET", [](ID3D12Device* d) { | ||
| 4424 | const auto desc = | ||
| 4425 | tiled(texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)); | ||
| 4426 | return reserved(d, &desc, D3D12_RESOURCE_STATE_RENDER_TARGET, nullptr, false); | ||
| 4427 | }}, | ||
| 4428 | {"reserved: wrong interface", [](ID3D12Device* d) { | ||
| 4429 | const auto desc = buffer_desc(64 * 1024); | ||
| 4430 | return reserved(d, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, true, __uuidof(ID3D12Fence)); | ||
| 4431 | }}, | ||
| 4432 | {"reserved: buffer with layout UNKNOWN", [](ID3D12Device* d) { | ||
| 4433 | auto desc = buffer_desc(64 * 1024); | ||
| 4434 | desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; | ||
| 4435 | return reserved(d, desc); | ||
| 4436 | }}, | ||
| 4437 | {"reserved: buffer width 0", [](ID3D12Device* d) { return reserved(d, buffer_desc(0)); }}, | ||
| 4438 | {"reserved: buffer height 2", [](ID3D12Device* d) { | ||
| 4439 | auto desc = buffer_desc(64 * 1024); | ||
| 4440 | desc.Height = 2; | ||
| 4441 | return reserved(d, desc); | ||
| 4442 | }}, | ||
| 4443 | {"reserved: buffer with a format", [](ID3D12Device* d) { | ||
| 4444 | auto desc = buffer_desc(64 * 1024); | ||
| 4445 | desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| 4446 | return reserved(d, desc); | ||
| 4447 | }}, | ||
| 4448 | {"reserved: buffer with 4 KiB alignment", [](ID3D12Device* d) { | ||
| 4449 | auto desc = buffer_desc(64 * 1024); | ||
| 4450 | desc.Alignment = D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT; | ||
| 4451 | return reserved(d, desc); | ||
| 4452 | }}, | ||
| 4453 | {"reserved: buffer in COPY_DEST", [](ID3D12Device* d) { | ||
| 4454 | return reserved(d, buffer_desc(64 * 1024), D3D12_RESOURCE_STATE_COPY_DEST); | ||
| 4455 | }}, | ||
| 4456 | {"reserved: buffer in state 0x80000000", [](ID3D12Device* d) { | ||
| 4457 | return reserved(d, buffer_desc(64 * 1024), D3D12_RESOURCE_STATES(0x80000000u)); | ||
| 4458 | }}, | ||
| 4459 | {"reserved: texture", [](ID3D12Device* d) { | ||
| 4460 | return reserved(d, tiled(texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE))); | ||
| 4461 | }}, | ||
| 4462 | {"reserved: texture with layout UNKNOWN", [](ID3D12Device* d) { | ||
| 4463 | return reserved(d, texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)); | ||
| 4464 | }}, | ||
| 4465 | {"reserved: texture with layout ROW_MAJOR", [](ID3D12Device* d) { | ||
| 4466 | auto desc = texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE); | ||
| 4467 | desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; | ||
| 4468 | return reserved(d, desc); | ||
| 4469 | }}, | ||
| 4470 | {"reserved: texture with 64KB_STANDARD_SWIZZLE", [](ID3D12Device* d) { | ||
| 4471 | auto desc = texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE); | ||
| 4472 | desc.Layout = D3D12_TEXTURE_LAYOUT_64KB_STANDARD_SWIZZLE; | ||
| 4473 | return reserved(d, desc); | ||
| 4474 | }}, | ||
| 4475 | {"reserved: texture width 0", [](ID3D12Device* d) { | ||
| 4476 | return reserved(d, tiled(texture_desc(0, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE))); | ||
| 4477 | }}, | ||
| 4478 | {"reserved: full mip chain", [](ID3D12Device* d) { | ||
| 4479 | return reserved(d, tiled(texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE, | ||
| 4480 | 0))); | ||
| 4481 | }}, | ||
| 4482 | {"reserved: BC1 texture", [](ID3D12Device* d) { | ||
| 4483 | return reserved(d, tiled(texture_desc(256, 256, DXGI_FORMAT_BC1_UNORM, D3D12_RESOURCE_FLAG_NONE))); | ||
| 4484 | }}, | ||
| 4485 | {"reserved: 1D texture", [](ID3D12Device* d) { | ||
| 4486 | auto desc = tiled(texture_desc(256, 1, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)); | ||
| 4487 | desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE1D; | ||
| 4488 | return reserved(d, desc); | ||
| 4489 | }}, | ||
| 4490 | {"reserved: D24S8 depth texture", [](ID3D12Device* d) { | ||
| 4491 | return reserved(d, tiled(texture_desc(256, 256, DXGI_FORMAT_D24_UNORM_S8_UINT, | ||
| 4492 | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL))); | ||
| 4493 | }}, | ||
| 4494 | {"reserved: D32 depth texture", [](ID3D12Device* d) { | ||
| 4495 | return reserved(d, tiled(texture_desc(256, 256, DXGI_FORMAT_D32_FLOAT, | ||
| 4496 | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL))); | ||
| 4497 | }}, | ||
| 4498 | {"reserved: R32G32B32 texture", [](ID3D12Device* d) { | ||
| 4499 | return reserved(d, tiled(texture_desc(256, 256, DXGI_FORMAT_R32G32B32_FLOAT, D3D12_RESOURCE_FLAG_NONE))); | ||
| 4500 | }}, | ||
| 4501 | {"reserved: texture with ALLOW_SIMULTANEOUS_ACCESS", [](ID3D12Device* d) { | ||
| 4502 | return reserved(d, tiled(texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, | ||
| 4503 | D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS))); | ||
| 4504 | }}, | ||
| 4505 | {"reserved: render target with a clear value", [](ID3D12Device* d) { | ||
| 4506 | static const D3D12_CLEAR_VALUE clear{DXGI_FORMAT_R8G8B8A8_UNORM, {0.f, 0.f, 0.f, 1.f}}; | ||
| 4507 | return reserved(d, tiled(texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, | ||
| 4508 | D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET)), | ||
| 4509 | D3D12_RESOURCE_STATE_COMMON, &clear); | ||
| 4510 | }}, | ||
| 4511 | {"reserved: plain texture with a clear value", [](ID3D12Device* d) { | ||
| 4512 | static const D3D12_CLEAR_VALUE clear{DXGI_FORMAT_R8G8B8A8_UNORM, {0.f, 0.f, 0.f, 1.f}}; | ||
| 4513 | return reserved(d, tiled(texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)), | ||
| 4514 | D3D12_RESOURCE_STATE_COMMON, &clear); | ||
| 4515 | }}, | ||
| 4516 | {"reserved: plain texture in RENDER_TARGET", [](ID3D12Device* d) { | ||
| 4517 | return reserved(d, tiled(texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)), | ||
| 4518 | D3D12_RESOURCE_STATE_RENDER_TARGET); | ||
| 4519 | }}, | ||
| 4520 | {"reserved: 3D texture", [](ID3D12Device* d) { | ||
| 4521 | auto desc = tiled(texture_desc(64, 64, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE, 1, 16)); | ||
| 4522 | desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; | ||
| 4523 | return reserved(d, desc); | ||
| 4524 | }}, | ||
| 4525 | {"reserved: 4x MSAA render target", [](ID3D12Device* d) { | ||
| 4526 | auto desc = tiled(texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, | ||
| 4527 | D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET)); | ||
| 4528 | desc.SampleDesc.Count = 4; | ||
| 4529 | return reserved(d, desc); | ||
| 4530 | }}, | ||
| 4531 | }; | ||
| 4532 | const bool verbose = GetEnvironmentVariableA("LEONIDA_D3D49_VERBOSE", nullptr, 0) > 0; | ||
| 4533 | int mismatches = 0; | ||
| 4534 | for (const Case& c : cases) { | ||
| 4535 | if (verbose) { | ||
| 4536 | std::printf("invalid arguments %s:", c.name); | ||
| 4537 | std::fflush(stdout); | ||
| 4538 | } | ||
| 4539 | const HRESULT a = call_guarded(c.call, ours), b = call_guarded(c.call, host.p); | ||
| 4540 | if (verbose) std::printf(" ours 0x%08lx host 0x%08lx\n", a, b); | ||
| 4541 | if (a == b) continue; | ||
| 4542 | if (c.comparable && !c.comparable(host.p)) { | ||
| 4543 | std::printf("invalid arguments %s: not comparable on this host (ours 0x%08lx, host 0x%08lx)\n", c.name, | ||
| 4544 | a, b); | ||
| 4545 | continue; | ||
| 4546 | } | ||
| 4547 | ++mismatches; | ||
| 4548 | std::fprintf(stderr, "invalid arguments %s: ours 0x%08lx, host 0x%08lx\n", c.name, a, b); | ||
| 4549 | } | ||
| 4550 | return mismatches; | ||
| 4551 | } | ||
| 4552 | |||
| 3785 | // CheckFeatureSupport's error paths must match the host runtime's exactly: games and middleware branch on these | 4553 | // CheckFeatureSupport's error paths must match the host runtime's exactly: games and middleware branch on these |
| 3786 | // HRESULTs at startup, and a wrong success or a wrong error sends them down the wrong path. A null data pointer, a | 4554 | // HRESULTs at startup, and a wrong success or a wrong error sends them down the wrong path. A null data pointer, a |
| 3787 | // structure smaller than the feature requires, or a feature value no runtime defines must all return the same HRESULT | 4555 | // structure smaller than the feature requires, or a feature value no runtime defines must all return the same HRESULT |
| @@ -3990,15 +4758,62 @@ int main() { | |||
| 3990 | EXPECT(format_support.Support1 & D3D12_FORMAT_SUPPORT1_RENDER_TARGET); | 4758 | EXPECT(format_support.Support1 & D3D12_FORMAT_SUPPORT1_RENDER_TARGET); |
| 3991 | EXPECT(format_support.Support1 & D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE); | 4759 | EXPECT(format_support.Support1 & D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE); |
| 3992 | 4760 | ||
| 3993 | D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS invalid_sample_count{}; | 4761 | // RTX 5070 / 621.14 host answers, without requiring a host device for this regression. |
| 3994 | invalid_sample_count.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | 4762 | for (const UINT samples : {0u, 33u, 64u, UINT_MAX}) { |
| 3995 | invalid_sample_count.SampleCount = D3D12_MAX_MULTISAMPLE_SAMPLE_COUNT * 2; | 4763 | D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS quality{DXGI_FORMAT_R8G8B8A8_UNORM, samples, |
| 3996 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &invalid_sample_count, | 4764 | D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE, 99}; |
| 3997 | sizeof(invalid_sample_count)) == E_INVALIDARG); | 4765 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &quality, |
| 3998 | EXPECT(invalid_sample_count.NumQualityLevels == 0); | 4766 | sizeof(quality)) == E_FAIL); |
| 3999 | invalid_sample_count.SampleCount = 0; | 4767 | EXPECT(quality.NumQualityLevels == 0); |
| 4000 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &invalid_sample_count, | 4768 | } |
| 4001 | sizeof(invalid_sample_count)) == E_INVALIDARG); | 4769 | for (UINT format = 0; format <= 192; ++format) { |
| 4770 | const bool known = format != UINT(DXGI_FORMAT_R1_UNORM) && | ||
| 4771 | (format <= 115 || (format >= 189 && format <= 191)); | ||
| 4772 | for (const UINT samples : {1u, 3u, 31u}) { | ||
| 4773 | D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS quality{DXGI_FORMAT(format), samples, | ||
| 4774 | D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE, 99}; | ||
| 4775 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &quality, | ||
| 4776 | sizeof(quality)) == (known ? S_OK : E_FAIL)); | ||
| 4777 | EXPECT(quality.NumQualityLevels == (known ? UINT(samples == 1) : 99u)); | ||
| 4778 | } | ||
| 4779 | } | ||
| 4780 | D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS invalid_format_levels{DXGI_FORMAT_FORCE_UINT, 1, | ||
| 4781 | D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE, 99}; | ||
| 4782 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &invalid_format_levels, | ||
| 4783 | sizeof(invalid_format_levels)) == E_FAIL); | ||
| 4784 | EXPECT(invalid_format_levels.NumQualityLevels == 99); | ||
| 4785 | // Native (RTX 5070 / 621.24): an unknown format keeps the output even with an invalid count. | ||
| 4786 | D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS unknown_zero{DXGI_FORMAT(192), 0, | ||
| 4787 | D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE, 99}; | ||
| 4788 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &unknown_zero, | ||
| 4789 | sizeof(unknown_zero)) == E_FAIL); | ||
| 4790 | EXPECT(unknown_zero.NumQualityLevels == 99); | ||
| 4791 | for (const auto format : {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_R32G32B32_FLOAT}) { | ||
| 4792 | for (const UINT samples : {1u, 3u, 4u, 32u}) { | ||
| 4793 | for (const UINT flags : {0u, 1u}) { | ||
| 4794 | D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS plain{format, samples, | ||
| 4795 | D3D12_MULTISAMPLE_QUALITY_LEVEL_FLAGS(flags)}; | ||
| 4796 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &plain, | ||
| 4797 | sizeof(plain)) == S_OK); | ||
| 4798 | if (flags && format == DXGI_FORMAT_R32G32B32_FLOAT) EXPECT(plain.NumQualityLevels == 0); | ||
| 4799 | for (const UINT extra : {2u, 0xfeu}) { | ||
| 4800 | auto undefined_flags = plain; | ||
| 4801 | undefined_flags.Flags = D3D12_MULTISAMPLE_QUALITY_LEVEL_FLAGS(flags | extra); | ||
| 4802 | undefined_flags.NumQualityLevels = 99; | ||
| 4803 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &undefined_flags, | ||
| 4804 | sizeof(undefined_flags)) == S_OK); | ||
| 4805 | EXPECT(undefined_flags.NumQualityLevels == plain.NumQualityLevels); | ||
| 4806 | } | ||
| 4807 | } | ||
| 4808 | } | ||
| 4809 | } | ||
| 4810 | D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS wrong_size[2]{{DXGI_FORMAT_R8G8B8A8_UNORM, 1, | ||
| 4811 | D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE, 99}}; | ||
| 4812 | for (const UINT bytes : {UINT(sizeof(wrong_size[0]) - 1), UINT(sizeof(wrong_size))}) { | ||
| 4813 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, wrong_size, | ||
| 4814 | bytes) == E_INVALIDARG); | ||
| 4815 | EXPECT(wrong_size[0].NumQualityLevels == 99); | ||
| 4816 | } | ||
| 4002 | 4817 | ||
| 4003 | D3D12_RESOURCE_DESC unsupported_quality = | 4818 | D3D12_RESOURCE_DESC unsupported_quality = |
| 4004 | texture_desc(size, size, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET); | 4819 | texture_desc(size, size, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET); |
| @@ -4006,8 +4821,20 @@ int main() { | |||
| 4006 | unsupported_quality.SampleDesc.Quality = 1; | 4821 | unsupported_quality.SampleDesc.Quality = 1; |
| 4007 | EXPECT(device->GetResourceAllocationInfo(0, 1, &unsupported_quality).SizeInBytes == UINT64_MAX); | 4822 | EXPECT(device->GetResourceAllocationInfo(0, 1, &unsupported_quality).SizeInBytes == UINT64_MAX); |
| 4008 | 4823 | ||
| 4009 | D3D12_FEATURE_DATA_FORMAT_SUPPORT invalid_format{DXGI_FORMAT_UNKNOWN}; | 4824 | // UNKNOWN is a buffer format to the host runtime (S_OK, Support1 BUFFER; "format support: UNKNOWN" compares |
| 4010 | EXPECT(FAILED(device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &invalid_format, sizeof(invalid_format)))); | 4825 | // it), and a value past its format table is E_FAIL. |
| 4826 | D3D12_FEATURE_DATA_FORMAT_SUPPORT unknown_format{DXGI_FORMAT_UNKNOWN}; | ||
| 4827 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &unknown_format, sizeof(unknown_format)) == | ||
| 4828 | S_OK && | ||
| 4829 | unknown_format.Support1 == D3D12_FORMAT_SUPPORT1_BUFFER); | ||
| 4830 | D3D12_FEATURE_DATA_FORMAT_SUPPORT invalid_format{static_cast<DXGI_FORMAT>(116)}; | ||
| 4831 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &invalid_format, sizeof(invalid_format)) == | ||
| 4832 | E_FAIL); | ||
| 4833 | // The table's last entries before and after the gap are formats, whatever this GPU supports of them. | ||
| 4834 | for (const UINT edge : {115u, 189u, 191u}) { // B4G4R4A4_UNORM, SAMPLER_FEEDBACK_MIN_MIP_OPAQUE, A4B4G4R4_UNORM | ||
| 4835 | D3D12_FEATURE_DATA_FORMAT_SUPPORT known{static_cast<DXGI_FORMAT>(edge)}; | ||
| 4836 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &known, sizeof(known)) != E_FAIL); | ||
| 4837 | } | ||
| 4011 | 4838 | ||
| 4012 | // D3D-61: XR_BIAS is a display-only format with the R10G10B10A2 bit layout. The layer can create and | 4839 | // D3D-61: XR_BIAS is a display-only format with the R10G10B10A2 bit layout. The layer can create and |
| 4013 | // copy it, and its views can cast to the ordinary 10:10:10:2 format, but it does not claim display or | 4840 | // copy it, and its views can cast to the ordinary 10:10:10:2 format, but it does not claim display or |
| @@ -4220,6 +5047,11 @@ int main() { | |||
| 4220 | EXPECT(above.HighestShaderModel == D3D_SHADER_MODEL_6_0); // clamped to what the layer accepts | 5047 | EXPECT(above.HighestShaderModel == D3D_SHADER_MODEL_6_0); // clamped to what the layer accepts |
| 4221 | D3D12_FEATURE_DATA_SHADER_MODEL below{static_cast<D3D_SHADER_MODEL>(0)}; | 5048 | D3D12_FEATURE_DATA_SHADER_MODEL below{static_cast<D3D_SHADER_MODEL>(0)}; |
| 4222 | EXPECT(FAILED(device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &below, sizeof(below)))); | 5049 | EXPECT(FAILED(device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &below, sizeof(below)))); |
| 5050 | // Between 5.1 and 6.0 no runtime names a model: refused (the host's E_INVALIDARG), not echoed back. | ||
| 5051 | for (const UINT undefined : {0x52u, 0x5au, 0x5fu}) { | ||
| 5052 | D3D12_FEATURE_DATA_SHADER_MODEL gap{static_cast<D3D_SHADER_MODEL>(undefined)}; | ||
| 5053 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &gap, sizeof(gap)) == E_INVALIDARG); | ||
| 5054 | } | ||
| 4223 | 5055 | ||
| 4224 | D3D12_FEATURE_DATA_ROOT_SIGNATURE signature{D3D_ROOT_SIGNATURE_VERSION_1_1}; | 5056 | D3D12_FEATURE_DATA_ROOT_SIGNATURE signature{D3D_ROOT_SIGNATURE_VERSION_1_1}; |
| 4225 | EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_ROOT_SIGNATURE, &signature, sizeof(signature)))); | 5057 | EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_ROOT_SIGNATURE, &signature, sizeof(signature)))); |
| @@ -5238,8 +6070,9 @@ int main() { | |||
| 5238 | EXPECT(tiled->GetDesc().Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE); | 6070 | EXPECT(tiled->GetDesc().Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE); |
| 5239 | D3D12_HEAP_PROPERTIES reserved_heap{}; | 6071 | D3D12_HEAP_PROPERTIES reserved_heap{}; |
| 5240 | EXPECT(tiled->GetHeapProperties(&reserved_heap, nullptr) == E_INVALIDARG); // no heap of its own | 6072 | EXPECT(tiled->GetHeapProperties(&reserved_heap, nullptr) == E_INVALIDARG); // no heap of its own |
| 6073 | // A null output is E_UNEXPECTED, as on the host runtime (compare_placed_reserved, "reserved:"). | ||
| 5241 | EXPECT(device->CreateReservedResource(&tiled_desc, D3D12_RESOURCE_STATE_COMMON, nullptr, | 6074 | EXPECT(device->CreateReservedResource(&tiled_desc, D3D12_RESOURCE_STATE_COMMON, nullptr, |
| 5242 | __uuidof(ID3D12Resource), nullptr) == S_FALSE); | 6075 | __uuidof(ID3D12Resource), nullptr) == E_UNEXPECTED); |
| 5243 | const auto refuses = [&](D3D12_RESOURCE_DESC desc) { | 6076 | const auto refuses = [&](D3D12_RESOURCE_DESC desc) { |
| 5244 | const HRESULT hr = device->CreateReservedResource(&desc, D3D12_RESOURCE_STATE_COMMON, nullptr, | 6077 | const HRESULT hr = device->CreateReservedResource(&desc, D3D12_RESOURCE_STATE_COMMON, nullptr, |
| 5245 | IID_PPV_ARGS(&refused.p)); | 6078 | IID_PPV_ARGS(&refused.p)); |
| @@ -5411,7 +6244,8 @@ int main() { | |||
| 5411 | Ref<ID3D12QueryHeap> occlusion, timestamps, statistics, refused; | 6244 | Ref<ID3D12QueryHeap> occlusion, timestamps, statistics, refused; |
| 5412 | D3D12_QUERY_HEAP_DESC query_desc{D3D12_QUERY_HEAP_TYPE_OCCLUSION, 4, 0}; | 6245 | D3D12_QUERY_HEAP_DESC query_desc{D3D12_QUERY_HEAP_TYPE_OCCLUSION, 4, 0}; |
| 5413 | EXPECT(SUCCEEDED(device->CreateQueryHeap(&query_desc, IID_PPV_ARGS(&occlusion.p)))); | 6246 | EXPECT(SUCCEEDED(device->CreateQueryHeap(&query_desc, IID_PPV_ARGS(&occlusion.p)))); |
| 5414 | EXPECT(device->CreateQueryHeap(&query_desc, __uuidof(ID3D12QueryHeap), nullptr) == S_FALSE); | 6247 | // A null output is E_UNEXPECTED, as on the host runtime (compare_invalid_arguments, "query heap:"). |
| 6248 | EXPECT(device->CreateQueryHeap(&query_desc, __uuidof(ID3D12QueryHeap), nullptr) == E_UNEXPECTED); | ||
| 5415 | { | 6249 | { |
| 5416 | Ref<ID3D12Device> parent; | 6250 | Ref<ID3D12Device> parent; |
| 5417 | EXPECT(SUCCEEDED(occlusion->GetDevice(IID_PPV_ARGS(&parent.p))) && parent.p == device.p); | 6251 | EXPECT(SUCCEEDED(occlusion->GetDevice(IID_PPV_ARGS(&parent.p))) && parent.p == device.p); |
| @@ -5482,6 +6316,33 @@ int main() { | |||
| 5482 | EXPECT(submit_and_wait()); | 6316 | EXPECT(submit_and_wait()); |
| 5483 | EXPECT(u64(again_at) >= t1 && u64(again_at + 8) == t1); | 6317 | EXPECT(u64(again_at) >= t1 && u64(again_at + 8) == t1); |
| 5484 | 6318 | ||
| 6319 | // A timestamp written by one execution and resolved by the next, with nothing waited for in between, as | ||
| 6320 | // a game resolves last frame's timestamps. The resolve reads the new value (on MoltenVK only because the | ||
| 6321 | // queue orders the two; docs/d3d12_vulkan.md section 4.6). | ||
| 6322 | { | ||
| 6323 | constexpr UINT64 later_at = 2048; | ||
| 6324 | Ref<ID3D12CommandAllocator> writer_allocator; | ||
| 6325 | Ref<ID3D12GraphicsCommandList> writer; | ||
| 6326 | EXPECT(SUCCEEDED(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, | ||
| 6327 | IID_PPV_ARGS(&writer_allocator.p)))); | ||
| 6328 | EXPECT(SUCCEEDED(device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, writer_allocator.p, | ||
| 6329 | nullptr, IID_PPV_ARGS(&writer.p)))); | ||
| 6330 | writer->CopyBufferRegion(readback.p, 8192, upload.p, 0, 32768); | ||
| 6331 | writer->EndQuery(timestamps.p, D3D12_QUERY_TYPE_TIMESTAMP, 2); | ||
| 6332 | EXPECT(writer->Close() == S_OK); | ||
| 6333 | EXPECT(SUCCEEDED(allocator->Reset()) && SUCCEEDED(list->Reset(allocator.p, nullptr))); | ||
| 6334 | list->ResolveQueryData(timestamps.p, D3D12_QUERY_TYPE_TIMESTAMP, 0, 3, readback.p, later_at); | ||
| 6335 | EXPECT(list->Close() == S_OK); | ||
| 6336 | ID3D12CommandList* const writers[] = {writer.p}; | ||
| 6337 | queue->ExecuteCommandLists(1, writers); | ||
| 6338 | EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success); | ||
| 6339 | queue->ExecuteCommandLists(1, lists); | ||
| 6340 | EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success); | ||
| 6341 | EXPECT(submit_and_wait()); | ||
| 6342 | EXPECT(u64(later_at) == u64(again_at) && u64(later_at + 8) == t1); | ||
| 6343 | EXPECT(u64(later_at + 16) >= u64(again_at) && u64(later_at + 16) != 0xcdcdcdcdcdcdcdcdull); | ||
| 6344 | } | ||
| 6345 | |||
| 5485 | // Lists that break the rules. Close reports what it can see; the rest is refused at execution, and | 6346 | // Lists that break the rules. Close reports what it can see; the rest is refused at execution, and |
| 5486 | // nothing is submitted. | 6347 | // nothing is submitted. |
| 5487 | const auto refuse = [&](HRESULT close, leonida::ReplayResult result, auto&& record) { | 6348 | const auto refuse = [&](HRESULT close, leonida::ReplayResult result, auto&& record) { |
| @@ -5506,11 +6367,13 @@ int main() { | |||
| 5506 | [&] { list->ResolveQueryData(timestamps.p, D3D12_QUERY_TYPE_TIMESTAMP, 0, 1, rt_resource.p, 0); })); | 6367 | [&] { list->ResolveQueryData(timestamps.p, D3D12_QUERY_TYPE_TIMESTAMP, 0, 1, rt_resource.p, 0); })); |
| 5507 | EXPECT(refuse(S_OK, R::invalid_query, // past the end of the buffer | 6368 | EXPECT(refuse(S_OK, R::invalid_query, // past the end of the buffer |
| 5508 | [&] { list->ResolveQueryData(timestamps.p, D3D12_QUERY_TYPE_TIMESTAMP, 0, 2, readback.p, 65528); })); | 6369 | [&] { list->ResolveQueryData(timestamps.p, D3D12_QUERY_TYPE_TIMESTAMP, 0, 2, readback.p, 65528); })); |
| 5509 | EXPECT(refuse(S_OK, R::unsupported, [&] { // valid D3D12, but Vulkan runs one occlusion query at a time | 6370 | EXPECT(refuse(S_OK, R::success, [&] { // overlapping occlusion kinds share physical segments (D3D-252) |
| 5510 | list->BeginQuery(occlusion.p, D3D12_QUERY_TYPE_OCCLUSION, 0); | 6371 | list->BeginQuery(occlusion.p, D3D12_QUERY_TYPE_OCCLUSION, 0); |
| 5511 | list->BeginQuery(occlusion.p, D3D12_QUERY_TYPE_BINARY_OCCLUSION, 1); | 6372 | list->BeginQuery(occlusion.p, D3D12_QUERY_TYPE_BINARY_OCCLUSION, 1); |
| 5512 | list->EndQuery(occlusion.p, D3D12_QUERY_TYPE_BINARY_OCCLUSION, 1); | 6373 | list->EndQuery(occlusion.p, D3D12_QUERY_TYPE_BINARY_OCCLUSION, 1); |
| 5513 | list->EndQuery(occlusion.p, D3D12_QUERY_TYPE_OCCLUSION, 0); | 6374 | list->EndQuery(occlusion.p, D3D12_QUERY_TYPE_OCCLUSION, 0); |
| 6375 | list->ResolveQueryData(occlusion.p, D3D12_QUERY_TYPE_OCCLUSION, 0, 1, readback.p, 0); | ||
| 6376 | list->ResolveQueryData(occlusion.p, D3D12_QUERY_TYPE_BINARY_OCCLUSION, 1, 1, readback.p, 8); | ||
| 5514 | })); | 6377 | })); |
| 5515 | EXPECT(SUCCEEDED(allocator->Reset()) && SUCCEEDED(list->Reset(allocator.p, nullptr))); | 6378 | EXPECT(SUCCEEDED(allocator->Reset()) && SUCCEEDED(list->Reset(allocator.p, nullptr))); |
| 5516 | EXPECT(SUCCEEDED(list->Close())); | 6379 | EXPECT(SUCCEEDED(list->Close())); |
| @@ -5894,6 +6757,11 @@ int main() { | |||
| 5894 | if (heap_mismatches < 0) | 6757 | if (heap_mismatches < 0) |
| 5895 | std::printf("CreateHeap valid neighbours: no host D3D12 device to compare with, skipped\n"); | 6758 | std::printf("CreateHeap valid neighbours: no host D3D12 device to compare with, skipped\n"); |
| 5896 | EXPECT(heap_mismatches <= 0); | 6759 | EXPECT(heap_mismatches <= 0); |
| 6760 | const int placed_mismatches = compare_placed_reserved(standalone.p); | ||
| 6761 | if (placed_mismatches < 0) | ||
| 6762 | std::printf("CreatePlacedResource/CreateReservedResource arguments: no host D3D12 device to compare " | ||
| 6763 | "with, skipped\n"); | ||
| 6764 | EXPECT(placed_mismatches <= 0); | ||
| 5897 | } | 6765 | } |
| 5898 | 6766 | ||
| 5899 | auto tiled_2d = [&](UINT w, UINT h, DXGI_FORMAT fmt, UINT16 mips, D3D12_RESOURCE_FLAGS flags, | 6767 | auto tiled_2d = [&](UINT w, UINT h, DXGI_FORMAT fmt, UINT16 mips, D3D12_RESOURCE_FLAGS flags, |
diff --git a/runtime/test/descriptor_table_test.cpp b/runtime/test/descriptor_table_test.cpp index 26fb39083..7a24117e3 100644 --- a/runtime/test/descriptor_table_test.cpp +++ b/runtime/test/descriptor_table_test.cpp | |||
| @@ -408,7 +408,49 @@ int test_erase_moves_no_other_entry() { | |||
| 408 | return 0; | 408 | return 0; |
| 409 | } | 409 | } |
| 410 | 410 | ||
| 411 | int test_unresolvable_hash_collision() { | ||
| 412 | DescriptorTable table(32); | ||
| 413 | std::array<DescriptorKey, 9> keys{}; | ||
| 414 | for (std::uint32_t i = 0; i < keys.size(); ++i) { | ||
| 415 | keys[i][0] = i; | ||
| 416 | // Invert the final FNV multiplication to make every complete hash zero. | ||
| 417 | std::uint32_t prefix = kFnvOffsetBasis; | ||
| 418 | for (int word = 0; word < 7; ++word) prefix = (prefix ^ keys[i][word]) * kFnvPrime; | ||
| 419 | keys[i][7] = prefix; | ||
| 420 | EXPECT(hash_descriptor_key(keys[i]) == 0); | ||
| 421 | } | ||
| 422 | for (std::uint32_t i = 0; i < 8; ++i) table.insert(keys[i], i + 1); | ||
| 423 | const auto before = table.build_gpu_buffer(); | ||
| 424 | bool rejected = false; | ||
| 425 | try { table.insert(keys[8], 9); } | ||
| 426 | catch (const std::length_error&) { rejected = true; } | ||
| 427 | EXPECT(rejected && table.size() == 8 && table.capacity() == 32); | ||
| 428 | EXPECT(table.build_gpu_buffer() == before); | ||
| 429 | for (std::uint32_t i = 0; i < 8; ++i) EXPECT(table.lookup(keys[i]) == i + 1); | ||
| 430 | EXPECT(table.insert_or_update(keys[0].data(), 99) == DescriptorTable::InsertResult::replaced); | ||
| 431 | EXPECT(table.lookup(keys[0]) == 99); | ||
| 432 | EXPECT(table.erase(keys[0])); | ||
| 433 | EXPECT(table.insert(keys[8], 9) && table.lookup(keys[8]) == 9); | ||
| 434 | return 0; | ||
| 435 | } | ||
| 436 | |||
| 437 | int test_capacity_overflow() { | ||
| 438 | for (std::uint32_t requested : {0x80000001u, 0xffffffffu}) { | ||
| 439 | bool rejected = false; | ||
| 440 | try { DescriptorTable table(requested); } | ||
| 441 | catch (const std::length_error&) { rejected = true; } | ||
| 442 | EXPECT(rejected); | ||
| 443 | } | ||
| 444 | for (std::uint32_t requested : {0u, 1u, 16u, 17u, 31u, 32u}) { | ||
| 445 | DescriptorTable table(requested); | ||
| 446 | EXPECT(table.capacity() == (requested <= 16 ? 16 : 32)); | ||
| 447 | } | ||
| 448 | return 0; | ||
| 449 | } | ||
| 450 | |||
| 411 | int main() { | 451 | int main() { |
| 452 | EXPECT(test_unresolvable_hash_collision() == 0); | ||
| 453 | EXPECT(test_capacity_overflow() == 0); | ||
| 412 | EXPECT(test_fnv1a_hash_matches_contract() == 0); | 454 | EXPECT(test_fnv1a_hash_matches_contract() == 0); |
| 413 | EXPECT(test_ssharp_key_padding() == 0); | 455 | EXPECT(test_ssharp_key_padding() == 0); |
| 414 | EXPECT(test_basic_insertion_and_lookup() == 0); | 456 | EXPECT(test_basic_insertion_and_lookup() == 0); |
diff --git a/runtime/test/dll_thread_calls_test.cpp b/runtime/test/dll_thread_calls_test.cpp new file mode 100644 index 000000000..1cc6928ca --- /dev/null +++ b/runtime/test/dll_thread_calls_test.cpp | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | // DisableThreadLibraryCalls from a mapped image's DllMain (shims/library_loader.cpp). | ||
| 2 | // | ||
| 3 | // The real function only accepts a module the Windows loader knows, so for a manually mapped image it returned FALSE | ||
| 4 | // and a DllMain that returns its result made Loader::initialise() throw "DllMain returned FALSE". The shim answers | ||
| 5 | // TRUE for a mapped module and for a module the shims own (a pseudo-handle), and leaves every other handle to the | ||
| 6 | // real function. | ||
| 7 | // | ||
| 8 | // Maps dll_thread_calls.dll (test/fixtures/dll_thread_calls.cpp). xmem.cpp is linked only so the shims own a module | ||
| 9 | // (xmem.dll) to hand out a pseudo-handle for. No game files. | ||
| 10 | #include <windows.h> | ||
| 11 | |||
| 12 | #include <cstdio> | ||
| 13 | #include <filesystem> | ||
| 14 | #include <stdexcept> | ||
| 15 | #include <string> | ||
| 16 | |||
| 17 | #include "pe_loader.h" | ||
| 18 | #include "shims.h" | ||
| 19 | |||
| 20 | namespace { | ||
| 21 | |||
| 22 | int g_failures = 0; | ||
| 23 | |||
| 24 | void check(bool ok, const std::string& what) { | ||
| 25 | std::printf("%s %s\n", ok ? "PASS" : "FAIL", what.c_str()); | ||
| 26 | std::fflush(stdout); | ||
| 27 | if (!ok) ++g_failures; | ||
| 28 | } | ||
| 29 | |||
| 30 | } // namespace | ||
| 31 | |||
| 32 | int main(int argc, char** argv) { | ||
| 33 | if (argc != 2) { | ||
| 34 | std::fprintf(stderr, "usage: dll_thread_calls_test <dll_thread_calls.dll>\n"); | ||
| 35 | return 2; | ||
| 36 | } | ||
| 37 | const std::filesystem::path dll = argv[1]; | ||
| 38 | try { | ||
| 39 | rt::Loader loader(dll.parent_path()); | ||
| 40 | rt::Module& m = loader.load(dll); | ||
| 41 | |||
| 42 | bool shimmed = false; | ||
| 43 | for (const auto& r : m.imports) | ||
| 44 | if (r.name == "DisableThreadLibraryCalls") shimmed = r.binding == rt::Binding::Shim; | ||
| 45 | check(shimmed, "the DisableThreadLibraryCalls import is bound to the shim"); | ||
| 46 | |||
| 47 | bool initialised = true; | ||
| 48 | try { | ||
| 49 | loader.initialise(); | ||
| 50 | } catch (const std::exception& e) { | ||
| 51 | initialised = false; | ||
| 52 | std::printf(" initialise() threw: %s\n", e.what()); | ||
| 53 | } | ||
| 54 | check(initialised, "initialise() succeeds when DllMain returns DisableThreadLibraryCalls(hinstance)"); | ||
| 55 | |||
| 56 | const auto bogus = | ||
| 57 | reinterpret_cast<BOOL(__cdecl*)()>(m.exports.at("dll_thread_calls_bogus_handle")); | ||
| 58 | SetLastError(0); | ||
| 59 | check(bogus() == FALSE, "a handle that names no module still gets the real answer (FALSE)"); | ||
| 60 | |||
| 61 | // A shim pseudo-handle is no module the Windows loader knows, so the real function would fail on it. | ||
| 62 | using GetModuleHandleAFn = HMODULE(WINAPI*)(LPCSTR); | ||
| 63 | using DisableFn = BOOL(WINAPI*)(HMODULE); | ||
| 64 | const auto get_module = | ||
| 65 | reinterpret_cast<GetModuleHandleAFn>(rt::shims::find("kernel32.dll", "GetModuleHandleA")); | ||
| 66 | const auto disable = | ||
| 67 | reinterpret_cast<DisableFn>(rt::shims::find("kernel32.dll", "DisableThreadLibraryCalls")); | ||
| 68 | check(get_module != nullptr && disable != nullptr, | ||
| 69 | "the registry serves GetModuleHandleA and DisableThreadLibraryCalls"); | ||
| 70 | const HMODULE owned = get_module ? get_module("xmem.dll") : nullptr; | ||
| 71 | check(owned != nullptr, "the shims hand out a pseudo-handle for the module they own (xmem.dll)"); | ||
| 72 | check(disable != nullptr && owned != nullptr && disable(owned) == TRUE, | ||
| 73 | "DisableThreadLibraryCalls on a shim pseudo-handle answers TRUE"); | ||
| 74 | } catch (const std::exception& e) { | ||
| 75 | std::printf("FAIL unexpected exception: %s\n", e.what()); | ||
| 76 | ++g_failures; | ||
| 77 | } | ||
| 78 | std::printf("dll_thread_calls_test: %s (%d failures)\n", g_failures ? "FAILED" : "OK", g_failures); | ||
| 79 | return g_failures ? 1 : 0; | ||
| 80 | } | ||
diff --git a/runtime/test/dxgi_swapchain_test.cpp b/runtime/test/dxgi_swapchain_test.cpp index bc1b99486..95bf9bb06 100644 --- a/runtime/test/dxgi_swapchain_test.cpp +++ b/runtime/test/dxgi_swapchain_test.cpp | |||
| @@ -318,18 +318,63 @@ int main() { | |||
| 318 | 318 | ||
| 319 | if (!check_statistics_disjoint(sc)) return fail("initial frame-statistics disjoint notification"); | 319 | if (!check_statistics_disjoint(sc)) return fail("initial frame-statistics disjoint notification"); |
| 320 | 320 | ||
| 321 | ID3D12CommandQueue* got_queue = nullptr; | 321 | ID3D12Device* got_device = nullptr; |
| 322 | if (FAILED(sc->GetDevice(IID_PPV_ARGS(&got_queue))) || got_queue != queue) { | 322 | if (FAILED(sc->GetDevice(IID_PPV_ARGS(&got_device))) || got_device != dev) { |
| 323 | if (got_queue) got_queue->Release(); | 323 | if (got_device) got_device->Release(); |
| 324 | return fail("GetDevice"); | 324 | return fail("GetDevice did not return the command queue's parent device"); |
| 325 | } | 325 | } |
| 326 | got_queue->Release(); | 326 | got_device->Release(); |
| 327 | |||
| 328 | IUnknown* got_unknown = nullptr; | ||
| 329 | IUnknown* expected_device_unknown = nullptr; | ||
| 330 | IUnknown* queue_unknown = nullptr; | ||
| 331 | const HRESULT got_unknown_hr = sc->GetDevice(IID_PPV_ARGS(&got_unknown)); | ||
| 332 | if (FAILED(got_unknown_hr) || !got_unknown) { | ||
| 333 | if (got_unknown) got_unknown->Release(); | ||
| 334 | return fail("GetDevice(IUnknown) failed"); | ||
| 335 | } | ||
| 336 | if (FAILED(dev->QueryInterface(IID_PPV_ARGS(&expected_device_unknown))) || !expected_device_unknown) { | ||
| 337 | got_unknown->Release(); | ||
| 338 | return fail("QueryInterface(IUnknown) on device failed"); | ||
| 339 | } | ||
| 340 | if (FAILED(queue->QueryInterface(IID_PPV_ARGS(&queue_unknown))) || !queue_unknown) { | ||
| 341 | expected_device_unknown->Release(); | ||
| 342 | got_unknown->Release(); | ||
| 343 | return fail("QueryInterface(IUnknown) on queue failed"); | ||
| 344 | } | ||
| 345 | const bool has_device_identity = got_unknown == expected_device_unknown && got_unknown != queue_unknown; | ||
| 346 | queue_unknown->Release(); | ||
| 347 | expected_device_unknown->Release(); | ||
| 348 | got_unknown->Release(); | ||
| 349 | if (!has_device_identity) | ||
| 350 | return fail("GetDevice(IUnknown) returned the queue identity instead of its parent device"); | ||
| 327 | DXGI_SWAP_CHAIN_FULLSCREEN_DESC fullscreen{}; | 351 | DXGI_SWAP_CHAIN_FULLSCREEN_DESC fullscreen{}; |
| 328 | if (FAILED(sc->GetFullscreenDesc(&fullscreen)) || !fullscreen.Windowed || | 352 | if (FAILED(sc->GetFullscreenDesc(&fullscreen)) || !fullscreen.Windowed || |
| 329 | fullscreen.Scaling != DXGI_MODE_SCALING_UNSPECIFIED || | 353 | fullscreen.Scaling != DXGI_MODE_SCALING_UNSPECIFIED || |
| 330 | fullscreen.ScanlineOrdering != DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED) | 354 | fullscreen.ScanlineOrdering != DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED) |
| 331 | return fail("GetFullscreenDesc"); | 355 | return fail("GetFullscreenDesc"); |
| 332 | 356 | ||
| 357 | // Factory::GetParent: root DXGI object has no parent; native DXGI returns E_NOINTERFACE | ||
| 358 | void* parent_out = reinterpret_cast<void*>(1); | ||
| 359 | if (factory->GetParent(IID_IUnknown, nullptr) != E_POINTER) | ||
| 360 | return fail("Factory::GetParent with null out should return E_POINTER"); | ||
| 361 | if (factory->GetParent(IID_IUnknown, &parent_out) != E_NOINTERFACE || parent_out != nullptr) | ||
| 362 | return fail("Factory::GetParent should return E_NOINTERFACE and set null out"); | ||
| 363 | |||
| 364 | // SwapChain::GetCoreWindow: HWND swapchain is not associated with a CoreWindow | ||
| 365 | void* cw_out = reinterpret_cast<void*>(1); | ||
| 366 | if (sc->GetCoreWindow(IID_IUnknown, nullptr) != DXGI_ERROR_INVALID_CALL) | ||
| 367 | return fail("GetCoreWindow with null out should return DXGI_ERROR_INVALID_CALL"); | ||
| 368 | if (sc->GetCoreWindow(IID_IUnknown, &cw_out) != DXGI_ERROR_INVALID_CALL || cw_out != nullptr) | ||
| 369 | return fail("GetCoreWindow on HWND swapchain should return DXGI_ERROR_INVALID_CALL and set null out"); | ||
| 370 | |||
| 371 | // SwapChain::GetRestrictToOutput: unrestricted swapchain returns DXGI_ERROR_NOT_FOUND | ||
| 372 | IDXGIOutput* restrict_out = reinterpret_cast<IDXGIOutput*>(1); | ||
| 373 | if (sc->GetRestrictToOutput(nullptr) != E_INVALIDARG) | ||
| 374 | return fail("GetRestrictToOutput with null out should return E_INVALIDARG"); | ||
| 375 | if (sc->GetRestrictToOutput(&restrict_out) != DXGI_ERROR_NOT_FOUND || restrict_out != nullptr) | ||
| 376 | return fail("GetRestrictToOutput on unrestricted swapchain should return DXGI_ERROR_NOT_FOUND and set null out"); | ||
| 377 | |||
| 333 | D3D12_DESCRIPTOR_HEAP_DESC rtv_hd{D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1, D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0}; | 378 | D3D12_DESCRIPTOR_HEAP_DESC rtv_hd{D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1, D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0}; |
| 334 | ID3D12DescriptorHeap* rtv_heap = nullptr; | 379 | ID3D12DescriptorHeap* rtv_heap = nullptr; |
| 335 | if (FAILED(dev->CreateDescriptorHeap(&rtv_hd, IID_PPV_ARGS(&rtv_heap)))) return fail("CreateDescriptorHeap"); | 380 | if (FAILED(dev->CreateDescriptorHeap(&rtv_hd, IID_PPV_ARGS(&rtv_heap)))) return fail("CreateDescriptorHeap"); |
| @@ -1088,6 +1133,77 @@ int main() { | |||
| 1088 | CloseHandle(ev); | 1133 | CloseHandle(ev); |
| 1089 | } | 1134 | } |
| 1090 | 1135 | ||
| 1136 | // Classic IDXGIFactory::CreateSwapChain delegation | ||
| 1137 | { | ||
| 1138 | if (factory->CreateSwapChain(nullptr, nullptr, nullptr) != DXGI_ERROR_INVALID_CALL) | ||
| 1139 | return fail("CreateSwapChain(null out) should return DXGI_ERROR_INVALID_CALL"); | ||
| 1140 | IDXGISwapChain* legacy_sc = nullptr; | ||
| 1141 | if (factory->CreateSwapChain(nullptr, nullptr, &legacy_sc) != DXGI_ERROR_INVALID_CALL) | ||
| 1142 | return fail("CreateSwapChain(null device, null desc) should return DXGI_ERROR_INVALID_CALL"); | ||
| 1143 | if (factory->CreateSwapChain(queue, nullptr, &legacy_sc) != DXGI_ERROR_INVALID_CALL) | ||
| 1144 | return fail("CreateSwapChain(valid device, null desc) should return DXGI_ERROR_INVALID_CALL"); | ||
| 1145 | |||
| 1146 | HWND hwnd_legacy = create_test_window(160, 120); | ||
| 1147 | if (!hwnd_legacy) return fail("CreateWindowExW (legacy)"); | ||
| 1148 | |||
| 1149 | DXGI_SWAP_CHAIN_DESC leg_desc{}; | ||
| 1150 | leg_desc.BufferDesc.Width = 160; | ||
| 1151 | leg_desc.BufferDesc.Height = 120; | ||
| 1152 | leg_desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; | ||
| 1153 | leg_desc.SampleDesc.Count = 1; | ||
| 1154 | leg_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; | ||
| 1155 | leg_desc.BufferCount = 2; | ||
| 1156 | leg_desc.OutputWindow = hwnd_legacy; | ||
| 1157 | leg_desc.Windowed = TRUE; | ||
| 1158 | leg_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; | ||
| 1159 | |||
| 1160 | if (FAILED(factory->CreateSwapChain(queue, &leg_desc, &legacy_sc)) || !legacy_sc) { | ||
| 1161 | DestroyWindow(hwnd_legacy); | ||
| 1162 | return fail("CreateSwapChain failed"); | ||
| 1163 | } | ||
| 1164 | |||
| 1165 | DXGI_SWAP_CHAIN_DESC got_leg_desc{}; | ||
| 1166 | if (FAILED(legacy_sc->GetDesc(&got_leg_desc)) || got_leg_desc.BufferDesc.Width != 160 || | ||
| 1167 | got_leg_desc.BufferDesc.Height != 120) { | ||
| 1168 | legacy_sc->Release(); | ||
| 1169 | DestroyWindow(hwnd_legacy); | ||
| 1170 | return fail("GetDesc on legacy swapchain mismatch"); | ||
| 1171 | } | ||
| 1172 | |||
| 1173 | // Fullscreen request fallback: when exclusive fullscreen is unavailable, | ||
| 1174 | // CreateSwapChain falls back to windowed chain and returns DXGI_STATUS_OCCLUDED. | ||
| 1175 | HWND hwnd_fs = create_test_window(160, 120); | ||
| 1176 | if (!hwnd_fs) return fail("CreateWindowExW (fullscreen fallback)"); | ||
| 1177 | DXGI_SWAP_CHAIN_DESC fs_req_desc = leg_desc; | ||
| 1178 | fs_req_desc.OutputWindow = hwnd_fs; | ||
| 1179 | fs_req_desc.Windowed = FALSE; | ||
| 1180 | IDXGISwapChain* fs_sc = nullptr; | ||
| 1181 | const HRESULT fs_hr = factory->CreateSwapChain(queue, &fs_req_desc, &fs_sc); | ||
| 1182 | if (fs_hr != DXGI_STATUS_OCCLUDED || !fs_sc) { | ||
| 1183 | if (fs_sc) fs_sc->Release(); | ||
| 1184 | DestroyWindow(hwnd_fs); | ||
| 1185 | return fail("CreateSwapChain(Windowed == FALSE) should return DXGI_STATUS_OCCLUDED fallback"); | ||
| 1186 | } | ||
| 1187 | BOOL is_fs = TRUE; | ||
| 1188 | fs_sc->GetFullscreenState(&is_fs, nullptr); | ||
| 1189 | if (is_fs != FALSE) { | ||
| 1190 | fs_sc->Release(); | ||
| 1191 | DestroyWindow(hwnd_fs); | ||
| 1192 | return fail("GetFullscreenState should remain FALSE on fallback windowed swapchain"); | ||
| 1193 | } | ||
| 1194 | fs_sc->Release(); | ||
| 1195 | DestroyWindow(hwnd_fs); | ||
| 1196 | |||
| 1197 | if (FAILED(legacy_sc->Present(0, 0))) { | ||
| 1198 | legacy_sc->Release(); | ||
| 1199 | DestroyWindow(hwnd_legacy); | ||
| 1200 | return fail("Present on legacy swapchain failed"); | ||
| 1201 | } | ||
| 1202 | |||
| 1203 | legacy_sc->Release(); | ||
| 1204 | DestroyWindow(hwnd_legacy); | ||
| 1205 | } | ||
| 1206 | |||
| 1091 | rtv_heap->Release(); | 1207 | rtv_heap->Release(); |
| 1092 | sc->Release(); | 1208 | sc->Release(); |
| 1093 | fence->Release(); | 1209 | fence->Release(); |
| @@ -1107,7 +1223,7 @@ int main() { | |||
| 1107 | return 1; | 1223 | return 1; |
| 1108 | } | 1224 | } |
| 1109 | std::printf("device: %s (validation %s)\n", chosen.deviceName, val_active ? "on" : "off"); | 1225 | std::printf("device: %s (validation %s)\n", chosen.deviceName, val_active ? "on" : "off"); |
| 1110 | std::printf("dxgi_swapchain_test: PASS (CreateSwapChainForHwnd, CreateSwapChainForCoreWindow, occlusion status, " | 1226 | std::printf("dxgi_swapchain_test: PASS (CreateSwapChain, CreateSwapChainForHwnd, CreateSwapChainForCoreWindow, occlusion status, " |
| 1111 | "GetBuffer+GetDesc, clear+readback, Present, ResizeBuffers; 0 validation errors)\n"); | 1227 | "GetBuffer+GetDesc, clear+readback, Present, ResizeBuffers; 0 validation errors)\n"); |
| 1112 | return 0; | 1228 | return 0; |
| 1113 | } | 1229 | } |
diff --git a/runtime/test/fixtures/dll_thread_calls.cpp b/runtime/test/fixtures/dll_thread_calls.cpp new file mode 100644 index 000000000..4f4d73eb8 --- /dev/null +++ b/runtime/test/fixtures/dll_thread_calls.cpp | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | // A DLL whose DllMain returns the result of DisableThreadLibraryCalls(hinstance), the way the MSVC runtime's satellite | ||
| 2 | // DLLs do (msvcp140_1.dll, msvcp140_2.dll, msvcp140_atomic_wait.dll, msvcp140_codecvt_ids.dll). Built without the | ||
| 3 | // CRT, so nothing but this one call runs at DLL_PROCESS_ATTACH. dll_thread_calls_test maps it with the loader. No game | ||
| 4 | // data. | ||
| 5 | #include <windows.h> | ||
| 6 | |||
| 7 | extern "C" BOOL WINAPI dll_thread_calls_main(HINSTANCE instance, DWORD reason, LPVOID) { | ||
| 8 | if (reason == DLL_PROCESS_ATTACH) return DisableThreadLibraryCalls(instance); | ||
| 9 | return TRUE; | ||
| 10 | } | ||
| 11 | |||
| 12 | // The same call on a handle that names no module: the answer must stay the Windows one (FALSE). | ||
| 13 | extern "C" __declspec(dllexport) BOOL dll_thread_calls_bogus_handle() { | ||
| 14 | return DisableThreadLibraryCalls(reinterpret_cast<HMODULE>(static_cast<uintptr_t>(0x10000))); | ||
| 15 | } | ||
diff --git a/runtime/test/fixtures/tiny_gdk_load.cpp b/runtime/test/fixtures/tiny_gdk_load.cpp index f4c6a163c..99a5c8c2b 100644 --- a/runtime/test/fixtures/tiny_gdk_load.cpp +++ b/runtime/test/fixtures/tiny_gdk_load.cpp | |||
| @@ -68,32 +68,10 @@ int main() { | |||
| 68 | reinterpret_cast<Close>(vtable[17])(obj, queue); | 68 | reinterpret_cast<Close>(vtable[17])(obj, queue); |
| 69 | reinterpret_cast<Release>(vtable[2])(obj); | 69 | reinterpret_cast<Release>(vtable[2])(obj); |
| 70 | 70 | ||
| 71 | // XNetworkingImpl is served through QueryApiImpl (slot 15: XNetworkingGetConnectivityHint). | 71 | // A class not served (an id no runtime class has) is refused, with the out pointer cleared. |
| 72 | const GUID networking = {0x37e56907, 0x2f10, 0x41e8, {0xb7, 0x2f, 0x36, 0xed, 0xb1, 0x85, 0x33, 0x1a}}; | 72 | const GUID unserved = {0x973a344e, 0x24bf, 0x4d0f, {0x84, 0x57, 0x56, 0xc5, 0x34, 0x89, 0x2b, 0x29}}; |
| 73 | void* net_obj = nullptr; | ||
| 74 | hr = query(&networking, networking, &net_obj); | ||
| 75 | if (hr != S_OK || !net_obj) | ||
| 76 | return fail("QueryApiImpl hands out XNetworkingImpl", static_cast<unsigned long>(hr)); | ||
| 77 | void* const* net_vtable = *static_cast<void* const* const*>(net_obj); | ||
| 78 | struct Hint { | ||
| 79 | UINT32 level; | ||
| 80 | UINT32 cost; | ||
| 81 | UINT32 iana; | ||
| 82 | bool init; | ||
| 83 | bool appr; | ||
| 84 | bool over; | ||
| 85 | bool roam; | ||
| 86 | } hint{}; | ||
| 87 | using GetHint = HRESULT(STDMETHODCALLTYPE*)(void*, Hint*); | ||
| 88 | hr = reinterpret_cast<GetHint>(net_vtable[15])(net_obj, &hint); | ||
| 89 | if (hr != S_OK || !hint.init) | ||
| 90 | return fail("XNetworkingImpl slot 15 (XNetworkingGetConnectivityHint)", static_cast<unsigned long>(hr)); | ||
| 91 | reinterpret_cast<Release>(net_vtable[2])(net_obj); | ||
| 92 | |||
| 93 | // A class not served yet (an unprovided class id) is refused, with the out pointer cleared. | ||
| 94 | const GUID unprovided = {0x973a344e, 0x24bf, 0x4d0f, {0x84, 0x57, 0x56, 0xc5, 0x34, 0x89, 0x2b, 0x29}}; | ||
| 95 | void* out = reinterpret_cast<void*>(1); | 73 | void* out = reinterpret_cast<void*>(1); |
| 96 | hr = query(&unprovided, unprovided, &out); | 74 | hr = query(&unserved, unserved, &out); |
| 97 | if (hr != static_cast<HRESULT>(0x80070032) || out != nullptr) | 75 | if (hr != static_cast<HRESULT>(0x80070032) || out != nullptr) |
| 98 | return fail("QueryApiImpl refuses an unprovided class and clears its out pointer", static_cast<unsigned long>(hr)); | 76 | return fail("QueryApiImpl refuses an unprovided class and clears its out pointer", static_cast<unsigned long>(hr)); |
| 99 | hr = uninit(); | 77 | hr = uninit(); |
diff --git a/runtime/test/fixtures/tiny_startup_cmdline.cpp b/runtime/test/fixtures/tiny_startup_cmdline.cpp new file mode 100644 index 000000000..ac0de4364 --- /dev/null +++ b/runtime/test/fixtures/tiny_startup_cmdline.cpp | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | // Synthetic startup fixture: process-attach callbacks must see the entry point's command line. | ||
| 2 | #include <windows.h> | ||
| 3 | |||
| 4 | #include <cstdio> | ||
| 5 | #include <cstdlib> | ||
| 6 | #include <cstring> | ||
| 7 | #include <cwchar> | ||
| 8 | |||
| 9 | namespace { | ||
| 10 | |||
| 11 | struct Snapshot { | ||
| 12 | int argc; | ||
| 13 | char argv[8][256]; | ||
| 14 | wchar_t wargv[8][256]; | ||
| 15 | char line[2048]; | ||
| 16 | wchar_t wline[2048]; | ||
| 17 | }; | ||
| 18 | |||
| 19 | Snapshot g_startup{}; | ||
| 20 | bool g_captured = false; | ||
| 21 | |||
| 22 | template <typename C, size_t N> | ||
| 23 | bool copy(C (&to)[N], const C* from) { | ||
| 24 | if (!from) return false; | ||
| 25 | size_t i = 0; | ||
| 26 | for (; i + 1 < N && from[i]; ++i) to[i] = from[i]; | ||
| 27 | to[i] = 0; | ||
| 28 | return from[i] == 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | bool capture(Snapshot& s) { | ||
| 32 | s.argc = *__p___argc(); | ||
| 33 | char** args = *__p___argv(); | ||
| 34 | wchar_t** wargs = *__p___wargv(); | ||
| 35 | if (s.argc < 1 || s.argc > 8 || !args || !wargs) return false; | ||
| 36 | for (int i = 0; i < s.argc; ++i) | ||
| 37 | if (!copy(s.argv[i], args[i]) || !copy(s.wargv[i], wargs[i])) return false; | ||
| 38 | return !args[s.argc] && !wargs[s.argc] && copy(s.line, GetCommandLineA()) && | ||
| 39 | copy(s.wline, GetCommandLineW()); | ||
| 40 | } | ||
| 41 | |||
| 42 | bool matches(const Snapshot& a, const Snapshot& b) { | ||
| 43 | if (a.argc != b.argc || std::strcmp(a.line, b.line) || std::wcscmp(a.wline, b.wline)) return false; | ||
| 44 | for (int i = 0; i < a.argc; ++i) | ||
| 45 | if (std::strcmp(a.argv[i], b.argv[i]) || std::wcscmp(a.wargv[i], b.wargv[i])) return false; | ||
| 46 | return true; | ||
| 47 | } | ||
| 48 | |||
| 49 | } // namespace | ||
| 50 | |||
| 51 | #ifdef STARTUP_CMDLINE_DLL | ||
| 52 | |||
| 53 | extern "C" __declspec(dllexport) bool __cdecl startup_cmdline_matches(const Snapshot* entry) { | ||
| 54 | return g_captured && matches(g_startup, *entry); | ||
| 55 | } | ||
| 56 | |||
| 57 | BOOL WINAPI DllMain(HINSTANCE, DWORD reason, LPVOID) { | ||
| 58 | if (reason == DLL_PROCESS_ATTACH) { | ||
| 59 | g_captured = capture(g_startup); | ||
| 60 | if (std::strstr(GetCommandLineA(), "fail-init")) return FALSE; | ||
| 61 | } | ||
| 62 | return TRUE; | ||
| 63 | } | ||
| 64 | |||
| 65 | #else | ||
| 66 | |||
| 67 | extern "C" __declspec(dllimport) bool __cdecl startup_cmdline_matches(const Snapshot* entry); | ||
| 68 | |||
| 69 | namespace { | ||
| 70 | void NTAPI startup_callback(PVOID, DWORD reason, PVOID) { | ||
| 71 | if (reason == DLL_PROCESS_ATTACH) g_captured = capture(g_startup); | ||
| 72 | } | ||
| 73 | } // namespace | ||
| 74 | |||
| 75 | #pragma section(".CRT$XLB", read) | ||
| 76 | extern "C" __declspec(allocate(".CRT$XLB")) PIMAGE_TLS_CALLBACK g_startup_callback = startup_callback; | ||
| 77 | #pragma comment(linker, "/INCLUDE:_tls_used") | ||
| 78 | #pragma comment(linker, "/INCLUDE:g_startup_callback") | ||
| 79 | |||
| 80 | int main(int argc, char** argv) { | ||
| 81 | Snapshot entry{}; | ||
| 82 | bool ok = capture(entry) && g_captured && matches(g_startup, entry) && startup_cmdline_matches(&entry); | ||
| 83 | ok = ok && argc == entry.argc; | ||
| 84 | for (int i = 0; ok && i < argc; ++i) ok = std::strcmp(argv[i], entry.argv[i]) == 0; | ||
| 85 | std::printf("tiny_startup_cmdline: %s\n", ok ? "PASS" : "FAIL"); | ||
| 86 | return ok ? 0 : 1; | ||
| 87 | } | ||
| 88 | |||
| 89 | #endif | ||
diff --git a/runtime/test/fsr_dispatch_test.cpp b/runtime/test/fsr_dispatch_test.cpp index 9a66071ac..ee30460b8 100644 --- a/runtime/test/fsr_dispatch_test.cpp +++ b/runtime/test/fsr_dispatch_test.cpp | |||
| @@ -161,6 +161,9 @@ int capture_fault(const EXCEPTION_POINTERS* ep, Call& c) { | |||
| 161 | return EXCEPTION_EXECUTE_HANDLER; | 161 | return EXCEPTION_EXECUTE_HANDLER; |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | // Each guard returns a copy of `c`, not `c` itself: with `return c;` the local becomes the named return value, and | ||
| 165 | // clang-cl 19 and 20 crash (exit 139, in recoverAddrOfEscapedLocal) generating the __except filter that writes it, | ||
| 166 | // which stops the Linux cross-build (runtime/cmake/clang-cl-xwin.cmake). MSVC is fine either way. | ||
| 164 | Call guarded_configure(ffx::PfnConfigure fn, ffx::Context* ctx, const ffx::Header* desc) { | 167 | Call guarded_configure(ffx::PfnConfigure fn, ffx::Context* ctx, const ffx::Header* desc) { |
| 165 | Call c; | 168 | Call c; |
| 166 | __try { | 169 | __try { |
| @@ -168,7 +171,7 @@ Call guarded_configure(ffx::PfnConfigure fn, ffx::Context* ctx, const ffx::Heade | |||
| 168 | } __except (capture_fault(GetExceptionInformation(), c)) { | 171 | } __except (capture_fault(GetExceptionInformation(), c)) { |
| 169 | c.faulted = true; | 172 | c.faulted = true; |
| 170 | } | 173 | } |
| 171 | return c; | 174 | return Call(c); |
| 172 | } | 175 | } |
| 173 | 176 | ||
| 174 | Call guarded_query(ffx::PfnQuery fn, ffx::Context* ctx, ffx::Header* desc) { | 177 | Call guarded_query(ffx::PfnQuery fn, ffx::Context* ctx, ffx::Header* desc) { |
| @@ -178,7 +181,7 @@ Call guarded_query(ffx::PfnQuery fn, ffx::Context* ctx, ffx::Header* desc) { | |||
| 178 | } __except (capture_fault(GetExceptionInformation(), c)) { | 181 | } __except (capture_fault(GetExceptionInformation(), c)) { |
| 179 | c.faulted = true; | 182 | c.faulted = true; |
| 180 | } | 183 | } |
| 181 | return c; | 184 | return Call(c); |
| 182 | } | 185 | } |
| 183 | 186 | ||
| 184 | Call guarded_create(ffx::PfnCreateContext fn, ffx::Context* ctx, ffx::Header* desc) { | 187 | Call guarded_create(ffx::PfnCreateContext fn, ffx::Context* ctx, ffx::Header* desc) { |
| @@ -188,7 +191,7 @@ Call guarded_create(ffx::PfnCreateContext fn, ffx::Context* ctx, ffx::Header* de | |||
| 188 | } __except (capture_fault(GetExceptionInformation(), c)) { | 191 | } __except (capture_fault(GetExceptionInformation(), c)) { |
| 189 | c.faulted = true; | 192 | c.faulted = true; |
| 190 | } | 193 | } |
| 191 | return c; | 194 | return Call(c); |
| 192 | } | 195 | } |
| 193 | 196 | ||
| 194 | Call guarded_destroy(ffx::PfnDestroyContext fn, ffx::Context* ctx) { | 197 | Call guarded_destroy(ffx::PfnDestroyContext fn, ffx::Context* ctx) { |
| @@ -198,7 +201,7 @@ Call guarded_destroy(ffx::PfnDestroyContext fn, ffx::Context* ctx) { | |||
| 198 | } __except (capture_fault(GetExceptionInformation(), c)) { | 201 | } __except (capture_fault(GetExceptionInformation(), c)) { |
| 199 | c.faulted = true; | 202 | c.faulted = true; |
| 200 | } | 203 | } |
| 201 | return c; | 204 | return Call(c); |
| 202 | } | 205 | } |
| 203 | 206 | ||
| 204 | Call guarded_dispatch(ffx::PfnDispatch fn, ffx::Context* ctx, const ffx::Header* desc) { | 207 | Call guarded_dispatch(ffx::PfnDispatch fn, ffx::Context* ctx, const ffx::Header* desc) { |
| @@ -208,7 +211,7 @@ Call guarded_dispatch(ffx::PfnDispatch fn, ffx::Context* ctx, const ffx::Header* | |||
| 208 | } __except (capture_fault(GetExceptionInformation(), c)) { | 211 | } __except (capture_fault(GetExceptionInformation(), c)) { |
| 209 | c.faulted = true; | 212 | c.faulted = true; |
| 210 | } | 213 | } |
| 211 | return c; | 214 | return Call(c); |
| 212 | } | 215 | } |
| 213 | 216 | ||
| 214 | // PC stand-in for one console capability. The console build creates a DXGI_FORMAT_R9G9B9E5_SHAREDEXP texture with | 217 | // PC stand-in for one console capability. The console build creates a DXGI_FORMAT_R9G9B9E5_SHAREDEXP texture with |
diff --git a/runtime/test/gameinput_probe.cpp b/runtime/test/gameinput_probe.cpp index 32ddf5d91..a56132ed5 100644 --- a/runtime/test/gameinput_probe.cpp +++ b/runtime/test/gameinput_probe.cpp | |||
| @@ -26,8 +26,10 @@ std::vector<IGameInputDevice*> g_devices; | |||
| 26 | 26 | ||
| 27 | void CALLBACK on_device(GameInputCallbackToken, void*, IGameInputDevice* device, uint64_t, uint32_t current, uint32_t previous) { | 27 | void CALLBACK on_device(GameInputCallbackToken, void*, IGameInputDevice* device, uint64_t, uint32_t current, uint32_t previous) { |
| 28 | const GameInputDeviceInfo* i = device->GetDeviceInfo(); | 28 | const GameInputDeviceInfo* i = device->GetDeviceInfo(); |
| 29 | std::printf("\n%s %s (%04x:%04x) motors=0x%x\n", (current & GameInputDeviceConnected) ? "connected " : "disconnected", | 29 | std::printf("\n%s %s (%04x:%04x) motors=0x%x forcefeedback=%u haptic=%u\n", |
| 30 | i->displayName ? i->displayName->data : "?", i->vendorId, i->productId, i->supportedRumbleMotors); | 30 | (current & GameInputDeviceConnected) ? "connected " : "disconnected", |
| 31 | i->displayName ? i->displayName->data : "?", i->vendorId, i->productId, i->supportedRumbleMotors, | ||
| 32 | i->forceFeedbackMotorCount, i->hapticFeedbackMotorCount); | ||
| 31 | if ((current & GameInputDeviceConnected) && !(previous & GameInputDeviceConnected)) { | 33 | if ((current & GameInputDeviceConnected) && !(previous & GameInputDeviceConnected)) { |
| 32 | device->AddRef(); | 34 | device->AddRef(); |
| 33 | g_devices.push_back(device); | 35 | g_devices.push_back(device); |
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index a65b444a1..99e74a082 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp | |||
| @@ -130,8 +130,11 @@ void CALLBACK on_device(GameInputCallbackToken token, void*, IGameInputDevice* d | |||
| 130 | uint32_t previous) { | 130 | uint32_t previous) { |
| 131 | g_device_events.push_back({device, current, previous, token}); | 131 | g_device_events.push_back({device, current, previous, token}); |
| 132 | } | 132 | } |
| 133 | DWORD g_reading_sleep_ms = 0; // makes on_reading slow, for the Dispatch quota checks | ||
| 134 | |||
| 133 | void CALLBACK on_reading(GameInputCallbackToken, void*, IGameInputReading* reading, bool) { | 135 | void CALLBACK on_reading(GameInputCallbackToken, void*, IGameInputReading* reading, bool) { |
| 134 | if (reading) ++g_reading_events; | 136 | if (reading) ++g_reading_events; |
| 137 | if (g_reading_sleep_ms) Sleep(g_reading_sleep_ms); | ||
| 135 | } | 138 | } |
| 136 | void CALLBACK on_guide(GameInputCallbackToken, void*, IGameInputDevice*, uint64_t, bool pressed) { | 139 | void CALLBACK on_guide(GameInputCallbackToken, void*, IGameInputDevice*, uint64_t, bool pressed) { |
| 137 | g_guide_events.push_back(pressed); | 140 | g_guide_events.push_back(pressed); |
| @@ -763,6 +766,324 @@ void test_twins(IGameInput* input) { | |||
| 763 | check(rt::gameinput::connected_count() == 0, "twins: removed at the end"); | 766 | check(rt::gameinput::connected_count() == 0, "twins: removed at the end"); |
| 764 | } | 767 | } |
| 765 | 768 | ||
| 769 | // ---- force feedback and haptic motors: a fake SDL haptic backend ---- | ||
| 770 | // SDL's virtual joysticks report no haptics, so the shim's haptic calls go through this table instead. It records what | ||
| 771 | // the shim asked SDL to do and reports the capabilities a force-feedback wheel has. | ||
| 772 | struct FakeHaptic { | ||
| 773 | uint32_t features = SDL_HAPTIC_CONSTANT | SDL_HAPTIC_SINE | SDL_HAPTIC_SQUARE | SDL_HAPTIC_TRIANGLE | | ||
| 774 | SDL_HAPTIC_SAWTOOTHUP | SDL_HAPTIC_SAWTOOTHDOWN | SDL_HAPTIC_RAMP | SDL_HAPTIC_SPRING | | ||
| 775 | SDL_HAPTIC_FRICTION | SDL_HAPTIC_DAMPER | SDL_HAPTIC_INERTIA; | ||
| 776 | int max_effects = 8; | ||
| 777 | int opens = 0, closes = 0, creates = 0, updates = 0, runs = 0, stops = 0, destroys = 0; | ||
| 778 | int gain_calls = 0, last_gain = -1; | ||
| 779 | uint32_t last_iterations = 0; | ||
| 780 | SDL_HapticEffect last{}; | ||
| 781 | }; | ||
| 782 | FakeHaptic g_fake; | ||
| 783 | bool g_fake_open = false; // pads attached while this is set are opened as haptic devices | ||
| 784 | |||
| 785 | void* fake_open(void*) { | ||
| 786 | if (!g_fake_open) return nullptr; | ||
| 787 | ++g_fake.opens; | ||
| 788 | return &g_fake; | ||
| 789 | } | ||
| 790 | void fake_close(void*) { ++g_fake.closes; } | ||
| 791 | uint32_t fake_features(void* h) { return static_cast<FakeHaptic*>(h)->features; } | ||
| 792 | int fake_max_effects(void* h) { return static_cast<FakeHaptic*>(h)->max_effects; } | ||
| 793 | int fake_create(void* h, const void* e) { | ||
| 794 | FakeHaptic* f = static_cast<FakeHaptic*>(h); | ||
| 795 | ++f->creates; | ||
| 796 | f->last = *static_cast<const SDL_HapticEffect*>(e); | ||
| 797 | return 1; | ||
| 798 | } | ||
| 799 | bool fake_update(void* h, int, const void* e) { | ||
| 800 | FakeHaptic* f = static_cast<FakeHaptic*>(h); | ||
| 801 | ++f->updates; | ||
| 802 | f->last = *static_cast<const SDL_HapticEffect*>(e); | ||
| 803 | return true; | ||
| 804 | } | ||
| 805 | bool fake_run(void* h, int, uint32_t iterations) { | ||
| 806 | FakeHaptic* f = static_cast<FakeHaptic*>(h); | ||
| 807 | ++f->runs; | ||
| 808 | f->last_iterations = iterations; | ||
| 809 | return true; | ||
| 810 | } | ||
| 811 | bool fake_stop(void* h, int) { | ||
| 812 | ++static_cast<FakeHaptic*>(h)->stops; | ||
| 813 | return true; | ||
| 814 | } | ||
| 815 | void fake_destroy(void* h, int) { ++static_cast<FakeHaptic*>(h)->destroys; } | ||
| 816 | bool fake_gain(void* h, int gain) { | ||
| 817 | FakeHaptic* f = static_cast<FakeHaptic*>(h); | ||
| 818 | ++f->gain_calls; | ||
| 819 | f->last_gain = gain; | ||
| 820 | return true; | ||
| 821 | } | ||
| 822 | const rt::gameinput::HapticApi kFakeHaptic{fake_open, fake_close, fake_features, fake_max_effects, fake_create, | ||
| 823 | fake_update, fake_run, fake_stop, fake_destroy, fake_gain}; | ||
| 824 | |||
| 825 | // The motors of one device, and the effect object its force-feedback motor hands out. Runs with no other pad. | ||
| 826 | void test_force_feedback(IGameInput* input) { | ||
| 827 | rt::gameinput::set_haptic_source(&kFakeHaptic); | ||
| 828 | g_fake = {}; | ||
| 829 | g_fake_open = true; | ||
| 830 | Pad wheel; | ||
| 831 | attach(wheel, "Leonida virtual wheel", 0x046D, 0xC24F, false); | ||
| 832 | const size_t before = g_device_events.size(); | ||
| 833 | rt::gameinput::poll(); | ||
| 834 | IGameInputDevice* dev = g_device_events.size() > before ? g_device_events.back().device : nullptr; | ||
| 835 | check(dev && rt::gameinput::connected_count() == 1 && g_fake.opens == 1, | ||
| 836 | "force feedback: the pad's joystick is opened as an SDL haptic device"); | ||
| 837 | if (!dev) return; | ||
| 838 | dev->AddRef(); | ||
| 839 | rt::gameinput::OutputState out{}; | ||
| 840 | check(rt::gameinput::output_state(0, &out) && out.force_feedback, "force feedback: the output state says so"); | ||
| 841 | IGameInputReading* r = current(input, dev); | ||
| 842 | check(r != nullptr, "force feedback: the pad still reads normally with a haptic device open"); | ||
| 843 | if (r) r->Release(); | ||
| 844 | |||
| 845 | const GameInputDeviceInfo* info = dev->GetDeviceInfo(); | ||
| 846 | check(info->forceFeedbackMotorCount == 1 && info->forceFeedbackMotorInfo != nullptr, | ||
| 847 | "force feedback: the device reports one force-feedback motor"); | ||
| 848 | const GameInputForceFeedbackMotorInfo* motor = | ||
| 849 | static_cast<const GameInputForceFeedbackMotorInfo*>(info->forceFeedbackMotorInfo); | ||
| 850 | check(motor->supportedAxes == GameInputFeedbackAxisLinearX && motor->location == GameInputLocationChassis && | ||
| 851 | motor->maxSimultaneousEffects == 8, | ||
| 852 | "force feedback: motorInfo carries the axis, the location and the effect limit"); | ||
| 853 | check(motor->isConstantEffectSupported && motor->isRampEffectSupported && motor->isSpringEffectSupported && | ||
| 854 | motor->isSawtoothDownWaveEffectSupported, | ||
| 855 | "force feedback: the effect kinds come from SDL's feature bits"); | ||
| 856 | check(info->hapticFeedbackMotorCount == 0, "force feedback: a wheel without trigger motors reports no haptics"); | ||
| 857 | check(dev->IsForceFeedbackMotorPoweredOn(0) && !dev->IsForceFeedbackMotorPoweredOn(1), | ||
| 858 | "force feedback: motor 0 is powered on, and motor 1 does not exist"); | ||
| 859 | |||
| 860 | IGameInputForceFeedbackEffect* effect = nullptr; | ||
| 861 | GameInputForceFeedbackParams params{}; | ||
| 862 | params.kind = GameInputForceFeedbackConstant; | ||
| 863 | params.data.constant.magnitude.linearX = 0.5f; | ||
| 864 | check(dev->CreateForceFeedbackEffect(1, ¶ms, reinterpret_cast<void**>(&effect)) == E_INVALIDARG && !effect, | ||
| 865 | "force feedback: motor 1 does not exist"); | ||
| 866 | check(dev->CreateForceFeedbackEffect(0, ¶ms, nullptr) == E_POINTER, "force feedback: a null effect is E_POINTER"); | ||
| 867 | check(dev->CreateForceFeedbackEffect(0, nullptr, reinterpret_cast<void**>(&effect)) == E_INVALIDARG, | ||
| 868 | "force feedback: null parameters are E_INVALIDARG"); | ||
| 869 | GameInputForceFeedbackParams unknown{}; | ||
| 870 | unknown.kind = static_cast<GameInputForceFeedbackEffectKind>(11); | ||
| 871 | check(dev->CreateForceFeedbackEffect(0, &unknown, reinterpret_cast<void**>(&effect)) == E_INVALIDARG, | ||
| 872 | "force feedback: an effect kind outside the enum is E_INVALIDARG"); | ||
| 873 | check(dev->CreateForceFeedbackEffect(0, ¶ms, reinterpret_cast<void**>(&effect)) == S_OK && effect, | ||
| 874 | "force feedback: CreateForceFeedbackEffect"); | ||
| 875 | if (!effect) { // leave nothing behind for the next test | ||
| 876 | detach(wheel); | ||
| 877 | dev->Release(); | ||
| 878 | rt::gameinput::poll(); | ||
| 879 | rt::gameinput::set_haptic_source(nullptr); | ||
| 880 | return; | ||
| 881 | } | ||
| 882 | check(effect->GetMotorIndex() == 0 && approx(effect->GetGain(), 1.0f) && effect->GetState() == GameInputFeedbackRunning, | ||
| 883 | "force feedback: a new effect is on motor 0, at full gain, running"); | ||
| 884 | IGameInputDevice* owner = nullptr; | ||
| 885 | effect->GetDevice(&owner); | ||
| 886 | check(owner == dev, "force feedback: the effect names its device"); | ||
| 887 | if (owner) owner->Release(); | ||
| 888 | |||
| 889 | // Nothing is asked of SDL before the poll thread runs: the title only wrote the parameters. | ||
| 890 | const int runs0 = g_fake.runs; | ||
| 891 | rt::gameinput::poll(); | ||
| 892 | check(g_fake.creates == 1 && g_fake.runs == runs0 + 1, "force feedback: the poll thread creates and runs the effect"); | ||
| 893 | check(g_fake.last.type == SDL_HAPTIC_CONSTANT && g_fake.last.constant.level == 16384, | ||
| 894 | "force feedback: a constant 0.5 becomes SDL_HAPTIC_CONSTANT level 16384"); | ||
| 895 | check(g_fake.last.constant.length == 60000 && g_fake.last_iterations == 0, | ||
| 896 | "force feedback: no duration in GameInput is SDL's 60 s hold, run until stopped"); | ||
| 897 | rt::gameinput::poll(); | ||
| 898 | check(g_fake.runs == runs0 + 1, "force feedback: an unchanged effect is not re-sent every poll"); | ||
| 899 | |||
| 900 | params.data.constant.magnitude.linearX = -1.0f; | ||
| 901 | check(effect->SetParams(¶ms), "force feedback: SetParams"); | ||
| 902 | rt::gameinput::poll(); | ||
| 903 | check(g_fake.updates == 1 && g_fake.runs == runs0 + 2 && g_fake.last.constant.level == -32767, | ||
| 904 | "force feedback: changed parameters update the SDL effect once"); | ||
| 905 | GameInputForceFeedbackParams read{}; | ||
| 906 | effect->GetParams(&read); | ||
| 907 | check(read.kind == GameInputForceFeedbackConstant && read.data.constant.magnitude.linearX == -1.0f, | ||
| 908 | "force feedback: GetParams returns what was set"); | ||
| 909 | |||
| 910 | effect->SetGain(0.5f); | ||
| 911 | rt::gameinput::poll(); | ||
| 912 | check(approx(effect->GetGain(), 0.5f) && g_fake.last.constant.level == -16384, | ||
| 913 | "force feedback: the effect's gain scales the SDL level"); | ||
| 914 | // The device gain is SDL's, sent once when the pad is opened (100) and once per change. | ||
| 915 | check(g_fake.last_gain == 100 && g_fake.gain_calls == 1, "force feedback: the device gain starts at SDL's full 100"); | ||
| 916 | dev->SetForceFeedbackMotorGain(0, 0.5f); | ||
| 917 | rt::gameinput::poll(); | ||
| 918 | check(g_fake.last_gain == 50 && g_fake.gain_calls == 2, | ||
| 919 | "force feedback: SetForceFeedbackMotorGain sets SDL's device gain once"); | ||
| 920 | dev->SetForceFeedbackMotorGain(0, 1.0f); | ||
| 921 | effect->SetGain(1.0f); | ||
| 922 | rt::gameinput::poll(); | ||
| 923 | check(g_fake.last_gain == 100, "force feedback: the master gain follows the request"); | ||
| 924 | |||
| 925 | // A wave with GameInput's envelope: 50 Hz for 90 degrees over 100 ms, played once. | ||
| 926 | GameInputForceFeedbackParams wave{}; | ||
| 927 | wave.kind = GameInputForceFeedbackSineWave; | ||
| 928 | wave.data.sineWave.envelope.sustainDuration = 100'000; // microseconds | ||
| 929 | wave.data.sineWave.envelope.sustainGain = 1.0f; | ||
| 930 | wave.data.sineWave.envelope.playCount = 1; | ||
| 931 | wave.data.sineWave.magnitude.linearX = 1.0f; | ||
| 932 | wave.data.sineWave.frequency = 50.0f; | ||
| 933 | wave.data.sineWave.phase = 90.0f; | ||
| 934 | check(effect->SetParams(&wave), "force feedback: SetParams for a sine wave"); | ||
| 935 | rt::gameinput::poll(); | ||
| 936 | check(g_fake.last.type == SDL_HAPTIC_SINE && g_fake.last.periodic.period == 20 && | ||
| 937 | g_fake.last.periodic.magnitude == 32767 && g_fake.last.periodic.phase == 9000, | ||
| 938 | "force feedback: a 50 Hz sine with a 90 degree phase becomes SDL's period and hundredths of a degree"); | ||
| 939 | check(g_fake.last.periodic.length == 100 && g_fake.last_iterations == 1, | ||
| 940 | "force feedback: the envelope's 100 ms is SDL's length and its playCount the iteration count"); | ||
| 941 | Sleep(130); | ||
| 942 | rt::gameinput::poll(); | ||
| 943 | check(effect->GetState() == GameInputFeedbackStopped && g_fake.stops >= 1, | ||
| 944 | "force feedback: an effect that ran its duration reports stopped"); | ||
| 945 | |||
| 946 | // A condition effect: coefficients, saturations, dead zone and centre. | ||
| 947 | GameInputForceFeedbackParams spring{}; | ||
| 948 | spring.kind = GameInputForceFeedbackSpring; | ||
| 949 | spring.data.spring.magnitude.linearX = 0.5f; | ||
| 950 | spring.data.spring.positiveCoefficient = 0.5f; | ||
| 951 | spring.data.spring.negativeCoefficient = 0.25f; | ||
| 952 | spring.data.spring.maxPositiveMagnitude = 1.0f; | ||
| 953 | spring.data.spring.maxNegativeMagnitude = 0.5f; | ||
| 954 | spring.data.spring.deadZone = 0.1f; | ||
| 955 | check(effect->SetParams(&spring), "force feedback: SetParams for a spring"); | ||
| 956 | effect->SetState(GameInputFeedbackRunning); | ||
| 957 | rt::gameinput::poll(); | ||
| 958 | check(g_fake.last.type == SDL_HAPTIC_SPRING && g_fake.last.condition.right_coeff[0] == 16384 && | ||
| 959 | g_fake.last.condition.left_coeff[0] == -8192 && g_fake.last.condition.right_sat[0] == 65535 && | ||
| 960 | g_fake.last.condition.left_sat[0] == 32768 && g_fake.last.condition.deadband[0] == 6554 && | ||
| 961 | g_fake.last.condition.center[0] == 16384, | ||
| 962 | "force feedback: a spring maps its coefficients, saturations, dead zone and centre"); | ||
| 963 | |||
| 964 | effect->SetState(GameInputFeedbackPaused); | ||
| 965 | const int stops0 = g_fake.stops; | ||
| 966 | rt::gameinput::poll(); | ||
| 967 | check(g_fake.stops == stops0 + 1 && effect->GetState() == GameInputFeedbackPaused, | ||
| 968 | "force feedback: a paused effect is stopped in SDL"); | ||
| 969 | |||
| 970 | // LEONIDA_RUMBLE=0 silences this path too: a running effect is stopped, and it runs again when the mute lifts. | ||
| 971 | effect->SetState(GameInputFeedbackRunning); | ||
| 972 | rt::gameinput::poll(); | ||
| 973 | const int runs1 = g_fake.runs, stops1 = g_fake.stops; | ||
| 974 | check(g_fake.runs == runs1, "force feedback: the effect is running before the mute"); | ||
| 975 | set_env("LEONIDA_RUMBLE", "0"); | ||
| 976 | rt::gameinput::reload_config(); | ||
| 977 | rt::gameinput::poll(); | ||
| 978 | check(g_fake.runs == runs1 && g_fake.stops == stops1 + 1, "force feedback: LEONIDA_RUMBLE=0 stops the effect"); | ||
| 979 | set_env("LEONIDA_RUMBLE", nullptr); | ||
| 980 | rt::gameinput::reload_config(); | ||
| 981 | rt::gameinput::poll(); | ||
| 982 | check(g_fake.runs == runs1 + 1, "force feedback: and it runs again once the mute is lifted"); | ||
| 983 | |||
| 984 | check(effect->Release() == 0, "force feedback: the effect is freed once the title releases it"); | ||
| 985 | rt::gameinput::poll(); | ||
| 986 | check(g_fake.destroys == 1, "force feedback: its SDL effect is destroyed on the poll thread"); | ||
| 987 | |||
| 988 | detach(wheel); | ||
| 989 | rt::gameinput::poll(); | ||
| 990 | check(g_fake.closes == 1 && !dev->IsForceFeedbackMotorPoweredOn(0), | ||
| 991 | "force feedback: unplugging closes the haptic device"); | ||
| 992 | dev->Release(); | ||
| 993 | |||
| 994 | // A pad SDL opens no haptic device for keeps the old answer: no motor, and no effect. | ||
| 995 | g_fake_open = false; | ||
| 996 | Pad plain; | ||
| 997 | attach(plain, "Leonida virtual plain pad", 0x045E, 0x02FF, false); | ||
| 998 | const size_t plain_before = g_device_events.size(); | ||
| 999 | rt::gameinput::poll(); | ||
| 1000 | IGameInputDevice* plaindev = g_device_events.size() > plain_before ? g_device_events.back().device : nullptr; | ||
| 1001 | check(plaindev && plaindev->GetDeviceInfo()->forceFeedbackMotorCount == 0 && | ||
| 1002 | plaindev->GetDeviceInfo()->forceFeedbackMotorInfo == nullptr, | ||
| 1003 | "force feedback: a pad without SDL haptics reports no motor"); | ||
| 1004 | if (plaindev) { | ||
| 1005 | effect = nullptr; | ||
| 1006 | check(plaindev->CreateForceFeedbackEffect(0, ¶ms, reinterpret_cast<void**>(&effect)) == E_INVALIDARG && !effect, | ||
| 1007 | "force feedback: so CreateForceFeedbackEffect is E_INVALIDARG"); | ||
| 1008 | check(!plaindev->IsForceFeedbackMotorPoweredOn(0), "force feedback: and no motor is powered on"); | ||
| 1009 | } | ||
| 1010 | detach(plain); | ||
| 1011 | rt::gameinput::poll(); | ||
| 1012 | rt::gameinput::set_haptic_source(nullptr); | ||
| 1013 | } | ||
| 1014 | |||
| 1015 | // The trigger haptic motors of a pad that has them. Runs with no other pad. | ||
| 1016 | void test_haptic_motors(IGameInput* input) { | ||
| 1017 | set_env("LEONIDA_DS_TRIGGERS", nullptr); | ||
| 1018 | rt::gameinput::reload_config(); | ||
| 1019 | Pad xbox; | ||
| 1020 | attach(xbox, "Leonida virtual Xbox pad", 0x045E, 0x0B12, true); | ||
| 1021 | const size_t before = g_device_events.size(); | ||
| 1022 | rt::gameinput::poll(); | ||
| 1023 | IGameInputDevice* dev = g_device_events.size() > before ? g_device_events.back().device : nullptr; | ||
| 1024 | check(dev && rt::gameinput::connected_count() == 1, "haptics: the pad with trigger motors is connected"); | ||
| 1025 | if (!dev) return; | ||
| 1026 | dev->AddRef(); | ||
| 1027 | const GameInputDeviceInfo* info = dev->GetDeviceInfo(); | ||
| 1028 | check(info->hapticFeedbackMotorCount == 2 && info->hapticFeedbackMotorInfo != nullptr, | ||
| 1029 | "haptics: the pad reports two haptic motors"); | ||
| 1030 | const GameInputHapticFeedbackMotorInfo* motors = | ||
| 1031 | static_cast<const GameInputHapticFeedbackMotorInfo*>(info->hapticFeedbackMotorInfo); | ||
| 1032 | check(motors[0].mappedRumbleMotors == GameInputRumbleLeftTrigger && | ||
| 1033 | motors[1].mappedRumbleMotors == GameInputRumbleRightTrigger && motors[0].waveformCount == 1 && | ||
| 1034 | motors[0].waveformInfo != nullptr && motors[0].waveformInfo->isIntensitySupported, | ||
| 1035 | "haptics: they are the left and right trigger, one waveform each, an intensity"); | ||
| 1036 | check(sticks_at_rest(pad_state(input, dev)), "haptics: the pad still reads normally"); | ||
| 1037 | |||
| 1038 | GameInputHapticFeedbackParams p{}; | ||
| 1039 | p.intensity = 0.5f; | ||
| 1040 | p.duration = 100'000; // microseconds | ||
| 1041 | p.playCount = 1; | ||
| 1042 | check(dev->SetHapticMotorState(2, &p) == E_INVALIDARG, "haptics: motor 2 does not exist"); | ||
| 1043 | GameInputHapticFeedbackParams other_wave = p; | ||
| 1044 | other_wave.waveformIndex = 1; | ||
| 1045 | check(dev->SetHapticMotorState(0, &other_wave) == E_INVALIDARG, "haptics: waveform 1 does not exist"); | ||
| 1046 | check(dev->SetHapticMotorState(0, &p) == S_OK, "haptics: SetHapticMotorState on the left trigger"); | ||
| 1047 | rt::gameinput::poll(); | ||
| 1048 | check(xbox.left == 32768 && xbox.right == 0, "haptics: the intensity reaches the trigger motor"); | ||
| 1049 | Sleep(130); | ||
| 1050 | rt::gameinput::poll(); | ||
| 1051 | check(xbox.left == 0, "haptics: the request ends with its duration"); | ||
| 1052 | |||
| 1053 | p.intensity = 1.0f; | ||
| 1054 | p.playCount = 0; // until changed | ||
| 1055 | check(dev->SetHapticMotorState(1, &p) == S_OK, "haptics: playCount 0 plays until changed"); | ||
| 1056 | rt::gameinput::poll(); | ||
| 1057 | check(xbox.right == 65535 && xbox.left == 0, "haptics: the right trigger takes its own motor"); | ||
| 1058 | Sleep(130); | ||
| 1059 | rt::gameinput::poll(); | ||
| 1060 | check(xbox.right == 65535, "haptics: and keeps playing past the duration"); | ||
| 1061 | check(dev->SetHapticMotorState(1, nullptr) == S_OK, "haptics: a null state stops the motor"); | ||
| 1062 | rt::gameinput::poll(); | ||
| 1063 | check(xbox.right == 0 && xbox.left == 0, "haptics: both triggers are silent again"); | ||
| 1064 | |||
| 1065 | // SetRumbleState still works on the same pad, and the two share the trigger output. | ||
| 1066 | GameInputRumbleParams rumble{0, 0, 0.25f, 0}; | ||
| 1067 | dev->SetRumbleState(&rumble); | ||
| 1068 | rt::gameinput::poll(); | ||
| 1069 | check(xbox.left == 16384, "haptics: SetRumbleState still drives the trigger motor"); | ||
| 1070 | p.intensity = 1.0f; | ||
| 1071 | p.playCount = 1; | ||
| 1072 | p.duration = 0; // no deadline at playCount 1 either: the level holds until it is set again | ||
| 1073 | dev->SetHapticMotorState(0, &p); | ||
| 1074 | rt::gameinput::poll(); | ||
| 1075 | check(xbox.left == 65535, "haptics: the stronger of the two wins on one trigger"); | ||
| 1076 | dev->SetRumbleState(nullptr); | ||
| 1077 | dev->SetHapticMotorState(0, nullptr); | ||
| 1078 | rt::gameinput::poll(); | ||
| 1079 | check(xbox.left == 0, "haptics: releasing both leaves the trigger silent"); | ||
| 1080 | |||
| 1081 | detach(xbox); | ||
| 1082 | rt::gameinput::poll(); | ||
| 1083 | check(rt::gameinput::connected_count() == 0, "haptics: detached"); | ||
| 1084 | dev->Release(); | ||
| 1085 | } | ||
| 1086 | |||
| 766 | } // namespace | 1087 | } // namespace |
| 767 | 1088 | ||
| 768 | int main() { | 1089 | int main() { |
| @@ -1024,6 +1345,32 @@ int main() { | |||
| 1024 | check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled"); | 1345 | check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled"); |
| 1025 | if (dispatcher) dispatcher->Dispatch(1000); | 1346 | if (dispatcher) dispatcher->Dispatch(1000); |
| 1026 | check(g_reading_events > before_dispatch, "Dispatch runs them"); | 1347 | check(g_reading_events > before_dispatch, "Dispatch runs them"); |
| 1348 | |||
| 1349 | // The quota: Dispatch runs at least one queued event, takes no more once the quota has passed, and returns whether | ||
| 1350 | // events remain (re-signalling the wait handle). Four button changes queue four reading events. | ||
| 1351 | auto queue_changes = [&](int n) { | ||
| 1352 | for (int i = 0; i < n; ++i) { | ||
| 1353 | SDL_SetJoystickVirtualButton(xbox.js, SDL_GAMEPAD_BUTTON_NORTH, i % 2 == 1); // NORTH is down now: up, down, up, down | ||
| 1354 | rt::gameinput::poll(); | ||
| 1355 | } | ||
| 1356 | }; | ||
| 1357 | if (dispatcher) { | ||
| 1358 | while (dispatcher->Dispatch(UINT64_MAX)) {} | ||
| 1359 | queue_changes(4); | ||
| 1360 | int before_quota = g_reading_events; | ||
| 1361 | if (wait) WaitForSingleObject(wait, 0); // consume the signal from queueing | ||
| 1362 | check(dispatcher->Dispatch(0) && g_reading_events == before_quota + 1, "Dispatch(0) runs exactly one event and reports more"); | ||
| 1363 | check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled again while events remain"); | ||
| 1364 | g_reading_sleep_ms = 5; | ||
| 1365 | before_quota = g_reading_events; | ||
| 1366 | check(dispatcher->Dispatch(1000) && g_reading_events == before_quota + 1, | ||
| 1367 | "a 1 ms quota stops after a 5 ms callback and reports more"); | ||
| 1368 | g_reading_sleep_ms = 0; | ||
| 1369 | before_quota = g_reading_events; | ||
| 1370 | check(!dispatcher->Dispatch(1'000'000) && g_reading_events >= before_quota + 2, | ||
| 1371 | "a large quota drains the queue and returns false"); | ||
| 1372 | check(!dispatcher->Dispatch(0), "Dispatch on an empty queue returns false"); | ||
| 1373 | } | ||
| 1027 | if (wait) CloseHandle(wait); | 1374 | if (wait) CloseHandle(wait); |
| 1028 | if (dispatcher) dispatcher->Release(); | 1375 | if (dispatcher) dispatcher->Release(); |
| 1029 | 1376 | ||
| @@ -1226,6 +1573,8 @@ int main() { | |||
| 1226 | test_keyboard_pad(input); | 1573 | test_keyboard_pad(input); |
| 1227 | test_motion(input); | 1574 | test_motion(input); |
| 1228 | test_aggregate_device(input); | 1575 | test_aggregate_device(input); |
| 1576 | test_force_feedback(input); | ||
| 1577 | test_haptic_motors(input); | ||
| 1229 | input->Release(); | 1578 | input->Release(); |
| 1230 | 1579 | ||
| 1231 | std::printf("%d checks, %d failures\n", g_checks, g_failures); | 1580 | std::printf("%d checks, %d failures\n", g_checks, g_failures); |
diff --git a/runtime/test/gfx10_tiling_test.cpp b/runtime/test/gfx10_tiling_test.cpp new file mode 100644 index 000000000..fd0d14779 --- /dev/null +++ b/runtime/test/gfx10_tiling_test.cpp | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | #include "../src/gfx10_tiling.h" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <array> | ||
| 5 | #include <cstdio> | ||
| 6 | #include <limits> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #define CHECK(condition) do { \ | ||
| 10 | if (!(condition)) { \ | ||
| 11 | std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); \ | ||
| 12 | return 1; \ | ||
| 13 | } \ | ||
| 14 | } while (0) | ||
| 15 | |||
| 16 | using leonida::gfx10::TileMode; | ||
| 17 | using leonida::gfx10::TiledSurface2D; | ||
| 18 | |||
| 19 | int check_surface(TileMode mode, std::size_t bpe, std::size_t width, std::size_t height) { | ||
| 20 | TiledSurface2D surface; | ||
| 21 | CHECK(TiledSurface2D::make(mode, bpe, width, height, surface)); | ||
| 22 | const auto bw = surface.tile_width(), bh = surface.tile_height(); | ||
| 23 | const auto pw = (width + bw - 1) / bw * bw, ph = (height + bh - 1) / bh * bh; | ||
| 24 | CHECK(surface.tiled_size() == pw * ph * bpe); | ||
| 25 | TiledSurface2D padded; | ||
| 26 | CHECK(TiledSurface2D::make(mode, bpe, pw, ph, padded)); | ||
| 27 | std::vector<bool> seen(surface.tiled_size()); | ||
| 28 | for (std::size_t y = 0; y < ph; ++y) { | ||
| 29 | for (std::size_t x = 0; x < pw; ++x) { | ||
| 30 | std::size_t offset; | ||
| 31 | CHECK(padded.element_offset(x, y, offset)); | ||
| 32 | CHECK(offset % bpe == 0 && offset <= seen.size() - bpe); | ||
| 33 | for (std::size_t byte = 0; byte < bpe; ++byte) { | ||
| 34 | CHECK(!seen[offset + byte]); | ||
| 35 | seen[offset + byte] = true; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | CHECK(std::all_of(seen.begin(), seen.end(), [](bool value) { return value; })); | ||
| 40 | |||
| 41 | const std::size_t row_bytes = width * bpe; | ||
| 42 | for (const auto pitch : {row_bytes, row_bytes + 13}) { | ||
| 43 | const std::size_t linear_size = (height - 1) * pitch + row_bytes; | ||
| 44 | std::vector<std::byte> linear(linear_size), tiled(surface.tiled_size(), std::byte{0xcc}); | ||
| 45 | for (std::size_t i = 0; i < linear.size(); ++i) linear[i] = std::byte((i * 37 + i / 251) & 255); | ||
| 46 | std::vector<std::byte> decoded(linear_size, std::byte{0xab}); | ||
| 47 | CHECK(surface.tile(linear, tiled, pitch)); | ||
| 48 | CHECK(surface.detile(tiled, decoded, pitch)); | ||
| 49 | std::vector<std::byte> expected(linear_size, std::byte{0xab}); | ||
| 50 | for (std::size_t y = 0; y < height; ++y) | ||
| 51 | std::copy_n(linear.begin() + y * pitch, row_bytes, expected.begin() + y * pitch); | ||
| 52 | CHECK(decoded == expected); | ||
| 53 | std::vector<std::byte> reference(linear_size, std::byte{0xab}); | ||
| 54 | for (std::size_t y = 0; y < height; ++y) { | ||
| 55 | for (std::size_t x = 0; x < width; ++x) { | ||
| 56 | std::size_t offset; | ||
| 57 | CHECK(surface.element_offset(x, y, offset)); | ||
| 58 | std::copy_n(tiled.begin() + offset, bpe, reference.begin() + y * pitch + x * bpe); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | CHECK(decoded == reference); | ||
| 62 | std::vector<std::byte> encoded(tiled.size(), std::byte{0xcc}); | ||
| 63 | CHECK(surface.tile(decoded, encoded, pitch)); | ||
| 64 | CHECK(encoded == tiled); | ||
| 65 | std::vector<bool> active(tiled.size()); | ||
| 66 | for (std::size_t y = 0; y < height; ++y) { | ||
| 67 | for (std::size_t x = 0; x < width; ++x) { | ||
| 68 | std::size_t offset; | ||
| 69 | CHECK(surface.element_offset(x, y, offset)); | ||
| 70 | for (std::size_t byte = 0; byte < bpe; ++byte) { | ||
| 71 | CHECK(tiled[offset + byte] == linear[y * pitch + x * bpe + byte]); | ||
| 72 | active[offset + byte] = true; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | for (std::size_t i = 0; i < tiled.size(); ++i) CHECK(active[i] || tiled[i] == std::byte{0xcc}); | ||
| 77 | |||
| 78 | const auto before_tiled = tiled, before_decoded = decoded; | ||
| 79 | CHECK(!surface.tile(std::span(linear).first(linear_size - 1), tiled, pitch)); | ||
| 80 | CHECK(!surface.tile(linear, std::span(tiled).first(tiled.size() - 1), pitch)); | ||
| 81 | CHECK(!surface.detile(std::span(tiled).first(tiled.size() - 1), decoded, pitch)); | ||
| 82 | CHECK(!surface.detile(tiled, std::span(decoded).first(linear_size - 1), pitch)); | ||
| 83 | CHECK(!surface.tile(linear, tiled, row_bytes - 1)); | ||
| 84 | CHECK(!surface.detile(tiled, decoded, row_bytes - 1)); | ||
| 85 | CHECK(!surface.tile({}, tiled, pitch)); | ||
| 86 | CHECK(!surface.detile(tiled, {}, pitch)); | ||
| 87 | CHECK(tiled == before_tiled && decoded == before_decoded); | ||
| 88 | } | ||
| 89 | std::size_t offset = 123; | ||
| 90 | CHECK(!surface.element_offset(width, 0, offset)); | ||
| 91 | CHECK(!surface.element_offset(0, height, offset)); | ||
| 92 | CHECK(offset == 123); | ||
| 93 | std::vector<std::byte> shared(std::max(surface.tiled_size(), width * height * bpe) + 1); | ||
| 94 | const auto before = shared; | ||
| 95 | CHECK(!surface.tile(shared, shared, row_bytes)); | ||
| 96 | CHECK(!surface.detile(shared, shared, row_bytes)); | ||
| 97 | CHECK(!surface.tile(std::span(shared).subspan(1), std::span(shared).first(shared.size() - 1), row_bytes)); | ||
| 98 | CHECK(!surface.detile(std::span(shared).first(shared.size() - 1), std::span(shared).subspan(1), row_bytes)); | ||
| 99 | CHECK(shared == before); | ||
| 100 | return 0; | ||
| 101 | } | ||
| 102 | |||
| 103 | int main() { | ||
| 104 | // Source byte offsets reconstructed by calling ttpf_mips.detile on synthetic address-labelled bytes, | ||
| 105 | // three passes (address >> 0/8/16). Extent 300x130; points (4,4), (32,16), (299,129). | ||
| 106 | constexpr std::size_t answers[2][5][3] = { | ||
| 107 | {{68, 2304, 59419}, {72, 3072, 100502}, {192, 5120, 201244}, | ||
| 108 | {384, 45056, 365144}, {768, 86016, 698576}}, | ||
| 109 | {{36, 2304, 84051}, {72, 3072, 198806}, {192, 9216, 336412}, | ||
| 110 | {320, 12288, 533048}, {768, 36864, 952432}}}; | ||
| 111 | constexpr std::array<std::array<std::size_t, 2>, 3> points{{{4, 4}, {32, 16}, {299, 129}}}; | ||
| 112 | unsigned mode_index = 0; | ||
| 113 | for (const auto mode : {TileMode::sw_4kb_s, TileMode::sw_64kb_d}) { | ||
| 114 | unsigned bpe_index = 0; | ||
| 115 | for (const std::size_t bpe : {1, 2, 4, 8, 16}) { | ||
| 116 | TiledSurface2D surface; | ||
| 117 | CHECK(TiledSurface2D::make(mode, bpe, 300, 130, surface)); | ||
| 118 | for (unsigned i = 0; i < points.size(); ++i) { | ||
| 119 | std::size_t offset; | ||
| 120 | CHECK(surface.element_offset(points[i][0], points[i][1], offset)); | ||
| 121 | CHECK(offset == answers[mode_index][bpe_index][i]); | ||
| 122 | } | ||
| 123 | CHECK(check_surface(mode, bpe, 1, 1) == 0); | ||
| 124 | CHECK(check_surface(mode, bpe, 33, 17) == 0); | ||
| 125 | CHECK(check_surface(mode, bpe, 300, 130) == 0); | ||
| 126 | CHECK(check_surface(mode, bpe, surface.tile_width() * 2, surface.tile_height() * 2) == 0); | ||
| 127 | ++bpe_index; | ||
| 128 | } | ||
| 129 | ++mode_index; | ||
| 130 | } | ||
| 131 | TiledSurface2D invalid; | ||
| 132 | for (const std::size_t bpe : {0, 3, 12, 32}) | ||
| 133 | CHECK(!TiledSurface2D::make(TileMode::sw_4kb_s, bpe, 1, 1, invalid)); | ||
| 134 | CHECK(!TiledSurface2D::make(TileMode(99), 4, 1, 1, invalid)); | ||
| 135 | CHECK(!TiledSurface2D::make(TileMode::sw_4kb_s, 4, 0, 1, invalid)); | ||
| 136 | CHECK(!TiledSurface2D::make(TileMode::sw_4kb_s, 4, 1, 0, invalid)); | ||
| 137 | constexpr auto max = std::numeric_limits<std::size_t>::max(); | ||
| 138 | for (const auto mode : {TileMode::sw_4kb_s, TileMode::sw_64kb_d}) { | ||
| 139 | CHECK(!TiledSurface2D::make(mode, 16, max, 1, invalid)); | ||
| 140 | CHECK(!TiledSurface2D::make(mode, 1, max, max, invalid)); | ||
| 141 | CHECK(!TiledSurface2D::make(mode, 1, 1, max, invalid)); | ||
| 142 | } | ||
| 143 | CHECK(invalid.tiled_size() == 0); | ||
| 144 | std::size_t offset; | ||
| 145 | CHECK(!invalid.element_offset(0, 0, offset)); | ||
| 146 | CHECK(!invalid.tile({}, {}, 0)); | ||
| 147 | CHECK(!invalid.detile({}, {}, 0)); | ||
| 148 | TiledSurface2D surface; | ||
| 149 | CHECK(TiledSurface2D::make(TileMode::sw_4kb_s, 4, 1, 3, surface)); | ||
| 150 | std::vector<std::byte> tiled(surface.tiled_size()), linear(12); | ||
| 151 | CHECK(!surface.tile(linear, tiled, max)); | ||
| 152 | CHECK(!surface.detile(tiled, linear, max)); | ||
| 153 | std::puts("gfx10_tiling: 40 surface round trips, padded bijections, 30 Python offsets and invalid arguments passed"); | ||
| 154 | return 0; | ||
| 155 | } | ||
diff --git a/runtime/test/glsl/gs_double.geom b/runtime/test/glsl/gs_double.geom new file mode 100644 index 000000000..4181b4f9d --- /dev/null +++ b/runtime/test/glsl/gs_double.geom | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #version 460 | ||
| 2 | // A geometry shader with the interface of a translated one (docs/design.md, "Geometry shaders": triangles in, a | ||
| 3 | // triangle strip out, inputs and outputs at the signature's locations), for d3d12_geometry_test. It emits every | ||
| 4 | // input triangle twice: as it is, and moved right by one in clip space, so a quad drawn in the top-left quadrant | ||
| 5 | // also covers the top-right one. The colour at location 0 (vs_draw.vert's output) passes through. | ||
| 6 | |||
| 7 | layout(triangles) in; | ||
| 8 | layout(triangle_strip, max_vertices = 6) out; | ||
| 9 | |||
| 10 | layout(location = 0) in vec4 in_color[]; | ||
| 11 | layout(location = 0) out vec4 out_color; | ||
| 12 | |||
| 13 | void main() { | ||
| 14 | for (int copy = 0; copy < 2; ++copy) { | ||
| 15 | for (int i = 0; i < 3; ++i) { | ||
| 16 | gl_Position = gl_in[i].gl_Position + vec4(float(copy), 0.0, 0.0, 0.0); | ||
| 17 | out_color = in_color[i]; | ||
| 18 | EmitVertex(); | ||
| 19 | } | ||
| 20 | EndPrimitive(); | ||
| 21 | } | ||
| 22 | } | ||
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp index 194174b00..73bc49206 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -184,6 +184,28 @@ void expect_rejects(const char* what, const std::vector<uint8_t>& bytes) { | |||
| 184 | 184 | ||
| 185 | void test_valid_image() { expect_loads("a valid image maps with its section intact", make_image()); } | 185 | void test_valid_image() { expect_loads("a valid image maps with its section intact", make_image()); } |
| 186 | 186 | ||
| 187 | void test_entry_bounds() { | ||
| 188 | for (bool is_dll : {false, true}) { | ||
| 189 | for (uint32_t entry : {0u, 0x1000u, 0x1FFFu, 0x2000u, 0x2001u}) { | ||
| 190 | auto img = make_image(); | ||
| 191 | if (is_dll) nt_of(img)->FileHeader.Characteristics |= IMAGE_FILE_DLL; | ||
| 192 | nt_of(img)->OptionalHeader.AddressOfEntryPoint = entry; | ||
| 193 | const std::string what = std::string(is_dll ? "DLL" : "EXE") + " entry RVA " + std::to_string(entry); | ||
| 194 | if (entry < nt_of(img)->OptionalHeader.SizeOfImage) { | ||
| 195 | expect_loads(what.c_str(), img); | ||
| 196 | } else { | ||
| 197 | std::string error; | ||
| 198 | if (load(write_image(img), error) == 0) | ||
| 199 | failed(what.c_str(), "the image loaded"); | ||
| 200 | else if (error.find("the entry point is outside the image") == std::string::npos) | ||
| 201 | failed(what.c_str(), "unexpected error: " + error); | ||
| 202 | else | ||
| 203 | pass(what.c_str()); | ||
| 204 | } | ||
| 205 | } | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 187 | void test_header_bounds() { | 209 | void test_header_bounds() { |
| 188 | { | 210 | { |
| 189 | auto img = make_image(); | 211 | auto img = make_image(); |
| @@ -941,6 +963,19 @@ std::vector<uint8_t> make_unwind_image(const std::vector<RUNTIME_FUNCTION>& entr | |||
| 941 | return img; | 963 | return img; |
| 942 | } | 964 | } |
| 943 | 965 | ||
| 966 | // PE/COFF: NumberOfRvaAndSizes counts the data directories; the slots past it are not directories whatever they hold. | ||
| 967 | // With 9 directories the TLS slot (index 9) is not one, so bytes left in it must not make the image fail to load. | ||
| 968 | void test_tls_directory_count() { | ||
| 969 | auto img = make_image(); | ||
| 970 | auto& tls = nt_of(img)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS]; | ||
| 971 | tls.VirtualAddress = 0xFFFF0000; // would run past the image if it were read as a TLS directory | ||
| 972 | tls.Size = sizeof(IMAGE_TLS_DIRECTORY64); | ||
| 973 | nt_of(img)->OptionalHeader.NumberOfRvaAndSizes = IMAGE_DIRECTORY_ENTRY_TLS; | ||
| 974 | expect_loads("a TLS slot past NumberOfRvaAndSizes is not read as a TLS directory", img); | ||
| 975 | nt_of(img)->OptionalHeader.NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES; | ||
| 976 | expect_rejects("the same TLS slot within NumberOfRvaAndSizes is checked and refused", img); | ||
| 977 | } | ||
| 978 | |||
| 944 | void test_unwind_registration() { | 979 | void test_unwind_registration() { |
| 945 | const std::vector<RUNTIME_FUNCTION> entries = {{0x1000, 0x1010, kUnwindRva}, {0x1010, 0x1020, kUnwindRva}}; | 980 | const std::vector<RUNTIME_FUNCTION> entries = {{0x1000, 0x1010, kUnwindRva}, {0x1010, 0x1020, kUnwindRva}}; |
| 946 | uintptr_t pc = 0; | 981 | uintptr_t pc = 0; |
| @@ -1093,6 +1128,7 @@ int main() { | |||
| 1093 | return 1; | 1128 | return 1; |
| 1094 | } | 1129 | } |
| 1095 | test_valid_image(); | 1130 | test_valid_image(); |
| 1131 | test_entry_bounds(); | ||
| 1096 | test_header_bounds(); | 1132 | test_header_bounds(); |
| 1097 | test_section_bounds(); | 1133 | test_section_bounds(); |
| 1098 | test_truncation(); | 1134 | test_truncation(); |
| @@ -1109,6 +1145,7 @@ int main() { | |||
| 1109 | test_delay_descriptor_fields(); | 1145 | test_delay_descriptor_fields(); |
| 1110 | test_forwarded_exports(); | 1146 | test_forwarded_exports(); |
| 1111 | test_export_bounds(); | 1147 | test_export_bounds(); |
| 1148 | test_tls_directory_count(); | ||
| 1112 | test_unwind_registration(); | 1149 | test_unwind_registration(); |
| 1113 | } catch (const std::exception& e) { | 1150 | } catch (const std::exception& e) { |
| 1114 | // A write that fails (write_image throws) ends the run with the reason, instead of terminating the process. | 1151 | // A write that fails (write_image throws) ends the run with the reason, instead of terminating the process. |
diff --git a/runtime/test/replay_query_edges_test.cpp b/runtime/test/replay_query_edges_test.cpp new file mode 100644 index 000000000..1bd55d237 --- /dev/null +++ b/runtime/test/replay_query_edges_test.cpp | |||
| @@ -0,0 +1,1043 @@ | |||
| 1 | // Query heap boundaries, resolve helper chunking, arena offsets, query reuse across lists/submissions, and | ||
| 2 | // predication around copies. These edge cases are only reached by GPU tests today; this CPU mock lets CI | ||
| 3 | // without a GPU check replay planning, emitted commands, destination guards, and pool ownership on submit failure. | ||
| 4 | // Shader arithmetic and Vulkan entry points are mocked; no driver is loaded. No GPU or game data. | ||
| 5 | #include "../src/vulkan_backend.h" | ||
| 6 | |||
| 7 | #include <algorithm> | ||
| 8 | #include <array> | ||
| 9 | #include <cstdint> | ||
| 10 | #include <cstdio> | ||
| 11 | #include <cstring> | ||
| 12 | #include <map> | ||
| 13 | #include <memory> | ||
| 14 | #include <set> | ||
| 15 | #include <stdexcept> | ||
| 16 | #include <string> | ||
| 17 | #include <string_view> | ||
| 18 | #include <utility> | ||
| 19 | #include <vector> | ||
| 20 | |||
| 21 | namespace { | ||
| 22 | |||
| 23 | using namespace leonida; | ||
| 24 | |||
| 25 | // OcclusionResolve keeps these capacities private (runtime/src/vulkan_backend.h). Pin the expected boundaries | ||
| 26 | // here so a change to its chunking still has an independent oracle; derive public result sizes from the IR. | ||
| 27 | constexpr unsigned sum_capacity = 256; | ||
| 28 | constexpr unsigned binary_capacity = 1024; | ||
| 29 | constexpr unsigned statistics_capacity = 64; | ||
| 30 | constexpr unsigned binary_group_size = 64; | ||
| 31 | constexpr VkDeviceSize word_size = sizeof(std::uint64_t); | ||
| 32 | constexpr unsigned statistics_size = query_result_size(d3d12_query::pipeline_statistics); | ||
| 33 | constexpr unsigned statistics_counters = statistics_size / word_size; | ||
| 34 | constexpr VkDeviceSize scratch_size = std::max({sum_capacity + 1, binary_capacity, | ||
| 35 | (statistics_capacity + 1) * statistics_counters}) * word_size; | ||
| 36 | constexpr unsigned char guard_byte = 0xa5; | ||
| 37 | |||
| 38 | template<class T> | ||
| 39 | T handle(std::uintptr_t n) { | ||
| 40 | return reinterpret_cast<T>(n); | ||
| 41 | } | ||
| 42 | |||
| 43 | // Stop the current case on failure so a failed mock bounds check cannot turn into an out-of-bounds access. | ||
| 44 | void expect(bool ok, const char* what) { | ||
| 45 | if (!ok) { | ||
| 46 | throw std::runtime_error(what); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | struct Call { | ||
| 50 | VkQueryPool pool; | ||
| 51 | unsigned first; | ||
| 52 | unsigned count; | ||
| 53 | VkDeviceSize offset; | ||
| 54 | VkDeviceSize stride; | ||
| 55 | }; | ||
| 56 | |||
| 57 | struct MockReplay { | ||
| 58 | static inline MockReplay* current; | ||
| 59 | std::map<VkBuffer, std::vector<unsigned char>> buffers; | ||
| 60 | std::map<VkQueryPool, std::vector<std::array<std::uint64_t, statistics_counters>>> values; | ||
| 61 | std::vector<Call> copies; | ||
| 62 | std::vector<std::pair<VkQueryPool, unsigned>> resets; | ||
| 63 | std::set<VkQueryPool> statistics_pools; | ||
| 64 | std::vector<unsigned> chunks; | ||
| 65 | std::vector<unsigned> groups; | ||
| 66 | std::vector<VkBufferCopy> transfers; | ||
| 67 | std::vector<std::string> events; | ||
| 68 | std::map<VkQueryPool, std::set<unsigned>> active; | ||
| 69 | bool conditional = false; | ||
| 70 | bool execute = true; | ||
| 71 | unsigned captures = 0; | ||
| 72 | unsigned pred_copies = 0; | ||
| 73 | unsigned native_copies = 0; | ||
| 74 | std::uint64_t snapshot = 0; | ||
| 75 | std::uint64_t serial = 10; | ||
| 76 | enum Mode { | ||
| 77 | none, | ||
| 78 | sum, | ||
| 79 | binary, | ||
| 80 | statistics | ||
| 81 | }; | ||
| 82 | Mode mode = none; | ||
| 83 | MockReplay() { | ||
| 84 | current = this; | ||
| 85 | // OcclusionResolve is exercised without initialize(); the null buffer stands in for its scratch storage. | ||
| 86 | buffers[VK_NULL_HANDLE].resize(scratch_size); | ||
| 87 | } | ||
| 88 | |||
| 89 | auto& bytes(VkBuffer b, VkDeviceSize offset, VkDeviceSize size) { | ||
| 90 | auto& v = buffers.at(b); | ||
| 91 | expect(offset <= v.size() && size <= v.size() - offset, "mock buffer access out of bounds"); | ||
| 92 | return v; | ||
| 93 | } | ||
| 94 | |||
| 95 | std::uint64_t word(VkBuffer b, VkDeviceSize off) { | ||
| 96 | std::uint64_t v; | ||
| 97 | auto&a = bytes(b, off, word_size); | ||
| 98 | std::memcpy(&v, a.data() + off, word_size); | ||
| 99 | return v; | ||
| 100 | } | ||
| 101 | |||
| 102 | void word(VkBuffer b, VkDeviceSize off, std::uint64_t v) { | ||
| 103 | auto&a = bytes(b, off, word_size); | ||
| 104 | std::memcpy(a.data() + off, &v, word_size); | ||
| 105 | } | ||
| 106 | |||
| 107 | void query(VkQueryPool p, unsigned first, unsigned count, VkBuffer b, VkDeviceSize off, VkDeviceSize stride, | ||
| 108 | VkQueryResultFlags flags) { | ||
| 109 | constexpr auto result_flags = VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT; | ||
| 110 | expect((flags & result_flags) == result_flags, "query result flags"); | ||
| 111 | copies.push_back({p, first, count, off, stride}); | ||
| 112 | auto& q = values.at(p); | ||
| 113 | expect(first <= q.size() && count <= q.size() - first, "mock query access out of bounds"); | ||
| 114 | for (unsigned i = 0; i < count; ++i) { | ||
| 115 | for (unsigned j = 0; j < (stride == statistics_size ? statistics_counters : 1u); ++j) { | ||
| 116 | word(b, off + i * stride + word_size * j, q[first + i][j]); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | events.push_back("query_copy"); | ||
| 120 | } | ||
| 121 | |||
| 122 | void fill(VkBuffer b, VkDeviceSize off, VkDeviceSize n, unsigned value) { | ||
| 123 | auto& v = bytes(b, off, n); | ||
| 124 | for (VkDeviceSize i = 0; i < n; i += sizeof(value)) { | ||
| 125 | std::memcpy(v.data() + off + i, &value, sizeof(value)); | ||
| 126 | } | ||
| 127 | events.push_back("fill"); | ||
| 128 | } | ||
| 129 | |||
| 130 | void copy(VkBuffer a, VkBuffer b, const VkBufferCopy& c) { | ||
| 131 | auto& av = bytes(a, c.srcOffset, c.size); | ||
| 132 | auto& bv = bytes(b, c.dstOffset, c.size); | ||
| 133 | std::memmove(bv.data() + c.dstOffset, av.data() + c.srcOffset, c.size); | ||
| 134 | transfers.push_back(c); | ||
| 135 | } | ||
| 136 | |||
| 137 | ReplayFunctions replay_functions() { | ||
| 138 | ReplayFunctions v{}; | ||
| 139 | v.reset_query_pool = +[](VkCommandBuffer, VkQueryPool p, unsigned first, unsigned count) { | ||
| 140 | auto& c = *current; | ||
| 141 | expect(first <= c.values.at(p).size() && count <= c.values.at(p).size() - first, "reset query bounds"); | ||
| 142 | for (unsigned i = 0; i < count; ++i) { | ||
| 143 | expect(!c.active[p].count(first + i), "reset active query"); | ||
| 144 | c.values[p][first + i] = {}; | ||
| 145 | c.resets.emplace_back(p, first + i); | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | v.begin_query = +[](VkCommandBuffer, VkQueryPool p, unsigned i, VkQueryControlFlags) { | ||
| 149 | expect(current->active[p].empty(), "overlapping physical query"); | ||
| 150 | current->active[p].insert(i); | ||
| 151 | current->events.push_back("begin_query"); | ||
| 152 | }; | ||
| 153 | v.end_query = +[](VkCommandBuffer, VkQueryPool p, unsigned i) { | ||
| 154 | expect(current->active[p].erase(i) == 1, "end inactive query"); | ||
| 155 | for (unsigned j = 0; j < statistics_counters; ++j) { | ||
| 156 | current->values.at(p).at(i)[j] = ++current->serial + j; | ||
| 157 | } | ||
| 158 | current->events.push_back("end_query"); | ||
| 159 | }; | ||
| 160 | v.write_timestamp = +[](VkCommandBuffer, VkPipelineStageFlagBits, VkQueryPool p, unsigned i) { | ||
| 161 | current->values.at(p).at(i)[0] = ++current->serial; | ||
| 162 | }; | ||
| 163 | v.copy_query_pool_results = +[](VkCommandBuffer, VkQueryPool p, unsigned first, unsigned count, VkBuffer b, | ||
| 164 | VkDeviceSize off, VkDeviceSize stride, VkQueryResultFlags flags) { | ||
| 165 | current->query(p, first, count, b, off, stride, flags); | ||
| 166 | }; | ||
| 167 | v.fill_buffer = +[](VkCommandBuffer, VkBuffer b, VkDeviceSize off, VkDeviceSize n, unsigned value) { | ||
| 168 | expect(!current->conditional, "resolve fill inside predicate"); | ||
| 169 | current->fill(b, off, n, value); | ||
| 170 | }; | ||
| 171 | v.copy_buffer = +[](VkCommandBuffer, VkBuffer a, VkBuffer b, unsigned n, const VkBufferCopy* copies) { | ||
| 172 | ++current->native_copies; | ||
| 173 | for (unsigned i = 0; i < n; ++i) { | ||
| 174 | current->copy(a, b, copies[i]); | ||
| 175 | } | ||
| 176 | current->events.push_back("native_copy"); | ||
| 177 | }; | ||
| 178 | // Capability entries are never called in buffer-only tests. | ||
| 179 | v.copy_buffer_to_image = +[](VkCommandBuffer, VkBuffer, VkImage, VkImageLayout, unsigned, | ||
| 180 | const VkBufferImageCopy*) { | ||
| 181 | expect(false, "unexpected image copy"); | ||
| 182 | }; | ||
| 183 | v.copy_image_to_buffer = +[](VkCommandBuffer, VkImage, VkImageLayout, VkBuffer, unsigned, | ||
| 184 | const VkBufferImageCopy*) { | ||
| 185 | expect(false, "unexpected image copy"); | ||
| 186 | }; | ||
| 187 | v.copy_image = +[](VkCommandBuffer, VkImage, VkImageLayout, VkImage, VkImageLayout, unsigned, | ||
| 188 | const VkImageCopy*) { | ||
| 189 | expect(false, "unexpected image copy"); | ||
| 190 | }; | ||
| 191 | v.begin_conditional_rendering = +[](VkCommandBuffer, const VkConditionalRenderingBeginInfoEXT* info) { | ||
| 192 | auto& c = *current; | ||
| 193 | expect(!c.conditional, "nested predicate"); | ||
| 194 | c.conditional = true; | ||
| 195 | c.execute = (c.snapshot != 0); | ||
| 196 | if (info->flags & VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT) { | ||
| 197 | c.execute = !c.execute; | ||
| 198 | } | ||
| 199 | c.events.push_back("begin_cond"); | ||
| 200 | }; | ||
| 201 | v.end_conditional_rendering = +[](VkCommandBuffer) { | ||
| 202 | expect(current->conditional, "end missing predicate"); | ||
| 203 | current->conditional = false; | ||
| 204 | current->events.push_back("end_cond"); | ||
| 205 | }; | ||
| 206 | v.prepare_predicate = [](VkBuffer b, VkDeviceSize off, PredicateCapture& out) { | ||
| 207 | out = {b, off, handle<VkBuffer>(99), 0, handle<VkDescriptorSet>(99)}; | ||
| 208 | return true; | ||
| 209 | }; | ||
| 210 | v.capture_predicate = [](VkCommandBuffer, const PredicateCapture& p) { | ||
| 211 | expect(!current->conditional, "predicated capture"); | ||
| 212 | current->snapshot = current->word(p.source, p.source_offset); | ||
| 213 | ++current->captures; | ||
| 214 | current->events.push_back("capture"); | ||
| 215 | }; | ||
| 216 | auto helper = [](bool stats, bool binary, VkQueryPool p, unsigned first, unsigned count, VkBuffer dst, | ||
| 217 | VkDeviceSize off) { | ||
| 218 | auto& c = *current; | ||
| 219 | expect(!c.conditional, "predicated resolve helper"); | ||
| 220 | c.events.push_back("helper"); | ||
| 221 | for (auto pool : c.statistics_pools) { | ||
| 222 | expect(c.active[pool].empty(), "resolve helper pollutes active pipeline-statistics query"); | ||
| 223 | } | ||
| 224 | if (binary) { | ||
| 225 | for (unsigned i = 0; i < count; ++i) { | ||
| 226 | c.word(dst, off + word_size * i, c.values.at(p).at(first + i)[0] != 0); | ||
| 227 | } | ||
| 228 | } else { | ||
| 229 | for (unsigned j = 0; j < (stats ? statistics_counters : 1u); ++j) { | ||
| 230 | std::uint64_t total = 0; | ||
| 231 | for (unsigned i = 0; i < count; ++i) { | ||
| 232 | total += c.values.at(p).at(first + i)[j]; | ||
| 233 | } | ||
| 234 | c.word(dst, off + word_size * j, total); | ||
| 235 | } | ||
| 236 | } | ||
| 237 | }; | ||
| 238 | v.sum_occlusion = [helper](VkCommandBuffer, VkQueryPool p, unsigned f, unsigned n, VkBuffer b, | ||
| 239 | VkDeviceSize off) { | ||
| 240 | helper(false, false, p, f, n, b, off); | ||
| 241 | }; | ||
| 242 | v.sum_statistics = [helper](VkCommandBuffer, VkQueryPool p, unsigned f, unsigned n, VkBuffer b, | ||
| 243 | VkDeviceSize off) { | ||
| 244 | helper(true, false, p, f, n, b, off); | ||
| 245 | }; | ||
| 246 | v.resolve_binary_occlusion = [helper](VkCommandBuffer, VkQueryPool p, unsigned f, unsigned n, VkBuffer b, | ||
| 247 | VkDeviceSize off) { | ||
| 248 | helper(false, true, p, f, n, b, off); | ||
| 249 | }; | ||
| 250 | return v; | ||
| 251 | } | ||
| 252 | }; | ||
| 253 | |||
| 254 | inline std::shared_ptr<OcclusionSegmentPool> make_segment_pool(unsigned id) { | ||
| 255 | auto p = std::make_shared<OcclusionSegmentPool>(); | ||
| 256 | p->pool = handle<VkQueryPool>(id); | ||
| 257 | p->destroy = +[](VkDevice, VkQueryPool, const VkAllocationCallbacks*) {}; | ||
| 258 | return p; | ||
| 259 | } | ||
| 260 | |||
| 261 | void test_helper_chunks() { | ||
| 262 | constexpr unsigned first_query = 7; | ||
| 263 | constexpr VkDeviceSize arena_offset = 40; | ||
| 264 | constexpr VkDeviceSize resolve_offset = 24; | ||
| 265 | constexpr VkDeviceSize output_offset = arena_offset + resolve_offset; | ||
| 266 | constexpr unsigned buffer_bytes = 10000; | ||
| 267 | constexpr std::uint64_t reset_sum = 3; | ||
| 268 | constexpr std::uint64_t reset_counter = 9; | ||
| 269 | |||
| 270 | MockReplay c; | ||
| 271 | VulkanDeviceFunctions vk{}; | ||
| 272 | vk.vkCmdFillBuffer = +[](VkCommandBuffer, VkBuffer b, VkDeviceSize off, VkDeviceSize n, unsigned value) { | ||
| 273 | MockReplay::current->fill(b, off, n, value); | ||
| 274 | }; | ||
| 275 | vk.vkCmdCopyQueryPoolResults = +[](VkCommandBuffer, VkQueryPool p, unsigned first, unsigned count, VkBuffer b, | ||
| 276 | VkDeviceSize off, VkDeviceSize stride, VkQueryResultFlags flags) { | ||
| 277 | MockReplay::current->query(p, first, count, b, off, stride, flags); | ||
| 278 | }; | ||
| 279 | vk.vkCmdCopyBuffer = +[](VkCommandBuffer, VkBuffer a, VkBuffer b, unsigned n, const VkBufferCopy* copies) { | ||
| 280 | for (unsigned i = 0; i < n; ++i) { | ||
| 281 | MockReplay::current->copy(a, b, copies[i]); | ||
| 282 | } | ||
| 283 | }; | ||
| 284 | vk.vkCmdBindPipeline = +[](VkCommandBuffer, VkPipelineBindPoint, VkPipeline) {}; | ||
| 285 | vk.vkCmdBindDescriptorSets = +[](VkCommandBuffer, VkPipelineBindPoint, VkPipelineLayout, unsigned, unsigned, | ||
| 286 | const VkDescriptorSet*, unsigned, const unsigned*) {}; | ||
| 287 | vk.vkCmdPushConstants = +[](VkCommandBuffer, VkPipelineLayout, VkShaderStageFlags, unsigned off, unsigned size, | ||
| 288 | const void*p) { | ||
| 289 | expect(off == 0 && size == sizeof(unsigned), "chunk push constants"); | ||
| 290 | MockReplay::current->chunks.push_back(*static_cast<const unsigned *>(p)); | ||
| 291 | }; | ||
| 292 | vk.vkCmdDispatch = +[](VkCommandBuffer, unsigned x, unsigned y, unsigned z) { | ||
| 293 | auto& c = *MockReplay::current; | ||
| 294 | c.groups.push_back(x); | ||
| 295 | expect(y == 1 && z == 1, "dispatch dimensions"); | ||
| 296 | auto n = c.chunks.back(); | ||
| 297 | if (c.mode == MockReplay::binary) { | ||
| 298 | for (unsigned i = 0; i < n; ++i) { | ||
| 299 | c.word(VK_NULL_HANDLE, word_size * i, c.word(VK_NULL_HANDLE, word_size * i) != 0); | ||
| 300 | } | ||
| 301 | } else { | ||
| 302 | for (unsigned j = 0; j < (c.mode == MockReplay::statistics ? statistics_counters : 1u); ++j) { | ||
| 303 | unsigned width = c.mode == MockReplay::statistics ? statistics_counters : 1; | ||
| 304 | auto total = c.word(VK_NULL_HANDLE, word_size * j); | ||
| 305 | for (unsigned i = 0; i < n; ++i) { | ||
| 306 | total += c.word(VK_NULL_HANDLE, word_size * (width * (i + 1) + j)); | ||
| 307 | } | ||
| 308 | c.word(VK_NULL_HANDLE, word_size * j, total); | ||
| 309 | } | ||
| 310 | } | ||
| 311 | }; | ||
| 312 | vk.vkCmdPipelineBarrier = +[](VkCommandBuffer, VkPipelineStageFlags, VkPipelineStageFlags, VkDependencyFlags, | ||
| 313 | unsigned, const VkMemoryBarrier*, unsigned n, const VkBufferMemoryBarrier* b, unsigned, | ||
| 314 | const VkImageMemoryBarrier*) { | ||
| 315 | expect(n == 1 && b->offset == 0 && b->size == scratch_size, "scratch barrier covers the shared scratch buffer"); | ||
| 316 | }; | ||
| 317 | OcclusionResolve helper(vk, VK_NULL_HANDLE); | ||
| 318 | auto qp = handle<VkQueryPool>(1); | ||
| 319 | auto dst = handle<VkBuffer>(2); | ||
| 320 | for (auto mode : {MockReplay::sum, MockReplay::binary, MockReplay::statistics}) { | ||
| 321 | for (unsigned extra : {0u, 1u}) { | ||
| 322 | c.mode = mode; | ||
| 323 | const unsigned capacity = mode == MockReplay::sum ? sum_capacity | ||
| 324 | : mode == MockReplay::binary ? binary_capacity | ||
| 325 | : statistics_capacity; | ||
| 326 | const unsigned n = capacity + extra; | ||
| 327 | const unsigned first = first_query; | ||
| 328 | const unsigned width = mode == MockReplay::statistics ? statistics_counters : 1; | ||
| 329 | c.values[qp].resize(first + n); | ||
| 330 | for (unsigned i = 0; i < first + n; ++i) { | ||
| 331 | for (unsigned j = 0; j < statistics_counters; ++j) { | ||
| 332 | c.values[qp][i][j] = i % 3 == 0 ? 0 : (UINT64_C(1) << 32) + i * 17 + j; | ||
| 333 | } | ||
| 334 | } | ||
| 335 | c.buffers[dst].assign(buffer_bytes, guard_byte); | ||
| 336 | auto expected = c.buffers[dst]; | ||
| 337 | c.copies.clear(); | ||
| 338 | c.chunks.clear(); | ||
| 339 | c.groups.clear(); | ||
| 340 | c.transfers.clear(); | ||
| 341 | if (mode == MockReplay::binary) { | ||
| 342 | helper.normalize({}, qp, first, n, dst, output_offset); | ||
| 343 | for (unsigned i = 0; i < n; ++i) { | ||
| 344 | std::uint64_t v = c.values[qp][first + i][0] != 0; | ||
| 345 | std::memcpy(expected.data() + output_offset + word_size * i, &v, word_size); | ||
| 346 | } | ||
| 347 | } else { | ||
| 348 | if (mode == MockReplay::statistics) { | ||
| 349 | helper.sum_statistics({}, qp, first, n, dst, output_offset); | ||
| 350 | } else { | ||
| 351 | helper.sum({}, qp, first, n, dst, output_offset); | ||
| 352 | } | ||
| 353 | for (unsigned j = 0; j < width; ++j) { | ||
| 354 | std::uint64_t v = 0; | ||
| 355 | for (unsigned i = 0; i < n; ++i) { | ||
| 356 | v += c.values[qp][first + i][j]; | ||
| 357 | } | ||
| 358 | std::memcpy(expected.data() + output_offset + word_size * j, &v, word_size); | ||
| 359 | } | ||
| 360 | } | ||
| 361 | expect(c.buffers[dst] == expected, "numeric helper result and destination guard bytes"); | ||
| 362 | expect(c.chunks == (extra ? std::vector<unsigned>{capacity, 1} | ||
| 363 | : std::vector<unsigned>{capacity}), "exact chunk sizes"); | ||
| 364 | expect(c.copies.size() == 1 + extra && c.copies[0].first == first && (!extra | ||
| 365 | || c.copies[1].first == first + capacity), "chunk query indices end exactly at heap boundary"); | ||
| 366 | std::vector<unsigned> expected_groups(1 + extra, 1); | ||
| 367 | if (mode == MockReplay::binary) { | ||
| 368 | expected_groups[0] = binary_capacity / binary_group_size; | ||
| 369 | } | ||
| 370 | expect(c.groups == expected_groups, "dispatch workgroup counts"); | ||
| 371 | if (mode == MockReplay::binary) { | ||
| 372 | expect(c.transfers.size() == 1 + extra && (!extra | ||
| 373 | || c.transfers[1].dstOffset == output_offset + word_size * capacity), | ||
| 374 | "binary second output chunk offset"); | ||
| 375 | } else { | ||
| 376 | expect(c.transfers.size() == 1 && c.transfers[0].size == word_size * width, | ||
| 377 | "sum copies only the final accumulator"); | ||
| 378 | } | ||
| 379 | } | ||
| 380 | } | ||
| 381 | |||
| 382 | // A previous call must not leave stale accumulator state in the next call. | ||
| 383 | c.mode = MockReplay::sum; | ||
| 384 | c.values[qp][first_query][0] = reset_sum; | ||
| 385 | helper.sum({}, qp, first_query, 1, dst, output_offset); | ||
| 386 | expect(c.word(dst, output_offset) == reset_sum, "sum accumulator reset between calls"); | ||
| 387 | c.mode = MockReplay::statistics; | ||
| 388 | c.values[qp][first_query].fill(reset_counter); | ||
| 389 | helper.sum_statistics({}, qp, first_query, 1, dst, output_offset); | ||
| 390 | for (unsigned j = 0; j < statistics_counters; ++j) { | ||
| 391 | expect(c.word(dst, output_offset + word_size * j) == reset_counter, "statistics accumulator reset"); | ||
| 392 | } | ||
| 393 | } | ||
| 394 | |||
| 395 | void test_query_state() { | ||
| 396 | constexpr unsigned heap_count = 4; | ||
| 397 | constexpr unsigned overlap_segments = 3; | ||
| 398 | constexpr unsigned split_statistics_segments = 5; | ||
| 399 | constexpr unsigned mixed_statistics_segments = 4; | ||
| 400 | constexpr VkDeviceSize arena_offset = 40; | ||
| 401 | constexpr VkDeviceSize boundary_offset = 24; | ||
| 402 | constexpr VkDeviceSize buffer_bytes = 4200; | ||
| 403 | constexpr VkDeviceSize resource_bytes = 4096; | ||
| 404 | constexpr VkDeviceSize reused_offset = 16; | ||
| 405 | constexpr VkDeviceSize repeated_offset = 128; | ||
| 406 | constexpr VkDeviceSize overwrite_offset = 144; | ||
| 407 | constexpr VkDeviceSize zero_offset = 200; | ||
| 408 | constexpr VkDeviceSize statistics_offset = 256; | ||
| 409 | constexpr VkDeviceSize later_statistics_offset = 512; | ||
| 410 | constexpr VkDeviceSize inner_statistics_offset = 768; | ||
| 411 | constexpr VkDeviceSize binary_offset = 864; | ||
| 412 | constexpr VkDeviceSize timestamp_offset = 880; | ||
| 413 | constexpr VkDeviceSize sum_offset = 896; | ||
| 414 | constexpr VkDeviceSize mixed_statistics_offset = 1024; | ||
| 415 | constexpr std::uint64_t first_saved_count = 17; | ||
| 416 | constexpr std::uint64_t second_saved_count = 23; | ||
| 417 | |||
| 418 | MockReplay c; | ||
| 419 | auto vk = c.replay_functions(); | ||
| 420 | ResourceBinding dst{}; | ||
| 421 | dst.buffer = handle<VkBuffer>(1); | ||
| 422 | dst.buffer_offset = arena_offset; | ||
| 423 | dst.size = resource_bytes; | ||
| 424 | dst.host_readable = true; | ||
| 425 | c.buffers[dst.buffer].assign(buffer_bytes, guard_byte); | ||
| 426 | auto resource = [&](ResourceId id) -> const ResourceBinding* { | ||
| 427 | return id == 1 ? &dst : nullptr; | ||
| 428 | }; | ||
| 429 | QueryPool heap{handle<VkQueryPool>(2), d3d12_query_heap::occlusion, heap_count, true, | ||
| 430 | std::vector<bool>(heap_count), {}}; | ||
| 431 | QueryPool stat{handle<VkQueryPool>(3), d3d12_query_heap::pipeline_statistics, heap_count, false, | ||
| 432 | std::vector<bool>(heap_count), {}}; | ||
| 433 | QueryPool time{handle<VkQueryPool>(4), d3d12_query_heap::timestamp, heap_count, false, | ||
| 434 | std::vector<bool>(heap_count), {}}; | ||
| 435 | for (auto p : {heap.pool, stat.pool, time.pool}) { | ||
| 436 | c.values[p].resize(heap_count); | ||
| 437 | } | ||
| 438 | vk.query_pool = [&](QueryHeapId id) -> QueryPool* { | ||
| 439 | return id == 1 ? &heap : id == 2 ? &stat : id == 3 ? &time : nullptr; | ||
| 440 | }; | ||
| 441 | auto prep = [&](CommandList& list, PreparedList& out) { | ||
| 442 | expect(list.close(), "close query list"); | ||
| 443 | expect(prepare(list, resource, vk, out) == ReplayResult::success, "prepare query list"); | ||
| 444 | }; | ||
| 445 | |||
| 446 | // Inclusive final slot / exclusive heap end, for every supported resolve result width. | ||
| 447 | for (auto type : {d3d12_query::occlusion, d3d12_query::binary_occlusion, d3d12_query::timestamp, | ||
| 448 | d3d12_query::pipeline_statistics}) { | ||
| 449 | unsigned id = type == d3d12_query::timestamp ? 3 : type == d3d12_query::pipeline_statistics ? 2 : 1; | ||
| 450 | auto* hp = vk.query_pool(id); | ||
| 451 | hp->ended = {false, false, true, true}; | ||
| 452 | for (unsigned i = 2; i < heap_count; ++i) { | ||
| 453 | for (unsigned j = 0; j < statistics_counters; ++j) { | ||
| 454 | c.values[hp->pool][i][j] = (UINT64_C(1) << 32) + 100 * i + j; | ||
| 455 | } | ||
| 456 | } | ||
| 457 | auto size = query_result_size(type); | ||
| 458 | for (unsigned count : {1u, 2u}) { | ||
| 459 | CommandList list; | ||
| 460 | expect(list.resolve_queries({id, type, heap_count - count, count, 1, boundary_offset}), | ||
| 461 | "record boundary resolve"); | ||
| 462 | PreparedList out; | ||
| 463 | dst.size = boundary_offset + size * count; | ||
| 464 | c.buffers[dst.buffer].assign(buffer_bytes, guard_byte); | ||
| 465 | auto expected = c.buffers[dst.buffer]; | ||
| 466 | prep(list, out); | ||
| 467 | QueryReplay q; | ||
| 468 | expect(q.plan(out, {}, 0, true) == ReplayResult::success, "plan boundary"); | ||
| 469 | emit(out, {}, vk); | ||
| 470 | for (unsigned i = 0; i < count; ++i) { | ||
| 471 | for (unsigned j = 0; j < size / word_size; ++j) { | ||
| 472 | const auto v = type == d3d12_query::binary_occlusion | ||
| 473 | ? UINT64_C(1) | ||
| 474 | : c.values[hp->pool][heap_count - count + i][j]; | ||
| 475 | std::memcpy(expected.data() + arena_offset + boundary_offset + size * i + word_size * j, &v, | ||
| 476 | word_size); | ||
| 477 | } | ||
| 478 | } | ||
| 479 | expect(c.buffers[dst.buffer] == expected, "heap-end resolve numeric values, arena offset and guards"); | ||
| 480 | expect(out.wrote_readback, "query resolve readback visibility"); | ||
| 481 | } | ||
| 482 | CommandList bad; | ||
| 483 | expect(bad.resolve_queries({id, type, heap_count - 1, 2, 1, 0}) && bad.close(), "record one-past heap end"); | ||
| 484 | PreparedList invalid; | ||
| 485 | expect(prepare(bad, resource, vk, invalid) == ReplayResult::invalid_query, "reject one-past heap range"); | ||
| 486 | CommandList short_dst; | ||
| 487 | expect(short_dst.resolve_queries({id, type, heap_count - 1, 1, 1, boundary_offset}) && short_dst.close(), | ||
| 488 | "record short destination"); | ||
| 489 | dst.size = boundary_offset + size - 1; | ||
| 490 | expect(prepare(short_dst, resource, vk, invalid) == ReplayResult::invalid_query, | ||
| 491 | "reject destination one byte short"); | ||
| 492 | } | ||
| 493 | dst.size = resource_bytes; | ||
| 494 | heap.ended.assign(heap_count, false); | ||
| 495 | heap.occlusion.clear(); | ||
| 496 | |||
| 497 | // Plan three lists as VulkanQueue::execute does, before any emission or commit. | ||
| 498 | CommandList a, b, d; | ||
| 499 | PreparedList pa, pb, pd; | ||
| 500 | expect(a.begin_query({1, d3d12_query::occlusion, 0}) && a.begin_query({1, d3d12_query::occlusion, 1}) | ||
| 501 | && a.end_query({1, d3d12_query::occlusion, 0}) && a.end_query({1, d3d12_query::occlusion, 1}), | ||
| 502 | "record overlap"); | ||
| 503 | expect(b.resolve_queries({1, d3d12_query::occlusion, 0, 2, 1, 0}) && b.begin_query({1, d3d12_query::occlusion, | ||
| 504 | 0}) && b.end_query({1, d3d12_query::occlusion, 0}) && b.resolve_queries({1, d3d12_query::occlusion, 0, 1, | ||
| 505 | 1, reused_offset}), "record reuse after resolve"); | ||
| 506 | expect(d.resolve_queries({1, d3d12_query::occlusion, 0, 2, 1, boundary_offset}), "record third list resolve"); | ||
| 507 | prep(a, pa); | ||
| 508 | prep(b, pb); | ||
| 509 | prep(d, pd); | ||
| 510 | expect(pa.segment_count == overlap_segments && pb.segment_count == 0 && pd.segment_count == 0, | ||
| 511 | "queue needs exactly three physical occlusion slots"); | ||
| 512 | auto physical = make_segment_pool(10); | ||
| 513 | c.values[physical->pool].resize(overlap_segments); | ||
| 514 | std::weak_ptr<const OcclusionSegmentPool> alive = physical; | ||
| 515 | QueryReplay batch; | ||
| 516 | unsigned base = 0; | ||
| 517 | for (auto* p : {&pa, &pb, &pd}) { | ||
| 518 | expect(batch.plan(*p, physical, base, true) == ReplayResult::success, "plan multi-list batch"); | ||
| 519 | base += p->segment_count; | ||
| 520 | } | ||
| 521 | expect(heap.occlusion.empty() && !heap.ended[0] && !heap.ended[1], | ||
| 522 | "planning does not publish results before commit"); | ||
| 523 | emit(pa, {}, vk); | ||
| 524 | auto old0 = c.values[physical->pool][0][0] + c.values[physical->pool][1][0]; | ||
| 525 | auto old1 = c.values[physical->pool][1][0] + c.values[physical->pool][2][0]; | ||
| 526 | emit(pb, {}, vk); | ||
| 527 | auto new0 = c.values[heap.pool][0][0]; | ||
| 528 | emit(pd, {}, vk); | ||
| 529 | expect(c.word(dst.buffer, arena_offset) == old0 && c.word(dst.buffer, arena_offset + word_size) == old1 | ||
| 530 | && c.word(dst.buffer, arena_offset + reused_offset) == new0 && c.word(dst.buffer, | ||
| 531 | arena_offset + boundary_offset) == new0 && c.word(dst.buffer, | ||
| 532 | arena_offset + boundary_offset + word_size) == old1, | ||
| 533 | "pending results, resolve preservation and slot reuse across three lists"); | ||
| 534 | batch.commit(); | ||
| 535 | expect(heap.ended[0] && heap.ended[1] && !heap.occlusion.count(0) && heap.occlusion.at(1).count == 2, | ||
| 536 | "commit replaces reused slot metadata only"); | ||
| 537 | physical.reset(); | ||
| 538 | batch.retained.clear(); | ||
| 539 | expect(!alive.expired(), "heap retains segment pool after submission owner releases it"); | ||
| 540 | for (unsigned submission = 0; submission < 3; ++submission) { | ||
| 541 | CommandList list; | ||
| 542 | PreparedList p; | ||
| 543 | expect(list.resolve_queries({1, d3d12_query::occlusion, 0, 2, 1, repeated_offset}), "record later resolve"); | ||
| 544 | prep(list, p); | ||
| 545 | QueryReplay q; | ||
| 546 | expect(q.plan(p, {}, 0, true) == ReplayResult::success, "plan later submission"); | ||
| 547 | emit(p, {}, vk); | ||
| 548 | q.commit(); | ||
| 549 | expect(c.word(dst.buffer, arena_offset + repeated_offset) == new0 && c.word(dst.buffer, | ||
| 550 | arena_offset + repeated_offset + word_size) == old1, "repeat resolve across submissions"); | ||
| 551 | } | ||
| 552 | CommandList overwrite; | ||
| 553 | PreparedList po; | ||
| 554 | expect(overwrite.begin_query({1, d3d12_query::occlusion, 1}) && overwrite.end_query({1, d3d12_query::occlusion, | ||
| 555 | 1}) && overwrite.resolve_queries({1, d3d12_query::occlusion, 1, 1, 1, overwrite_offset}), | ||
| 556 | "record last segment overwrite"); | ||
| 557 | prep(overwrite, po); | ||
| 558 | { | ||
| 559 | QueryReplay q; | ||
| 560 | expect(q.plan(po, {}, 0, true) == ReplayResult::success, "plan native replacement"); | ||
| 561 | emit(po, {}, vk); | ||
| 562 | q.commit(); | ||
| 563 | expect(!heap.occlusion.count(1) && c.word(dst.buffer, | ||
| 564 | arena_offset + overwrite_offset) == c.values[heap.pool][1][0], | ||
| 565 | "native result replaces last virtual result"); | ||
| 566 | } | ||
| 567 | expect(alive.expired(), "last heap overwrite releases old segment pool"); | ||
| 568 | |||
| 569 | // Statistics pool size/base accumulation across two split lists; resolve during statistics must not count helpers. | ||
| 570 | heap.ended[3] = false; | ||
| 571 | CommandList s0, s1; | ||
| 572 | PreparedList ps0, ps1; | ||
| 573 | for (unsigned index = 0; index < 2; ++index) { | ||
| 574 | auto& list = index ? s1 : s0; | ||
| 575 | expect(list.begin_query({2, d3d12_query::pipeline_statistics, index}), "statistics begin"); | ||
| 576 | for (unsigned i = 0; i <= index; ++i) { | ||
| 577 | expect(list.resolve_queries({1, d3d12_query::occlusion, 3, 1, 1, zero_offset}), "inner zero-fill resolve"); | ||
| 578 | } | ||
| 579 | expect(list.resolve_queries({1, d3d12_query::occlusion, heap_count, 0, 1, 0}), "zero-count resolve at heap end"); | ||
| 580 | expect(list.end_query({2, d3d12_query::pipeline_statistics, index}) && list.resolve_queries({2, | ||
| 581 | d3d12_query::pipeline_statistics, index, 1, 1, statistics_offset + statistics_size * index}), | ||
| 582 | "statistics end and resolve"); | ||
| 583 | } | ||
| 584 | prep(s0, ps0); | ||
| 585 | prep(s1, ps1); | ||
| 586 | expect(ps0.statistics_segment_count == 2 && ps1.statistics_segment_count == 3, | ||
| 587 | "zero-count resolves allocate no statistics segment"); | ||
| 588 | auto sp = make_segment_pool(11); | ||
| 589 | c.values[sp->pool].resize(split_statistics_segments); | ||
| 590 | c.statistics_pools.insert(sp->pool); | ||
| 591 | QueryReplay stats; | ||
| 592 | unsigned sb = 0; | ||
| 593 | for (auto* p : {&ps0, &ps1}) { | ||
| 594 | expect(stats.plan(*p, {}, 0, true, sp, sb) == ReplayResult::success, "plan split statistics lists"); | ||
| 595 | sb += p->statistics_segment_count; | ||
| 596 | } | ||
| 597 | emit(ps0, {}, vk); | ||
| 598 | emit(ps1, {}, vk); | ||
| 599 | stats.commit(); | ||
| 600 | expect(stat.occlusion.at(0).first == 0 && stat.occlusion.at(1).first == 2 && sb == split_statistics_segments, | ||
| 601 | "queue statistics pool sizing and disjoint bases"); | ||
| 602 | for (unsigned i = 0; i < 2; ++i) { | ||
| 603 | for (unsigned j = 0; j < statistics_counters; ++j) { | ||
| 604 | std::uint64_t total = 0; | ||
| 605 | auto r = stat.occlusion.at(i); | ||
| 606 | for (unsigned k = 0; k < r.count; ++k) { | ||
| 607 | total += c.values[sp->pool][r.first + k][j]; | ||
| 608 | } | ||
| 609 | expect(c.word(dst.buffer, | ||
| 610 | arena_offset + statistics_offset + statistics_size * i + word_size * j) == total, | ||
| 611 | "all 11 split statistics counters"); | ||
| 612 | } | ||
| 613 | } | ||
| 614 | |||
| 615 | // No segment ownership is needed on the next submission: heap metadata carries it. | ||
| 616 | CommandList later; | ||
| 617 | PreparedList pl; | ||
| 618 | expect(later.resolve_queries({2, d3d12_query::pipeline_statistics, 0, 2, 1, later_statistics_offset}), | ||
| 619 | "later statistics resolve"); | ||
| 620 | prep(later, pl); | ||
| 621 | QueryReplay later_batch; | ||
| 622 | expect(later_batch.plan(pl, {}, 0, true) == ReplayResult::success && later_batch.needs_statistics_sum, | ||
| 623 | "later statistics helper selection"); | ||
| 624 | emit(pl, {}, vk); | ||
| 625 | for (unsigned i = 0; i < (2 * statistics_size); i += word_size) { | ||
| 626 | expect(c.word(dst.buffer, arena_offset + later_statistics_offset + i) == c.word(dst.buffer, | ||
| 627 | arena_offset + statistics_offset + i), "statistics persist after commit"); | ||
| 628 | } | ||
| 629 | |||
| 630 | // Mixed helper types inside one statistics scope, including a timestamp copy that must not split it. | ||
| 631 | auto saved = make_segment_pool(12); | ||
| 632 | c.values[saved->pool].resize(2); | ||
| 633 | c.values[saved->pool][0][0] = 17; | ||
| 634 | c.values[saved->pool][1][0] = 23; | ||
| 635 | heap.occlusion[2] = {saved, 0, 2}; | ||
| 636 | heap.ended[2] = true; | ||
| 637 | CommandList mixed; | ||
| 638 | PreparedList pm; | ||
| 639 | expect(mixed.begin_query({2, d3d12_query::pipeline_statistics, 2}) && mixed.resolve_queries({2, | ||
| 640 | d3d12_query::pipeline_statistics, 0, 1, 1, inner_statistics_offset}) && mixed.resolve_queries({1, | ||
| 641 | d3d12_query::binary_occlusion, 0, 1, 1, binary_offset}) && mixed.resolve_queries({3, | ||
| 642 | d3d12_query::timestamp, 3, 1, 1, timestamp_offset}) && mixed.resolve_queries({1, d3d12_query::occlusion, | ||
| 643 | 2, 1, 1, sum_offset}) && mixed.end_query({2, d3d12_query::pipeline_statistics, 2}) | ||
| 644 | && mixed.resolve_queries({2, d3d12_query::pipeline_statistics, 2, 1, 1, mixed_statistics_offset}), | ||
| 645 | "mixed helpers inside statistics"); | ||
| 646 | prep(mixed, pm); | ||
| 647 | expect(pm.statistics_segment_count == mixed_statistics_segments, "only three non-timestamp resolves split statistics"); | ||
| 648 | auto mixed_pool = make_segment_pool(13); | ||
| 649 | c.values[mixed_pool->pool].resize(mixed_statistics_segments); | ||
| 650 | c.statistics_pools.insert(mixed_pool->pool); | ||
| 651 | QueryReplay mixed_batch; | ||
| 652 | expect(mixed_batch.plan(pm, {}, 0, true, mixed_pool) == ReplayResult::success && mixed_batch.needs_sum | ||
| 653 | && mixed_batch.needs_binary && mixed_batch.needs_statistics_sum, "mixed helper selection"); | ||
| 654 | emit(pm, {}, vk); | ||
| 655 | mixed_batch.commit(); | ||
| 656 | expect(c.word(dst.buffer, arena_offset + sum_offset) == first_saved_count + second_saved_count | ||
| 657 | && c.word(dst.buffer, arena_offset + binary_offset) == 1, | ||
| 658 | "ordinary sum and binary results inside statistics"); | ||
| 659 | for (unsigned j = 0; j < statistics_counters; ++j) { | ||
| 660 | std::uint64_t total = 0; | ||
| 661 | for (unsigned k = 0; k < mixed_statistics_segments; ++k) { | ||
| 662 | total += c.values[mixed_pool->pool][k][j]; | ||
| 663 | } | ||
| 664 | expect(c.word(dst.buffer, arena_offset + mixed_statistics_offset + word_size * j) == total, | ||
| 665 | "mixed statistics sum"); | ||
| 666 | expect(c.word(dst.buffer, arena_offset + inner_statistics_offset + word_size * j) == c.word(dst.buffer, | ||
| 667 | arena_offset + statistics_offset + word_size * j), "previous statistics sum inside a new scope"); | ||
| 668 | } | ||
| 669 | } | ||
| 670 | |||
| 671 | void test_predicated_copies() { | ||
| 672 | constexpr VkDeviceSize source_arena = 32; | ||
| 673 | constexpr VkDeviceSize destination_arena = 40; | ||
| 674 | constexpr VkDeviceSize predicate_arena = 24; | ||
| 675 | constexpr VkDeviceSize predicate_offset = word_size; | ||
| 676 | constexpr VkDeviceSize predicate_address = predicate_arena + predicate_offset; | ||
| 677 | constexpr unsigned resource_bytes = 128; | ||
| 678 | constexpr unsigned backing_bytes = 200; | ||
| 679 | constexpr unsigned predicate_backing_bytes = 64; | ||
| 680 | constexpr unsigned copy_source = 9; | ||
| 681 | constexpr unsigned copy_bytes = 7; | ||
| 682 | constexpr unsigned cleared_offset = 8; | ||
| 683 | constexpr unsigned resolved_offset = 16; | ||
| 684 | constexpr unsigned snapshot_offset = 24; | ||
| 685 | constexpr unsigned skipped_offset = 32; | ||
| 686 | constexpr unsigned inverted_offset = 40; | ||
| 687 | constexpr unsigned second_cleared_offset = 48; | ||
| 688 | constexpr unsigned next_list_offset = 56; | ||
| 689 | constexpr unsigned high_word_offset = 65; | ||
| 690 | constexpr unsigned high_word_source = 11; | ||
| 691 | constexpr std::uint32_t invalid_operation = 999; | ||
| 692 | |||
| 693 | MockReplay c; | ||
| 694 | auto vk = c.replay_functions(); | ||
| 695 | ResourceBinding src{}, dst{}, pred{}; | ||
| 696 | src.buffer = handle<VkBuffer>(1); | ||
| 697 | src.buffer_offset = source_arena; | ||
| 698 | src.size = resource_bytes; | ||
| 699 | dst.buffer = handle<VkBuffer>(2); | ||
| 700 | dst.buffer_offset = destination_arena; | ||
| 701 | dst.size = resource_bytes; | ||
| 702 | dst.host_readable = true; | ||
| 703 | pred.buffer = handle<VkBuffer>(3); | ||
| 704 | pred.buffer_offset = predicate_arena; | ||
| 705 | pred.size = 2 * word_size; | ||
| 706 | c.buffers[src.buffer].resize(backing_bytes); | ||
| 707 | for (unsigned i = 0; i < backing_bytes; ++i) { | ||
| 708 | c.buffers[src.buffer][i] = static_cast<unsigned char>(i); | ||
| 709 | } | ||
| 710 | c.word(src.buffer, source_arena, 0); | ||
| 711 | c.buffers[dst.buffer].assign(backing_bytes, guard_byte); | ||
| 712 | auto expected = c.buffers[dst.buffer]; | ||
| 713 | c.buffers[pred.buffer].assign(predicate_backing_bytes, guard_byte); | ||
| 714 | c.word(pred.buffer, predicate_address, 0); | ||
| 715 | QueryPool heap{handle<VkQueryPool>(4), d3d12_query_heap::occlusion, 1, false, {true}, {}}; | ||
| 716 | c.values[heap.pool].resize(1); | ||
| 717 | c.values[heap.pool][0][0] = UINT64_C(1) << 40; | ||
| 718 | vk.query_pool = [&](QueryHeapId id) -> QueryPool* { | ||
| 719 | return id == 1 ? &heap : nullptr; | ||
| 720 | }; | ||
| 721 | auto resources = [&](ResourceId id) -> const ResourceBinding* { | ||
| 722 | return id == 1 ? &src : id == 2 ? &dst : id == 3 ? &pred : nullptr; | ||
| 723 | }; | ||
| 724 | struct Job { | ||
| 725 | VkBuffer a, b; | ||
| 726 | VkBufferCopy copy; | ||
| 727 | }; | ||
| 728 | std::vector<Job> jobs; | ||
| 729 | vk.prepare_predicated_copy = [&](VkBuffer a, VkBuffer b, VkDeviceSize so, VkDeviceSize d, VkDeviceSize n, | ||
| 730 | std::vector<PredicatedCopyDispatch>& out) { | ||
| 731 | jobs.push_back({a, b, {so, d, n}}); | ||
| 732 | out.push_back({handle<VkDescriptorSet>(jobs.size()), 0, 0, static_cast<unsigned>(n)}); | ||
| 733 | return true; | ||
| 734 | }; | ||
| 735 | vk.emit_predicated_copy = [&](VkCommandBuffer, const std::vector<PredicatedCopyDispatch>& out) { | ||
| 736 | expect(c.conditional, "predicated copy outside scope"); | ||
| 737 | ++c.pred_copies; | ||
| 738 | c.events.push_back("pred_copy"); | ||
| 739 | for (auto& p : out) { | ||
| 740 | auto& job = jobs.at(reinterpret_cast<std::uintptr_t>(p.set) - 1); | ||
| 741 | if (c.execute) { | ||
| 742 | c.copy(job.a, job.b, job.copy); | ||
| 743 | } | ||
| 744 | } | ||
| 745 | }; | ||
| 746 | auto expect_copy = [&](unsigned dest, unsigned source, unsigned n) { | ||
| 747 | std::memcpy(expected.data() + destination_arena + dest, | ||
| 748 | c.buffers[src.buffer].data() + source_arena + source, n); | ||
| 749 | }; | ||
| 750 | CommandList list; | ||
| 751 | expect(list.set_predication({3, predicate_offset, d3d12_predication::equal_zero}) && list.copy_buffer({2, 0, 1, | ||
| 752 | copy_source, copy_bytes}), "record skipped copy"); | ||
| 753 | expect(list.resolve_queries({1, d3d12_query::binary_occlusion, 0, 1, 3, predicate_offset}) | ||
| 754 | && list.copy_buffer({2, 0, 1, copy_source, copy_bytes}), | ||
| 755 | "resolve into active predicate then copy without recapture"); | ||
| 756 | expect(list.set_predication({0, UINT64_MAX, UINT32_MAX}) && list.copy_buffer({2, cleared_offset, 1, copy_source, | ||
| 757 | copy_bytes}), "clear predicate ignores invalid offset/op"); | ||
| 758 | expect_copy(cleared_offset, copy_source, copy_bytes); | ||
| 759 | expect(list.set_predication({3, predicate_offset, d3d12_predication::equal_zero}) && list.copy_buffer({2, | ||
| 760 | resolved_offset, 1, copy_source, copy_bytes}), "recapture resolved nonzero"); | ||
| 761 | expect_copy(resolved_offset, copy_source, copy_bytes); | ||
| 762 | expect(list.copy_buffer({3, predicate_offset, 1, 0, word_size}) && list.copy_buffer({2, snapshot_offset, 1, | ||
| 763 | copy_source, copy_bytes}), "overwrite predicate without recapture"); | ||
| 764 | expect_copy(snapshot_offset, copy_source, copy_bytes); | ||
| 765 | expect(list.set_predication({3, predicate_offset, d3d12_predication::equal_zero}) && list.copy_buffer({2, | ||
| 766 | skipped_offset, 1, copy_source, copy_bytes}), "recapture zero skips"); | ||
| 767 | expect(list.set_predication({3, predicate_offset, d3d12_predication::not_equal_zero}) && list.copy_buffer({2, | ||
| 768 | inverted_offset, 1, copy_source, copy_bytes}), "inverted zero executes"); | ||
| 769 | expect_copy(inverted_offset, copy_source, copy_bytes); | ||
| 770 | expect(list.set_predication({0, 7, invalid_operation}) && list.copy_buffer({2, second_cleared_offset, 1, | ||
| 771 | copy_source, copy_bytes}), "clear then native copy"); | ||
| 772 | expect_copy(second_cleared_offset, copy_source, copy_bytes); | ||
| 773 | expect(list.set_predication({3, predicate_offset, d3d12_predication::equal_zero}) && list.copy_buffer({2, | ||
| 774 | resource_bytes, 1, resource_bytes, 0}) && list.close(), "zero-length copy at buffer end while predicated"); | ||
| 775 | PreparedList p; | ||
| 776 | expect(prepare(list, resources, vk, p) == ReplayResult::success, "prepare mixed list"); | ||
| 777 | expect(p.unpredicated_copies == 0, "buffer copies never counted as unsupported predication fallback"); | ||
| 778 | expect(p.readback_src_stages == (VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_2_COPY_BIT), | ||
| 779 | "mixed readback producers"); | ||
| 780 | QueryReplay q; | ||
| 781 | expect(q.plan(p, {}, 0, true) == ReplayResult::success, "plan resolve into predicate"); | ||
| 782 | emit(p, {}, vk); | ||
| 783 | q.commit(); | ||
| 784 | expect(c.buffers[dst.buffer] == expected, "all copied/skipped bytes and guards match independent oracle"); | ||
| 785 | expect(c.word(pred.buffer, predicate_address) == 0, "predicate overwrite executes"); | ||
| 786 | expect(c.captures == 5 && c.pred_copies == 7 && c.native_copies == 2 && !c.conditional, | ||
| 787 | "capture/copy counts; no zero-byte dispatch; final scope balanced"); | ||
| 788 | auto expected_pred = std::vector<unsigned char>(predicate_backing_bytes, guard_byte); | ||
| 789 | std::uint64_t zero = 0; | ||
| 790 | std::memcpy(expected_pred.data() + predicate_address, &zero, word_size); | ||
| 791 | expect(c.buffers[pred.buffer] == expected_pred, "predicate-buffer arena guards"); | ||
| 792 | CommandList next; | ||
| 793 | expect(next.copy_buffer({2, next_list_offset, 1, copy_source, copy_bytes}) && next.close(), | ||
| 794 | "next list starts unpredicated"); | ||
| 795 | expect(replay(next, {}, resources, vk) == ReplayResult::success, "replay next list"); | ||
| 796 | expect_copy(next_list_offset, copy_source, copy_bytes); | ||
| 797 | expect(c.buffers[dst.buffer] == expected && c.native_copies == 3, "predication does not leak to next list"); | ||
| 798 | c.word(pred.buffer, predicate_address, UINT64_C(1) << 40); | ||
| 799 | CommandList high; | ||
| 800 | expect(high.set_predication({3, predicate_offset, d3d12_predication::equal_zero}) && high.copy_buffer({2, | ||
| 801 | high_word_offset, 1, high_word_source, copy_bytes}) && high.close(), "high-word-only predicate"); | ||
| 802 | expect(replay(high, {}, resources, vk) == ReplayResult::success, "replay high-word predicate"); | ||
| 803 | expect_copy(high_word_offset, high_word_source, copy_bytes); | ||
| 804 | expect(c.buffers[dst.buffer] == expected, "full 64-bit predicate and unaligned copy offsets"); | ||
| 805 | |||
| 806 | // Recording-time controls; false returns must not mutate active query state. | ||
| 807 | CommandList validation; | ||
| 808 | expect(!validation.begin_query({1, d3d12_query::timestamp, 0}), "timestamp begin rejected"); | ||
| 809 | expect(validation.begin_query({1, d3d12_query::occlusion, 0}), "ordinary begin"); | ||
| 810 | expect(!validation.begin_query({1, d3d12_query::occlusion, 0}), "duplicate active slot rejected"); | ||
| 811 | expect(!validation.end_query({1, d3d12_query::binary_occlusion, 0}), "mismatched end type rejected"); | ||
| 812 | expect(!validation.resolve_queries({1, d3d12_query::occlusion, 0, 1, 2, 0}), "active slot resolve rejected"); | ||
| 813 | expect(validation.end_query({1, d3d12_query::occlusion, 0}), "rejected operations preserve matching end"); | ||
| 814 | expect(validation.begin_query({1, d3d12_query::occlusion, 0}) && validation.end_query({1, | ||
| 815 | d3d12_query::occlusion, 0}), "same-list slot reuse"); | ||
| 816 | expect(!validation.resolve_queries({1, d3d12_query::occlusion, UINT32_MAX, 2, 2, 0}), | ||
| 817 | "overflowing query range rejected"); | ||
| 818 | expect(!validation.resolve_queries({1, d3d12_query::occlusion, 0, 1, 2, 1}), "unaligned resolve offset rejected"); | ||
| 819 | expect(!validation.set_predication({3, 1, 0}) && !validation.set_predication({3, 0, invalid_operation}), | ||
| 820 | "invalid nonnull predicate rejected"); | ||
| 821 | auto n = validation.commands().size(); | ||
| 822 | expect(validation.resolve_queries({1, d3d12_query::occlusion, 1, 0, 2, 0}) && validation.copy_buffer({2, | ||
| 823 | UINT64_MAX, 1, UINT64_MAX, 0}) && validation.commands().size() == n, "zero-count commands record no IR"); | ||
| 824 | expect(validation.close() && !validation.copy_buffer({2, 0, 1, 0, 0}), "closed list rejects even zero-byte copies"); | ||
| 825 | CommandList open; | ||
| 826 | expect(open.begin_query({1, d3d12_query::occlusion, 0}) && open.close(), "close synthetic IR with active query"); | ||
| 827 | PreparedList invalid; | ||
| 828 | expect(prepare(open, resources, vk, invalid) == ReplayResult::invalid_query, "replay rejects unended query"); | ||
| 829 | pred.size = predicate_offset + word_size - 1; | ||
| 830 | CommandList short_pred; | ||
| 831 | expect(short_pred.set_predication({3, predicate_offset, 0}) && short_pred.close(), "record short predicate"); | ||
| 832 | expect(prepare(short_pred, resources, vk, invalid) == ReplayResult::invalid_predication, | ||
| 833 | "all eight predicate bytes required"); | ||
| 834 | } | ||
| 835 | |||
| 836 | VulkanDeviceFunctions driver; | ||
| 837 | std::vector<std::pair<VkQueryType, unsigned>> allocations; | ||
| 838 | std::set<VkQueryPool> destroyed; | ||
| 839 | constexpr unsigned first_pool_id = 100; | ||
| 840 | unsigned next_pool = first_pool_id; | ||
| 841 | bool fail_submit = false; | ||
| 842 | PFN_vkVoidFunction VKAPI_CALL get(VkDevice, const char* name) { | ||
| 843 | #define MOCK_DEVICE_FUNCTION(n) \ | ||
| 844 | if (std::string_view(name) == #n) { \ | ||
| 845 | return reinterpret_cast<PFN_vkVoidFunction>(driver.n); \ | ||
| 846 | } | ||
| 847 | LEONIDA_VK_DEVICE_FUNCTIONS(MOCK_DEVICE_FUNCTION) | ||
| 848 | #undef MOCK_DEVICE_FUNCTION | ||
| 849 | return nullptr; | ||
| 850 | } | ||
| 851 | |||
| 852 | void test_queue_segments() { | ||
| 853 | constexpr unsigned list_count = 2; | ||
| 854 | constexpr unsigned overlap_segments = 3; | ||
| 855 | constexpr unsigned occlusion_slots_needed = list_count * overlap_segments; | ||
| 856 | constexpr unsigned statistics_slots_needed = 2 + 3; | ||
| 857 | constexpr unsigned successful_occlusion_pool = first_pool_id + 2; | ||
| 858 | constexpr unsigned successful_statistics_pool = first_pool_id + 3; | ||
| 859 | constexpr VkQueryPipelineStatisticFlags statistics_mask = (1u << statistics_counters) - 1; | ||
| 860 | constexpr VkDeviceSize arena_offset = 24; | ||
| 861 | constexpr VkDeviceSize probe_occlusion_offset = 16; | ||
| 862 | constexpr VkDeviceSize probe_statistics_offset = 32; | ||
| 863 | constexpr unsigned resource_bytes = 128; | ||
| 864 | constexpr unsigned backing_bytes = 160; | ||
| 865 | |||
| 866 | MockReplay c; | ||
| 867 | auto r = c.replay_functions(); | ||
| 868 | // Only the entry points used by a query-only queue are supplied. No Vulkan loader is involved. | ||
| 869 | driver.vkCmdResetQueryPool = r.reset_query_pool; | ||
| 870 | driver.vkCmdBeginQuery = r.begin_query; | ||
| 871 | driver.vkCmdEndQuery = r.end_query; | ||
| 872 | driver.vkCmdWriteTimestamp = r.write_timestamp; | ||
| 873 | driver.vkCmdCopyQueryPoolResults = r.copy_query_pool_results; | ||
| 874 | driver.vkCmdFillBuffer = r.fill_buffer; | ||
| 875 | driver.vkCreateCommandPool = +[](VkDevice, const VkCommandPoolCreateInfo*, const VkAllocationCallbacks*, | ||
| 876 | VkCommandPool* p) { | ||
| 877 | *p = handle<VkCommandPool>(1); | ||
| 878 | return VK_SUCCESS; | ||
| 879 | }; | ||
| 880 | driver.vkDestroyCommandPool = +[](VkDevice, VkCommandPool, const VkAllocationCallbacks*) {}; | ||
| 881 | driver.vkCreateSemaphore = +[](VkDevice, const VkSemaphoreCreateInfo*, const VkAllocationCallbacks*, | ||
| 882 | VkSemaphore* s) { | ||
| 883 | *s = handle<VkSemaphore>(1); | ||
| 884 | return VK_SUCCESS; | ||
| 885 | }; | ||
| 886 | driver.vkDestroySemaphore = +[](VkDevice, VkSemaphore, const VkAllocationCallbacks*) {}; | ||
| 887 | driver.vkGetSemaphoreCounterValue = +[](VkDevice, VkSemaphore, std::uint64_t* v) { | ||
| 888 | *v = UINT64_MAX; | ||
| 889 | return VK_SUCCESS; | ||
| 890 | }; | ||
| 891 | driver.vkQueueWaitIdle = +[](VkQueue) { | ||
| 892 | return VK_SUCCESS; | ||
| 893 | }; | ||
| 894 | driver.vkAllocateCommandBuffers = +[](VkDevice, const VkCommandBufferAllocateInfo* info, VkCommandBuffer* b) { | ||
| 895 | expect(info->commandBufferCount == 1, "one command buffer"); | ||
| 896 | *b = handle<VkCommandBuffer>(1); | ||
| 897 | return VK_SUCCESS; | ||
| 898 | }; | ||
| 899 | driver.vkResetCommandBuffer = +[](VkCommandBuffer, VkCommandBufferResetFlags) { | ||
| 900 | return VK_SUCCESS; | ||
| 901 | }; | ||
| 902 | driver.vkBeginCommandBuffer = +[](VkCommandBuffer, const VkCommandBufferBeginInfo*) { | ||
| 903 | return VK_SUCCESS; | ||
| 904 | }; | ||
| 905 | driver.vkEndCommandBuffer = +[](VkCommandBuffer) { | ||
| 906 | return VK_SUCCESS; | ||
| 907 | }; | ||
| 908 | driver.vkQueueSubmit = +[](VkQueue, unsigned, const VkSubmitInfo*, VkFence) { | ||
| 909 | return fail_submit ? VK_ERROR_OUT_OF_HOST_MEMORY : VK_SUCCESS; | ||
| 910 | }; | ||
| 911 | driver.vkCreateQueryPool = +[](VkDevice, const VkQueryPoolCreateInfo* info, const VkAllocationCallbacks*, | ||
| 912 | VkQueryPool* out) { | ||
| 913 | expect(info->queryCount > 0, "no empty pool allocation"); | ||
| 914 | if (info->queryType == VK_QUERY_TYPE_PIPELINE_STATISTICS) { | ||
| 915 | expect(info->pipelineStatistics == statistics_mask, "all 11 counters selected"); | ||
| 916 | } | ||
| 917 | allocations.emplace_back(info->queryType, info->queryCount); | ||
| 918 | *out = handle<VkQueryPool>(next_pool++); | ||
| 919 | MockReplay::current->values[*out].resize(info->queryCount); | ||
| 920 | return VK_SUCCESS; | ||
| 921 | }; | ||
| 922 | driver.vkDestroyQueryPool = +[](VkDevice, VkQueryPool p, const VkAllocationCallbacks*) { | ||
| 923 | expect(destroyed.insert(p).second, "pool destroyed twice"); | ||
| 924 | }; | ||
| 925 | VulkanContext context(get, handle<VkDevice>(1), true); | ||
| 926 | VkPhysicalDeviceMemoryProperties memory{}; | ||
| 927 | memory.memoryTypeCount = 1; | ||
| 928 | context.set_occlusion_resolve_memory(memory); | ||
| 929 | QueryPool heap{handle<VkQueryPool>(2), d3d12_query_heap::occlusion, 4, false, std::vector<bool>(4), {}}; | ||
| 930 | QueryPool stat{handle<VkQueryPool>(3), d3d12_query_heap::pipeline_statistics, 2, false, std::vector<bool>(2), {}}; | ||
| 931 | c.values[heap.pool].resize(4); | ||
| 932 | c.values[stat.pool].resize(2); | ||
| 933 | context.add_query_pool(1, heap); | ||
| 934 | context.add_query_pool(2, stat); | ||
| 935 | ResourceBinding dst{}; | ||
| 936 | dst.buffer = handle<VkBuffer>(1); | ||
| 937 | dst.size = resource_bytes; | ||
| 938 | dst.buffer_offset = arena_offset; | ||
| 939 | context.add_resource(1, dst); | ||
| 940 | c.buffers[dst.buffer].assign(backing_bytes, guard_byte); | ||
| 941 | { | ||
| 942 | VulkanQueue queue(context, handle<VkQueue>(1), 0); | ||
| 943 | expect(queue.ok(), "mock queue initialized"); | ||
| 944 | CommandList a, b; | ||
| 945 | for (unsigned i = 0; i < list_count; ++i) { | ||
| 946 | auto& list = i ? b : a; | ||
| 947 | expect(list.begin_query({1, d3d12_query::occlusion, 0}) && list.begin_query({1, d3d12_query::occlusion, | ||
| 948 | 1}) && list.end_query({1, d3d12_query::occlusion, 0}) && list.end_query({1, | ||
| 949 | d3d12_query::occlusion, 1}), "overlap scope"); | ||
| 950 | expect(list.begin_query({2, d3d12_query::pipeline_statistics, i}), "statistics begin"); | ||
| 951 | for (unsigned k = 0; k <= i; ++k) { | ||
| 952 | expect(list.resolve_queries({1, d3d12_query::occlusion, 3, 1, 1, 0}), "split statistics on zero fill"); | ||
| 953 | } | ||
| 954 | expect(list.end_query({2, d3d12_query::pipeline_statistics, i}) && list.close(), "statistics end"); | ||
| 955 | } | ||
| 956 | const CommandList* lists[]{&a, &b}; | ||
| 957 | fail_submit = true; | ||
| 958 | expect(queue.execute(lists) == ReplayResult::unsupported, "injected transient submit failure"); | ||
| 959 | fail_submit = false; | ||
| 960 | const std::vector<std::pair<VkQueryType, unsigned>> want{{VK_QUERY_TYPE_OCCLUSION, occlusion_slots_needed}, | ||
| 961 | {VK_QUERY_TYPE_PIPELINE_STATISTICS, statistics_slots_needed}}; | ||
| 962 | expect(allocations == want && destroyed.size() == 2, "failed submission frees exact six/five-slot pools"); | ||
| 963 | // Published query state must still say 'never ended'. If commit ran on failure this would need a sum helper. | ||
| 964 | CommandList probe; | ||
| 965 | expect(probe.resolve_queries({1, d3d12_query::occlusion, 0, 2, 1, probe_occlusion_offset}) | ||
| 966 | && probe.resolve_queries({2, d3d12_query::pipeline_statistics, 0, 1, 1, probe_statistics_offset}) | ||
| 967 | && probe.close(), "failure-state probe"); | ||
| 968 | const CommandList* pp = &probe; | ||
| 969 | expect(queue.execute({&pp, 1}) == ReplayResult::success, "failed query results were not published"); | ||
| 970 | expect(c.word(dst.buffer, arena_offset + probe_occlusion_offset) == 0 && c.word(dst.buffer, | ||
| 971 | arena_offset + probe_occlusion_offset + word_size) == 0, "ordinary failure state zero-filled"); | ||
| 972 | for (unsigned j = 0; j < statistics_counters; ++j) { | ||
| 973 | expect(c.word(dst.buffer, arena_offset + probe_statistics_offset + word_size * j) == 0, | ||
| 974 | "statistics failure state zero-filled"); | ||
| 975 | } | ||
| 976 | expect(allocations == want, "resolve-only batch allocates no segment pools"); | ||
| 977 | allocations.clear(); | ||
| 978 | c.resets.clear(); | ||
| 979 | expect(queue.execute(lists) == ReplayResult::success, "retry multi-list submission"); | ||
| 980 | expect(allocations == want, "actual queue sums all list segment counts"); | ||
| 981 | std::vector<unsigned> occlusion_slots, statistics_slots; | ||
| 982 | for (auto [p, i] : c.resets) { | ||
| 983 | if (p == handle<VkQueryPool>(successful_occlusion_pool)) { | ||
| 984 | occlusion_slots.push_back(i); | ||
| 985 | } | ||
| 986 | if (p == handle<VkQueryPool>(successful_statistics_pool)) { | ||
| 987 | statistics_slots.push_back(i); | ||
| 988 | } | ||
| 989 | } | ||
| 990 | expect(occlusion_slots == std::vector<unsigned>({0, 1, 2, 3, 4, 5}) | ||
| 991 | && statistics_slots == std::vector<unsigned>({0, 1, 2, 3, 4}), | ||
| 992 | "second-list bases use every allocated slot exactly once"); | ||
| 993 | // Mock reset/end entry points bounds-check every index against the actual allocations. Nonzero bases in the | ||
| 994 | // second list must cover occlusion slots 3..5 and statistics slots 2..4, without overlap or overflow. | ||
| 995 | for (unsigned i = first_pool_id; i <= successful_statistics_pool; ++i) { | ||
| 996 | expect(c.active[handle<VkQueryPool>(i)].empty(), "all physical queries ended"); | ||
| 997 | } | ||
| 998 | expect(!destroyed.count(handle<VkQueryPool>(successful_occlusion_pool)) | ||
| 999 | && !destroyed.count(handle<VkQueryPool>(successful_statistics_pool)), "successful pools remain alive"); | ||
| 1000 | context.remove_query_pool(1); | ||
| 1001 | context.remove_query_pool(2); | ||
| 1002 | expect(!destroyed.count(handle<VkQueryPool>(successful_occlusion_pool)) | ||
| 1003 | && !destroyed.count(handle<VkQueryPool>(successful_statistics_pool)), | ||
| 1004 | "in-flight command slot retains pools after heap removal"); | ||
| 1005 | CommandList empty; | ||
| 1006 | expect(empty.close(), "empty list"); | ||
| 1007 | const CommandList* ep = ∅ | ||
| 1008 | expect(queue.execute({&ep, 1}) == ReplayResult::success, "reuse completed command slot"); | ||
| 1009 | expect(destroyed.count(handle<VkQueryPool>(successful_occlusion_pool)) | ||
| 1010 | && destroyed.count(handle<VkQueryPool>(successful_statistics_pool)), | ||
| 1011 | "completed slot releases pools after final owner disappears"); | ||
| 1012 | } | ||
| 1013 | } | ||
| 1014 | |||
| 1015 | } // namespace | ||
| 1016 | |||
| 1017 | int main() { | ||
| 1018 | struct TestCase { | ||
| 1019 | const char* name; | ||
| 1020 | void (*run)(); | ||
| 1021 | }; | ||
| 1022 | const TestCase cases[] = { | ||
| 1023 | {"helper chunk boundaries", test_helper_chunks}, | ||
| 1024 | {"query boundaries and persistent state", test_query_state}, | ||
| 1025 | {"predication and recording checks", test_predicated_copies}, | ||
| 1026 | {"queue segment allocation and failed submit", test_queue_segments}, | ||
| 1027 | }; | ||
| 1028 | unsigned failures = 0; | ||
| 1029 | for (const auto& test : cases) { | ||
| 1030 | try { | ||
| 1031 | test.run(); | ||
| 1032 | } catch (const std::exception& error) { | ||
| 1033 | std::fprintf(stderr, "FAIL: %s: %s\n", test.name, error.what()); | ||
| 1034 | ++failures; | ||
| 1035 | } | ||
| 1036 | } | ||
| 1037 | if (failures) { | ||
| 1038 | return 1; | ||
| 1039 | } | ||
| 1040 | std::puts("replay_query_edges_test: heap boundaries, chunking, persistent queries, " | ||
| 1041 | "predicated copies and queue ownership passed"); | ||
| 1042 | return 0; | ||
| 1043 | } | ||
diff --git a/runtime/test/replay_query_predication_test.cpp b/runtime/test/replay_query_predication_test.cpp index 621fb4eee..df4e22718 100644 --- a/runtime/test/replay_query_predication_test.cpp +++ b/runtime/test/replay_query_predication_test.cpp | |||
| @@ -3,7 +3,9 @@ | |||
| 3 | // an active conditional rendering scope (D3D-148). Check that emit() suspends conditional rendering for the | 3 | // an active conditional rendering scope (D3D-148). Check that emit() suspends conditional rendering for the |
| 4 | // entire ResolveQueryData loop (not only before helper dispatches) and restores it afterward. Cases 5 and 6 check | 4 | // entire ResolveQueryData loop (not only before helper dispatches) and restores it afterward. Cases 5 and 6 check |
| 5 | // how resolves inside a pipeline-statistics query are replayed; cases 7 and 8 cover the other helper dispatches | 5 | // how resolves inside a pipeline-statistics query are replayed; cases 7 and 8 cover the other helper dispatches |
| 6 | // and their no-pool fallback (D3D-162). No GPU or game data. | 6 | // and their no-pool fallback (D3D-162). Cases 9 to 13 check overlapping queries: statistics over statistics, binary |
| 7 | // inside ordinary, the composite sum-and-normalize binary resolve, helper dispatches inside overlapping statistics | ||
| 8 | // queries, and the single-list refusal (D3D-252). No GPU or game data. | ||
| 7 | #include "../src/vulkan_replay.h" | 9 | #include "../src/vulkan_replay.h" |
| 8 | #include <cstdint> | 10 | #include <cstdint> |
| 9 | #include <cstdio> | 11 | #include <cstdio> |
| @@ -133,6 +135,14 @@ int main() { | |||
| 133 | if (g_trace->cond_active) ++g_trace->binary_while_cond; | 135 | if (g_trace->cond_active) ++g_trace->binary_while_cond; |
| 134 | g_trace->events.push_back("binary"); | 136 | g_trace->events.push_back("binary"); |
| 135 | }; | 137 | }; |
| 138 | vk.sum_occlusion = [](VkCommandBuffer, VkQueryPool pool, std::uint32_t first, std::uint32_t count, VkBuffer, | ||
| 139 | VkDeviceSize) { | ||
| 140 | g_trace->events.push_back(query_event("sum_occlusion", pool, first) + "+" + std::to_string(count)); | ||
| 141 | }; | ||
| 142 | vk.sum_binary_occlusion = [](VkCommandBuffer, VkQueryPool pool, std::uint32_t first, std::uint32_t count, | ||
| 143 | VkBuffer, VkDeviceSize) { | ||
| 144 | g_trace->events.push_back(query_event("sum_binary_occlusion", pool, first) + "+" + std::to_string(count)); | ||
| 145 | }; | ||
| 136 | 146 | ||
| 137 | // 1. Binary occlusion resolve with leading and trailing un-ended queries under a predicate: | 147 | // 1. Binary occlusion resolve with leading and trailing un-ended queries under a predicate: |
| 138 | // conditional rendering must end before the leading fill_buffer and resume after the trailing fill_buffer. | 148 | // conditional rendering must end before the leading fill_buffer and resume after the trailing fill_buffer. |
| @@ -370,6 +380,197 @@ int main() { | |||
| 370 | } | 380 | } |
| 371 | } | 381 | } |
| 372 | 382 | ||
| 383 | // 9. D3D-252, overlapping pipeline-statistics queries: the segments follow every Begin and End, so each logical | ||
| 384 | // query keeps a contiguous range — the intersection interval is shared — and each resolve sums its range. | ||
| 385 | // A resolve may only name an ended query, so the second resolve follows the second End. | ||
| 386 | { | ||
| 387 | Trace trace; | ||
| 388 | g_trace = &trace; | ||
| 389 | CommandList list; | ||
| 390 | expect(list.begin_query({6, d3d12_query::pipeline_statistics, 0}), "record overlap begin 0"); | ||
| 391 | expect(list.begin_query({6, d3d12_query::pipeline_statistics, 1}), "record overlap begin 1"); | ||
| 392 | expect(list.end_query({6, d3d12_query::pipeline_statistics, 0}), "record overlap end 0"); | ||
| 393 | expect(list.resolve_queries({6, d3d12_query::pipeline_statistics, 0, 1, 1, 0}), "record overlap resolve 0"); | ||
| 394 | expect(list.end_query({6, d3d12_query::pipeline_statistics, 1}), "record overlap end 1"); | ||
| 395 | expect(list.resolve_queries({6, d3d12_query::pipeline_statistics, 1, 1, 1, 0}), "record overlap resolve 1"); | ||
| 396 | expect(list.close(), "close overlap statistics list"); | ||
| 397 | PreparedList prepared; | ||
| 398 | expect(prepare(list, resolve, vk, prepared) == ReplayResult::success, "prepare overlap statistics list"); | ||
| 399 | expect(prepared.statistics_segment_count == 4, "overlap statistics: four physical segments"); | ||
| 400 | auto segments = std::make_shared<OcclusionSegmentPool>(); | ||
| 401 | segments->pool = handle<VkQueryPool>(9); | ||
| 402 | segments->destroy = mock_destroy_pool; | ||
| 403 | QueryReplay queries; | ||
| 404 | expect(queries.plan(prepared, {}, 0, true, segments, 4) == ReplayResult::success, | ||
| 405 | "plan overlap statistics list"); | ||
| 406 | expect(queries.needs_statistics_sum, "overlap statistics: the sum helper is needed"); | ||
| 407 | emit(prepared, VK_NULL_HANDLE, vk); | ||
| 408 | queries.commit(); | ||
| 409 | const std::vector<std::string> want{"begin_query 9:4", "end_query 9:4", "begin_query 9:5", | ||
| 410 | "end_query 9:5", "begin_query 9:6", "end_query 9:6", | ||
| 411 | "sum_statistics 9:4+2", "begin_query 9:7", "end_query 9:7", | ||
| 412 | "sum_statistics 9:5+3"}; | ||
| 413 | expect(trace.events == want, "overlap statistics: one open segment per event, resolves sum the ranges"); | ||
| 414 | expect(statistics_heap.occlusion.count(0) && statistics_heap.occlusion[0].count == 2 && | ||
| 415 | statistics_heap.occlusion.count(1) && statistics_heap.occlusion[1].count == 3, | ||
| 416 | "overlap statistics: both heaps keep their segment ranges"); | ||
| 417 | } | ||
| 418 | |||
| 419 | // 10. D3D-252, a binary occlusion query open inside an ordinary one: both are virtualized into the same physical | ||
| 420 | // pool. The ordinary resolve sums three segments; the binary resolve normalizes its one segment to 0/1. | ||
| 421 | { | ||
| 422 | Trace trace; | ||
| 423 | g_trace = &trace; | ||
| 424 | CommandList list; | ||
| 425 | expect(list.begin_query({1, d3d12_query::occlusion, 0}), "record kind overlap begin ordinary"); | ||
| 426 | expect(list.begin_query({1, d3d12_query::binary_occlusion, 1}), "record kind overlap begin binary"); | ||
| 427 | expect(list.end_query({1, d3d12_query::binary_occlusion, 1}), "record kind overlap end binary"); | ||
| 428 | expect(list.end_query({1, d3d12_query::occlusion, 0}), "record kind overlap end ordinary"); | ||
| 429 | expect(list.resolve_queries({1, d3d12_query::occlusion, 0, 1, 1, 0}), "record kind overlap resolve ordinary"); | ||
| 430 | expect(list.resolve_queries({1, d3d12_query::binary_occlusion, 1, 1, 1, 16}), "record kind overlap resolve binary"); | ||
| 431 | expect(list.close(), "close kind overlap list"); | ||
| 432 | PreparedList prepared; | ||
| 433 | expect(prepare(list, resolve, vk, prepared) == ReplayResult::success, "prepare kind overlap list"); | ||
| 434 | expect(prepared.segment_count == 3, "kind overlap: three physical segments"); | ||
| 435 | auto segments = std::make_shared<OcclusionSegmentPool>(); | ||
| 436 | segments->pool = handle<VkQueryPool>(9); | ||
| 437 | segments->destroy = mock_destroy_pool; | ||
| 438 | QueryReplay queries; | ||
| 439 | expect(queries.plan(prepared, segments, 0, true, {}, 0) == ReplayResult::success, | ||
| 440 | "plan kind overlap list"); | ||
| 441 | expect(queries.needs_sum && queries.needs_binary && !queries.needs_sum_binary, | ||
| 442 | "kind overlap: sum for the ordinary resolve, normalize for the single-segment binary"); | ||
| 443 | emit(prepared, VK_NULL_HANDLE, vk); | ||
| 444 | queries.commit(); | ||
| 445 | const std::vector<std::string> want{"begin_query 9:0", "end_query 9:0", "begin_query 9:1", | ||
| 446 | "end_query 9:1", "begin_query 9:2", "end_query 9:2", | ||
| 447 | "sum_occlusion 9:0+3", "binary"}; | ||
| 448 | expect(trace.events == want, "kind overlap: shared physical segments, sum and normalize resolves"); | ||
| 449 | expect(heap.occlusion.count(0) && heap.occlusion[0].count == 3 && heap.occlusion.count(1) && | ||
| 450 | heap.occlusion[1].count == 1, | ||
| 451 | "kind overlap: both kinds keep their segment ranges in the heap"); | ||
| 452 | } | ||
| 453 | |||
| 454 | // 11. D3D-252, a binary query overlapping the ordinary one with two segments: the resolve sums the segments and | ||
| 455 | // then normalizes the total (the composite helper), not one 0/1 per segment. | ||
| 456 | { | ||
| 457 | Trace trace; | ||
| 458 | g_trace = &trace; | ||
| 459 | CommandList list; | ||
| 460 | expect(list.begin_query({1, d3d12_query::occlusion, 0}), "record composite begin ordinary"); | ||
| 461 | expect(list.begin_query({1, d3d12_query::binary_occlusion, 1}), "record composite begin binary"); | ||
| 462 | expect(list.end_query({1, d3d12_query::occlusion, 0}), "record composite end ordinary"); | ||
| 463 | expect(list.end_query({1, d3d12_query::binary_occlusion, 1}), "record composite end binary"); | ||
| 464 | expect(list.resolve_queries({1, d3d12_query::binary_occlusion, 1, 1, 1, 16}), "record composite resolve binary"); | ||
| 465 | expect(list.close(), "close composite list"); | ||
| 466 | PreparedList prepared; | ||
| 467 | expect(prepare(list, resolve, vk, prepared) == ReplayResult::success, "prepare composite list"); | ||
| 468 | expect(prepared.segment_count == 3, "composite: three physical segments"); | ||
| 469 | auto segments = std::make_shared<OcclusionSegmentPool>(); | ||
| 470 | segments->pool = handle<VkQueryPool>(9); | ||
| 471 | segments->destroy = mock_destroy_pool; | ||
| 472 | QueryReplay queries; | ||
| 473 | expect(queries.plan(prepared, segments, 0, true, {}, 0) == ReplayResult::success, "plan composite list"); | ||
| 474 | expect(queries.needs_sum_binary, "composite: the sum-and-normalize helper is needed"); | ||
| 475 | emit(prepared, VK_NULL_HANDLE, vk); | ||
| 476 | queries.commit(); | ||
| 477 | const std::vector<std::string> want{"begin_query 9:0", "end_query 9:0", "begin_query 9:1", | ||
| 478 | "end_query 9:1", "begin_query 9:2", "end_query 9:2", | ||
| 479 | "sum_binary_occlusion 9:1+2"}; | ||
| 480 | expect(trace.events == want, "composite: the binary resolve sums its segments and normalizes once"); | ||
| 481 | } | ||
| 482 | |||
| 483 | // 12. D3D-252, helper dispatches inside overlapping statistics queries: the helpers share the segment numbering | ||
| 484 | // here too — the shared physical segment closes before the dispatches and a new one opens after them, so a | ||
| 485 | // footprint conversion stays out of every query still running (D3D-162). | ||
| 486 | { | ||
| 487 | Trace trace; | ||
| 488 | g_trace = &trace; | ||
| 489 | auto helpers = vk; | ||
| 490 | helpers.depth24_prepare = [&](Depth24Job& job, std::vector<Depth24Job>& parts) { | ||
| 491 | job.scratch = handle<VkBuffer>(10); | ||
| 492 | parts.assign(2, job); | ||
| 493 | return true; | ||
| 494 | }; | ||
| 495 | helpers.depth24_run = [](VkCommandBuffer, const Depth24Job&) { | ||
| 496 | expect(!g_trace->cond_active, "footprint helper is unconditional"); | ||
| 497 | g_trace->events.push_back("footprint"); | ||
| 498 | }; | ||
| 499 | helpers.pipeline_barrier = +[](VkCommandBuffer, VkPipelineStageFlags, VkPipelineStageFlags, | ||
| 500 | VkDependencyFlags, std::uint32_t, const VkMemoryBarrier*, std::uint32_t, | ||
| 501 | const VkBufferMemoryBarrier*, std::uint32_t, const VkImageMemoryBarrier*) {}; | ||
| 502 | helpers.copy_buffer = +[](VkCommandBuffer, VkBuffer, VkBuffer, std::uint32_t, const VkBufferCopy*) {}; | ||
| 503 | helpers.copy_buffer_to_image = +[](VkCommandBuffer, VkBuffer, VkImage, VkImageLayout, | ||
| 504 | std::uint32_t, const VkBufferImageCopy*) {}; | ||
| 505 | helpers.copy_image = +[](VkCommandBuffer, VkImage, VkImageLayout, VkImage, VkImageLayout, | ||
| 506 | std::uint32_t, const VkImageCopy*) {}; | ||
| 507 | helpers.copy_image_to_buffer = +[](VkCommandBuffer, VkImage, VkImageLayout, VkBuffer, | ||
| 508 | std::uint32_t, const VkBufferImageCopy*) { | ||
| 509 | g_trace->events.push_back("readback"); | ||
| 510 | }; | ||
| 511 | ResourceBinding buffer = dst; | ||
| 512 | buffer.buffer_offset = 0; | ||
| 513 | buffer.size = 512; | ||
| 514 | ResourceBinding image{}; | ||
| 515 | image.image = handle<VkImage>(11); | ||
| 516 | image.format = VK_FORMAT_D32_SFLOAT_S8_UINT; | ||
| 517 | image.aspects = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; | ||
| 518 | image.width = image.height = image.depth = image.mip_levels = image.array_layers = image.samples = 1; | ||
| 519 | image.rgb96 = false; | ||
| 520 | image.depth24 = image.depth24_as_float = true; | ||
| 521 | const auto resources = [&](ResourceId id) -> const ResourceBinding* { | ||
| 522 | return id == 1 ? &buffer : id == 3 ? &image : nullptr; | ||
| 523 | }; | ||
| 524 | const CopyLocation texture{3, false, 0, 0, 0, 0, 0, 0}; | ||
| 525 | const CopyLocation footprint{1, true, 0, 0, 1, 1, 1, 256}; | ||
| 526 | CommandList list; | ||
| 527 | expect(list.begin_query({6, d3d12_query::pipeline_statistics, 0}), "overlap helper begin 0"); | ||
| 528 | expect(list.begin_query({6, d3d12_query::pipeline_statistics, 1}), "overlap helper begin 1"); | ||
| 529 | expect(list.end_query({6, d3d12_query::pipeline_statistics, 0}), "overlap helper end 0"); | ||
| 530 | expect(list.copy_texture({footprint, 0, 0, 0, texture, false, {}}), "overlap helper footprint copy"); | ||
| 531 | expect(list.end_query({6, d3d12_query::pipeline_statistics, 1}), "overlap helper end 1"); | ||
| 532 | expect(list.resolve_queries({6, d3d12_query::pipeline_statistics, 0, 1, 1, 0}), "overlap helper resolve 0"); | ||
| 533 | expect(list.resolve_queries({6, d3d12_query::pipeline_statistics, 1, 1, 1, 0}), "overlap helper resolve 1"); | ||
| 534 | expect(list.close(), "close overlap helper list"); | ||
| 535 | PreparedList prepared; | ||
| 536 | expect(prepare(list, resources, helpers, prepared, true) == ReplayResult::success, | ||
| 537 | "prepare overlap helper list"); | ||
| 538 | expect(prepared.statistics_segment_count == 4, "the helper adds its two segments to the overlap"); | ||
| 539 | auto segments = std::make_shared<OcclusionSegmentPool>(); | ||
| 540 | segments->pool = handle<VkQueryPool>(9); | ||
| 541 | segments->destroy = mock_destroy_pool; | ||
| 542 | QueryReplay queries; | ||
| 543 | expect(queries.plan(prepared, {}, 0, true, segments, 4) == ReplayResult::success, | ||
| 544 | "plan overlap helper list"); | ||
| 545 | expect(queries.needs_statistics_sum, "overlap helpers need the statistics sum"); | ||
| 546 | emit(prepared, VK_NULL_HANDLE, helpers); | ||
| 547 | queries.commit(); | ||
| 548 | const std::vector<std::string> want{ | ||
| 549 | "begin_query 9:4", "end_query 9:4", "begin_query 9:5", "end_query 9:5", "begin_query 9:6", | ||
| 550 | "readback", "end_query 9:6", "footprint", "footprint", "begin_query 9:7", | ||
| 551 | "end_query 9:7", "sum_statistics 9:4+2", "sum_statistics 9:5+3"}; | ||
| 552 | expect(trace.events == want, "overlap helpers: the dispatches run outside every open segment"); | ||
| 553 | expect(statistics_heap.occlusion.count(0) && statistics_heap.occlusion[0].count == 2 && | ||
| 554 | statistics_heap.occlusion.count(1) && statistics_heap.occlusion[1].count == 3, | ||
| 555 | "overlap helpers: the queries keep their segment ranges"); | ||
| 556 | } | ||
| 557 | |||
| 558 | // 13. D3D-252, the single-list replay() helper: it has no segment pool, and running overlapping statistics | ||
| 559 | // queries whole would keep two Vulkan queries of one type active, so the list is refused outright. | ||
| 560 | { | ||
| 561 | Trace trace; | ||
| 562 | g_trace = &trace; | ||
| 563 | CommandList list; | ||
| 564 | expect(list.begin_query({6, d3d12_query::pipeline_statistics, 0}), "record helper begin 0"); | ||
| 565 | expect(list.begin_query({6, d3d12_query::pipeline_statistics, 1}), "record helper begin 1"); | ||
| 566 | expect(list.end_query({6, d3d12_query::pipeline_statistics, 0}), "record helper end 0"); | ||
| 567 | expect(list.end_query({6, d3d12_query::pipeline_statistics, 1}), "record helper end 1"); | ||
| 568 | expect(list.close(), "close helper list"); | ||
| 569 | expect(replay(list, VK_NULL_HANDLE, resolve, vk) == ReplayResult::unsupported, | ||
| 570 | "no segment pool: overlapping statistics queries are refused instead of run whole"); | ||
| 571 | expect(trace.events.empty(), "no segment pool: nothing was emitted for the refused list"); | ||
| 572 | } | ||
| 573 | |||
| 373 | if (failures) return 1; | 574 | if (failures) return 1; |
| 374 | std::puts("replay_query_predication_test: query resolves suspend conditional rendering around fills, copies and dispatches"); | 575 | std::puts("replay_query_predication_test: query resolves suspend conditional rendering around fills, copies and dispatches"); |
| 375 | return 0; | 576 | return 0; |
diff --git a/runtime/test/resource_tiling_test.cpp b/runtime/test/resource_tiling_test.cpp index 848e2f57c..9bbcfbf3a 100644 --- a/runtime/test/resource_tiling_test.cpp +++ b/runtime/test/resource_tiling_test.cpp | |||
| @@ -111,8 +111,8 @@ int main() { | |||
| 111 | // AMD's split (D3D-65). Every layout below was measured on the AMD PC runtime and is identical on an RX 9070 XT | 111 | // AMD's split (D3D-65). Every layout below was measured on the AMD PC runtime and is identical on an RX 9070 XT |
| 112 | // (RDNA4, driver 32.0.31041.1004) and a Ryzen 7 9800X3D iGPU (RDNA2, 32.0.21045.5002): compare_tiling's 17 texture | 112 | // (RDNA4, driver 32.0.31041.1004) and a Ryzen 7 9800X3D iGPU (RDNA2, 32.0.21045.5002): compare_tiling's 17 texture |
| 113 | // layouts, then 30 edge cases (a mip exactly at or just past half a tile, thin and tall textures, non-square 2D and | 113 | // layouts, then 30 edge cases (a mip exactly at or just past half a tile, thin and tall textures, non-square 2D and |
| 114 | // volume tiles). The standard and packed mip counts and the packed start are AMD's. The packed tiles are this | 114 | // volume tiles), then 36 volumes whose packed tail is deeper than a tile. Every field is AMD's: the standard and |
| 115 | // layer's tight count, which is AMD's except for the two deep volumes packed from mip 0, where AMD reserves 2. | 115 | // packed mip counts, the packed start, and the packed tiles, one per tile-depth slice the tail spans. |
| 116 | struct AmdCase { | 116 | struct AmdCase { |
| 117 | const char* name; | 117 | const char* name; |
| 118 | TilingDesc desc; | 118 | TilingDesc desc; |
| @@ -159,13 +159,50 @@ int main() { | |||
| 159 | {"132x4 BC7", {TiledKind::texture2d, 132, 4, 1, 8, 16, 4}, 1, 7, 1, 1}, | 159 | {"132x4 BC7", {TiledKind::texture2d, 132, 4, 1, 8, 16, 4}, 1, 7, 1, 1}, |
| 160 | {"32^3 R8 vol", {TiledKind::texture3d, 32, 32, 32, 6, 1, 1}, 0, 6, 1, 0}, | 160 | {"32^3 R8 vol", {TiledKind::texture3d, 32, 32, 32, 6, 1, 1}, 0, 6, 1, 0}, |
| 161 | {"33x4x4 R8 vol", {TiledKind::texture3d, 33, 4, 4, 6, 1, 1}, 1, 5, 1, 1}, | 161 | {"33x4x4 R8 vol", {TiledKind::texture3d, 33, 4, 4, 6, 1, 1}, 1, 5, 1, 1}, |
| 162 | {"8x8x64 R8 vol", {TiledKind::texture3d, 8, 8, 64, 7, 1, 1}, 0, 7, 1, 0}, // AMD reserves 2 | 162 | {"8x8x64 R8 vol", {TiledKind::texture3d, 8, 8, 64, 7, 1, 1}, 0, 7, 2, 0}, |
| 163 | {"32x17x17 R8 vol", {TiledKind::texture3d, 32, 17, 17, 6, 1, 1}, 0, 6, 1, 0}, | 163 | {"32x17x17 R8 vol", {TiledKind::texture3d, 32, 17, 17, 6, 1, 1}, 0, 6, 1, 0}, |
| 164 | {"16^3 RGBA8 vol", {TiledKind::texture3d, 16, 16, 16, 5, 4, 1}, 0, 5, 1, 0}, | 164 | {"16^3 RGBA8 vol", {TiledKind::texture3d, 16, 16, 16, 5, 4, 1}, 0, 5, 1, 0}, |
| 165 | {"16x16x17 RGBA8 vol", {TiledKind::texture3d, 16, 16, 17, 5, 4, 1}, 0, 5, 1, 0}, // AMD reserves 2 | 165 | {"16x16x17 RGBA8 vol", {TiledKind::texture3d, 16, 16, 17, 5, 4, 1}, 0, 5, 2, 0}, |
| 166 | {"16x9x9 RGBA8 vol", {TiledKind::texture3d, 16, 9, 9, 5, 4, 1}, 0, 5, 1, 0}, | 166 | {"16x9x9 RGBA8 vol", {TiledKind::texture3d, 16, 9, 9, 5, 4, 1}, 0, 5, 1, 0}, |
| 167 | {"8^3 RGBA32F vol", {TiledKind::texture3d, 8, 8, 8, 4, 16, 1}, 0, 4, 1, 0}, | 167 | {"8^3 RGBA32F vol", {TiledKind::texture3d, 8, 8, 8, 4, 16, 1}, 0, 4, 1, 0}, |
| 168 | {"9x1x1 RGBA32F vol", {TiledKind::texture3d, 9, 1, 1, 4, 16, 1}, 1, 3, 1, 1}, | 168 | {"9x1x1 RGBA32F vol", {TiledKind::texture3d, 9, 1, 1, 4, 16, 1}, 1, 3, 1, 1}, |
| 169 | // Packed tails deeper than one tile: one packed tile per tile-depth slice. | ||
| 170 | {"8x8x16 R8 vol", {TiledKind::texture3d, 8, 8, 16, 5, 1, 1}, 0, 5, 1, 0}, | ||
| 171 | {"8x8x32 R8 vol", {TiledKind::texture3d, 8, 8, 32, 6, 1, 1}, 0, 6, 1, 0}, | ||
| 172 | {"8x8x33 R8 vol", {TiledKind::texture3d, 8, 8, 33, 6, 1, 1}, 0, 6, 2, 0}, | ||
| 173 | {"8x8x48 R8 vol", {TiledKind::texture3d, 8, 8, 48, 6, 1, 1}, 0, 6, 2, 0}, | ||
| 174 | {"8x8x64 R8 vol", {TiledKind::texture3d, 8, 8, 64, 7, 1, 1}, 0, 7, 2, 0}, | ||
| 175 | {"8x8x65 R8 vol", {TiledKind::texture3d, 8, 8, 65, 7, 1, 1}, 0, 7, 3, 0}, | ||
| 176 | {"8x8x96 R8 vol", {TiledKind::texture3d, 8, 8, 96, 7, 1, 1}, 0, 7, 3, 0}, | ||
| 177 | {"8x8x128 R8 vol", {TiledKind::texture3d, 8, 8, 128, 8, 1, 1}, 0, 8, 4, 0}, | ||
| 178 | {"8x8x129 R8 vol", {TiledKind::texture3d, 8, 8, 129, 8, 1, 1}, 0, 8, 5, 0}, | ||
| 179 | {"8x8x256 R8 vol", {TiledKind::texture3d, 8, 8, 256, 9, 1, 1}, 0, 9, 8, 0}, | ||
| 180 | {"16x16x16 RGBA8 vol", {TiledKind::texture3d, 16, 16, 16, 5, 4, 1}, 0, 5, 1, 0}, | ||
| 181 | {"16x16x17 RGBA8 vol", {TiledKind::texture3d, 16, 16, 17, 5, 4, 1}, 0, 5, 2, 0}, | ||
| 182 | {"16x16x32 RGBA8 vol", {TiledKind::texture3d, 16, 16, 32, 6, 4, 1}, 0, 6, 2, 0}, | ||
| 183 | {"16x16x33 RGBA8 vol", {TiledKind::texture3d, 16, 16, 33, 6, 4, 1}, 0, 6, 3, 0}, | ||
| 184 | {"16x16x48 RGBA8 vol", {TiledKind::texture3d, 16, 16, 48, 6, 4, 1}, 0, 6, 3, 0}, | ||
| 185 | {"16x16x64 RGBA8 vol", {TiledKind::texture3d, 16, 16, 64, 7, 4, 1}, 0, 7, 4, 0}, | ||
| 186 | {"16x16x128 RGBA8 vol", {TiledKind::texture3d, 16, 16, 128, 8, 4, 1}, 0, 8, 8, 0}, | ||
| 187 | {"16x16x32 R16F vol", {TiledKind::texture3d, 16, 16, 32, 6, 2, 1}, 0, 6, 1, 0}, | ||
| 188 | {"16x16x33 R16F vol", {TiledKind::texture3d, 16, 16, 33, 6, 2, 1}, 0, 6, 2, 0}, | ||
| 189 | {"16x16x64 R16F vol", {TiledKind::texture3d, 16, 16, 64, 7, 2, 1}, 0, 7, 2, 0}, | ||
| 190 | {"16x16x100 R16F vol", {TiledKind::texture3d, 16, 16, 100, 7, 2, 1}, 0, 7, 4, 0}, | ||
| 191 | {"16x16x16 RGBA16F vol", {TiledKind::texture3d, 16, 16, 16, 5, 8, 1}, 0, 5, 1, 0}, | ||
| 192 | {"16x16x17 RGBA16F vol", {TiledKind::texture3d, 16, 16, 17, 5, 8, 1}, 0, 5, 2, 0}, | ||
| 193 | {"16x16x64 RGBA16F vol", {TiledKind::texture3d, 16, 16, 64, 7, 8, 1}, 0, 7, 4, 0}, | ||
| 194 | {"8x8x8 RGBA32F vol", {TiledKind::texture3d, 8, 8, 8, 4, 16, 1}, 0, 4, 1, 0}, | ||
| 195 | {"8x8x16 RGBA32F vol", {TiledKind::texture3d, 8, 8, 16, 5, 16, 1}, 0, 5, 1, 0}, | ||
| 196 | {"8x8x17 RGBA32F vol", {TiledKind::texture3d, 8, 8, 17, 5, 16, 1}, 0, 5, 2, 0}, | ||
| 197 | {"8x8x64 RGBA32F vol", {TiledKind::texture3d, 8, 8, 64, 7, 16, 1}, 0, 7, 4, 0}, | ||
| 198 | {"32x32x64 R8 vol", {TiledKind::texture3d, 32, 32, 64, 7, 1, 1}, 0, 7, 2, 0}, | ||
| 199 | {"1x1x256 R8 vol", {TiledKind::texture3d, 1, 1, 256, 9, 1, 1}, 0, 9, 8, 0}, | ||
| 200 | {"16x4x100 RGBA8 vol", {TiledKind::texture3d, 16, 4, 100, 7, 4, 1}, 0, 7, 7, 0}, | ||
| 201 | {"64x8x256 R8 vol", {TiledKind::texture3d, 64, 8, 256, 9, 1, 1}, 1, 8, 4, 8}, | ||
| 202 | {"32x8x64 RGBA8 vol", {TiledKind::texture3d, 32, 8, 64, 7, 4, 1}, 1, 6, 2, 4}, | ||
| 203 | {"128x16x128 RGBA8 vol", {TiledKind::texture3d, 128, 16, 128, 8, 4, 1}, 3, 5, 1, 42}, | ||
| 204 | {"64x64x256 R8 vol", {TiledKind::texture3d, 64, 64, 256, 9, 1, 1}, 1, 8, 4, 16}, | ||
| 205 | {"32x16x64 RGBA16F vol", {TiledKind::texture3d, 32, 16, 64, 7, 8, 1}, 1, 6, 2, 4}, | ||
| 169 | }; | 206 | }; |
| 170 | for (const AmdCase& c : amd) { | 207 | for (const AmdCase& c : amd) { |
| 171 | if (!resource_tiling(c.desc, t) || t.standard_mips != c.standard || t.packed_mips != c.packed || | 208 | if (!resource_tiling(c.desc, t) || t.standard_mips != c.standard || t.packed_mips != c.packed || |
diff --git a/runtime/test/root_signature_test.cpp b/runtime/test/root_signature_test.cpp index f11302874..3952db5b8 100644 --- a/runtime/test/root_signature_test.cpp +++ b/runtime/test/root_signature_test.cpp | |||
| @@ -76,6 +76,18 @@ std::vector<uint8_t> build_payload() { | |||
| 76 | int main() { | 76 | int main() { |
| 77 | using namespace rt::rootsig; | 77 | using namespace rt::rootsig; |
| 78 | 78 | ||
| 79 | // The public packer also validates callers that construct the model directly. | ||
| 80 | { | ||
| 81 | RootSignature sig; | ||
| 82 | RootParameter invalid; | ||
| 83 | invalid.type = static_cast<ParamType>(0xffffffffu); | ||
| 84 | invalid.num_values = 1; | ||
| 85 | sig.params = {invalid}; | ||
| 86 | const auto result = pack(sig); | ||
| 87 | check(!result.ok && result.error.find("unknown") != std::string::npos, | ||
| 88 | "invalid parameter enum cannot produce a successful zero-cost layout"); | ||
| 89 | } | ||
| 90 | |||
| 79 | // Mixed signature: 4 constants + CBV + table + 1 static sampler. | 91 | // Mixed signature: 4 constants + CBV + table + 1 static sampler. |
| 80 | { | 92 | { |
| 81 | RootSignature sig; | 93 | RootSignature sig; |
diff --git a/runtime/test/shader_fixture_path.h b/runtime/test/shader_fixture_path.h new file mode 100644 index 000000000..fdfd4aa59 --- /dev/null +++ b/runtime/test/shader_fixture_path.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | // Synthetic GPU test shaders are packaged under generated/ in runtime-windows artifacts. | ||
| 2 | // Run downloaded tests from the artifact directory, as CTest does for a local build. | ||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <filesystem> | ||
| 6 | |||
| 7 | namespace vktest { | ||
| 8 | inline std::filesystem::path shader_fixture_path(const std::filesystem::path& compiled_path) { | ||
| 9 | if (std::filesystem::is_regular_file(compiled_path)) return compiled_path; | ||
| 10 | const auto packaged = std::filesystem::path("generated") / compiled_path.filename(); | ||
| 11 | if (std::filesystem::is_regular_file(packaged)) return packaged; | ||
| 12 | // Preserve the original path in the caller's missing-file diagnostic. | ||
| 13 | return compiled_path; | ||
| 14 | } | ||
| 15 | } // namespace vktest | ||
diff --git a/runtime/test/shader_fixture_path_test.cpp b/runtime/test/shader_fixture_path_test.cpp new file mode 100644 index 000000000..557986157 --- /dev/null +++ b/runtime/test/shader_fixture_path_test.cpp | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #include "shader_fixture_path.h" | ||
| 2 | #include <cstdio> | ||
| 3 | #include <chrono> | ||
| 4 | #include <fstream> | ||
| 5 | |||
| 6 | int main() { | ||
| 7 | namespace fs = std::filesystem; | ||
| 8 | const auto root = fs::temp_directory_path() / ("leonida_fixture_path_" + | ||
| 9 | std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())); | ||
| 10 | fs::create_directories(root / "generated"); | ||
| 11 | const auto previous = fs::current_path(); | ||
| 12 | int result = 0; | ||
| 13 | try { | ||
| 14 | fs::current_path(root); | ||
| 15 | std::ofstream("generated/test.spv") << "packaged"; | ||
| 16 | const auto original = root / "build" / "test.spv"; | ||
| 17 | if (vktest::shader_fixture_path(original) != fs::path("generated/test.spv")) result = 1; | ||
| 18 | fs::create_directory("build"); | ||
| 19 | std::ofstream(original) << "local"; | ||
| 20 | if (vktest::shader_fixture_path(original) != original) result = 1; | ||
| 21 | const auto missing = root / "build" / "missing.spv"; | ||
| 22 | if (vktest::shader_fixture_path(missing) != missing) result = 1; | ||
| 23 | fs::remove(original); | ||
| 24 | fs::remove("generated/test.spv"); | ||
| 25 | fs::create_directory("generated/test.spv"); | ||
| 26 | if (vktest::shader_fixture_path(original) != original) result = 1; | ||
| 27 | } catch (...) { result = 1; } | ||
| 28 | fs::current_path(previous); | ||
| 29 | fs::remove_all(root); | ||
| 30 | std::puts(result ? "shader fixture lookup failed" : "shader fixture lookup passed"); | ||
| 31 | return result; | ||
| 32 | } | ||
diff --git a/runtime/test/shader_library_test.cpp b/runtime/test/shader_library_test.cpp index 8a57d7bae..3a37018d6 100644 --- a/runtime/test/shader_library_test.cpp +++ b/runtime/test/shader_library_test.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <filesystem> | 7 | #include <filesystem> |
| 8 | #include <fstream> | 8 | #include <fstream> |
| 9 | #include <initializer_list> | 9 | #include <initializer_list> |
| 10 | #include <sstream> | ||
| 10 | #include <string> | 11 | #include <string> |
| 11 | #include <vector> | 12 | #include <vector> |
| 12 | 13 | ||
| @@ -251,6 +252,26 @@ int fspx_checks() { | |||
| 251 | int main() { | 252 | int main() { |
| 252 | using namespace leonida; | 253 | using namespace leonida; |
| 253 | 254 | ||
| 255 | // Test the shared file reader without passing malformed bytes to a driver. | ||
| 256 | const std::vector<std::uint32_t> header = {0x07230203, 0x00010300, 0, 1, 0}; | ||
| 257 | const std::string header_bytes(reinterpret_cast<const char*>(header.data()), header.size() * sizeof(header.front())); | ||
| 258 | { | ||
| 259 | std::istringstream input(header_bytes); | ||
| 260 | input.seekg(0, std::ios::end); | ||
| 261 | CHECK(read_spirv_words(input, input.tellg()) == header); | ||
| 262 | } | ||
| 263 | for (const auto& bad : {std::string{}, header_bytes.substr(0, 16), header_bytes + 'x', | ||
| 264 | std::string("bad!") + header_bytes.substr(4)}) { | ||
| 265 | std::istringstream input(bad); | ||
| 266 | input.seekg(0, std::ios::end); | ||
| 267 | CHECK(read_spirv_words(input, input.tellg()).empty()); | ||
| 268 | } | ||
| 269 | { | ||
| 270 | std::istringstream input(header_bytes); | ||
| 271 | input.seekg(0, std::ios::end); | ||
| 272 | CHECK(read_spirv_words(input, static_cast<std::streamoff>(header_bytes.size() + 4)).empty()); | ||
| 273 | } | ||
| 274 | |||
| 254 | CHECK(sha256_hex({}) == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); | 275 | CHECK(sha256_hex({}) == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); |
| 255 | CHECK(sha256_hex(bytes("abc")) == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"); | 276 | CHECK(sha256_hex(bytes("abc")) == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"); |
| 256 | CHECK(sha256_hex(bytes("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")) == | 277 | CHECK(sha256_hex(bytes("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")) == |
| @@ -339,7 +360,8 @@ int main() { | |||
| 339 | " \"vs_same_program\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << hash << "\", \"input_signature\": [" | 360 | " \"vs_same_program\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << hash << "\", \"input_signature\": [" |
| 340 | "{\"semantic\": \"TEXCOORD\", \"semantic_index\": 3, \"register\": -1, \"system_value\": 0, " | 361 | "{\"semantic\": \"TEXCOORD\", \"semantic_index\": 3, \"register\": -1, \"system_value\": 0, " |
| 341 | "\"component_type\": \"float\"}]},\n" | 362 | "\"component_type\": \"float\"}]},\n" |
| 342 | " \"ps_out\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << hash << "\", \"outputs\": [0, 2]},\n" | 363 | " \"ps_out\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << hash << "\", \"inputs\": [0, 1, 28, 29], " |
| 364 | "\"outputs\": [0, 2], \"f16_halves\": {\"0\": [28, 29], \"bad\": [1], \"7\": [20, 21]}},\n" | ||
| 343 | " \"ps_native\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << hash2 << "\", \"wave64\": true, " | 365 | " \"ps_native\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << hash2 << "\", \"wave64\": true, " |
| 344 | "\"subgroup_size\": 64},\n" | 366 | "\"subgroup_size\": 64},\n" |
| 345 | " \"cs_emulated\": {\"stage\": \"cs\", \"fssm_sha256\": \"" << hash2 << "\", \"wave64\": true, " | 367 | " \"cs_emulated\": {\"stage\": \"cs\", \"fssm_sha256\": \"" << hash2 << "\", \"wave64\": true, " |
| @@ -364,6 +386,9 @@ int main() { | |||
| 364 | vs_all[1]->input_signature[0].register_index == 0); | 386 | vs_all[1]->input_signature[0].register_index == 0); |
| 365 | const ShaderEntry* ps = library.find("ps", hash); | 387 | const ShaderEntry* ps = library.find("ps", hash); |
| 366 | CHECK(ps && ps->outputs.size() == 2 && ps->outputs[1] == 2); | 388 | CHECK(ps && ps->outputs.size() == 2 && ps->outputs[1] == 2); |
| 389 | CHECK(ps->inputs.size() == 4 && ps->inputs[0] == 0 && ps->inputs[3] == 29); | ||
| 390 | CHECK(ps->f16_halves.size() == 2 && ps->f16_halves.at(0)[0] == 28 && ps->f16_halves.at(0)[1] == 29 && | ||
| 391 | ps->f16_halves.at(7)[0] == 20 && ps->f16_halves.at(7)[1] == 21); | ||
| 367 | const ShaderEntry* entry = library.find("cs", sha256_hex(fssm_program(shader))); | 392 | const ShaderEntry* entry = library.find("cs", sha256_hex(fssm_program(shader))); |
| 368 | CHECK(entry && entry->name == "cs_test" && entry->binding_count == 1 && entry->push_constant_bytes == 144); | 393 | CHECK(entry && entry->name == "cs_test" && entry->binding_count == 1 && entry->push_constant_bytes == 144); |
| 369 | CHECK(entry->local_size[0] == 64 && entry->uses_code_base && !entry->wave64); | 394 | CHECK(entry->local_size[0] == 64 && entry->uses_code_base && !entry->wave64); |
diff --git a/runtime/test/shaders/build.py b/runtime/test/shaders/build.py index 412dc2b8f..4dd01f8e4 100644 --- a/runtime/test/shaders/build.py +++ b/runtime/test/shaders/build.py | |||
| @@ -22,6 +22,9 @@ With LEONIDA_BARY_FALLBACK=1, pixel shaders that read raw barycentrics are trans | |||
| 22 | each gets a pass-through geometry shader, <name>.bary_gs.spv, that check.py draws it with (tools/bary_fallback_gs.py). | 22 | each gets a pass-through geometry shader, <name>.bary_gs.spv, that check.py draws it with (tools/bary_fallback_gs.py). |
| 23 | Under that or LEONIDA_F16_INTERP_FALLBACK=1, ps_ij_computed isn't built: its computed I/J pair needs PerVertexKHR | 23 | Under that or LEONIDA_F16_INTERP_FALLBACK=1, ps_ij_computed isn't built: its computed I/J pair needs PerVertexKHR |
| 24 | inputs, and check.py reports it as SKIP. | 24 | inputs, and check.py reports it as SKIP. |
| 25 | With LEONIDA_PC_TAIL_UBO=1, every shader is translated with --pc-tail-ubo (s0..s31 in 128 push-constant bytes, the | ||
| 26 | heap base and code base in a uniform block at set 1), for devices whose maxPushConstantsSize is 128; set it for | ||
| 27 | check.py too, whose test programs then bind that block (runtime/test/vk_pc_tail.h). | ||
| 25 | """ | 28 | """ |
| 26 | import json | 29 | import json |
| 27 | import os | 30 | import os |
| @@ -165,6 +168,9 @@ def translate_tests(work, names): | |||
| 165 | cmd.append("--f16-interp-fallback") | 168 | cmd.append("--f16-interp-fallback") |
| 166 | if os.environ.get("LEONIDA_TEXOFF_FALLBACK") == "1": # texel offsets without VK_KHR_maintenance8 | 169 | if os.environ.get("LEONIDA_TEXOFF_FALLBACK") == "1": # texel offsets without VK_KHR_maintenance8 |
| 167 | cmd.append("--texel-offset-fallback") | 170 | cmd.append("--texel-offset-fallback") |
| 171 | # 128-byte push constants: the tail in a set-1 uniform block. The values the test programs accept (vk_pc_tail.h). | ||
| 172 | if (os.environ.get("LEONIDA_PC_TAIL_UBO") or "").strip().lower() in ("1", "true", "yes", "on"): | ||
| 173 | cmd.append("--pc-tail-ubo") | ||
| 168 | return subprocess.run(cmd).returncode | 174 | return subprocess.run(cmd).returncode |
| 169 | 175 | ||
| 170 | 176 | ||
diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py index bec6947e7..9771f17b1 100644 --- a/runtime/test/shaders/check.py +++ b/runtime/test/shaders/check.py | |||
| @@ -296,6 +296,8 @@ PIXEL_BITS = {"ps_clip_color": (0x3e800000, 0x3f000000, 0x3f400000, 0x3f800000), | |||
| 296 | "ps_ops8": (0x80000000, 0xbfffffff, 0x000f100e, 0x0f0f0f1f), | 296 | "ps_ops8": (0x80000000, 0xbfffffff, 0x000f100e, 0x0f0f0f1f), |
| 297 | "ps_f32_mods": (0xc0256a01, 0x3f800000, 0x41e00000, 0x3fc00000), | 297 | "ps_f32_mods": (0xc0256a01, 0x3f800000, 0x41e00000, 0x3fc00000), |
| 298 | "ps_scc": (1, 1, 3, 0x80000000), "ps_sdwa": (0x000000f1, 0xbffefff2, 0x3c003344, 0xbff70000), | 298 | "ps_scc": (1, 1, 3, 0x80000000), "ps_sdwa": (0x000000f1, 0xbffefff2, 0x3c003344, 0xbff70000), |
| 299 | # 16-bit SDWA results with dst_sel:DWORD zero the high half (.asm header, measured on gfx1036) | ||
| 300 | "ps_sdwa_dword_hi": (0x00004000, 0x00000003, 0x00004700, 0x0000c000), | ||
| 299 | "ps_vcc_x2": (0x11223344, 0x55667788, 0, 0), | 301 | "ps_vcc_x2": (0x11223344, 0x55667788, 0, 0), |
| 300 | # v_cmpx_{eq,gt,le,lt,ngt,nle}_f32, f_i32, t_u32, {eq,gt,le}_i64, {ge,lt,ne}_u64 (.asm header) | 302 | # v_cmpx_{eq,gt,le,lt,ngt,nle}_f32, f_i32, t_u32, {eq,gt,le}_i64, {ge,lt,ne}_u64 (.asm header) |
| 301 | "ps_vcmpx_forms": (0xf05b2a48, 0xf05e8a12, 0xb174be18, 0x15550000), | 303 | "ps_vcmpx_forms": (0xf05b2a48, 0xf05e8a12, 0xb174be18, 0x15550000), |
| @@ -325,6 +327,12 @@ PIXEL_BITS = {"ps_clip_color": (0x3e800000, 0x3f000000, 0x3f400000, 0x3f800000), | |||
| 325 | "ps_fnan_fract": (0x3f7fffff, 0x00003bff, 0xc0200000, 0xc0200000), | 327 | "ps_fnan_fract": (0x3f7fffff, 0x00003bff, 0xc0200000, 0xc0200000), |
| 326 | # TEST-175: docs/design.md rules that were checked on the CPU only (derivations in the .asm headers) | 328 | # TEST-175: docs/design.md rules that were checked on the CPU only (derivations in the .asm headers) |
| 327 | "ps_cmp_nlg": (0x40000037, 0x40000007, 0x40000001, 0x3f800000), | 329 | "ps_cmp_nlg": (0x40000037, 0x40000007, 0x40000001, 0x3f800000), |
| 330 | # 16-bit float v_cmp, all 16 predicates, e32 and e64 with swapped operands (.asm headers) | ||
| 331 | "ps_vcmp_f16": (0x48a12080, 0x4ce9b1a2, 0x4ba72c98, 0x4fefbdba), | ||
| 332 | "ps_vcmp_f16_e64": (0x44c11100, 0x4cf171c1, 0x47c71d18, 0x4ff77dd9), | ||
| 333 | # 16-bit float v_cmpx, all 16 predicates, EXEC result with VCC kept (.asm headers) | ||
| 334 | "ps_vcmpx_f16": (0x68a12080, 0x6ce9b1a2, 0x6ba72c98, 0x6fefbdba), | ||
| 335 | "ps_vcmpx_f16_e64": (0x64c11100, 0x6cf171c1, 0x67c71d18, 0x6ff77dd9), | ||
| 328 | "ps_cvt_off": (0xbf000000, 0x3ee00000, 0xbe800000, 0x3f800000), | 336 | "ps_cvt_off": (0xbf000000, 0x3ee00000, 0xbe800000, 0x3f800000), |
| 329 | "ps_fmac_f16_mods": (0xaaaa3c00, 0xaaaa3e00, 0xaaaa0000, 0xaaaa4000), | 337 | "ps_fmac_f16_mods": (0xaaaa3c00, 0xaaaa3e00, 0xaaaa0000, 0xaaaa4000), |
| 330 | "ps_vop3_const_mods": (0xc0000000, 0xbf800000, 0x3f800000, 0xaaaabc00), | 338 | "ps_vop3_const_mods": (0xc0000000, 0xbf800000, 0x3f800000, 0xaaaabc00), |
| @@ -367,6 +375,7 @@ CLIP_TESTS = ("vs_clip", "vs_clip_param4", "vs_clip_undeclared") | |||
| 367 | # One definition: a later assignment used to drop ps_texoff (and any entry added by an earlier assignment) from | 375 | # One definition: a later assignment used to drop ps_texoff (and any entry added by an earlier assignment) from |
| 368 | # the standalone run. Keep every pixel fixture in this tuple. | 376 | # the standalone run. Keep every pixel fixture in this tuple. |
| 369 | PIXEL_TESTS = sorted((*PIXEL_BITS, "ps_bary", "ps_flat", "ps_bitmask_perm", "ps_texoff", "ps_texoff_implicit", | 377 | PIXEL_TESTS = sorted((*PIXEL_BITS, "ps_bary", "ps_flat", "ps_bitmask_perm", "ps_texoff", "ps_texoff_implicit", |
| 378 | "ps_texoff_forms", | ||
| 370 | "ps_uniform_branch", "ps_wqm", "ps_scc_mask32", "ps_interp_f16_high", "ps_ij_computed", | 379 | "ps_uniform_branch", "ps_wqm", "ps_scc_mask32", "ps_interp_f16_high", "ps_ij_computed", |
| 371 | "ps_mandelbrot")) | 380 | "ps_mandelbrot")) |
| 372 | # Pixel fixtures drawn with another vertex shader than vs_ids. | 381 | # Pixel fixtures drawn with another vertex shader than vs_ids. |
| @@ -400,8 +409,10 @@ STORE_WORDS = { | |||
| 400 | "cs_imgatomic3d": ({}, dict(enumerate([0x101, 0xDB, 0xF4, 0xCE, 0xE6, 0xFF])), | 409 | "cs_imgatomic3d": ({}, dict(enumerate([0x101, 0xDB, 0xF4, 0xCE, 0xE6, 0xFF])), |
| 401 | {57: 0x111, 19: 3, 44: 0xF4, 6: 0xD00D, 30: 0xE6, 39: 0x10}), | 410 | {57: 0x111, 19: 3, 44: 0xF4, 6: 0xD00D, 30: 0xE6, 39: 0x10}), |
| 402 | # image_get_resinfo on a 16x4 image with five levels: (width, height, depth, levels) of levels 0, 1 and 3, then | 411 | # image_get_resinfo on a 16x4 image with five levels: (width, height, depth, levels) of levels 0, 1 and 3, then |
| 403 | # width and height of level 2 and an untouched register, height and levels of level 1, the levels alone | 412 | # width and height of level 2 and an untouched register, height and levels of level 1, the levels alone, and |
| 404 | "cs_resinfo": ({**dict(enumerate([16, 4, 1, 5, 8, 2, 1, 5, 2, 1, 1, 5, 4, 1, 0xABCD])), 16: 2, 17: 5, 18: 5}, | 413 | # level 5, past the last (2D depth 0 and the past-the-end zeros measured on RDNA2, SHADER-388) |
| 414 | "cs_resinfo": ({**dict(enumerate([16, 4, 0, 5, 8, 2, 0, 5, 2, 1, 0, 5, 4, 1, 0xABCD])), 16: 2, 17: 5, 18: 5, | ||
| 415 | 20: 0, 21: 0, 22: 0, 23: 5}, | ||
| 405 | {}, {}), | 416 | {}, {}), |
| 406 | } | 417 | } |
| 407 | # TEST-184: image_get_lod on vk_texture_test's textures. Per fixture, its draws: S# word 1 (MIN_LOD [11:0], MAX_LOD | 418 | # TEST-184: image_get_lod on vk_texture_test's textures. Per fixture, its draws: S# word 1 (MIN_LOD [11:0], MAX_LOD |
| @@ -903,7 +914,7 @@ def sampler_mismatch(data, words, view): | |||
| 903 | for i, got in enumerate(struct.iter_unpack("<4f", data)): | 914 | for i, got in enumerate(struct.iter_unpack("<4f", data)): |
| 904 | y, x = divmod(i, SAMPLER_SIZE) | 915 | y, x = divmod(i, SAMPLER_SIZE) |
| 905 | want = sampler_texel(explicit, x, y) + sampler_texel(implicit, x, y) | 916 | want = sampler_texel(explicit, x, y) + sampler_texel(implicit, x, y) |
| 906 | if any(abs(g - w) > 1e-6 for g, w in zip(got, want)): | 917 | if any(not math.isclose(g, w, rel_tol=0, abs_tol=1e-6) for g, w in zip(got, want)): |
| 907 | return f"({x},{y}): {tuple(round(g, 4) for g in got)} != {tuple(round(w, 4) for w in want)}" | 918 | return f"({x},{y}): {tuple(round(g, 4) for g in got)} != {tuple(round(w, 4) for w in want)}" |
| 908 | return "" | 919 | return "" |
| 909 | 920 | ||
| @@ -973,11 +984,15 @@ def texture_constant_test(tools, spirv, name): | |||
| 973 | return "" if not wrong else f"{wrong} of 4096 pixels differ from {expected}" | 984 | return "" if not wrong else f"{wrong} of 4096 pixels differ from {expected}" |
| 974 | 985 | ||
| 975 | 986 | ||
| 976 | def texoff_words(px, py): | 987 | def texoff_words(px, py, name="ps_texoff"): |
| 977 | """ps_texoff's mrt0 words at pixel (px, py), from the rule in docs/design.md (derivation in ps_texoff.asm).""" | 988 | """ps_texoff's mrt0 words at pixel (px, py), from the rule in docs/design.md (derivation in ps_texoff.asm). |
| 989 | ps_texoff_forms (image_sample_o, image_sample_b_o, image_gather4_l_o) puts the per-pixel sample in .x and .y and | ||
| 990 | the same two gathers in .z and .w (derivation in ps_texoff_forms.asm).""" | ||
| 978 | bx, by = px >> 3, py >> 3 # per-pixel offset (bx - 4, by - 4) from texel (4, 4) | 991 | bx, by = px >> 3, py >> 3 # per-pixel offset (bx - 4, by - 4) from texel (4, 4) |
| 979 | x0, y0 = max(bx - 1, 0), max(by - 1, 0) # gather footprint 3..4 moved by the offset, clamped at 0 | 992 | x0, y0 = max(bx - 1, 0), max(by - 1, 0) # gather footprint 3..4 moved by the offset, clamped at 0 |
| 980 | return (bx | by << 4, 0x0761, x0 | bx << 4 | bx << 8 | x0 << 12, by | by << 4 | y0 << 8 | y0 << 12) | 993 | sample = bx | by << 4 |
| 994 | return (sample, sample if name == "ps_texoff_forms" else 0x0761, x0 | bx << 4 | bx << 8 | x0 << 12, | ||
| 995 | by | by << 4 | y0 << 8 | y0 << 12) | ||
| 981 | 996 | ||
| 982 | 997 | ||
| 983 | # LEONIDA_TEXOFF_FALLBACK=1 (set for build.py too): image_sample*_o was translated with --texel-offset-fallback, so | 998 | # LEONIDA_TEXOFF_FALLBACK=1 (set for build.py too): image_sample*_o was translated with --texel-offset-fallback, so |
| @@ -985,7 +1000,7 @@ def texoff_words(px, py): | |||
| 985 | TEXOFF_FALLBACK = os.environ.get("LEONIDA_TEXOFF_FALLBACK") == "1" | 1000 | TEXOFF_FALLBACK = os.environ.get("LEONIDA_TEXOFF_FALLBACK") == "1" |
| 986 | 1001 | ||
| 987 | 1002 | ||
| 988 | def texoff_problem(data, output, all_offsets=None): | 1003 | def texoff_problem(data, output, all_offsets=None, name="ps_texoff"): |
| 989 | """Judge ps_texoff's 64x64 RGBA32 dump: (failure text or "", what was covered). The +16 / -32 sample (bits 8-15 | 1004 | """Judge ps_texoff's 64x64 RGBA32 dump: (failure text or "", what was covered). The +16 / -32 sample (bits 8-15 |
| 990 | of .y) is only defined, and so only judged, where vk_texture_test printed texel offset limits that cover it.""" | 1005 | of .y) is only defined, and so only judged, where vk_texture_test printed texel offset limits that cover it.""" |
| 991 | m = re.search(r"texel offset limits: (-?\d+)\.\.(-?\d+)", output) | 1006 | m = re.search(r"texel offset limits: (-?\d+)\.\.(-?\d+)", output) |
| @@ -994,18 +1009,22 @@ def texoff_problem(data, output, all_offsets=None): | |||
| 994 | wide = True # the offset is a coordinate shift: no device limit applies | 1009 | wide = True # the offset is a coordinate shift: no device limit applies |
| 995 | if len(data) != 64 * 64 * 16: | 1010 | if len(data) != 64 * 64 * 16: |
| 996 | return "vk_texture_test returned an unexpected pixel count", "" | 1011 | return "vk_texture_test returned an unexpected pixel count", "" |
| 1012 | if name == "ps_texoff_forms": | ||
| 1013 | wide = True # every offset there is in -4..3, inside Vulkan's guaranteed -8..7 | ||
| 997 | keep = (0xFFFFFFFF, 0xFFFFFFFF if wide else 0xFFFF00FF, 0xFFFFFFFF, 0xFFFFFFFF) | 1014 | keep = (0xFFFFFFFF, 0xFFFFFFFF if wide else 0xFFFF00FF, 0xFFFFFFFF, 0xFFFFFFFF) |
| 998 | px = list(struct.iter_unpack("<4I", data)) | 1015 | px = list(struct.iter_unpack("<4I", data)) |
| 999 | bad = [(i, got) for i, got in enumerate(px) | 1016 | bad = [(i, got) for i, got in enumerate(px) |
| 1000 | if any((g ^ w) & k for g, w, k in zip(got, texoff_words(i % 64, i // 64), keep))] | 1017 | if any((g ^ w) & k for g, w, k in zip(got, texoff_words(i % 64, i // 64, name), keep))] |
| 1001 | limits = f"{m.group(1)}..{m.group(2)}" if m else "unknown" | 1018 | limits = f"{m.group(1)}..{m.group(2)}" if m else "unknown" |
| 1002 | covered = ("offsets +16/-32 judged" + (" (texel offset fallback)" if wide and not ( | 1019 | covered = ("offsets +16/-32 judged" + (" (texel offset fallback)" if wide and not ( |
| 1003 | bool(m) and int(m.group(1)) <= -32 and int(m.group(2)) >= 16) else "")) if wide else f"offsets +16/-32 not judged (device texel offset limits {limits})" | 1020 | bool(m) and int(m.group(1)) <= -32 and int(m.group(2)) >= 16) else "")) if wide else f"offsets +16/-32 not judged (device texel offset limits {limits})" |
| 1021 | if name == "ps_texoff_forms": | ||
| 1022 | covered = "offsets -4..3 on image_sample_o, image_sample_b_o and image_gather4_l_o" | ||
| 1004 | if not bad: | 1023 | if not bad: |
| 1005 | return "", covered | 1024 | return "", covered |
| 1006 | i, got = bad[0] | 1025 | i, got = bad[0] |
| 1007 | return (f"{len(bad)} of {len(px)} pixels differ; first at ({i % 64},{i // 64}): got {[hex(x) for x in got]}, " | 1026 | return (f"{len(bad)} of {len(px)} pixels differ; first at ({i % 64},{i // 64}): got {[hex(x) for x in got]}, " |
| 1008 | f"want {[hex(x) for x in texoff_words(i % 64, i // 64)]} ({covered})"), covered | 1027 | f"want {[hex(x) for x in texoff_words(i % 64, i // 64, name)]} ({covered})"), covered |
| 1009 | 1028 | ||
| 1010 | 1029 | ||
| 1011 | def texoff_env(base=None): | 1030 | def texoff_env(base=None): |
| @@ -1028,7 +1047,7 @@ def texoff_test(tools, spirv, name): | |||
| 1028 | return Skip(f"SKIP ({m.group(0) if m else 'unsupported device'})") | 1047 | return Skip(f"SKIP ({m.group(0) if m else 'unsupported device'})") |
| 1029 | if code or not raw.is_file(): | 1048 | if code or not raw.is_file(): |
| 1030 | return failure(code, out, 2) | 1049 | return failure(code, out, 2) |
| 1031 | return texoff_problem(raw.read_bytes(), out)[0] | 1050 | return texoff_problem(raw.read_bytes(), out, name=name)[0] |
| 1032 | 1051 | ||
| 1033 | 1052 | ||
| 1034 | def store_words(name): | 1053 | def store_words(name): |
| @@ -1178,6 +1197,27 @@ def interp_f16_high_problem(px): | |||
| 1178 | return "" if err < 2e-3 else f"f16 halves off by {err:.3g}" | 1197 | return "" if err < 2e-3 else f"f16 halves off by {err:.3g}" |
| 1179 | 1198 | ||
| 1180 | 1199 | ||
| 1200 | def base_ids_test(tools, spirv): | ||
| 1201 | """vs_base_ids with ps_flat, drawn with firstVertex 16 and firstInstance 7: the VS input VGPRs are zero-based on | ||
| 1202 | the hardware, so every pixel must still see vertex 0 of instance 0 (0x101, 0x102), not 0x7111.""" | ||
| 1203 | for n in ("vs_base_ids", "ps_flat"): | ||
| 1204 | if not os.path.isfile(os.path.join(spirv, n + ".spv")): | ||
| 1205 | return f"missing {n}.spv" | ||
| 1206 | env = dict(os.environ, VKH_DRAW="16,7") | ||
| 1207 | with tempfile.TemporaryDirectory(prefix="leonida-pixels-") as tmp: | ||
| 1208 | raw = Path(tmp) / "pixels.raw" | ||
| 1209 | code, out = run(os.path.join(tools, "vk_harness" + EXE), os.path.join(spirv, "vs_base_ids.spv"), | ||
| 1210 | os.path.join(spirv, "ps_flat.spv"), raw, env=env) | ||
| 1211 | if code == UNSUPPORTED: | ||
| 1212 | m = re.search(r"unsupported: .*", out) | ||
| 1213 | return Skip(f"SKIP ({m.group(0) if m else 'unsupported device'})") | ||
| 1214 | if code or not raw.is_file(): | ||
| 1215 | return out if out.startswith("could not start") else "vk_harness failed or returned no pixels" | ||
| 1216 | px = list(struct.iter_unpack("<2I2f", raw.read_bytes())) | ||
| 1217 | wrong = [p for p in px if (p[0], p[1]) != (0x101, 0x102)] | ||
| 1218 | return "" if px and not wrong else f"{len(wrong)} of {len(px)} pixels differ, e.g. {hex(wrong[0][0]) if wrong else '-'}" | ||
| 1219 | |||
| 1220 | |||
| 1181 | def wide_pixel_skip(name, out): | 1221 | def wide_pixel_skip(name, out): |
| 1182 | """A Skip when `name` needs a 64-wide pixel stage (WIDE_PIXEL_TESTS) and vk_harness's output does not say that size | 1222 | """A Skip when `name` needs a 64-wide pixel stage (WIDE_PIXEL_TESTS) and vk_harness's output does not say that size |
| 1183 | was required of the fragment stage, else None.""" | 1223 | was required of the fragment stage, else None.""" |
| @@ -1236,7 +1276,7 @@ def pixel_test(tools, spirv, name): | |||
| 1236 | return Skip("SKIP (computed I/J pairs need PerVertexKHR inputs: no --bary-fallback / --f16-interp-fallback)") | 1276 | return Skip("SKIP (computed I/J pairs need PerVertexKHR inputs: no --bary-fallback / --f16-interp-fallback)") |
| 1237 | if not os.path.isfile(path): | 1277 | if not os.path.isfile(path): |
| 1238 | return f"missing {name}.spv" | 1278 | return f"missing {name}.spv" |
| 1239 | if name in ("ps_texoff", "ps_texoff_implicit"): | 1279 | if name in ("ps_texoff", "ps_texoff_implicit", "ps_texoff_forms"): |
| 1240 | return texoff_test(tools, spirv, name) | 1280 | return texoff_test(tools, spirv, name) |
| 1241 | if name == "ps_interp_f16_high" and BARY_FALLBACK and not F16_HALVES: # with F16_HALVES it reads decoded halves | 1281 | if name == "ps_interp_f16_high" and BARY_FALLBACK and not F16_HALVES: # with F16_HALVES it reads decoded halves |
| 1242 | return Skip("SKIP (per-vertex interpolants need VK_KHR_fragment_shader_barycentric)") | 1282 | return Skip("SKIP (per-vertex interpolants need VK_KHR_fragment_shader_barycentric)") |
| @@ -1389,6 +1429,7 @@ def main(): | |||
| 1389 | results.append((name, pixel_test(tools, spirv, name))) | 1429 | results.append((name, pixel_test(tools, spirv, name))) |
| 1390 | for name in TEXTURE_CONSTANTS: | 1430 | for name in TEXTURE_CONSTANTS: |
| 1391 | results.append((name, texture_constant_test(tools, spirv, name))) | 1431 | results.append((name, texture_constant_test(tools, spirv, name))) |
| 1432 | results.append(("vs_base_ids", base_ids_test(tools, spirv))) | ||
| 1392 | results.append(("ps_tex", bindless_test(tools, spirv))) | 1433 | results.append(("ps_tex", bindless_test(tools, spirv))) |
| 1393 | results.append(("ps_ssharp", sampler_test(tools, spirv))) | 1434 | results.append(("ps_ssharp", sampler_test(tools, spirv))) |
| 1394 | results.append(("ps_imgatomic", bindless_test(tools, spirv, "ps_imgatomic"))) | 1435 | results.append(("ps_imgatomic", bindless_test(tools, spirv, "ps_imgatomic"))) |
diff --git a/runtime/test/shaders/compute_fixture.py b/runtime/test/shaders/compute_fixture.py index c5cdb438f..ec8dad37a 100644 --- a/runtime/test/shaders/compute_fixture.py +++ b/runtime/test/shaders/compute_fixture.py | |||
| @@ -14,7 +14,7 @@ def compute_header(asm_path): | |||
| 14 | continue | 14 | continue |
| 15 | if not line.startswith(";"): | 15 | if not line.startswith(";"): |
| 16 | break | 16 | break |
| 17 | size = re.match(r";\s*group:\s*(\d+),(\d+),(\d+)", line) | 17 | size = re.match(r";\s*group:\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)", line) |
| 18 | if size: | 18 | if size: |
| 19 | group = tuple(map(int, size.groups())) | 19 | group = tuple(map(int, size.groups())) |
| 20 | elif line[1:].lstrip().startswith("rsrc2:"): | 20 | elif line[1:].lstrip().startswith("rsrc2:"): |
diff --git a/runtime/test/shaders/cs_buf_fmt8.asm b/runtime/test/shaders/cs_buf_fmt8.asm new file mode 100644 index 000000000..120eba435 --- /dev/null +++ b/runtime/test/shaders/cs_buf_fmt8.asm | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | ; TEST-510: GFX10_FORMAT_8_UINT (code 5) loads on the GPU (docs/design.md, "Sub-dword MUBUF loads and | ||
| 2 | ; GFX10_FORMAT_8_UINT"; CPU-checked by tests/semantic/test_buffer_load_sub.py). Thread 0 seeds heap bytes 0x40..0x43 | ||
| 3 | ; with 7f 80 ff 01. Every V# has base 0x40, stride 0, NUM_RECORDS 4 and OOB_SELECT 3 (RAW). Words, in out[0..7]: | ||
| 4 | ; 0..3 tbuffer_load_format_x format:[BUF_FMT_8_UINT] at 0..3, V# format 20 (32_UINT): the instruction's own format | ||
| 5 | ; is used, one byte zero-extended: 0x7f 0x80 0xff 0x01 | ||
| 6 | ; 4 the same at 4: 4 + 1 > 4 -> 0 | ||
| 7 | ; 5 the same at 1 with V# format 0 (INVALID): an MTBUF load of an invalid V# reads 0 even in range | ||
| 8 | ; 6, 7 buffer_load_format_xyzw at 2 with V# format 5 (8_UINT) and DST_SEL (X, 0, 1, 1): x = 0xff and w = integer 1 | ||
| 9 | ; (not 1.0f, 0x3f800000) | ||
| 10 | ; One thread, no wave64 requirement. | ||
| 11 | ; Run: vk_compute_test cs_buf_fmt8.spv 1 dump -> out[0..7] = 0x0000007f 0x00000080 0x000000ff 0x00000001 0x00000000 | ||
| 12 | ; 0x00000000 0x000000ff 0x00000001 (127 128 255 1 0 0 255 1). | ||
| 13 | v_cmpx_eq_u32_e32 0, v0 | ||
| 14 | v_mov_b32 v1, 0x01ff807f | ||
| 15 | buffer_store_dword v1, off, s[0:3], 0 offset:64 | ||
| 16 | s_waitcnt vmcnt(0) | ||
| 17 | s_mov_b32 s4, 0x40 | ||
| 18 | s_mov_b32 s5, 0 | ||
| 19 | s_mov_b32 s6, 4 | ||
| 20 | s_mov_b32 s7, 0x31014fac | ||
| 21 | s_mov_b32 s8, 0x40 | ||
| 22 | s_mov_b32 s9, 0 | ||
| 23 | s_mov_b32 s10, 4 | ||
| 24 | s_mov_b32 s11, 0x31000fac | ||
| 25 | s_mov_b32 s12, 0x40 | ||
| 26 | s_mov_b32 s13, 0 | ||
| 27 | s_mov_b32 s14, 4 | ||
| 28 | s_mov_b32 s15, 0x31005244 | ||
| 29 | v_mov_b32 v20, 0 | ||
| 30 | v_mov_b32 v21, 1 | ||
| 31 | v_mov_b32 v22, 2 | ||
| 32 | v_mov_b32 v23, 3 | ||
| 33 | v_mov_b32 v24, 4 | ||
| 34 | tbuffer_load_format_x v10, v20, s[4:7], 0 format:[BUF_FMT_8_UINT] offen | ||
| 35 | tbuffer_load_format_x v11, v21, s[4:7], 0 format:[BUF_FMT_8_UINT] offen | ||
| 36 | tbuffer_load_format_x v12, v22, s[4:7], 0 format:[BUF_FMT_8_UINT] offen | ||
| 37 | tbuffer_load_format_x v13, v23, s[4:7], 0 format:[BUF_FMT_8_UINT] offen | ||
| 38 | tbuffer_load_format_x v14, v24, s[4:7], 0 format:[BUF_FMT_8_UINT] offen | ||
| 39 | tbuffer_load_format_x v15, v21, s[8:11], 0 format:[BUF_FMT_8_UINT] offen | ||
| 40 | buffer_load_format_xyzw v[30:33], v22, s[12:15], 0 offen | ||
| 41 | s_waitcnt vmcnt(0) | ||
| 42 | v_mov_b32 v16, v30 | ||
| 43 | v_mov_b32 v17, v33 | ||
| 44 | buffer_store_dwordx4 v[10:13], off, s[0:3], 0 | ||
| 45 | buffer_store_dwordx4 v[14:17], off, s[0:3], 0 offset:16 | ||
| 46 | s_endpgm | ||
diff --git a/runtime/test/shaders/cs_buf_load_sub.asm b/runtime/test/shaders/cs_buf_load_sub.asm new file mode 100644 index 000000000..48ffd4e47 --- /dev/null +++ b/runtime/test/shaders/cs_buf_load_sub.asm | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | ; TEST-510: sub-dword MUBUF loads on the GPU (docs/design.md, "Sub-dword MUBUF loads and GFX10_FORMAT_8_UINT"; | ||
| 2 | ; CPU-checked by tests/semantic/test_buffer_load_sub.py). Thread 0 seeds heap bytes 0x40..0x47 with 7f 80 ff 01 ab cd | ||
| 3 | ; 00 fe; the heap is 0xee-filled past them. The V# has base 0x40, stride 0, NUM_RECORDS 8 and OOB_SELECT 3 (RAW: an | ||
| 4 | ; element is in range when offset + size <= NUM_RECORDS; out of range reads 0 without touching memory). Words, in | ||
| 5 | ; out[0..7]: | ||
| 6 | ; 0 buffer_load_ubyte at 1: 0x80 zero-extended | ||
| 7 | ; 1 buffer_load_sbyte at 1: 0x80 -> 0xffffff80 sign-extended | ||
| 8 | ; 2 buffer_load_ushort at 2: ff 01 -> 0x01ff | ||
| 9 | ; 3 buffer_load_sshort at 0: 7f 80 -> 0xffff807f | ||
| 10 | ; 4 buffer_load_ushort at 3: 01 ab -> 0xab01 crosses into the next dword (3 + 2 <= 8) | ||
| 11 | ; 5 buffer_load_sshort at 5: cd 00 -> 0x000000cd positive, no sign bits | ||
| 12 | ; 6 buffer_load_ubyte at 8: 8 + 1 > 8 -> 0 | ||
| 13 | ; 7 buffer_load_ushort at 7: 7 + 2 > 8 -> 0 a start-only check would read fe ee -> 0xeefe | ||
| 14 | ; One thread, no wave64 requirement. | ||
| 15 | ; Run: vk_compute_test cs_buf_load_sub.spv 1 dump -> out[0..7] = 0x00000080 0xffffff80 0x000001ff 0xffff807f | ||
| 16 | ; 0x0000ab01 0x000000cd 0x00000000 0x00000000 (128 4294967168 511 4294934655 43777 205 0 0). | ||
| 17 | v_cmpx_eq_u32_e32 0, v0 | ||
| 18 | v_mov_b32 v1, 0x01ff807f | ||
| 19 | v_mov_b32 v2, 0xfe00cdab | ||
| 20 | buffer_store_dwordx2 v[1:2], off, s[0:3], 0 offset:64 | ||
| 21 | s_waitcnt vmcnt(0) | ||
| 22 | s_mov_b32 s4, 0x40 | ||
| 23 | s_mov_b32 s5, 0 | ||
| 24 | s_mov_b32 s6, 8 | ||
| 25 | s_mov_b32 s7, 0x31016fac | ||
| 26 | v_mov_b32 v20, 1 | ||
| 27 | v_mov_b32 v21, 2 | ||
| 28 | v_mov_b32 v22, 0 | ||
| 29 | v_mov_b32 v23, 3 | ||
| 30 | v_mov_b32 v24, 5 | ||
| 31 | v_mov_b32 v25, 8 | ||
| 32 | v_mov_b32 v26, 7 | ||
| 33 | buffer_load_ubyte v10, v20, s[4:7], 0 offen | ||
| 34 | buffer_load_sbyte v11, v20, s[4:7], 0 offen | ||
| 35 | buffer_load_ushort v12, v21, s[4:7], 0 offen | ||
| 36 | buffer_load_sshort v13, v22, s[4:7], 0 offen | ||
| 37 | buffer_load_ushort v14, v23, s[4:7], 0 offen | ||
| 38 | buffer_load_sshort v15, v24, s[4:7], 0 offen | ||
| 39 | buffer_load_ubyte v16, v25, s[4:7], 0 offen | ||
| 40 | buffer_load_ushort v17, v26, s[4:7], 0 offen | ||
| 41 | s_waitcnt vmcnt(0) | ||
| 42 | buffer_store_dwordx4 v[10:13], off, s[0:3], 0 | ||
| 43 | buffer_store_dwordx4 v[14:17], off, s[0:3], 0 offset:16 | ||
| 44 | s_endpgm | ||
diff --git a/runtime/test/shaders/cs_f64_add.asm b/runtime/test/shaders/cs_f64_add.asm new file mode 100644 index 000000000..4dbba4123 --- /dev/null +++ b/runtime/test/shaders/cs_f64_add.asm | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | ; group: 1,1,1 | ||
| 2 | ; Store binary64 (0.75 + 0.5) * 2 = 2.5 as low/high words: 0x00000000, 0x40040000. | ||
| 3 | v_mov_b32 v0, 0 | ||
| 4 | v_mov_b32 v1, 0x3fe80000 | ||
| 5 | v_mov_b32 v2, 0 | ||
| 6 | v_mov_b32 v3, 0x3fe00000 | ||
| 7 | v_add_f64 v[4:5], v[0:1], v[2:3] mul:2 | ||
| 8 | v_mov_b32 v6, 0 | ||
| 9 | buffer_store_dwordx2 v[4:5], v6, s[0:3], 0 offen | ||
| 10 | s_endpgm | ||
diff --git a/runtime/test/shaders/cs_resinfo.asm b/runtime/test/shaders/cs_resinfo.asm index 41ecaf7f7..88be15028 100644 --- a/runtime/test/shaders/cs_resinfo.asm +++ b/runtime/test/shaders/cs_resinfo.asm | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | ; image_get_resinfo on a 16x4 image with five mip levels. RDNA2 ISA (MIMG): the address register holds a mip level, | 1 | ; image_get_resinfo on a 16x4 image with five mip levels. RDNA2 ISA (MIMG): the address register holds a mip level, |
| 2 | ; there is no sampler, and the result is four integers, {num_mip_levels, depth, height, width} in VGPRs 3..0, of | 2 | ; there is no sampler, and the result is four integers, {num_mip_levels, depth, height, width} in VGPRs 3..0, of |
| 3 | ; which dmask keeps some and packs them into consecutive registers. Width and height are those of the level asked | 3 | ; which dmask keeps some and packs them into consecutive registers. Width and height are those of the level asked |
| 4 | ; for (halved per level, never below 1), depth is 1 for an image that is neither 3D nor an array, and the level | 4 | ; for (halved per level, never below 1), the depth word is 0 for a 2D image (not the T#'s DEPTH field + 1), and the |
| 5 | ; count is that of the view. | 5 | ; level count is that of the view; past the last level width, height and depth are 0 (both measured on RDNA2 gfx1036 |
| 6 | ; with tools/image_query_probe.py, SHADER-388). | ||
| 6 | ; Run: vk_store_test cs_resinfo.spv words | 7 | ; Run: vk_store_test cs_resinfo.spv words |
| 7 | ; The T# in s[8:15] is the one of that image, as Mesa's gfx10 register database lays it out (and as | 8 | ; The T# in s[8:15] is the one of that image, as Mesa's gfx10 register database lays it out (and as |
| 8 | ; runtime/src/gfx10_descriptors.h writes it): word 1 = FORMAT 56 (rgba8 unorm) << 20 | (width - 1 = 15) low two bits | 9 | ; runtime/src/gfx10_descriptors.h writes it): word 1 = FORMAT 56 (rgba8 unorm) << 20 | (width - 1 = 15) low two bits |
| @@ -10,13 +11,14 @@ | |||
| 10 | ; TYPE 9 (2D) << 28, word 5 = MAX_MIP 4 << 4. vk_store_test binds a 16x4 rgba8 image with five levels behind exactly | 11 | ; TYPE 9 (2D) << 28, word 5 = MAX_MIP 4 << 4. vk_store_test binds a 16x4 rgba8 image with five levels behind exactly |
| 11 | ; these eight words. Thread 0 stores each result word into its own texel of the uint image (T# 0x2000...), texel | 12 | ; these eight words. Thread 0 stores each result word into its own texel of the uint image (T# 0x2000...), texel |
| 12 | ; i = 8y + x: | 13 | ; i = 8y + x: |
| 13 | ; level 0, dmask 0xf -> words 0..3 = 16 4 1 5 | 14 | ; level 0, dmask 0xf -> words 0..3 = 16 4 0 5 |
| 14 | ; level 1, dmask 0xf -> words 4..7 = 8 2 1 5 | 15 | ; level 1, dmask 0xf -> words 4..7 = 8 2 0 5 |
| 15 | ; level 3, dmask 0xf -> words 8..11 = 2 1 1 5 (4 >> 3 would be 0: the height stays 1) | 16 | ; level 3, dmask 0xf -> words 8..11 = 2 1 0 5 (4 >> 3 would be 0: the height stays 1) |
| 16 | ; level 2, dmask 0x3 -> words 12..13 = 4 1 width and height | 17 | ; level 2, dmask 0x3 -> words 12..13 = 4 1 width and height |
| 17 | ; word 14 = 0xabcd the register after them is not written | 18 | ; word 14 = 0xabcd the register after them is not written |
| 18 | ; level 1, dmask 0xa -> words 16..17 = 2 5 height and level count, packed into two registers | 19 | ; level 1, dmask 0xa -> words 16..17 = 2 5 height and level count, packed into two registers |
| 19 | ; level 4, dmask 0x8 -> word 18 = 5 the level count alone | 20 | ; level 4, dmask 0x8 -> word 18 = 5 the level count alone |
| 21 | ; level 5, dmask 0xf -> words 20..23 = 0 0 0 5 past the last level | ||
| 20 | ; Every other word keeps the tool's fill, 100 + i, and the sint image its -2i. | 22 | ; Every other word keeps the tool's fill, 100 + i, and the sint image its -2i. |
| 21 | v_cmpx_eq_u32_e32 0, v0 | 23 | v_cmpx_eq_u32_e32 0, v0 |
| 22 | s_mov_b32 s8, 0x4000 | 24 | s_mov_b32 s8, 0x4000 |
| @@ -93,4 +95,16 @@ image_get_resinfo v13, v3, s[8:15] dmask:0x8 dim:SQ_RSRC_IMG_2D | |||
| 93 | s_waitcnt vmcnt(0) | 95 | s_waitcnt vmcnt(0) |
| 94 | v_mov_b32_e32 v1, 2 | 96 | v_mov_b32_e32 v1, 2 |
| 95 | image_store v13, v[1:2], s[16:23] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm | 97 | image_store v13, v[1:2], s[16:23] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm |
| 98 | v_mov_b32_e32 v3, 5 | ||
| 99 | image_get_resinfo v[4:7], v3, s[8:15] dmask:0xf dim:SQ_RSRC_IMG_2D | ||
| 100 | s_waitcnt vmcnt(0) | ||
| 101 | v_mov_b32_e32 v2, 2 | ||
| 102 | v_mov_b32_e32 v1, 4 | ||
| 103 | image_store v4, v[1:2], s[16:23] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm | ||
| 104 | v_mov_b32_e32 v1, 5 | ||
| 105 | image_store v5, v[1:2], s[16:23] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm | ||
| 106 | v_mov_b32_e32 v1, 6 | ||
| 107 | image_store v6, v[1:2], s[16:23] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm | ||
| 108 | v_mov_b32_e32 v1, 7 | ||
| 109 | image_store v7, v[1:2], s[16:23] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm | ||
| 96 | s_endpgm | 110 | s_endpgm |
diff --git a/runtime/test/shaders/ps_sdwa_dword_hi.asm b/runtime/test/shaders/ps_sdwa_dword_hi.asm new file mode 100644 index 000000000..09f3740b7 --- /dev/null +++ b/runtime/test/shaders/ps_sdwa_dword_hi.asm | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | ; 16-bit SDWA results written with dst_sel:DWORD. The non-SDWA f16 VOP1/VOP2 forms keep the destination's high | ||
| 2 | ; half (docs/design.md, 16-bit results), but an SDWA destination with dst_sel:DWORD takes the whole dword: the | ||
| 3 | ; 16-bit result zero-extended, whatever dst_unused says. Measured natively on an AMD Radeon iGPU (gfx1036, RDNA2, | ||
| 4 | ; Windows driver 26.10.1) through tools/hw_oracle with this exact program: 0x00004000, 0x00000003, 0x00004700, | ||
| 5 | ; 0x0000c000; the same four ops with dst_sel:WORD_0 dst_unused:UNUSED_PRESERVE gave 0xdead4000, 0xdead0003, | ||
| 6 | ; 0xdead4700, 0xdeadc000 (the high half kept), so the zero comes from dst_sel:DWORD. | ||
| 7 | ; Every destination starts as 0xdeadbeef. Sources: v2 = 0x12343c00 (WORD_0 = 1.0), v4 = 0xc0004200 (WORD_0 = 3.0, | ||
| 8 | ; WORD_1 = -2.0), v6 = 0x00070000 (WORD_1 = 7). | ||
| 9 | ; x: v_add_f16 1.0 + 1.0 = 2.0 = 0x4000, UNUSED_PRESERVE -> 0x00004000 | ||
| 10 | ; y: v_cvt_u16_f16 of 3.0 = 3 = 0x0003, UNUSED_PAD -> 0x00000003 | ||
| 11 | ; z: v_cvt_f16_u16 of 7 = 7.0 = 0x4700 (exact), UNUSED_PRESERVE -> 0x00004700 | ||
| 12 | ; w: v_mul_f16 1.0 * -2.0 = -2.0 = 0xc000, UNUSED_SEXT -> 0x0000c000 (no sign copies above it) | ||
| 13 | ; All four are small positive denormal floats, kept bit-exact by the RGBA32F target (as 0x000000f1 in ps_sdwa). | ||
| 14 | ; Expected mrt0 bits: 0x00004000, 0x00000003, 0x00004700, 0x0000c000 | ||
| 15 | v_mov_b32 v1, 0xdeadbeef | ||
| 16 | v_mov_b32 v2, 0x12343c00 | ||
| 17 | v_mov_b32 v3, 0xdeadbeef | ||
| 18 | v_mov_b32 v4, 0xc0004200 | ||
| 19 | v_mov_b32 v5, 0xdeadbeef | ||
| 20 | v_mov_b32 v6, 0x70000 | ||
| 21 | v_mov_b32 v7, 0xdeadbeef | ||
| 22 | v_add_f16_sdwa v1, v2, v2 dst_sel:DWORD dst_unused:UNUSED_PRESERVE src0_sel:WORD_0 src1_sel:WORD_0 | ||
| 23 | v_cvt_u16_f16_sdwa v3, v4 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_0 | ||
| 24 | v_cvt_f16_u16_sdwa v5, v6 dst_sel:DWORD dst_unused:UNUSED_PRESERVE src0_sel:WORD_1 | ||
| 25 | v_mul_f16_sdwa v7, v2, v4 dst_sel:DWORD dst_unused:UNUSED_SEXT src0_sel:WORD_0 src1_sel:WORD_1 | ||
| 26 | exp mrt0 v1, v3, v5, v7 done vm | ||
| 27 | s_endpgm | ||
diff --git a/runtime/test/shaders/ps_texoff_forms.asm b/runtime/test/shaders/ps_texoff_forms.asm new file mode 100644 index 000000000..9076e4a01 --- /dev/null +++ b/runtime/test/shaders/ps_texoff_forms.asm | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | ; Texel offsets on the image_sample*_o forms ps_texoff does not run (SHADER-337): image_sample_o (implicit LOD), | ||
| 2 | ; image_sample_b_o (LOD bias) and image_gather4_l_o (explicit LOD). docs/design.md, "Texel offsets": the first address | ||
| 3 | ; dword packs signed 6-bit offsets, x = [5:0], y = [13:8]; the bias (_b) or the LOD (_l) follows the coordinates as | ||
| 4 | ; the MIMG address order puts them: _b_o = {offset, bias, s, t}, _l_o = {offset, s, t, lod}. | ||
| 5 | ; Run: vk_texture_test <vs> ps_texoff_forms.spv out.raw 2 92 0 0 0 (VKT_NEED_MAINTENANCE8=1: exit 77 without it) | ||
| 6 | ; Same set-up as ps_texoff.asm: an 8x8 RGBA8 texture whose texel (x, y) is r = 32x/255, g = 32y/255, one mip, a | ||
| 7 | ; point sampler that clamps to the edge (S# 0x92), 64x64 pixels with attr0.xy = ((px + 0.5) / 64, (py + 0.5) / 64). | ||
| 8 | ; Each sampled channel c reads back as its texel coordinate through rndne(c * 255/32). | ||
| 9 | ; | ||
| 10 | ; Every sample uses the per-pixel offset of ps_texoff's .x: ox = bx - 4, oy = by - 4 (bx = px >> 3, by = py >> 3), | ||
| 11 | ; all 64 pairs in -4..3, none clamped by the sample. Expected mrt0 words, derived from the rule and the texture: | ||
| 12 | ; .x image_sample_o at the centre of texel (4, 4); the coordinates are the same in every pixel, so the implicit | ||
| 13 | ; derivatives are 0 and the one mip is sampled: texel (bx, by), word = bx | by << 4. | ||
| 14 | ; .y image_sample_b_o with bias 0.0 at the same point: word = bx | by << 4. | ||
| 15 | ; .z image_gather4_l_o of red (dmask 1, LOD 0.0) at uv (0.5, 0.5), the corner of texels 3..4: X0 = max(bx - 1, 0), | ||
| 16 | ; X1 = bx; gather order (i0, j1), (i1, j1), (i1, j0), (i0, j0): word = X0 | X1 << 4 | X1 << 8 | X0 << 12. | ||
| 17 | ; .w the same gather of green: word = Y1 | Y1 << 4 | Y0 << 8 | Y0 << 12 (Y0 = max(by - 1, 0), Y1 = by). | ||
| 18 | ; .z and .w are ps_texoff's gather words (check.py texoff_words). Dropping the offset gives 0x44 in .x and .y; x and y | ||
| 19 | ; swapped give by | bx << 4. | ||
| 20 | s_load_dwordx8 s[8:15], s[2:3], 0 | ||
| 21 | s_mov_b32 s16, 0x92 | ||
| 22 | s_mov_b32 s17, 0 | ||
| 23 | s_mov_b32 s18, 0 | ||
| 24 | s_mov_b32 s19, 0 | ||
| 25 | v_interp_p1_f32_e32 v2, v0, attr0.x | ||
| 26 | v_interp_p2_f32_e32 v2, v1, attr0.x | ||
| 27 | v_interp_p1_f32_e32 v3, v0, attr0.y | ||
| 28 | v_interp_p2_f32_e32 v3, v1, attr0.y | ||
| 29 | v_mul_f32_e32 v2, 0x41000000, v2 | ||
| 30 | v_mul_f32_e32 v3, 0x41000000, v3 | ||
| 31 | v_cvt_u32_f32_e32 v2, v2 | ||
| 32 | v_cvt_u32_f32_e32 v3, v3 | ||
| 33 | v_add_nc_u32_e32 v2, -4, v2 | ||
| 34 | v_add_nc_u32_e32 v3, -4, v3 | ||
| 35 | v_and_b32_e32 v2, 63, v2 | ||
| 36 | v_and_b32_e32 v3, 63, v3 | ||
| 37 | v_lshl_or_b32 v10, v3, 8, v2 | ||
| 38 | v_mov_b32_e32 v11, 0x3f100000 | ||
| 39 | v_mov_b32_e32 v12, 0x3f100000 | ||
| 40 | s_waitcnt lgkmcnt(0) | ||
| 41 | image_sample_o v[4:5], v[10:12], s[8:15], s[16:19] dmask:0x3 dim:SQ_RSRC_IMG_2D | ||
| 42 | v_mov_b32_e32 v24, v10 | ||
| 43 | v_mov_b32_e32 v25, 0 | ||
| 44 | v_mov_b32_e32 v26, 0x3f100000 | ||
| 45 | v_mov_b32_e32 v27, 0x3f100000 | ||
| 46 | image_sample_b_o v[6:7], v[24:27], s[8:15], s[16:19] dmask:0x3 dim:SQ_RSRC_IMG_2D | ||
| 47 | v_mov_b32_e32 v13, v10 | ||
| 48 | v_mov_b32_e32 v14, 0.5 | ||
| 49 | v_mov_b32_e32 v15, 0.5 | ||
| 50 | v_mov_b32_e32 v28, 0 | ||
| 51 | v_mov_b32_e32 v29, v10 | ||
| 52 | v_mov_b32_e32 v30, 0.5 | ||
| 53 | v_mov_b32_e32 v31, 0.5 | ||
| 54 | v_mov_b32_e32 v32, 0 | ||
| 55 | image_gather4_l_o v[16:19], v[29:32], s[8:15], s[16:19] dmask:0x1 dim:SQ_RSRC_IMG_2D | ||
| 56 | image_gather4_l_o v[20:23], v[29:32], s[8:15], s[16:19] dmask:0x2 dim:SQ_RSRC_IMG_2D | ||
| 57 | s_waitcnt vmcnt(0) | ||
| 58 | v_mul_f32_e32 v4, 0x40ff0000, v4 | ||
| 59 | v_rndne_f32_e32 v4, v4 | ||
| 60 | v_cvt_u32_f32_e32 v4, v4 | ||
| 61 | v_mul_f32_e32 v5, 0x40ff0000, v5 | ||
| 62 | v_rndne_f32_e32 v5, v5 | ||
| 63 | v_cvt_u32_f32_e32 v5, v5 | ||
| 64 | v_mul_f32_e32 v6, 0x40ff0000, v6 | ||
| 65 | v_rndne_f32_e32 v6, v6 | ||
| 66 | v_cvt_u32_f32_e32 v6, v6 | ||
| 67 | v_mul_f32_e32 v7, 0x40ff0000, v7 | ||
| 68 | v_rndne_f32_e32 v7, v7 | ||
| 69 | v_cvt_u32_f32_e32 v7, v7 | ||
| 70 | v_mul_f32_e32 v16, 0x40ff0000, v16 | ||
| 71 | v_rndne_f32_e32 v16, v16 | ||
| 72 | v_cvt_u32_f32_e32 v16, v16 | ||
| 73 | v_mul_f32_e32 v17, 0x40ff0000, v17 | ||
| 74 | v_rndne_f32_e32 v17, v17 | ||
| 75 | v_cvt_u32_f32_e32 v17, v17 | ||
| 76 | v_mul_f32_e32 v18, 0x40ff0000, v18 | ||
| 77 | v_rndne_f32_e32 v18, v18 | ||
| 78 | v_cvt_u32_f32_e32 v18, v18 | ||
| 79 | v_mul_f32_e32 v19, 0x40ff0000, v19 | ||
| 80 | v_rndne_f32_e32 v19, v19 | ||
| 81 | v_cvt_u32_f32_e32 v19, v19 | ||
| 82 | v_mul_f32_e32 v20, 0x40ff0000, v20 | ||
| 83 | v_rndne_f32_e32 v20, v20 | ||
| 84 | v_cvt_u32_f32_e32 v20, v20 | ||
| 85 | v_mul_f32_e32 v21, 0x40ff0000, v21 | ||
| 86 | v_rndne_f32_e32 v21, v21 | ||
| 87 | v_cvt_u32_f32_e32 v21, v21 | ||
| 88 | v_mul_f32_e32 v22, 0x40ff0000, v22 | ||
| 89 | v_rndne_f32_e32 v22, v22 | ||
| 90 | v_cvt_u32_f32_e32 v22, v22 | ||
| 91 | v_mul_f32_e32 v23, 0x40ff0000, v23 | ||
| 92 | v_rndne_f32_e32 v23, v23 | ||
| 93 | v_cvt_u32_f32_e32 v23, v23 | ||
| 94 | v_lshl_or_b32 v40, v5, 4, v4 | ||
| 95 | v_lshl_or_b32 v41, v7, 4, v6 | ||
| 96 | v_lshl_or_b32 v42, v17, 4, v16 | ||
| 97 | v_lshl_or_b32 v42, v18, 8, v42 | ||
| 98 | v_lshl_or_b32 v42, v19, 12, v42 | ||
| 99 | v_lshl_or_b32 v43, v21, 4, v20 | ||
| 100 | v_lshl_or_b32 v43, v22, 8, v43 | ||
| 101 | v_lshl_or_b32 v43, v23, 12, v43 | ||
| 102 | exp mrt0 v40, v41, v42, v43 done vm | ||
| 103 | s_endpgm | ||
diff --git a/runtime/test/shaders/ps_vcmp_f16.asm b/runtime/test/shaders/ps_vcmp_f16.asm new file mode 100644 index 000000000..0c1a17733 --- /dev/null +++ b/runtime/test/shaders/ps_vcmp_f16.asm | |||
| @@ -0,0 +1,384 @@ | |||
| 1 | ; 16-bit float VOPC compares, e32 form (VCC destination): v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f16 | ||
| 2 | ; (all 16 IEEE predicates) on seven operand pairs covering the four relations less, greater, equal and unordered, with | ||
| 3 | ; +-0, +-inf, quiet and signalling NaN and f16 denormals, and junk in the high halves of the register operands. | ||
| 4 | ; RDNA2 ISA (VOPC, _F16): the compare reads S0.f16 and S1.f16 (bits 15:0 of the operands only) and writes one bit per lane | ||
| 5 | ; to VCC. Per the ISA pseudocode, for the relation of S0 to S1: | ||
| 6 | ; F = 0, TRU = 1; LT: S0 < S1; EQ: S0 == S1; LE: S0 <= S1; GT: S0 > S1; LG: S0 <> S1 (less or greater); | ||
| 7 | ; GE: S0 >= S1; O: !isNAN(S0) && !isNAN(S1); U: isNAN(S0) || isNAN(S1); NGE = !(S0 >= S1); NLG = !(S0 <> S1); | ||
| 8 | ; NGT = !(S0 > S1); NLE = !(S0 <= S1); NEQ = !(S0 == S1); NLT = !(S0 < S1). | ||
| 9 | ; Every ordered compare with a NaN operand is false, so the N* forms (negations) are true for an unordered pair; +0 == -0; | ||
| 10 | ; the f16 denormals 0x0001 and 0x0002 are kept (they are different numbers, 0x0001 < 0x0002). Cases (A = src0, B = src1, | ||
| 11 | ; the VGPR operand is shown as junk:value, junk = high half that must be ignored): | ||
| 12 | ; k0: A = inline 1.0 (0x3c00), B = 0x1234:0x4000 (2.0) less | ||
| 13 | ; k1: A = inline 2.0 (0x4000), B = 0xabcd:0x3c00 (1.0) greater | ||
| 14 | ; k2: A = inline 0 (+0), B = 0xffff:0x8000 (-0) equal | ||
| 15 | ; k3: A = 0xffff:0x7e00 (qNaN), B = 0x0001:0x3c00 (1.0) unordered | ||
| 16 | ; k4: A = 0x5555:0x3c00 (1.0), B = 0x7c00:0x7c01 (sNaN) unordered | ||
| 17 | ; k5: A = 0x0001:0x7c00 (+inf), B = 0xbeef:0xfc00 (-inf) greater | ||
| 18 | ; k6: A = 0xdead:0x0001 (denormal), B = 0x8000:0x0002 (denormal) less | ||
| 19 | ; Relation sets: LESS = {k0,k6} = 0x41, GREATER = {k1,k5} = 0x22, EQUAL = {k2} = 0x04, UNORDERED = {k3,k4} = 0x18. | ||
| 20 | ; Mask of an op (bit k = result on case k) is the union of the sets it is true for: | ||
| 21 | ; f 0x00 lt 0x41 eq 0x04 le 0x45 gt 0x22 lg 0x63 ge 0x26 o 0x67 | ||
| 22 | ; u 0x18 nge 0x59 nlg 0x1c ngt 0x5d nle 0x3a neq 0x7b nlt 0x3e tru 0x7f | ||
| 23 | ; Word w holds ops 4w..4w+3 (the order above), op j of the word at bit 7*j + k, plus bit 30 so the float export never | ||
| 24 | ; sees a denormal or NaN pattern: | ||
| 25 | ; word 0 = 0x40000000 | 0x00 | 0x41<<7 | 0x04<<14 | 0x45<<21 = 0x40000000 + 0x2080 + 0x10000 + 0x8a00000 = 0x48a12080 | ||
| 26 | ; word 1 = 0x40000000 | 0x22 | 0x63<<7 | 0x26<<14 | 0x67<<21 = 0x40000000 + 0x31a2 + 0x98000 + 0xce00000 = 0x4ce9b1a2 | ||
| 27 | ; word 2 = 0x40000000 | 0x18 | 0x59<<7 | 0x1c<<14 | 0x5d<<21 = 0x40000000 + 0x2c98 + 0x70000 + 0xba00000 = 0x4ba72c98 | ||
| 28 | ; word 3 = 0x40000000 | 0x3a | 0x7b<<7 | 0x3e<<14 | 0x7f<<21 = 0x40000000 + 0x3dba + 0xf8000 + 0xfe00000 = 0x4fefbdba | ||
| 29 | ; A translation that compared the whole 32-bit registers, flushed the denormals (k6 would become equal), ordered a NaN | ||
| 30 | ; (k3, k4 true for lt/gt/le/ge...), or took -0 below +0 (k2) moves bits in the words. | ||
| 31 | ; Expected mrt0 bits: 0x48a12080, 0x4ce9b1a2, 0x4ba72c98, 0x4fefbdba | ||
| 32 | v_mov_b32_e32 v8, 0x12344000 | ||
| 33 | v_mov_b32_e32 v9, 0xabcd3c00 | ||
| 34 | v_mov_b32_e32 v10, 0xffff8000 | ||
| 35 | v_mov_b32_e32 v4, 0xffff7e00 | ||
| 36 | v_mov_b32_e32 v11, 0x00013c00 | ||
| 37 | v_mov_b32_e32 v5, 0x55553c00 | ||
| 38 | v_mov_b32_e32 v12, 0x7c007c01 | ||
| 39 | v_mov_b32_e32 v6, 0x00017c00 | ||
| 40 | v_mov_b32_e32 v13, 0xbeeffc00 | ||
| 41 | v_mov_b32_e32 v7, 0xdead0001 | ||
| 42 | v_mov_b32_e32 v14, 0x80000002 | ||
| 43 | v_mov_b32_e32 v40, 0x40000000 | ||
| 44 | v_cmp_f_f16_e32 vcc_lo, 1.0, v8 | ||
| 45 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 46 | v_lshl_or_b32 v40, v20, 0, v40 | ||
| 47 | v_cmp_f_f16_e32 vcc_lo, 2.0, v9 | ||
| 48 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 49 | v_lshl_or_b32 v40, v20, 1, v40 | ||
| 50 | v_cmp_f_f16_e32 vcc_lo, 0, v10 | ||
| 51 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 52 | v_lshl_or_b32 v40, v20, 2, v40 | ||
| 53 | v_cmp_f_f16_e32 vcc_lo, v4, v11 | ||
| 54 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 55 | v_lshl_or_b32 v40, v20, 3, v40 | ||
| 56 | v_cmp_f_f16_e32 vcc_lo, v5, v12 | ||
| 57 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 58 | v_lshl_or_b32 v40, v20, 4, v40 | ||
| 59 | v_cmp_f_f16_e32 vcc_lo, v6, v13 | ||
| 60 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 61 | v_lshl_or_b32 v40, v20, 5, v40 | ||
| 62 | v_cmp_f_f16_e32 vcc_lo, v7, v14 | ||
| 63 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 64 | v_lshl_or_b32 v40, v20, 6, v40 | ||
| 65 | v_cmp_lt_f16_e32 vcc_lo, 1.0, v8 | ||
| 66 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 67 | v_lshl_or_b32 v40, v20, 7, v40 | ||
| 68 | v_cmp_lt_f16_e32 vcc_lo, 2.0, v9 | ||
| 69 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 70 | v_lshl_or_b32 v40, v20, 8, v40 | ||
| 71 | v_cmp_lt_f16_e32 vcc_lo, 0, v10 | ||
| 72 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 73 | v_lshl_or_b32 v40, v20, 9, v40 | ||
| 74 | v_cmp_lt_f16_e32 vcc_lo, v4, v11 | ||
| 75 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 76 | v_lshl_or_b32 v40, v20, 10, v40 | ||
| 77 | v_cmp_lt_f16_e32 vcc_lo, v5, v12 | ||
| 78 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 79 | v_lshl_or_b32 v40, v20, 11, v40 | ||
| 80 | v_cmp_lt_f16_e32 vcc_lo, v6, v13 | ||
| 81 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 82 | v_lshl_or_b32 v40, v20, 12, v40 | ||
| 83 | v_cmp_lt_f16_e32 vcc_lo, v7, v14 | ||
| 84 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 85 | v_lshl_or_b32 v40, v20, 13, v40 | ||
| 86 | v_cmp_eq_f16_e32 vcc_lo, 1.0, v8 | ||
| 87 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 88 | v_lshl_or_b32 v40, v20, 14, v40 | ||
| 89 | v_cmp_eq_f16_e32 vcc_lo, 2.0, v9 | ||
| 90 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 91 | v_lshl_or_b32 v40, v20, 15, v40 | ||
| 92 | v_cmp_eq_f16_e32 vcc_lo, 0, v10 | ||
| 93 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 94 | v_lshl_or_b32 v40, v20, 16, v40 | ||
| 95 | v_cmp_eq_f16_e32 vcc_lo, v4, v11 | ||
| 96 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 97 | v_lshl_or_b32 v40, v20, 17, v40 | ||
| 98 | v_cmp_eq_f16_e32 vcc_lo, v5, v12 | ||
| 99 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 100 | v_lshl_or_b32 v40, v20, 18, v40 | ||
| 101 | v_cmp_eq_f16_e32 vcc_lo, v6, v13 | ||
| 102 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 103 | v_lshl_or_b32 v40, v20, 19, v40 | ||
| 104 | v_cmp_eq_f16_e32 vcc_lo, v7, v14 | ||
| 105 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 106 | v_lshl_or_b32 v40, v20, 20, v40 | ||
| 107 | v_cmp_le_f16_e32 vcc_lo, 1.0, v8 | ||
| 108 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 109 | v_lshl_or_b32 v40, v20, 21, v40 | ||
| 110 | v_cmp_le_f16_e32 vcc_lo, 2.0, v9 | ||
| 111 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 112 | v_lshl_or_b32 v40, v20, 22, v40 | ||
| 113 | v_cmp_le_f16_e32 vcc_lo, 0, v10 | ||
| 114 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 115 | v_lshl_or_b32 v40, v20, 23, v40 | ||
| 116 | v_cmp_le_f16_e32 vcc_lo, v4, v11 | ||
| 117 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 118 | v_lshl_or_b32 v40, v20, 24, v40 | ||
| 119 | v_cmp_le_f16_e32 vcc_lo, v5, v12 | ||
| 120 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 121 | v_lshl_or_b32 v40, v20, 25, v40 | ||
| 122 | v_cmp_le_f16_e32 vcc_lo, v6, v13 | ||
| 123 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 124 | v_lshl_or_b32 v40, v20, 26, v40 | ||
| 125 | v_cmp_le_f16_e32 vcc_lo, v7, v14 | ||
| 126 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 127 | v_lshl_or_b32 v40, v20, 27, v40 | ||
| 128 | v_mov_b32_e32 v41, 0x40000000 | ||
| 129 | v_cmp_gt_f16_e32 vcc_lo, 1.0, v8 | ||
| 130 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 131 | v_lshl_or_b32 v41, v20, 0, v41 | ||
| 132 | v_cmp_gt_f16_e32 vcc_lo, 2.0, v9 | ||
| 133 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 134 | v_lshl_or_b32 v41, v20, 1, v41 | ||
| 135 | v_cmp_gt_f16_e32 vcc_lo, 0, v10 | ||
| 136 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 137 | v_lshl_or_b32 v41, v20, 2, v41 | ||
| 138 | v_cmp_gt_f16_e32 vcc_lo, v4, v11 | ||
| 139 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 140 | v_lshl_or_b32 v41, v20, 3, v41 | ||
| 141 | v_cmp_gt_f16_e32 vcc_lo, v5, v12 | ||
| 142 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 143 | v_lshl_or_b32 v41, v20, 4, v41 | ||
| 144 | v_cmp_gt_f16_e32 vcc_lo, v6, v13 | ||
| 145 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 146 | v_lshl_or_b32 v41, v20, 5, v41 | ||
| 147 | v_cmp_gt_f16_e32 vcc_lo, v7, v14 | ||
| 148 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 149 | v_lshl_or_b32 v41, v20, 6, v41 | ||
| 150 | v_cmp_lg_f16_e32 vcc_lo, 1.0, v8 | ||
| 151 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 152 | v_lshl_or_b32 v41, v20, 7, v41 | ||
| 153 | v_cmp_lg_f16_e32 vcc_lo, 2.0, v9 | ||
| 154 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 155 | v_lshl_or_b32 v41, v20, 8, v41 | ||
| 156 | v_cmp_lg_f16_e32 vcc_lo, 0, v10 | ||
| 157 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 158 | v_lshl_or_b32 v41, v20, 9, v41 | ||
| 159 | v_cmp_lg_f16_e32 vcc_lo, v4, v11 | ||
| 160 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 161 | v_lshl_or_b32 v41, v20, 10, v41 | ||
| 162 | v_cmp_lg_f16_e32 vcc_lo, v5, v12 | ||
| 163 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 164 | v_lshl_or_b32 v41, v20, 11, v41 | ||
| 165 | v_cmp_lg_f16_e32 vcc_lo, v6, v13 | ||
| 166 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 167 | v_lshl_or_b32 v41, v20, 12, v41 | ||
| 168 | v_cmp_lg_f16_e32 vcc_lo, v7, v14 | ||
| 169 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 170 | v_lshl_or_b32 v41, v20, 13, v41 | ||
| 171 | v_cmp_ge_f16_e32 vcc_lo, 1.0, v8 | ||
| 172 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 173 | v_lshl_or_b32 v41, v20, 14, v41 | ||
| 174 | v_cmp_ge_f16_e32 vcc_lo, 2.0, v9 | ||
| 175 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 176 | v_lshl_or_b32 v41, v20, 15, v41 | ||
| 177 | v_cmp_ge_f16_e32 vcc_lo, 0, v10 | ||
| 178 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 179 | v_lshl_or_b32 v41, v20, 16, v41 | ||
| 180 | v_cmp_ge_f16_e32 vcc_lo, v4, v11 | ||
| 181 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 182 | v_lshl_or_b32 v41, v20, 17, v41 | ||
| 183 | v_cmp_ge_f16_e32 vcc_lo, v5, v12 | ||
| 184 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 185 | v_lshl_or_b32 v41, v20, 18, v41 | ||
| 186 | v_cmp_ge_f16_e32 vcc_lo, v6, v13 | ||
| 187 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 188 | v_lshl_or_b32 v41, v20, 19, v41 | ||
| 189 | v_cmp_ge_f16_e32 vcc_lo, v7, v14 | ||
| 190 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 191 | v_lshl_or_b32 v41, v20, 20, v41 | ||
| 192 | v_cmp_o_f16_e32 vcc_lo, 1.0, v8 | ||
| 193 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 194 | v_lshl_or_b32 v41, v20, 21, v41 | ||
| 195 | v_cmp_o_f16_e32 vcc_lo, 2.0, v9 | ||
| 196 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 197 | v_lshl_or_b32 v41, v20, 22, v41 | ||
| 198 | v_cmp_o_f16_e32 vcc_lo, 0, v10 | ||
| 199 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 200 | v_lshl_or_b32 v41, v20, 23, v41 | ||
| 201 | v_cmp_o_f16_e32 vcc_lo, v4, v11 | ||
| 202 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 203 | v_lshl_or_b32 v41, v20, 24, v41 | ||
| 204 | v_cmp_o_f16_e32 vcc_lo, v5, v12 | ||
| 205 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 206 | v_lshl_or_b32 v41, v20, 25, v41 | ||
| 207 | v_cmp_o_f16_e32 vcc_lo, v6, v13 | ||
| 208 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 209 | v_lshl_or_b32 v41, v20, 26, v41 | ||
| 210 | v_cmp_o_f16_e32 vcc_lo, v7, v14 | ||
| 211 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 212 | v_lshl_or_b32 v41, v20, 27, v41 | ||
| 213 | v_mov_b32_e32 v42, 0x40000000 | ||
| 214 | v_cmp_u_f16_e32 vcc_lo, 1.0, v8 | ||
| 215 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 216 | v_lshl_or_b32 v42, v20, 0, v42 | ||
| 217 | v_cmp_u_f16_e32 vcc_lo, 2.0, v9 | ||
| 218 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 219 | v_lshl_or_b32 v42, v20, 1, v42 | ||
| 220 | v_cmp_u_f16_e32 vcc_lo, 0, v10 | ||
| 221 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 222 | v_lshl_or_b32 v42, v20, 2, v42 | ||
| 223 | v_cmp_u_f16_e32 vcc_lo, v4, v11 | ||
| 224 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 225 | v_lshl_or_b32 v42, v20, 3, v42 | ||
| 226 | v_cmp_u_f16_e32 vcc_lo, v5, v12 | ||
| 227 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 228 | v_lshl_or_b32 v42, v20, 4, v42 | ||
| 229 | v_cmp_u_f16_e32 vcc_lo, v6, v13 | ||
| 230 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 231 | v_lshl_or_b32 v42, v20, 5, v42 | ||
| 232 | v_cmp_u_f16_e32 vcc_lo, v7, v14 | ||
| 233 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 234 | v_lshl_or_b32 v42, v20, 6, v42 | ||
| 235 | v_cmp_nge_f16_e32 vcc_lo, 1.0, v8 | ||
| 236 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 237 | v_lshl_or_b32 v42, v20, 7, v42 | ||
| 238 | v_cmp_nge_f16_e32 vcc_lo, 2.0, v9 | ||
| 239 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 240 | v_lshl_or_b32 v42, v20, 8, v42 | ||
| 241 | v_cmp_nge_f16_e32 vcc_lo, 0, v10 | ||
| 242 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 243 | v_lshl_or_b32 v42, v20, 9, v42 | ||
| 244 | v_cmp_nge_f16_e32 vcc_lo, v4, v11 | ||
| 245 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 246 | v_lshl_or_b32 v42, v20, 10, v42 | ||
| 247 | v_cmp_nge_f16_e32 vcc_lo, v5, v12 | ||
| 248 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 249 | v_lshl_or_b32 v42, v20, 11, v42 | ||
| 250 | v_cmp_nge_f16_e32 vcc_lo, v6, v13 | ||
| 251 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 252 | v_lshl_or_b32 v42, v20, 12, v42 | ||
| 253 | v_cmp_nge_f16_e32 vcc_lo, v7, v14 | ||
| 254 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 255 | v_lshl_or_b32 v42, v20, 13, v42 | ||
| 256 | v_cmp_nlg_f16_e32 vcc_lo, 1.0, v8 | ||
| 257 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 258 | v_lshl_or_b32 v42, v20, 14, v42 | ||
| 259 | v_cmp_nlg_f16_e32 vcc_lo, 2.0, v9 | ||
| 260 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 261 | v_lshl_or_b32 v42, v20, 15, v42 | ||
| 262 | v_cmp_nlg_f16_e32 vcc_lo, 0, v10 | ||
| 263 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 264 | v_lshl_or_b32 v42, v20, 16, v42 | ||
| 265 | v_cmp_nlg_f16_e32 vcc_lo, v4, v11 | ||
| 266 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 267 | v_lshl_or_b32 v42, v20, 17, v42 | ||
| 268 | v_cmp_nlg_f16_e32 vcc_lo, v5, v12 | ||
| 269 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 270 | v_lshl_or_b32 v42, v20, 18, v42 | ||
| 271 | v_cmp_nlg_f16_e32 vcc_lo, v6, v13 | ||
| 272 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 273 | v_lshl_or_b32 v42, v20, 19, v42 | ||
| 274 | v_cmp_nlg_f16_e32 vcc_lo, v7, v14 | ||
| 275 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 276 | v_lshl_or_b32 v42, v20, 20, v42 | ||
| 277 | v_cmp_ngt_f16_e32 vcc_lo, 1.0, v8 | ||
| 278 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 279 | v_lshl_or_b32 v42, v20, 21, v42 | ||
| 280 | v_cmp_ngt_f16_e32 vcc_lo, 2.0, v9 | ||
| 281 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 282 | v_lshl_or_b32 v42, v20, 22, v42 | ||
| 283 | v_cmp_ngt_f16_e32 vcc_lo, 0, v10 | ||
| 284 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 285 | v_lshl_or_b32 v42, v20, 23, v42 | ||
| 286 | v_cmp_ngt_f16_e32 vcc_lo, v4, v11 | ||
| 287 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 288 | v_lshl_or_b32 v42, v20, 24, v42 | ||
| 289 | v_cmp_ngt_f16_e32 vcc_lo, v5, v12 | ||
| 290 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 291 | v_lshl_or_b32 v42, v20, 25, v42 | ||
| 292 | v_cmp_ngt_f16_e32 vcc_lo, v6, v13 | ||
| 293 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 294 | v_lshl_or_b32 v42, v20, 26, v42 | ||
| 295 | v_cmp_ngt_f16_e32 vcc_lo, v7, v14 | ||
| 296 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 297 | v_lshl_or_b32 v42, v20, 27, v42 | ||
| 298 | v_mov_b32_e32 v43, 0x40000000 | ||
| 299 | v_cmp_nle_f16_e32 vcc_lo, 1.0, v8 | ||
| 300 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 301 | v_lshl_or_b32 v43, v20, 0, v43 | ||
| 302 | v_cmp_nle_f16_e32 vcc_lo, 2.0, v9 | ||
| 303 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 304 | v_lshl_or_b32 v43, v20, 1, v43 | ||
| 305 | v_cmp_nle_f16_e32 vcc_lo, 0, v10 | ||
| 306 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 307 | v_lshl_or_b32 v43, v20, 2, v43 | ||
| 308 | v_cmp_nle_f16_e32 vcc_lo, v4, v11 | ||
| 309 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 310 | v_lshl_or_b32 v43, v20, 3, v43 | ||
| 311 | v_cmp_nle_f16_e32 vcc_lo, v5, v12 | ||
| 312 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 313 | v_lshl_or_b32 v43, v20, 4, v43 | ||
| 314 | v_cmp_nle_f16_e32 vcc_lo, v6, v13 | ||
| 315 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 316 | v_lshl_or_b32 v43, v20, 5, v43 | ||
| 317 | v_cmp_nle_f16_e32 vcc_lo, v7, v14 | ||
| 318 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 319 | v_lshl_or_b32 v43, v20, 6, v43 | ||
| 320 | v_cmp_neq_f16_e32 vcc_lo, 1.0, v8 | ||
| 321 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 322 | v_lshl_or_b32 v43, v20, 7, v43 | ||
| 323 | v_cmp_neq_f16_e32 vcc_lo, 2.0, v9 | ||
| 324 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 325 | v_lshl_or_b32 v43, v20, 8, v43 | ||
| 326 | v_cmp_neq_f16_e32 vcc_lo, 0, v10 | ||
| 327 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 328 | v_lshl_or_b32 v43, v20, 9, v43 | ||
| 329 | v_cmp_neq_f16_e32 vcc_lo, v4, v11 | ||
| 330 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 331 | v_lshl_or_b32 v43, v20, 10, v43 | ||
| 332 | v_cmp_neq_f16_e32 vcc_lo, v5, v12 | ||
| 333 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 334 | v_lshl_or_b32 v43, v20, 11, v43 | ||
| 335 | v_cmp_neq_f16_e32 vcc_lo, v6, v13 | ||
| 336 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 337 | v_lshl_or_b32 v43, v20, 12, v43 | ||
| 338 | v_cmp_neq_f16_e32 vcc_lo, v7, v14 | ||
| 339 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 340 | v_lshl_or_b32 v43, v20, 13, v43 | ||
| 341 | v_cmp_nlt_f16_e32 vcc_lo, 1.0, v8 | ||
| 342 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 343 | v_lshl_or_b32 v43, v20, 14, v43 | ||
| 344 | v_cmp_nlt_f16_e32 vcc_lo, 2.0, v9 | ||
| 345 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 346 | v_lshl_or_b32 v43, v20, 15, v43 | ||
| 347 | v_cmp_nlt_f16_e32 vcc_lo, 0, v10 | ||
| 348 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 349 | v_lshl_or_b32 v43, v20, 16, v43 | ||
| 350 | v_cmp_nlt_f16_e32 vcc_lo, v4, v11 | ||
| 351 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 352 | v_lshl_or_b32 v43, v20, 17, v43 | ||
| 353 | v_cmp_nlt_f16_e32 vcc_lo, v5, v12 | ||
| 354 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 355 | v_lshl_or_b32 v43, v20, 18, v43 | ||
| 356 | v_cmp_nlt_f16_e32 vcc_lo, v6, v13 | ||
| 357 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 358 | v_lshl_or_b32 v43, v20, 19, v43 | ||
| 359 | v_cmp_nlt_f16_e32 vcc_lo, v7, v14 | ||
| 360 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 361 | v_lshl_or_b32 v43, v20, 20, v43 | ||
| 362 | v_cmp_tru_f16_e32 vcc_lo, 1.0, v8 | ||
| 363 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 364 | v_lshl_or_b32 v43, v20, 21, v43 | ||
| 365 | v_cmp_tru_f16_e32 vcc_lo, 2.0, v9 | ||
| 366 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 367 | v_lshl_or_b32 v43, v20, 22, v43 | ||
| 368 | v_cmp_tru_f16_e32 vcc_lo, 0, v10 | ||
| 369 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 370 | v_lshl_or_b32 v43, v20, 23, v43 | ||
| 371 | v_cmp_tru_f16_e32 vcc_lo, v4, v11 | ||
| 372 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 373 | v_lshl_or_b32 v43, v20, 24, v43 | ||
| 374 | v_cmp_tru_f16_e32 vcc_lo, v5, v12 | ||
| 375 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 376 | v_lshl_or_b32 v43, v20, 25, v43 | ||
| 377 | v_cmp_tru_f16_e32 vcc_lo, v6, v13 | ||
| 378 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 379 | v_lshl_or_b32 v43, v20, 26, v43 | ||
| 380 | v_cmp_tru_f16_e32 vcc_lo, v7, v14 | ||
| 381 | v_cndmask_b32_e64 v20, 0, 1, vcc_lo | ||
| 382 | v_lshl_or_b32 v43, v20, 27, v43 | ||
| 383 | exp mrt0 v40, v41, v42, v43 done vm | ||
| 384 | s_endpgm | ||
diff --git a/runtime/test/shaders/ps_vcmp_f16_e64.asm b/runtime/test/shaders/ps_vcmp_f16_e64.asm new file mode 100644 index 000000000..4bad79619 --- /dev/null +++ b/runtime/test/shaders/ps_vcmp_f16_e64.asm | |||
| @@ -0,0 +1,369 @@ | |||
| 1 | ; 16-bit float VOPC compares, e64 form (SGPR destination) with swapped operands: v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg, | ||
| 2 | ; ngt,nle,neq,nlt,tru}_f16_e64 s4, B, A. Same seven operand pairs as ps_vcmp_f16 (see its header for the ISA rules and | ||
| 3 | ; the case list), but src0 is the VGPR B and src1 is A (the inline constant for k0..k2, the VGPR otherwise), so each | ||
| 4 | ; op sees the mirrored relation: less <-> greater, equal and unordered unchanged. | ||
| 5 | ; Cases (A to B as in ps_vcmp_f16): k0 1.0/2.0, k1 2.0/1.0, k2 +0/-0, k3 qNaN/1.0, k4 1.0/sNaN, | ||
| 6 | ; k5 +inf/-inf, k6 denormal 0x0001/0x0002; the high halves of the VGPR operands hold junk. | ||
| 7 | ; Relation of B (src0) to A (src1): LESS = {k1,k5} = 0x22, GREATER = {k0,k6} = 0x41, | ||
| 8 | ; EQUAL = {k2} = 0x04, UNORDERED = {k3,k4} = 0x18. Masks (bit k = result on case k): | ||
| 9 | ; f 0x00 lt 0x22 eq 0x04 le 0x26 gt 0x41 lg 0x63 ge 0x45 o 0x67 | ||
| 10 | ; u 0x18 nge 0x3a nlg 0x1c ngt 0x3e nle 0x59 neq 0x7b nlt 0x5d tru 0x7f | ||
| 11 | ; Word w holds ops 4w..4w+3, op j at bit 7*j + k, plus bit 30 (no denormal or NaN export pattern): | ||
| 12 | ; word 0 = 0x40000000 | 0x00 | 0x22<<7 | 0x04<<14 | 0x26<<21 = 0x40000000 + 0x1100 + 0x10000 + 0x4c00000 = 0x44c11100 | ||
| 13 | ; word 1 = 0x40000000 | 0x41 | 0x63<<7 | 0x45<<14 | 0x67<<21 = 0x40000000 + 0x31c1 + 0x114000 + 0xce00000 = 0x4cf171c1 | ||
| 14 | ; word 2 = 0x40000000 | 0x18 | 0x3a<<7 | 0x1c<<14 | 0x3e<<21 = 0x40000000 + 0x1d18 + 0x70000 + 0x7c00000 = 0x47c71d18 | ||
| 15 | ; word 3 = 0x40000000 | 0x59 | 0x7b<<7 | 0x5d<<14 | 0x7f<<21 = 0x40000000 + 0x3dd9 + 0x174000 + 0xfe00000 = 0x4ff77dd9 | ||
| 16 | ; Expected mrt0 bits: 0x44c11100, 0x4cf171c1, 0x47c71d18, 0x4ff77dd9 | ||
| 17 | v_mov_b32_e32 v8, 0x12344000 | ||
| 18 | v_mov_b32_e32 v9, 0xabcd3c00 | ||
| 19 | v_mov_b32_e32 v10, 0xffff8000 | ||
| 20 | v_mov_b32_e32 v4, 0xffff7e00 | ||
| 21 | v_mov_b32_e32 v11, 0x00013c00 | ||
| 22 | v_mov_b32_e32 v5, 0x55553c00 | ||
| 23 | v_mov_b32_e32 v12, 0x7c007c01 | ||
| 24 | v_mov_b32_e32 v6, 0x00017c00 | ||
| 25 | v_mov_b32_e32 v13, 0xbeeffc00 | ||
| 26 | v_mov_b32_e32 v7, 0xdead0001 | ||
| 27 | v_mov_b32_e32 v14, 0x80000002 | ||
| 28 | v_mov_b32_e32 v40, 0x40000000 | ||
| 29 | v_cmp_f_f16_e64 s4, v8, 1.0 | ||
| 30 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 31 | v_lshl_or_b32 v40, v20, 0, v40 | ||
| 32 | v_cmp_f_f16_e64 s4, v9, 2.0 | ||
| 33 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 34 | v_lshl_or_b32 v40, v20, 1, v40 | ||
| 35 | v_cmp_f_f16_e64 s4, v10, 0 | ||
| 36 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 37 | v_lshl_or_b32 v40, v20, 2, v40 | ||
| 38 | v_cmp_f_f16_e64 s4, v11, v4 | ||
| 39 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 40 | v_lshl_or_b32 v40, v20, 3, v40 | ||
| 41 | v_cmp_f_f16_e64 s4, v12, v5 | ||
| 42 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 43 | v_lshl_or_b32 v40, v20, 4, v40 | ||
| 44 | v_cmp_f_f16_e64 s4, v13, v6 | ||
| 45 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 46 | v_lshl_or_b32 v40, v20, 5, v40 | ||
| 47 | v_cmp_f_f16_e64 s4, v14, v7 | ||
| 48 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 49 | v_lshl_or_b32 v40, v20, 6, v40 | ||
| 50 | v_cmp_lt_f16_e64 s4, v8, 1.0 | ||
| 51 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 52 | v_lshl_or_b32 v40, v20, 7, v40 | ||
| 53 | v_cmp_lt_f16_e64 s4, v9, 2.0 | ||
| 54 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 55 | v_lshl_or_b32 v40, v20, 8, v40 | ||
| 56 | v_cmp_lt_f16_e64 s4, v10, 0 | ||
| 57 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 58 | v_lshl_or_b32 v40, v20, 9, v40 | ||
| 59 | v_cmp_lt_f16_e64 s4, v11, v4 | ||
| 60 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 61 | v_lshl_or_b32 v40, v20, 10, v40 | ||
| 62 | v_cmp_lt_f16_e64 s4, v12, v5 | ||
| 63 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 64 | v_lshl_or_b32 v40, v20, 11, v40 | ||
| 65 | v_cmp_lt_f16_e64 s4, v13, v6 | ||
| 66 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 67 | v_lshl_or_b32 v40, v20, 12, v40 | ||
| 68 | v_cmp_lt_f16_e64 s4, v14, v7 | ||
| 69 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 70 | v_lshl_or_b32 v40, v20, 13, v40 | ||
| 71 | v_cmp_eq_f16_e64 s4, v8, 1.0 | ||
| 72 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 73 | v_lshl_or_b32 v40, v20, 14, v40 | ||
| 74 | v_cmp_eq_f16_e64 s4, v9, 2.0 | ||
| 75 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 76 | v_lshl_or_b32 v40, v20, 15, v40 | ||
| 77 | v_cmp_eq_f16_e64 s4, v10, 0 | ||
| 78 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 79 | v_lshl_or_b32 v40, v20, 16, v40 | ||
| 80 | v_cmp_eq_f16_e64 s4, v11, v4 | ||
| 81 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 82 | v_lshl_or_b32 v40, v20, 17, v40 | ||
| 83 | v_cmp_eq_f16_e64 s4, v12, v5 | ||
| 84 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 85 | v_lshl_or_b32 v40, v20, 18, v40 | ||
| 86 | v_cmp_eq_f16_e64 s4, v13, v6 | ||
| 87 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 88 | v_lshl_or_b32 v40, v20, 19, v40 | ||
| 89 | v_cmp_eq_f16_e64 s4, v14, v7 | ||
| 90 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 91 | v_lshl_or_b32 v40, v20, 20, v40 | ||
| 92 | v_cmp_le_f16_e64 s4, v8, 1.0 | ||
| 93 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 94 | v_lshl_or_b32 v40, v20, 21, v40 | ||
| 95 | v_cmp_le_f16_e64 s4, v9, 2.0 | ||
| 96 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 97 | v_lshl_or_b32 v40, v20, 22, v40 | ||
| 98 | v_cmp_le_f16_e64 s4, v10, 0 | ||
| 99 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 100 | v_lshl_or_b32 v40, v20, 23, v40 | ||
| 101 | v_cmp_le_f16_e64 s4, v11, v4 | ||
| 102 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 103 | v_lshl_or_b32 v40, v20, 24, v40 | ||
| 104 | v_cmp_le_f16_e64 s4, v12, v5 | ||
| 105 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 106 | v_lshl_or_b32 v40, v20, 25, v40 | ||
| 107 | v_cmp_le_f16_e64 s4, v13, v6 | ||
| 108 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 109 | v_lshl_or_b32 v40, v20, 26, v40 | ||
| 110 | v_cmp_le_f16_e64 s4, v14, v7 | ||
| 111 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 112 | v_lshl_or_b32 v40, v20, 27, v40 | ||
| 113 | v_mov_b32_e32 v41, 0x40000000 | ||
| 114 | v_cmp_gt_f16_e64 s4, v8, 1.0 | ||
| 115 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 116 | v_lshl_or_b32 v41, v20, 0, v41 | ||
| 117 | v_cmp_gt_f16_e64 s4, v9, 2.0 | ||
| 118 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 119 | v_lshl_or_b32 v41, v20, 1, v41 | ||
| 120 | v_cmp_gt_f16_e64 s4, v10, 0 | ||
| 121 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 122 | v_lshl_or_b32 v41, v20, 2, v41 | ||
| 123 | v_cmp_gt_f16_e64 s4, v11, v4 | ||
| 124 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 125 | v_lshl_or_b32 v41, v20, 3, v41 | ||
| 126 | v_cmp_gt_f16_e64 s4, v12, v5 | ||
| 127 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 128 | v_lshl_or_b32 v41, v20, 4, v41 | ||
| 129 | v_cmp_gt_f16_e64 s4, v13, v6 | ||
| 130 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 131 | v_lshl_or_b32 v41, v20, 5, v41 | ||
| 132 | v_cmp_gt_f16_e64 s4, v14, v7 | ||
| 133 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 134 | v_lshl_or_b32 v41, v20, 6, v41 | ||
| 135 | v_cmp_lg_f16_e64 s4, v8, 1.0 | ||
| 136 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 137 | v_lshl_or_b32 v41, v20, 7, v41 | ||
| 138 | v_cmp_lg_f16_e64 s4, v9, 2.0 | ||
| 139 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 140 | v_lshl_or_b32 v41, v20, 8, v41 | ||
| 141 | v_cmp_lg_f16_e64 s4, v10, 0 | ||
| 142 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 143 | v_lshl_or_b32 v41, v20, 9, v41 | ||
| 144 | v_cmp_lg_f16_e64 s4, v11, v4 | ||
| 145 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 146 | v_lshl_or_b32 v41, v20, 10, v41 | ||
| 147 | v_cmp_lg_f16_e64 s4, v12, v5 | ||
| 148 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 149 | v_lshl_or_b32 v41, v20, 11, v41 | ||
| 150 | v_cmp_lg_f16_e64 s4, v13, v6 | ||
| 151 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 152 | v_lshl_or_b32 v41, v20, 12, v41 | ||
| 153 | v_cmp_lg_f16_e64 s4, v14, v7 | ||
| 154 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 155 | v_lshl_or_b32 v41, v20, 13, v41 | ||
| 156 | v_cmp_ge_f16_e64 s4, v8, 1.0 | ||
| 157 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 158 | v_lshl_or_b32 v41, v20, 14, v41 | ||
| 159 | v_cmp_ge_f16_e64 s4, v9, 2.0 | ||
| 160 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 161 | v_lshl_or_b32 v41, v20, 15, v41 | ||
| 162 | v_cmp_ge_f16_e64 s4, v10, 0 | ||
| 163 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 164 | v_lshl_or_b32 v41, v20, 16, v41 | ||
| 165 | v_cmp_ge_f16_e64 s4, v11, v4 | ||
| 166 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 167 | v_lshl_or_b32 v41, v20, 17, v41 | ||
| 168 | v_cmp_ge_f16_e64 s4, v12, v5 | ||
| 169 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 170 | v_lshl_or_b32 v41, v20, 18, v41 | ||
| 171 | v_cmp_ge_f16_e64 s4, v13, v6 | ||
| 172 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 173 | v_lshl_or_b32 v41, v20, 19, v41 | ||
| 174 | v_cmp_ge_f16_e64 s4, v14, v7 | ||
| 175 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 176 | v_lshl_or_b32 v41, v20, 20, v41 | ||
| 177 | v_cmp_o_f16_e64 s4, v8, 1.0 | ||
| 178 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 179 | v_lshl_or_b32 v41, v20, 21, v41 | ||
| 180 | v_cmp_o_f16_e64 s4, v9, 2.0 | ||
| 181 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 182 | v_lshl_or_b32 v41, v20, 22, v41 | ||
| 183 | v_cmp_o_f16_e64 s4, v10, 0 | ||
| 184 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 185 | v_lshl_or_b32 v41, v20, 23, v41 | ||
| 186 | v_cmp_o_f16_e64 s4, v11, v4 | ||
| 187 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 188 | v_lshl_or_b32 v41, v20, 24, v41 | ||
| 189 | v_cmp_o_f16_e64 s4, v12, v5 | ||
| 190 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 191 | v_lshl_or_b32 v41, v20, 25, v41 | ||
| 192 | v_cmp_o_f16_e64 s4, v13, v6 | ||
| 193 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 194 | v_lshl_or_b32 v41, v20, 26, v41 | ||
| 195 | v_cmp_o_f16_e64 s4, v14, v7 | ||
| 196 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 197 | v_lshl_or_b32 v41, v20, 27, v41 | ||
| 198 | v_mov_b32_e32 v42, 0x40000000 | ||
| 199 | v_cmp_u_f16_e64 s4, v8, 1.0 | ||
| 200 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 201 | v_lshl_or_b32 v42, v20, 0, v42 | ||
| 202 | v_cmp_u_f16_e64 s4, v9, 2.0 | ||
| 203 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 204 | v_lshl_or_b32 v42, v20, 1, v42 | ||
| 205 | v_cmp_u_f16_e64 s4, v10, 0 | ||
| 206 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 207 | v_lshl_or_b32 v42, v20, 2, v42 | ||
| 208 | v_cmp_u_f16_e64 s4, v11, v4 | ||
| 209 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 210 | v_lshl_or_b32 v42, v20, 3, v42 | ||
| 211 | v_cmp_u_f16_e64 s4, v12, v5 | ||
| 212 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 213 | v_lshl_or_b32 v42, v20, 4, v42 | ||
| 214 | v_cmp_u_f16_e64 s4, v13, v6 | ||
| 215 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 216 | v_lshl_or_b32 v42, v20, 5, v42 | ||
| 217 | v_cmp_u_f16_e64 s4, v14, v7 | ||
| 218 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 219 | v_lshl_or_b32 v42, v20, 6, v42 | ||
| 220 | v_cmp_nge_f16_e64 s4, v8, 1.0 | ||
| 221 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 222 | v_lshl_or_b32 v42, v20, 7, v42 | ||
| 223 | v_cmp_nge_f16_e64 s4, v9, 2.0 | ||
| 224 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 225 | v_lshl_or_b32 v42, v20, 8, v42 | ||
| 226 | v_cmp_nge_f16_e64 s4, v10, 0 | ||
| 227 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 228 | v_lshl_or_b32 v42, v20, 9, v42 | ||
| 229 | v_cmp_nge_f16_e64 s4, v11, v4 | ||
| 230 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 231 | v_lshl_or_b32 v42, v20, 10, v42 | ||
| 232 | v_cmp_nge_f16_e64 s4, v12, v5 | ||
| 233 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 234 | v_lshl_or_b32 v42, v20, 11, v42 | ||
| 235 | v_cmp_nge_f16_e64 s4, v13, v6 | ||
| 236 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 237 | v_lshl_or_b32 v42, v20, 12, v42 | ||
| 238 | v_cmp_nge_f16_e64 s4, v14, v7 | ||
| 239 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 240 | v_lshl_or_b32 v42, v20, 13, v42 | ||
| 241 | v_cmp_nlg_f16_e64 s4, v8, 1.0 | ||
| 242 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 243 | v_lshl_or_b32 v42, v20, 14, v42 | ||
| 244 | v_cmp_nlg_f16_e64 s4, v9, 2.0 | ||
| 245 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 246 | v_lshl_or_b32 v42, v20, 15, v42 | ||
| 247 | v_cmp_nlg_f16_e64 s4, v10, 0 | ||
| 248 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 249 | v_lshl_or_b32 v42, v20, 16, v42 | ||
| 250 | v_cmp_nlg_f16_e64 s4, v11, v4 | ||
| 251 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 252 | v_lshl_or_b32 v42, v20, 17, v42 | ||
| 253 | v_cmp_nlg_f16_e64 s4, v12, v5 | ||
| 254 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 255 | v_lshl_or_b32 v42, v20, 18, v42 | ||
| 256 | v_cmp_nlg_f16_e64 s4, v13, v6 | ||
| 257 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 258 | v_lshl_or_b32 v42, v20, 19, v42 | ||
| 259 | v_cmp_nlg_f16_e64 s4, v14, v7 | ||
| 260 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 261 | v_lshl_or_b32 v42, v20, 20, v42 | ||
| 262 | v_cmp_ngt_f16_e64 s4, v8, 1.0 | ||
| 263 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 264 | v_lshl_or_b32 v42, v20, 21, v42 | ||
| 265 | v_cmp_ngt_f16_e64 s4, v9, 2.0 | ||
| 266 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 267 | v_lshl_or_b32 v42, v20, 22, v42 | ||
| 268 | v_cmp_ngt_f16_e64 s4, v10, 0 | ||
| 269 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 270 | v_lshl_or_b32 v42, v20, 23, v42 | ||
| 271 | v_cmp_ngt_f16_e64 s4, v11, v4 | ||
| 272 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 273 | v_lshl_or_b32 v42, v20, 24, v42 | ||
| 274 | v_cmp_ngt_f16_e64 s4, v12, v5 | ||
| 275 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 276 | v_lshl_or_b32 v42, v20, 25, v42 | ||
| 277 | v_cmp_ngt_f16_e64 s4, v13, v6 | ||
| 278 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 279 | v_lshl_or_b32 v42, v20, 26, v42 | ||
| 280 | v_cmp_ngt_f16_e64 s4, v14, v7 | ||
| 281 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 282 | v_lshl_or_b32 v42, v20, 27, v42 | ||
| 283 | v_mov_b32_e32 v43, 0x40000000 | ||
| 284 | v_cmp_nle_f16_e64 s4, v8, 1.0 | ||
| 285 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 286 | v_lshl_or_b32 v43, v20, 0, v43 | ||
| 287 | v_cmp_nle_f16_e64 s4, v9, 2.0 | ||
| 288 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 289 | v_lshl_or_b32 v43, v20, 1, v43 | ||
| 290 | v_cmp_nle_f16_e64 s4, v10, 0 | ||
| 291 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 292 | v_lshl_or_b32 v43, v20, 2, v43 | ||
| 293 | v_cmp_nle_f16_e64 s4, v11, v4 | ||
| 294 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 295 | v_lshl_or_b32 v43, v20, 3, v43 | ||
| 296 | v_cmp_nle_f16_e64 s4, v12, v5 | ||
| 297 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 298 | v_lshl_or_b32 v43, v20, 4, v43 | ||
| 299 | v_cmp_nle_f16_e64 s4, v13, v6 | ||
| 300 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 301 | v_lshl_or_b32 v43, v20, 5, v43 | ||
| 302 | v_cmp_nle_f16_e64 s4, v14, v7 | ||
| 303 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 304 | v_lshl_or_b32 v43, v20, 6, v43 | ||
| 305 | v_cmp_neq_f16_e64 s4, v8, 1.0 | ||
| 306 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 307 | v_lshl_or_b32 v43, v20, 7, v43 | ||
| 308 | v_cmp_neq_f16_e64 s4, v9, 2.0 | ||
| 309 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 310 | v_lshl_or_b32 v43, v20, 8, v43 | ||
| 311 | v_cmp_neq_f16_e64 s4, v10, 0 | ||
| 312 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 313 | v_lshl_or_b32 v43, v20, 9, v43 | ||
| 314 | v_cmp_neq_f16_e64 s4, v11, v4 | ||
| 315 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 316 | v_lshl_or_b32 v43, v20, 10, v43 | ||
| 317 | v_cmp_neq_f16_e64 s4, v12, v5 | ||
| 318 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 319 | v_lshl_or_b32 v43, v20, 11, v43 | ||
| 320 | v_cmp_neq_f16_e64 s4, v13, v6 | ||
| 321 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 322 | v_lshl_or_b32 v43, v20, 12, v43 | ||
| 323 | v_cmp_neq_f16_e64 s4, v14, v7 | ||
| 324 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 325 | v_lshl_or_b32 v43, v20, 13, v43 | ||
| 326 | v_cmp_nlt_f16_e64 s4, v8, 1.0 | ||
| 327 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 328 | v_lshl_or_b32 v43, v20, 14, v43 | ||
| 329 | v_cmp_nlt_f16_e64 s4, v9, 2.0 | ||
| 330 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 331 | v_lshl_or_b32 v43, v20, 15, v43 | ||
| 332 | v_cmp_nlt_f16_e64 s4, v10, 0 | ||
| 333 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 334 | v_lshl_or_b32 v43, v20, 16, v43 | ||
| 335 | v_cmp_nlt_f16_e64 s4, v11, v4 | ||
| 336 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 337 | v_lshl_or_b32 v43, v20, 17, v43 | ||
| 338 | v_cmp_nlt_f16_e64 s4, v12, v5 | ||
| 339 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 340 | v_lshl_or_b32 v43, v20, 18, v43 | ||
| 341 | v_cmp_nlt_f16_e64 s4, v13, v6 | ||
| 342 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 343 | v_lshl_or_b32 v43, v20, 19, v43 | ||
| 344 | v_cmp_nlt_f16_e64 s4, v14, v7 | ||
| 345 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 346 | v_lshl_or_b32 v43, v20, 20, v43 | ||
| 347 | v_cmp_tru_f16_e64 s4, v8, 1.0 | ||
| 348 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 349 | v_lshl_or_b32 v43, v20, 21, v43 | ||
| 350 | v_cmp_tru_f16_e64 s4, v9, 2.0 | ||
| 351 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 352 | v_lshl_or_b32 v43, v20, 22, v43 | ||
| 353 | v_cmp_tru_f16_e64 s4, v10, 0 | ||
| 354 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 355 | v_lshl_or_b32 v43, v20, 23, v43 | ||
| 356 | v_cmp_tru_f16_e64 s4, v11, v4 | ||
| 357 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 358 | v_lshl_or_b32 v43, v20, 24, v43 | ||
| 359 | v_cmp_tru_f16_e64 s4, v12, v5 | ||
| 360 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 361 | v_lshl_or_b32 v43, v20, 25, v43 | ||
| 362 | v_cmp_tru_f16_e64 s4, v13, v6 | ||
| 363 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 364 | v_lshl_or_b32 v43, v20, 26, v43 | ||
| 365 | v_cmp_tru_f16_e64 s4, v14, v7 | ||
| 366 | v_cndmask_b32_e64 v20, 0, 1, s4 | ||
| 367 | v_lshl_or_b32 v43, v20, 27, v43 | ||
| 368 | exp mrt0 v40, v41, v42, v43 done vm | ||
| 369 | s_endpgm | ||
diff --git a/runtime/test/shaders/ps_vcmpx_f16.asm b/runtime/test/shaders/ps_vcmpx_f16.asm new file mode 100644 index 000000000..3a7cd338d --- /dev/null +++ b/runtime/test/shaders/ps_vcmpx_f16.asm | |||
| @@ -0,0 +1,653 @@ | |||
| 1 | ; 16-bit float v_cmpx, e32 form: v_cmpx_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f16 on the seven operand | ||
| 2 | ; pairs of ps_vcmp_f16 (see that header for the case list and the ISA rules of the 16 predicates: bits 15:0 of the | ||
| 3 | ; operands only, ordered compares false for a NaN, +0 == -0, denormals kept). A v_cmpx writes the result to EXEC | ||
| 4 | ; (EXEC = EXEC & compare, per lane) and to nothing else, so VCC is kept. Each compare runs alone: EXEC is copied out | ||
| 5 | ; and put back after it (s20 holds the EXEC the shader started with, s21 the copy), so a lane that was true shows as 1 | ||
| 6 | ; and every lane has the same operands. Cases (A = src0, B = src1; the junk is the high half that must be ignored): | ||
| 7 | ; k0: A = inline 1.0, B = 0x1234:2.0 less k4: A = 0x5555:1.0, B = 0x7c00:sNaN 0x7c01 unordered | ||
| 8 | ; k1: A = inline 2.0, B = 0xabcd:1.0 greater k5: A = 0x0001:+inf, B = 0xbeef:-inf greater | ||
| 9 | ; k2: A = inline 0, B = 0xffff:-0 equal k6: A = 0xdead:0x0001, B = 0x8000:0x0002 less (denormals) | ||
| 10 | ; k3: A = 0xffff:qNaN 0x7e00, B = 0x0001:1.0 unordered | ||
| 11 | ; Relation sets: LESS = {k0,k6} = 0x41, GREATER = {k1,k5} = 0x22, EQUAL = {k2} = 0x04, UNORDERED = {k3,k4} = 0x18; the | ||
| 12 | ; mask of an op (bit k = result on case k) is the union of the sets it is true for: | ||
| 13 | ; f 0x00 lt 0x41 eq 0x04 le 0x45 gt 0x22 lg 0x63 ge 0x26 o 0x67 | ||
| 14 | ; u 0x18 nge 0x59 nlg 0x1c ngt 0x5d nle 0x3a neq 0x7b nlt 0x3e tru 0x7f | ||
| 15 | ; Word w holds ops 4w..4w+3 (the order above), op j at bit 7*j + k. Three more bits per word, from one op of the form: | ||
| 16 | ; bit 30: always 1 (keeps the float export away from denormal and NaN patterns). | ||
| 17 | ; bit 29: VCC = 1 in every lane (v_cmp_tru_f16 v8, v8), then v_cmpx_f_f16 empties EXEC; after EXEC is restored VCC | ||
| 18 | ; must still be 1, because a v_cmpx writes EXEC only: the bit is 1. | ||
| 19 | ; bit 28: v_cmpx_f_f16 empties EXEC, the v_cmpx_tru_f16 after it is true in every lane, but v_cmpx only ANDs into | ||
| 20 | ; EXEC, so no lane comes back: the bit is 0. | ||
| 21 | ; word 0 = 0x60000000 | 0x00 | 0x41<<7 | 0x04<<14 | 0x45<<21 = 0x60000000 + 0x2080 + 0x10000 + 0x8a00000 = 0x68a12080 | ||
| 22 | ; word 1 = 0x60000000 | 0x22 | 0x63<<7 | 0x26<<14 | 0x67<<21 = 0x60000000 + 0x31a2 + 0x98000 + 0xce00000 = 0x6ce9b1a2 | ||
| 23 | ; word 2 = 0x60000000 | 0x18 | 0x59<<7 | 0x1c<<14 | 0x5d<<21 = 0x60000000 + 0x2c98 + 0x70000 + 0xba00000 = 0x6ba72c98 | ||
| 24 | ; word 3 = 0x60000000 | 0x3a | 0x7b<<7 | 0x3e<<14 | 0x7f<<21 = 0x60000000 + 0x3dba + 0xf8000 + 0xfe00000 = 0x6fefbdba | ||
| 25 | ; A v_cmpx that wrote VCC, or did not AND with the old EXEC, flips bit 29 or bit 28; one that ordered a NaN, flushed a | ||
| 26 | ; denormal, took -0 below +0 or read the high halves moves bits in the words. | ||
| 27 | ; Expected mrt0 bits: 0x68a12080, 0x6ce9b1a2, 0x6ba72c98, 0x6fefbdba | ||
| 28 | v_mov_b32_e32 v8, 0x12344000 | ||
| 29 | v_mov_b32_e32 v9, 0xabcd3c00 | ||
| 30 | v_mov_b32_e32 v10, 0xffff8000 | ||
| 31 | v_mov_b32_e32 v4, 0xffff7e00 | ||
| 32 | v_mov_b32_e32 v11, 0x00013c00 | ||
| 33 | v_mov_b32_e32 v5, 0x55553c00 | ||
| 34 | v_mov_b32_e32 v12, 0x7c007c01 | ||
| 35 | v_mov_b32_e32 v6, 0x00017c00 | ||
| 36 | v_mov_b32_e32 v13, 0xbeeffc00 | ||
| 37 | v_mov_b32_e32 v7, 0xdead0001 | ||
| 38 | v_mov_b32_e32 v14, 0x80000002 | ||
| 39 | s_mov_b32 s20, exec_lo | ||
| 40 | v_mov_b32_e32 v40, 0x40000000 | ||
| 41 | v_cmp_tru_f16_e32 vcc_lo, v8, v8 | ||
| 42 | v_cmpx_f_f16_e32 v8, v8 | ||
| 43 | s_mov_b32 s21, exec_lo | ||
| 44 | s_mov_b32 exec_lo, s20 | ||
| 45 | v_cndmask_b32_e64 v30, 0, 1, vcc_lo | ||
| 46 | v_lshl_or_b32 v40, v30, 29, v40 | ||
| 47 | v_cmpx_f_f16_e32 v8, v8 | ||
| 48 | v_cmpx_tru_f16_e32 v8, v8 | ||
| 49 | s_mov_b32 s21, exec_lo | ||
| 50 | s_mov_b32 exec_lo, s20 | ||
| 51 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 52 | v_lshl_or_b32 v40, v30, 28, v40 | ||
| 53 | v_cmpx_f_f16_e32 1.0, v8 | ||
| 54 | s_mov_b32 s21, exec_lo | ||
| 55 | s_mov_b32 exec_lo, s20 | ||
| 56 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 57 | v_lshl_or_b32 v40, v30, 0, v40 | ||
| 58 | v_cmpx_f_f16_e32 2.0, v9 | ||
| 59 | s_mov_b32 s21, exec_lo | ||
| 60 | s_mov_b32 exec_lo, s20 | ||
| 61 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 62 | v_lshl_or_b32 v40, v30, 1, v40 | ||
| 63 | v_cmpx_f_f16_e32 0, v10 | ||
| 64 | s_mov_b32 s21, exec_lo | ||
| 65 | s_mov_b32 exec_lo, s20 | ||
| 66 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 67 | v_lshl_or_b32 v40, v30, 2, v40 | ||
| 68 | v_cmpx_f_f16_e32 v4, v11 | ||
| 69 | s_mov_b32 s21, exec_lo | ||
| 70 | s_mov_b32 exec_lo, s20 | ||
| 71 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 72 | v_lshl_or_b32 v40, v30, 3, v40 | ||
| 73 | v_cmpx_f_f16_e32 v5, v12 | ||
| 74 | s_mov_b32 s21, exec_lo | ||
| 75 | s_mov_b32 exec_lo, s20 | ||
| 76 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 77 | v_lshl_or_b32 v40, v30, 4, v40 | ||
| 78 | v_cmpx_f_f16_e32 v6, v13 | ||
| 79 | s_mov_b32 s21, exec_lo | ||
| 80 | s_mov_b32 exec_lo, s20 | ||
| 81 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 82 | v_lshl_or_b32 v40, v30, 5, v40 | ||
| 83 | v_cmpx_f_f16_e32 v7, v14 | ||
| 84 | s_mov_b32 s21, exec_lo | ||
| 85 | s_mov_b32 exec_lo, s20 | ||
| 86 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 87 | v_lshl_or_b32 v40, v30, 6, v40 | ||
| 88 | v_cmpx_lt_f16_e32 1.0, v8 | ||
| 89 | s_mov_b32 s21, exec_lo | ||
| 90 | s_mov_b32 exec_lo, s20 | ||
| 91 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 92 | v_lshl_or_b32 v40, v30, 7, v40 | ||
| 93 | v_cmpx_lt_f16_e32 2.0, v9 | ||
| 94 | s_mov_b32 s21, exec_lo | ||
| 95 | s_mov_b32 exec_lo, s20 | ||
| 96 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 97 | v_lshl_or_b32 v40, v30, 8, v40 | ||
| 98 | v_cmpx_lt_f16_e32 0, v10 | ||
| 99 | s_mov_b32 s21, exec_lo | ||
| 100 | s_mov_b32 exec_lo, s20 | ||
| 101 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 102 | v_lshl_or_b32 v40, v30, 9, v40 | ||
| 103 | v_cmpx_lt_f16_e32 v4, v11 | ||
| 104 | s_mov_b32 s21, exec_lo | ||
| 105 | s_mov_b32 exec_lo, s20 | ||
| 106 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 107 | v_lshl_or_b32 v40, v30, 10, v40 | ||
| 108 | v_cmpx_lt_f16_e32 v5, v12 | ||
| 109 | s_mov_b32 s21, exec_lo | ||
| 110 | s_mov_b32 exec_lo, s20 | ||
| 111 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 112 | v_lshl_or_b32 v40, v30, 11, v40 | ||
| 113 | v_cmpx_lt_f16_e32 v6, v13 | ||
| 114 | s_mov_b32 s21, exec_lo | ||
| 115 | s_mov_b32 exec_lo, s20 | ||
| 116 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 117 | v_lshl_or_b32 v40, v30, 12, v40 | ||
| 118 | v_cmpx_lt_f16_e32 v7, v14 | ||
| 119 | s_mov_b32 s21, exec_lo | ||
| 120 | s_mov_b32 exec_lo, s20 | ||
| 121 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 122 | v_lshl_or_b32 v40, v30, 13, v40 | ||
| 123 | v_cmpx_eq_f16_e32 1.0, v8 | ||
| 124 | s_mov_b32 s21, exec_lo | ||
| 125 | s_mov_b32 exec_lo, s20 | ||
| 126 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 127 | v_lshl_or_b32 v40, v30, 14, v40 | ||
| 128 | v_cmpx_eq_f16_e32 2.0, v9 | ||
| 129 | s_mov_b32 s21, exec_lo | ||
| 130 | s_mov_b32 exec_lo, s20 | ||
| 131 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 132 | v_lshl_or_b32 v40, v30, 15, v40 | ||
| 133 | v_cmpx_eq_f16_e32 0, v10 | ||
| 134 | s_mov_b32 s21, exec_lo | ||
| 135 | s_mov_b32 exec_lo, s20 | ||
| 136 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 137 | v_lshl_or_b32 v40, v30, 16, v40 | ||
| 138 | v_cmpx_eq_f16_e32 v4, v11 | ||
| 139 | s_mov_b32 s21, exec_lo | ||
| 140 | s_mov_b32 exec_lo, s20 | ||
| 141 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 142 | v_lshl_or_b32 v40, v30, 17, v40 | ||
| 143 | v_cmpx_eq_f16_e32 v5, v12 | ||
| 144 | s_mov_b32 s21, exec_lo | ||
| 145 | s_mov_b32 exec_lo, s20 | ||
| 146 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 147 | v_lshl_or_b32 v40, v30, 18, v40 | ||
| 148 | v_cmpx_eq_f16_e32 v6, v13 | ||
| 149 | s_mov_b32 s21, exec_lo | ||
| 150 | s_mov_b32 exec_lo, s20 | ||
| 151 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 152 | v_lshl_or_b32 v40, v30, 19, v40 | ||
| 153 | v_cmpx_eq_f16_e32 v7, v14 | ||
| 154 | s_mov_b32 s21, exec_lo | ||
| 155 | s_mov_b32 exec_lo, s20 | ||
| 156 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 157 | v_lshl_or_b32 v40, v30, 20, v40 | ||
| 158 | v_cmpx_le_f16_e32 1.0, v8 | ||
| 159 | s_mov_b32 s21, exec_lo | ||
| 160 | s_mov_b32 exec_lo, s20 | ||
| 161 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 162 | v_lshl_or_b32 v40, v30, 21, v40 | ||
| 163 | v_cmpx_le_f16_e32 2.0, v9 | ||
| 164 | s_mov_b32 s21, exec_lo | ||
| 165 | s_mov_b32 exec_lo, s20 | ||
| 166 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 167 | v_lshl_or_b32 v40, v30, 22, v40 | ||
| 168 | v_cmpx_le_f16_e32 0, v10 | ||
| 169 | s_mov_b32 s21, exec_lo | ||
| 170 | s_mov_b32 exec_lo, s20 | ||
| 171 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 172 | v_lshl_or_b32 v40, v30, 23, v40 | ||
| 173 | v_cmpx_le_f16_e32 v4, v11 | ||
| 174 | s_mov_b32 s21, exec_lo | ||
| 175 | s_mov_b32 exec_lo, s20 | ||
| 176 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 177 | v_lshl_or_b32 v40, v30, 24, v40 | ||
| 178 | v_cmpx_le_f16_e32 v5, v12 | ||
| 179 | s_mov_b32 s21, exec_lo | ||
| 180 | s_mov_b32 exec_lo, s20 | ||
| 181 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 182 | v_lshl_or_b32 v40, v30, 25, v40 | ||
| 183 | v_cmpx_le_f16_e32 v6, v13 | ||
| 184 | s_mov_b32 s21, exec_lo | ||
| 185 | s_mov_b32 exec_lo, s20 | ||
| 186 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 187 | v_lshl_or_b32 v40, v30, 26, v40 | ||
| 188 | v_cmpx_le_f16_e32 v7, v14 | ||
| 189 | s_mov_b32 s21, exec_lo | ||
| 190 | s_mov_b32 exec_lo, s20 | ||
| 191 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 192 | v_lshl_or_b32 v40, v30, 27, v40 | ||
| 193 | v_mov_b32_e32 v41, 0x40000000 | ||
| 194 | v_cmp_tru_f16_e32 vcc_lo, v8, v8 | ||
| 195 | v_cmpx_f_f16_e32 v8, v8 | ||
| 196 | s_mov_b32 s21, exec_lo | ||
| 197 | s_mov_b32 exec_lo, s20 | ||
| 198 | v_cndmask_b32_e64 v30, 0, 1, vcc_lo | ||
| 199 | v_lshl_or_b32 v41, v30, 29, v41 | ||
| 200 | v_cmpx_f_f16_e32 v8, v8 | ||
| 201 | v_cmpx_tru_f16_e32 v8, v8 | ||
| 202 | s_mov_b32 s21, exec_lo | ||
| 203 | s_mov_b32 exec_lo, s20 | ||
| 204 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 205 | v_lshl_or_b32 v41, v30, 28, v41 | ||
| 206 | v_cmpx_gt_f16_e32 1.0, v8 | ||
| 207 | s_mov_b32 s21, exec_lo | ||
| 208 | s_mov_b32 exec_lo, s20 | ||
| 209 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 210 | v_lshl_or_b32 v41, v30, 0, v41 | ||
| 211 | v_cmpx_gt_f16_e32 2.0, v9 | ||
| 212 | s_mov_b32 s21, exec_lo | ||
| 213 | s_mov_b32 exec_lo, s20 | ||
| 214 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 215 | v_lshl_or_b32 v41, v30, 1, v41 | ||
| 216 | v_cmpx_gt_f16_e32 0, v10 | ||
| 217 | s_mov_b32 s21, exec_lo | ||
| 218 | s_mov_b32 exec_lo, s20 | ||
| 219 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 220 | v_lshl_or_b32 v41, v30, 2, v41 | ||
| 221 | v_cmpx_gt_f16_e32 v4, v11 | ||
| 222 | s_mov_b32 s21, exec_lo | ||
| 223 | s_mov_b32 exec_lo, s20 | ||
| 224 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 225 | v_lshl_or_b32 v41, v30, 3, v41 | ||
| 226 | v_cmpx_gt_f16_e32 v5, v12 | ||
| 227 | s_mov_b32 s21, exec_lo | ||
| 228 | s_mov_b32 exec_lo, s20 | ||
| 229 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 230 | v_lshl_or_b32 v41, v30, 4, v41 | ||
| 231 | v_cmpx_gt_f16_e32 v6, v13 | ||
| 232 | s_mov_b32 s21, exec_lo | ||
| 233 | s_mov_b32 exec_lo, s20 | ||
| 234 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 235 | v_lshl_or_b32 v41, v30, 5, v41 | ||
| 236 | v_cmpx_gt_f16_e32 v7, v14 | ||
| 237 | s_mov_b32 s21, exec_lo | ||
| 238 | s_mov_b32 exec_lo, s20 | ||
| 239 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 240 | v_lshl_or_b32 v41, v30, 6, v41 | ||
| 241 | v_cmpx_lg_f16_e32 1.0, v8 | ||
| 242 | s_mov_b32 s21, exec_lo | ||
| 243 | s_mov_b32 exec_lo, s20 | ||
| 244 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 245 | v_lshl_or_b32 v41, v30, 7, v41 | ||
| 246 | v_cmpx_lg_f16_e32 2.0, v9 | ||
| 247 | s_mov_b32 s21, exec_lo | ||
| 248 | s_mov_b32 exec_lo, s20 | ||
| 249 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 250 | v_lshl_or_b32 v41, v30, 8, v41 | ||
| 251 | v_cmpx_lg_f16_e32 0, v10 | ||
| 252 | s_mov_b32 s21, exec_lo | ||
| 253 | s_mov_b32 exec_lo, s20 | ||
| 254 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 255 | v_lshl_or_b32 v41, v30, 9, v41 | ||
| 256 | v_cmpx_lg_f16_e32 v4, v11 | ||
| 257 | s_mov_b32 s21, exec_lo | ||
| 258 | s_mov_b32 exec_lo, s20 | ||
| 259 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 260 | v_lshl_or_b32 v41, v30, 10, v41 | ||
| 261 | v_cmpx_lg_f16_e32 v5, v12 | ||
| 262 | s_mov_b32 s21, exec_lo | ||
| 263 | s_mov_b32 exec_lo, s20 | ||
| 264 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 265 | v_lshl_or_b32 v41, v30, 11, v41 | ||
| 266 | v_cmpx_lg_f16_e32 v6, v13 | ||
| 267 | s_mov_b32 s21, exec_lo | ||
| 268 | s_mov_b32 exec_lo, s20 | ||
| 269 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 270 | v_lshl_or_b32 v41, v30, 12, v41 | ||
| 271 | v_cmpx_lg_f16_e32 v7, v14 | ||
| 272 | s_mov_b32 s21, exec_lo | ||
| 273 | s_mov_b32 exec_lo, s20 | ||
| 274 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 275 | v_lshl_or_b32 v41, v30, 13, v41 | ||
| 276 | v_cmpx_ge_f16_e32 1.0, v8 | ||
| 277 | s_mov_b32 s21, exec_lo | ||
| 278 | s_mov_b32 exec_lo, s20 | ||
| 279 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 280 | v_lshl_or_b32 v41, v30, 14, v41 | ||
| 281 | v_cmpx_ge_f16_e32 2.0, v9 | ||
| 282 | s_mov_b32 s21, exec_lo | ||
| 283 | s_mov_b32 exec_lo, s20 | ||
| 284 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 285 | v_lshl_or_b32 v41, v30, 15, v41 | ||
| 286 | v_cmpx_ge_f16_e32 0, v10 | ||
| 287 | s_mov_b32 s21, exec_lo | ||
| 288 | s_mov_b32 exec_lo, s20 | ||
| 289 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 290 | v_lshl_or_b32 v41, v30, 16, v41 | ||
| 291 | v_cmpx_ge_f16_e32 v4, v11 | ||
| 292 | s_mov_b32 s21, exec_lo | ||
| 293 | s_mov_b32 exec_lo, s20 | ||
| 294 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 295 | v_lshl_or_b32 v41, v30, 17, v41 | ||
| 296 | v_cmpx_ge_f16_e32 v5, v12 | ||
| 297 | s_mov_b32 s21, exec_lo | ||
| 298 | s_mov_b32 exec_lo, s20 | ||
| 299 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 300 | v_lshl_or_b32 v41, v30, 18, v41 | ||
| 301 | v_cmpx_ge_f16_e32 v6, v13 | ||
| 302 | s_mov_b32 s21, exec_lo | ||
| 303 | s_mov_b32 exec_lo, s20 | ||
| 304 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 305 | v_lshl_or_b32 v41, v30, 19, v41 | ||
| 306 | v_cmpx_ge_f16_e32 v7, v14 | ||
| 307 | s_mov_b32 s21, exec_lo | ||
| 308 | s_mov_b32 exec_lo, s20 | ||
| 309 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 310 | v_lshl_or_b32 v41, v30, 20, v41 | ||
| 311 | v_cmpx_o_f16_e32 1.0, v8 | ||
| 312 | s_mov_b32 s21, exec_lo | ||
| 313 | s_mov_b32 exec_lo, s20 | ||
| 314 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 315 | v_lshl_or_b32 v41, v30, 21, v41 | ||
| 316 | v_cmpx_o_f16_e32 2.0, v9 | ||
| 317 | s_mov_b32 s21, exec_lo | ||
| 318 | s_mov_b32 exec_lo, s20 | ||
| 319 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 320 | v_lshl_or_b32 v41, v30, 22, v41 | ||
| 321 | v_cmpx_o_f16_e32 0, v10 | ||
| 322 | s_mov_b32 s21, exec_lo | ||
| 323 | s_mov_b32 exec_lo, s20 | ||
| 324 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 325 | v_lshl_or_b32 v41, v30, 23, v41 | ||
| 326 | v_cmpx_o_f16_e32 v4, v11 | ||
| 327 | s_mov_b32 s21, exec_lo | ||
| 328 | s_mov_b32 exec_lo, s20 | ||
| 329 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 330 | v_lshl_or_b32 v41, v30, 24, v41 | ||
| 331 | v_cmpx_o_f16_e32 v5, v12 | ||
| 332 | s_mov_b32 s21, exec_lo | ||
| 333 | s_mov_b32 exec_lo, s20 | ||
| 334 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 335 | v_lshl_or_b32 v41, v30, 25, v41 | ||
| 336 | v_cmpx_o_f16_e32 v6, v13 | ||
| 337 | s_mov_b32 s21, exec_lo | ||
| 338 | s_mov_b32 exec_lo, s20 | ||
| 339 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 340 | v_lshl_or_b32 v41, v30, 26, v41 | ||
| 341 | v_cmpx_o_f16_e32 v7, v14 | ||
| 342 | s_mov_b32 s21, exec_lo | ||
| 343 | s_mov_b32 exec_lo, s20 | ||
| 344 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 345 | v_lshl_or_b32 v41, v30, 27, v41 | ||
| 346 | v_mov_b32_e32 v42, 0x40000000 | ||
| 347 | v_cmp_tru_f16_e32 vcc_lo, v8, v8 | ||
| 348 | v_cmpx_f_f16_e32 v8, v8 | ||
| 349 | s_mov_b32 s21, exec_lo | ||
| 350 | s_mov_b32 exec_lo, s20 | ||
| 351 | v_cndmask_b32_e64 v30, 0, 1, vcc_lo | ||
| 352 | v_lshl_or_b32 v42, v30, 29, v42 | ||
| 353 | v_cmpx_f_f16_e32 v8, v8 | ||
| 354 | v_cmpx_tru_f16_e32 v8, v8 | ||
| 355 | s_mov_b32 s21, exec_lo | ||
| 356 | s_mov_b32 exec_lo, s20 | ||
| 357 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 358 | v_lshl_or_b32 v42, v30, 28, v42 | ||
| 359 | v_cmpx_u_f16_e32 1.0, v8 | ||
| 360 | s_mov_b32 s21, exec_lo | ||
| 361 | s_mov_b32 exec_lo, s20 | ||
| 362 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 363 | v_lshl_or_b32 v42, v30, 0, v42 | ||
| 364 | v_cmpx_u_f16_e32 2.0, v9 | ||
| 365 | s_mov_b32 s21, exec_lo | ||
| 366 | s_mov_b32 exec_lo, s20 | ||
| 367 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 368 | v_lshl_or_b32 v42, v30, 1, v42 | ||
| 369 | v_cmpx_u_f16_e32 0, v10 | ||
| 370 | s_mov_b32 s21, exec_lo | ||
| 371 | s_mov_b32 exec_lo, s20 | ||
| 372 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 373 | v_lshl_or_b32 v42, v30, 2, v42 | ||
| 374 | v_cmpx_u_f16_e32 v4, v11 | ||
| 375 | s_mov_b32 s21, exec_lo | ||
| 376 | s_mov_b32 exec_lo, s20 | ||
| 377 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 378 | v_lshl_or_b32 v42, v30, 3, v42 | ||
| 379 | v_cmpx_u_f16_e32 v5, v12 | ||
| 380 | s_mov_b32 s21, exec_lo | ||
| 381 | s_mov_b32 exec_lo, s20 | ||
| 382 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 383 | v_lshl_or_b32 v42, v30, 4, v42 | ||
| 384 | v_cmpx_u_f16_e32 v6, v13 | ||
| 385 | s_mov_b32 s21, exec_lo | ||
| 386 | s_mov_b32 exec_lo, s20 | ||
| 387 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 388 | v_lshl_or_b32 v42, v30, 5, v42 | ||
| 389 | v_cmpx_u_f16_e32 v7, v14 | ||
| 390 | s_mov_b32 s21, exec_lo | ||
| 391 | s_mov_b32 exec_lo, s20 | ||
| 392 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 393 | v_lshl_or_b32 v42, v30, 6, v42 | ||
| 394 | v_cmpx_nge_f16_e32 1.0, v8 | ||
| 395 | s_mov_b32 s21, exec_lo | ||
| 396 | s_mov_b32 exec_lo, s20 | ||
| 397 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 398 | v_lshl_or_b32 v42, v30, 7, v42 | ||
| 399 | v_cmpx_nge_f16_e32 2.0, v9 | ||
| 400 | s_mov_b32 s21, exec_lo | ||
| 401 | s_mov_b32 exec_lo, s20 | ||
| 402 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 403 | v_lshl_or_b32 v42, v30, 8, v42 | ||
| 404 | v_cmpx_nge_f16_e32 0, v10 | ||
| 405 | s_mov_b32 s21, exec_lo | ||
| 406 | s_mov_b32 exec_lo, s20 | ||
| 407 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 408 | v_lshl_or_b32 v42, v30, 9, v42 | ||
| 409 | v_cmpx_nge_f16_e32 v4, v11 | ||
| 410 | s_mov_b32 s21, exec_lo | ||
| 411 | s_mov_b32 exec_lo, s20 | ||
| 412 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 413 | v_lshl_or_b32 v42, v30, 10, v42 | ||
| 414 | v_cmpx_nge_f16_e32 v5, v12 | ||
| 415 | s_mov_b32 s21, exec_lo | ||
| 416 | s_mov_b32 exec_lo, s20 | ||
| 417 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 418 | v_lshl_or_b32 v42, v30, 11, v42 | ||
| 419 | v_cmpx_nge_f16_e32 v6, v13 | ||
| 420 | s_mov_b32 s21, exec_lo | ||
| 421 | s_mov_b32 exec_lo, s20 | ||
| 422 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 423 | v_lshl_or_b32 v42, v30, 12, v42 | ||
| 424 | v_cmpx_nge_f16_e32 v7, v14 | ||
| 425 | s_mov_b32 s21, exec_lo | ||
| 426 | s_mov_b32 exec_lo, s20 | ||
| 427 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 428 | v_lshl_or_b32 v42, v30, 13, v42 | ||
| 429 | v_cmpx_nlg_f16_e32 1.0, v8 | ||
| 430 | s_mov_b32 s21, exec_lo | ||
| 431 | s_mov_b32 exec_lo, s20 | ||
| 432 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 433 | v_lshl_or_b32 v42, v30, 14, v42 | ||
| 434 | v_cmpx_nlg_f16_e32 2.0, v9 | ||
| 435 | s_mov_b32 s21, exec_lo | ||
| 436 | s_mov_b32 exec_lo, s20 | ||
| 437 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 438 | v_lshl_or_b32 v42, v30, 15, v42 | ||
| 439 | v_cmpx_nlg_f16_e32 0, v10 | ||
| 440 | s_mov_b32 s21, exec_lo | ||
| 441 | s_mov_b32 exec_lo, s20 | ||
| 442 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 443 | v_lshl_or_b32 v42, v30, 16, v42 | ||
| 444 | v_cmpx_nlg_f16_e32 v4, v11 | ||
| 445 | s_mov_b32 s21, exec_lo | ||
| 446 | s_mov_b32 exec_lo, s20 | ||
| 447 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 448 | v_lshl_or_b32 v42, v30, 17, v42 | ||
| 449 | v_cmpx_nlg_f16_e32 v5, v12 | ||
| 450 | s_mov_b32 s21, exec_lo | ||
| 451 | s_mov_b32 exec_lo, s20 | ||
| 452 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 453 | v_lshl_or_b32 v42, v30, 18, v42 | ||
| 454 | v_cmpx_nlg_f16_e32 v6, v13 | ||
| 455 | s_mov_b32 s21, exec_lo | ||
| 456 | s_mov_b32 exec_lo, s20 | ||
| 457 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 458 | v_lshl_or_b32 v42, v30, 19, v42 | ||
| 459 | v_cmpx_nlg_f16_e32 v7, v14 | ||
| 460 | s_mov_b32 s21, exec_lo | ||
| 461 | s_mov_b32 exec_lo, s20 | ||
| 462 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 463 | v_lshl_or_b32 v42, v30, 20, v42 | ||
| 464 | v_cmpx_ngt_f16_e32 1.0, v8 | ||
| 465 | s_mov_b32 s21, exec_lo | ||
| 466 | s_mov_b32 exec_lo, s20 | ||
| 467 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 468 | v_lshl_or_b32 v42, v30, 21, v42 | ||
| 469 | v_cmpx_ngt_f16_e32 2.0, v9 | ||
| 470 | s_mov_b32 s21, exec_lo | ||
| 471 | s_mov_b32 exec_lo, s20 | ||
| 472 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 473 | v_lshl_or_b32 v42, v30, 22, v42 | ||
| 474 | v_cmpx_ngt_f16_e32 0, v10 | ||
| 475 | s_mov_b32 s21, exec_lo | ||
| 476 | s_mov_b32 exec_lo, s20 | ||
| 477 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 478 | v_lshl_or_b32 v42, v30, 23, v42 | ||
| 479 | v_cmpx_ngt_f16_e32 v4, v11 | ||
| 480 | s_mov_b32 s21, exec_lo | ||
| 481 | s_mov_b32 exec_lo, s20 | ||
| 482 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 483 | v_lshl_or_b32 v42, v30, 24, v42 | ||
| 484 | v_cmpx_ngt_f16_e32 v5, v12 | ||
| 485 | s_mov_b32 s21, exec_lo | ||
| 486 | s_mov_b32 exec_lo, s20 | ||
| 487 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 488 | v_lshl_or_b32 v42, v30, 25, v42 | ||
| 489 | v_cmpx_ngt_f16_e32 v6, v13 | ||
| 490 | s_mov_b32 s21, exec_lo | ||
| 491 | s_mov_b32 exec_lo, s20 | ||
| 492 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 493 | v_lshl_or_b32 v42, v30, 26, v42 | ||
| 494 | v_cmpx_ngt_f16_e32 v7, v14 | ||
| 495 | s_mov_b32 s21, exec_lo | ||
| 496 | s_mov_b32 exec_lo, s20 | ||
| 497 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 498 | v_lshl_or_b32 v42, v30, 27, v42 | ||
| 499 | v_mov_b32_e32 v43, 0x40000000 | ||
| 500 | v_cmp_tru_f16_e32 vcc_lo, v8, v8 | ||
| 501 | v_cmpx_f_f16_e32 v8, v8 | ||
| 502 | s_mov_b32 s21, exec_lo | ||
| 503 | s_mov_b32 exec_lo, s20 | ||
| 504 | v_cndmask_b32_e64 v30, 0, 1, vcc_lo | ||
| 505 | v_lshl_or_b32 v43, v30, 29, v43 | ||
| 506 | v_cmpx_f_f16_e32 v8, v8 | ||
| 507 | v_cmpx_tru_f16_e32 v8, v8 | ||
| 508 | s_mov_b32 s21, exec_lo | ||
| 509 | s_mov_b32 exec_lo, s20 | ||
| 510 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 511 | v_lshl_or_b32 v43, v30, 28, v43 | ||
| 512 | v_cmpx_nle_f16_e32 1.0, v8 | ||
| 513 | s_mov_b32 s21, exec_lo | ||
| 514 | s_mov_b32 exec_lo, s20 | ||
| 515 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 516 | v_lshl_or_b32 v43, v30, 0, v43 | ||
| 517 | v_cmpx_nle_f16_e32 2.0, v9 | ||
| 518 | s_mov_b32 s21, exec_lo | ||
| 519 | s_mov_b32 exec_lo, s20 | ||
| 520 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 521 | v_lshl_or_b32 v43, v30, 1, v43 | ||
| 522 | v_cmpx_nle_f16_e32 0, v10 | ||
| 523 | s_mov_b32 s21, exec_lo | ||
| 524 | s_mov_b32 exec_lo, s20 | ||
| 525 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 526 | v_lshl_or_b32 v43, v30, 2, v43 | ||
| 527 | v_cmpx_nle_f16_e32 v4, v11 | ||
| 528 | s_mov_b32 s21, exec_lo | ||
| 529 | s_mov_b32 exec_lo, s20 | ||
| 530 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 531 | v_lshl_or_b32 v43, v30, 3, v43 | ||
| 532 | v_cmpx_nle_f16_e32 v5, v12 | ||
| 533 | s_mov_b32 s21, exec_lo | ||
| 534 | s_mov_b32 exec_lo, s20 | ||
| 535 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 536 | v_lshl_or_b32 v43, v30, 4, v43 | ||
| 537 | v_cmpx_nle_f16_e32 v6, v13 | ||
| 538 | s_mov_b32 s21, exec_lo | ||
| 539 | s_mov_b32 exec_lo, s20 | ||
| 540 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 541 | v_lshl_or_b32 v43, v30, 5, v43 | ||
| 542 | v_cmpx_nle_f16_e32 v7, v14 | ||
| 543 | s_mov_b32 s21, exec_lo | ||
| 544 | s_mov_b32 exec_lo, s20 | ||
| 545 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 546 | v_lshl_or_b32 v43, v30, 6, v43 | ||
| 547 | v_cmpx_neq_f16_e32 1.0, v8 | ||
| 548 | s_mov_b32 s21, exec_lo | ||
| 549 | s_mov_b32 exec_lo, s20 | ||
| 550 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 551 | v_lshl_or_b32 v43, v30, 7, v43 | ||
| 552 | v_cmpx_neq_f16_e32 2.0, v9 | ||
| 553 | s_mov_b32 s21, exec_lo | ||
| 554 | s_mov_b32 exec_lo, s20 | ||
| 555 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 556 | v_lshl_or_b32 v43, v30, 8, v43 | ||
| 557 | v_cmpx_neq_f16_e32 0, v10 | ||
| 558 | s_mov_b32 s21, exec_lo | ||
| 559 | s_mov_b32 exec_lo, s20 | ||
| 560 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 561 | v_lshl_or_b32 v43, v30, 9, v43 | ||
| 562 | v_cmpx_neq_f16_e32 v4, v11 | ||
| 563 | s_mov_b32 s21, exec_lo | ||
| 564 | s_mov_b32 exec_lo, s20 | ||
| 565 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 566 | v_lshl_or_b32 v43, v30, 10, v43 | ||
| 567 | v_cmpx_neq_f16_e32 v5, v12 | ||
| 568 | s_mov_b32 s21, exec_lo | ||
| 569 | s_mov_b32 exec_lo, s20 | ||
| 570 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 571 | v_lshl_or_b32 v43, v30, 11, v43 | ||
| 572 | v_cmpx_neq_f16_e32 v6, v13 | ||
| 573 | s_mov_b32 s21, exec_lo | ||
| 574 | s_mov_b32 exec_lo, s20 | ||
| 575 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 576 | v_lshl_or_b32 v43, v30, 12, v43 | ||
| 577 | v_cmpx_neq_f16_e32 v7, v14 | ||
| 578 | s_mov_b32 s21, exec_lo | ||
| 579 | s_mov_b32 exec_lo, s20 | ||
| 580 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 581 | v_lshl_or_b32 v43, v30, 13, v43 | ||
| 582 | v_cmpx_nlt_f16_e32 1.0, v8 | ||
| 583 | s_mov_b32 s21, exec_lo | ||
| 584 | s_mov_b32 exec_lo, s20 | ||
| 585 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 586 | v_lshl_or_b32 v43, v30, 14, v43 | ||
| 587 | v_cmpx_nlt_f16_e32 2.0, v9 | ||
| 588 | s_mov_b32 s21, exec_lo | ||
| 589 | s_mov_b32 exec_lo, s20 | ||
| 590 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 591 | v_lshl_or_b32 v43, v30, 15, v43 | ||
| 592 | v_cmpx_nlt_f16_e32 0, v10 | ||
| 593 | s_mov_b32 s21, exec_lo | ||
| 594 | s_mov_b32 exec_lo, s20 | ||
| 595 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 596 | v_lshl_or_b32 v43, v30, 16, v43 | ||
| 597 | v_cmpx_nlt_f16_e32 v4, v11 | ||
| 598 | s_mov_b32 s21, exec_lo | ||
| 599 | s_mov_b32 exec_lo, s20 | ||
| 600 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 601 | v_lshl_or_b32 v43, v30, 17, v43 | ||
| 602 | v_cmpx_nlt_f16_e32 v5, v12 | ||
| 603 | s_mov_b32 s21, exec_lo | ||
| 604 | s_mov_b32 exec_lo, s20 | ||
| 605 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 606 | v_lshl_or_b32 v43, v30, 18, v43 | ||
| 607 | v_cmpx_nlt_f16_e32 v6, v13 | ||
| 608 | s_mov_b32 s21, exec_lo | ||
| 609 | s_mov_b32 exec_lo, s20 | ||
| 610 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 611 | v_lshl_or_b32 v43, v30, 19, v43 | ||
| 612 | v_cmpx_nlt_f16_e32 v7, v14 | ||
| 613 | s_mov_b32 s21, exec_lo | ||
| 614 | s_mov_b32 exec_lo, s20 | ||
| 615 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 616 | v_lshl_or_b32 v43, v30, 20, v43 | ||
| 617 | v_cmpx_tru_f16_e32 1.0, v8 | ||
| 618 | s_mov_b32 s21, exec_lo | ||
| 619 | s_mov_b32 exec_lo, s20 | ||
| 620 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 621 | v_lshl_or_b32 v43, v30, 21, v43 | ||
| 622 | v_cmpx_tru_f16_e32 2.0, v9 | ||
| 623 | s_mov_b32 s21, exec_lo | ||
| 624 | s_mov_b32 exec_lo, s20 | ||
| 625 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 626 | v_lshl_or_b32 v43, v30, 22, v43 | ||
| 627 | v_cmpx_tru_f16_e32 0, v10 | ||
| 628 | s_mov_b32 s21, exec_lo | ||
| 629 | s_mov_b32 exec_lo, s20 | ||
| 630 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 631 | v_lshl_or_b32 v43, v30, 23, v43 | ||
| 632 | v_cmpx_tru_f16_e32 v4, v11 | ||
| 633 | s_mov_b32 s21, exec_lo | ||
| 634 | s_mov_b32 exec_lo, s20 | ||
| 635 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 636 | v_lshl_or_b32 v43, v30, 24, v43 | ||
| 637 | v_cmpx_tru_f16_e32 v5, v12 | ||
| 638 | s_mov_b32 s21, exec_lo | ||
| 639 | s_mov_b32 exec_lo, s20 | ||
| 640 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 641 | v_lshl_or_b32 v43, v30, 25, v43 | ||
| 642 | v_cmpx_tru_f16_e32 v6, v13 | ||
| 643 | s_mov_b32 s21, exec_lo | ||
| 644 | s_mov_b32 exec_lo, s20 | ||
| 645 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 646 | v_lshl_or_b32 v43, v30, 26, v43 | ||
| 647 | v_cmpx_tru_f16_e32 v7, v14 | ||
| 648 | s_mov_b32 s21, exec_lo | ||
| 649 | s_mov_b32 exec_lo, s20 | ||
| 650 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 651 | v_lshl_or_b32 v43, v30, 27, v43 | ||
| 652 | exp mrt0 v40, v41, v42, v43 done vm | ||
| 653 | s_endpgm | ||
diff --git a/runtime/test/shaders/ps_vcmpx_f16_e64.asm b/runtime/test/shaders/ps_vcmpx_f16_e64.asm new file mode 100644 index 000000000..62250f738 --- /dev/null +++ b/runtime/test/shaders/ps_vcmpx_f16_e64.asm | |||
| @@ -0,0 +1,639 @@ | |||
| 1 | ; 16-bit float v_cmpx, e64 form with swapped operands: v_cmpx_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f16_e64 | ||
| 2 | ; B, A (no SDST: the VOP3 form of v_cmpx writes EXEC). Same seven operand pairs, EXEC copy-out/restore and VCC/AND bits | ||
| 3 | ; as ps_vcmpx_f16 (see its header), but src0 is the VGPR B and src1 is A (the inline constant for k0..k2), so each op | ||
| 4 | ; sees the mirrored relation: LESS = {k1,k5} = 0x22, GREATER = {k0,k6} = 0x41, EQUAL = {k2} = 0x04, | ||
| 5 | ; UNORDERED = {k3,k4} = 0x18. Masks (bit k = result on case k): | ||
| 6 | ; f 0x00 lt 0x22 eq 0x04 le 0x26 gt 0x41 lg 0x63 ge 0x45 o 0x67 | ||
| 7 | ; u 0x18 nge 0x3a nlg 0x1c ngt 0x3e nle 0x59 neq 0x7b nlt 0x5d tru 0x7f | ||
| 8 | ; Word w holds ops 4w..4w+3, op j at bit 7*j + k; bit 30 = 1, bit 29 = 1 (VCC kept), bit 28 = 0 (AND into EXEC): | ||
| 9 | ; word 0 = 0x60000000 | 0x00 | 0x22<<7 | 0x04<<14 | 0x26<<21 = 0x60000000 + 0x1100 + 0x10000 + 0x4c00000 = 0x64c11100 | ||
| 10 | ; word 1 = 0x60000000 | 0x41 | 0x63<<7 | 0x45<<14 | 0x67<<21 = 0x60000000 + 0x31c1 + 0x114000 + 0xce00000 = 0x6cf171c1 | ||
| 11 | ; word 2 = 0x60000000 | 0x18 | 0x3a<<7 | 0x1c<<14 | 0x3e<<21 = 0x60000000 + 0x1d18 + 0x70000 + 0x7c00000 = 0x67c71d18 | ||
| 12 | ; word 3 = 0x60000000 | 0x59 | 0x7b<<7 | 0x5d<<14 | 0x7f<<21 = 0x60000000 + 0x3dd9 + 0x174000 + 0xfe00000 = 0x6ff77dd9 | ||
| 13 | ; Expected mrt0 bits: 0x64c11100, 0x6cf171c1, 0x67c71d18, 0x6ff77dd9 | ||
| 14 | v_mov_b32_e32 v8, 0x12344000 | ||
| 15 | v_mov_b32_e32 v9, 0xabcd3c00 | ||
| 16 | v_mov_b32_e32 v10, 0xffff8000 | ||
| 17 | v_mov_b32_e32 v4, 0xffff7e00 | ||
| 18 | v_mov_b32_e32 v11, 0x00013c00 | ||
| 19 | v_mov_b32_e32 v5, 0x55553c00 | ||
| 20 | v_mov_b32_e32 v12, 0x7c007c01 | ||
| 21 | v_mov_b32_e32 v6, 0x00017c00 | ||
| 22 | v_mov_b32_e32 v13, 0xbeeffc00 | ||
| 23 | v_mov_b32_e32 v7, 0xdead0001 | ||
| 24 | v_mov_b32_e32 v14, 0x80000002 | ||
| 25 | s_mov_b32 s20, exec_lo | ||
| 26 | v_mov_b32_e32 v40, 0x40000000 | ||
| 27 | v_cmp_tru_f16_e32 vcc_lo, v8, v8 | ||
| 28 | v_cmpx_f_f16_e64 v8, v8 | ||
| 29 | s_mov_b32 s21, exec_lo | ||
| 30 | s_mov_b32 exec_lo, s20 | ||
| 31 | v_cndmask_b32_e64 v30, 0, 1, vcc_lo | ||
| 32 | v_lshl_or_b32 v40, v30, 29, v40 | ||
| 33 | v_cmpx_f_f16_e64 v8, v8 | ||
| 34 | v_cmpx_tru_f16_e64 v8, v8 | ||
| 35 | s_mov_b32 s21, exec_lo | ||
| 36 | s_mov_b32 exec_lo, s20 | ||
| 37 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 38 | v_lshl_or_b32 v40, v30, 28, v40 | ||
| 39 | v_cmpx_f_f16_e64 v8, 1.0 | ||
| 40 | s_mov_b32 s21, exec_lo | ||
| 41 | s_mov_b32 exec_lo, s20 | ||
| 42 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 43 | v_lshl_or_b32 v40, v30, 0, v40 | ||
| 44 | v_cmpx_f_f16_e64 v9, 2.0 | ||
| 45 | s_mov_b32 s21, exec_lo | ||
| 46 | s_mov_b32 exec_lo, s20 | ||
| 47 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 48 | v_lshl_or_b32 v40, v30, 1, v40 | ||
| 49 | v_cmpx_f_f16_e64 v10, 0 | ||
| 50 | s_mov_b32 s21, exec_lo | ||
| 51 | s_mov_b32 exec_lo, s20 | ||
| 52 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 53 | v_lshl_or_b32 v40, v30, 2, v40 | ||
| 54 | v_cmpx_f_f16_e64 v11, v4 | ||
| 55 | s_mov_b32 s21, exec_lo | ||
| 56 | s_mov_b32 exec_lo, s20 | ||
| 57 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 58 | v_lshl_or_b32 v40, v30, 3, v40 | ||
| 59 | v_cmpx_f_f16_e64 v12, v5 | ||
| 60 | s_mov_b32 s21, exec_lo | ||
| 61 | s_mov_b32 exec_lo, s20 | ||
| 62 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 63 | v_lshl_or_b32 v40, v30, 4, v40 | ||
| 64 | v_cmpx_f_f16_e64 v13, v6 | ||
| 65 | s_mov_b32 s21, exec_lo | ||
| 66 | s_mov_b32 exec_lo, s20 | ||
| 67 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 68 | v_lshl_or_b32 v40, v30, 5, v40 | ||
| 69 | v_cmpx_f_f16_e64 v14, v7 | ||
| 70 | s_mov_b32 s21, exec_lo | ||
| 71 | s_mov_b32 exec_lo, s20 | ||
| 72 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 73 | v_lshl_or_b32 v40, v30, 6, v40 | ||
| 74 | v_cmpx_lt_f16_e64 v8, 1.0 | ||
| 75 | s_mov_b32 s21, exec_lo | ||
| 76 | s_mov_b32 exec_lo, s20 | ||
| 77 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 78 | v_lshl_or_b32 v40, v30, 7, v40 | ||
| 79 | v_cmpx_lt_f16_e64 v9, 2.0 | ||
| 80 | s_mov_b32 s21, exec_lo | ||
| 81 | s_mov_b32 exec_lo, s20 | ||
| 82 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 83 | v_lshl_or_b32 v40, v30, 8, v40 | ||
| 84 | v_cmpx_lt_f16_e64 v10, 0 | ||
| 85 | s_mov_b32 s21, exec_lo | ||
| 86 | s_mov_b32 exec_lo, s20 | ||
| 87 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 88 | v_lshl_or_b32 v40, v30, 9, v40 | ||
| 89 | v_cmpx_lt_f16_e64 v11, v4 | ||
| 90 | s_mov_b32 s21, exec_lo | ||
| 91 | s_mov_b32 exec_lo, s20 | ||
| 92 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 93 | v_lshl_or_b32 v40, v30, 10, v40 | ||
| 94 | v_cmpx_lt_f16_e64 v12, v5 | ||
| 95 | s_mov_b32 s21, exec_lo | ||
| 96 | s_mov_b32 exec_lo, s20 | ||
| 97 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 98 | v_lshl_or_b32 v40, v30, 11, v40 | ||
| 99 | v_cmpx_lt_f16_e64 v13, v6 | ||
| 100 | s_mov_b32 s21, exec_lo | ||
| 101 | s_mov_b32 exec_lo, s20 | ||
| 102 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 103 | v_lshl_or_b32 v40, v30, 12, v40 | ||
| 104 | v_cmpx_lt_f16_e64 v14, v7 | ||
| 105 | s_mov_b32 s21, exec_lo | ||
| 106 | s_mov_b32 exec_lo, s20 | ||
| 107 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 108 | v_lshl_or_b32 v40, v30, 13, v40 | ||
| 109 | v_cmpx_eq_f16_e64 v8, 1.0 | ||
| 110 | s_mov_b32 s21, exec_lo | ||
| 111 | s_mov_b32 exec_lo, s20 | ||
| 112 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 113 | v_lshl_or_b32 v40, v30, 14, v40 | ||
| 114 | v_cmpx_eq_f16_e64 v9, 2.0 | ||
| 115 | s_mov_b32 s21, exec_lo | ||
| 116 | s_mov_b32 exec_lo, s20 | ||
| 117 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 118 | v_lshl_or_b32 v40, v30, 15, v40 | ||
| 119 | v_cmpx_eq_f16_e64 v10, 0 | ||
| 120 | s_mov_b32 s21, exec_lo | ||
| 121 | s_mov_b32 exec_lo, s20 | ||
| 122 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 123 | v_lshl_or_b32 v40, v30, 16, v40 | ||
| 124 | v_cmpx_eq_f16_e64 v11, v4 | ||
| 125 | s_mov_b32 s21, exec_lo | ||
| 126 | s_mov_b32 exec_lo, s20 | ||
| 127 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 128 | v_lshl_or_b32 v40, v30, 17, v40 | ||
| 129 | v_cmpx_eq_f16_e64 v12, v5 | ||
| 130 | s_mov_b32 s21, exec_lo | ||
| 131 | s_mov_b32 exec_lo, s20 | ||
| 132 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 133 | v_lshl_or_b32 v40, v30, 18, v40 | ||
| 134 | v_cmpx_eq_f16_e64 v13, v6 | ||
| 135 | s_mov_b32 s21, exec_lo | ||
| 136 | s_mov_b32 exec_lo, s20 | ||
| 137 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 138 | v_lshl_or_b32 v40, v30, 19, v40 | ||
| 139 | v_cmpx_eq_f16_e64 v14, v7 | ||
| 140 | s_mov_b32 s21, exec_lo | ||
| 141 | s_mov_b32 exec_lo, s20 | ||
| 142 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 143 | v_lshl_or_b32 v40, v30, 20, v40 | ||
| 144 | v_cmpx_le_f16_e64 v8, 1.0 | ||
| 145 | s_mov_b32 s21, exec_lo | ||
| 146 | s_mov_b32 exec_lo, s20 | ||
| 147 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 148 | v_lshl_or_b32 v40, v30, 21, v40 | ||
| 149 | v_cmpx_le_f16_e64 v9, 2.0 | ||
| 150 | s_mov_b32 s21, exec_lo | ||
| 151 | s_mov_b32 exec_lo, s20 | ||
| 152 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 153 | v_lshl_or_b32 v40, v30, 22, v40 | ||
| 154 | v_cmpx_le_f16_e64 v10, 0 | ||
| 155 | s_mov_b32 s21, exec_lo | ||
| 156 | s_mov_b32 exec_lo, s20 | ||
| 157 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 158 | v_lshl_or_b32 v40, v30, 23, v40 | ||
| 159 | v_cmpx_le_f16_e64 v11, v4 | ||
| 160 | s_mov_b32 s21, exec_lo | ||
| 161 | s_mov_b32 exec_lo, s20 | ||
| 162 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 163 | v_lshl_or_b32 v40, v30, 24, v40 | ||
| 164 | v_cmpx_le_f16_e64 v12, v5 | ||
| 165 | s_mov_b32 s21, exec_lo | ||
| 166 | s_mov_b32 exec_lo, s20 | ||
| 167 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 168 | v_lshl_or_b32 v40, v30, 25, v40 | ||
| 169 | v_cmpx_le_f16_e64 v13, v6 | ||
| 170 | s_mov_b32 s21, exec_lo | ||
| 171 | s_mov_b32 exec_lo, s20 | ||
| 172 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 173 | v_lshl_or_b32 v40, v30, 26, v40 | ||
| 174 | v_cmpx_le_f16_e64 v14, v7 | ||
| 175 | s_mov_b32 s21, exec_lo | ||
| 176 | s_mov_b32 exec_lo, s20 | ||
| 177 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 178 | v_lshl_or_b32 v40, v30, 27, v40 | ||
| 179 | v_mov_b32_e32 v41, 0x40000000 | ||
| 180 | v_cmp_tru_f16_e32 vcc_lo, v8, v8 | ||
| 181 | v_cmpx_f_f16_e64 v8, v8 | ||
| 182 | s_mov_b32 s21, exec_lo | ||
| 183 | s_mov_b32 exec_lo, s20 | ||
| 184 | v_cndmask_b32_e64 v30, 0, 1, vcc_lo | ||
| 185 | v_lshl_or_b32 v41, v30, 29, v41 | ||
| 186 | v_cmpx_f_f16_e64 v8, v8 | ||
| 187 | v_cmpx_tru_f16_e64 v8, v8 | ||
| 188 | s_mov_b32 s21, exec_lo | ||
| 189 | s_mov_b32 exec_lo, s20 | ||
| 190 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 191 | v_lshl_or_b32 v41, v30, 28, v41 | ||
| 192 | v_cmpx_gt_f16_e64 v8, 1.0 | ||
| 193 | s_mov_b32 s21, exec_lo | ||
| 194 | s_mov_b32 exec_lo, s20 | ||
| 195 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 196 | v_lshl_or_b32 v41, v30, 0, v41 | ||
| 197 | v_cmpx_gt_f16_e64 v9, 2.0 | ||
| 198 | s_mov_b32 s21, exec_lo | ||
| 199 | s_mov_b32 exec_lo, s20 | ||
| 200 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 201 | v_lshl_or_b32 v41, v30, 1, v41 | ||
| 202 | v_cmpx_gt_f16_e64 v10, 0 | ||
| 203 | s_mov_b32 s21, exec_lo | ||
| 204 | s_mov_b32 exec_lo, s20 | ||
| 205 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 206 | v_lshl_or_b32 v41, v30, 2, v41 | ||
| 207 | v_cmpx_gt_f16_e64 v11, v4 | ||
| 208 | s_mov_b32 s21, exec_lo | ||
| 209 | s_mov_b32 exec_lo, s20 | ||
| 210 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 211 | v_lshl_or_b32 v41, v30, 3, v41 | ||
| 212 | v_cmpx_gt_f16_e64 v12, v5 | ||
| 213 | s_mov_b32 s21, exec_lo | ||
| 214 | s_mov_b32 exec_lo, s20 | ||
| 215 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 216 | v_lshl_or_b32 v41, v30, 4, v41 | ||
| 217 | v_cmpx_gt_f16_e64 v13, v6 | ||
| 218 | s_mov_b32 s21, exec_lo | ||
| 219 | s_mov_b32 exec_lo, s20 | ||
| 220 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 221 | v_lshl_or_b32 v41, v30, 5, v41 | ||
| 222 | v_cmpx_gt_f16_e64 v14, v7 | ||
| 223 | s_mov_b32 s21, exec_lo | ||
| 224 | s_mov_b32 exec_lo, s20 | ||
| 225 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 226 | v_lshl_or_b32 v41, v30, 6, v41 | ||
| 227 | v_cmpx_lg_f16_e64 v8, 1.0 | ||
| 228 | s_mov_b32 s21, exec_lo | ||
| 229 | s_mov_b32 exec_lo, s20 | ||
| 230 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 231 | v_lshl_or_b32 v41, v30, 7, v41 | ||
| 232 | v_cmpx_lg_f16_e64 v9, 2.0 | ||
| 233 | s_mov_b32 s21, exec_lo | ||
| 234 | s_mov_b32 exec_lo, s20 | ||
| 235 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 236 | v_lshl_or_b32 v41, v30, 8, v41 | ||
| 237 | v_cmpx_lg_f16_e64 v10, 0 | ||
| 238 | s_mov_b32 s21, exec_lo | ||
| 239 | s_mov_b32 exec_lo, s20 | ||
| 240 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 241 | v_lshl_or_b32 v41, v30, 9, v41 | ||
| 242 | v_cmpx_lg_f16_e64 v11, v4 | ||
| 243 | s_mov_b32 s21, exec_lo | ||
| 244 | s_mov_b32 exec_lo, s20 | ||
| 245 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 246 | v_lshl_or_b32 v41, v30, 10, v41 | ||
| 247 | v_cmpx_lg_f16_e64 v12, v5 | ||
| 248 | s_mov_b32 s21, exec_lo | ||
| 249 | s_mov_b32 exec_lo, s20 | ||
| 250 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 251 | v_lshl_or_b32 v41, v30, 11, v41 | ||
| 252 | v_cmpx_lg_f16_e64 v13, v6 | ||
| 253 | s_mov_b32 s21, exec_lo | ||
| 254 | s_mov_b32 exec_lo, s20 | ||
| 255 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 256 | v_lshl_or_b32 v41, v30, 12, v41 | ||
| 257 | v_cmpx_lg_f16_e64 v14, v7 | ||
| 258 | s_mov_b32 s21, exec_lo | ||
| 259 | s_mov_b32 exec_lo, s20 | ||
| 260 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 261 | v_lshl_or_b32 v41, v30, 13, v41 | ||
| 262 | v_cmpx_ge_f16_e64 v8, 1.0 | ||
| 263 | s_mov_b32 s21, exec_lo | ||
| 264 | s_mov_b32 exec_lo, s20 | ||
| 265 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 266 | v_lshl_or_b32 v41, v30, 14, v41 | ||
| 267 | v_cmpx_ge_f16_e64 v9, 2.0 | ||
| 268 | s_mov_b32 s21, exec_lo | ||
| 269 | s_mov_b32 exec_lo, s20 | ||
| 270 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 271 | v_lshl_or_b32 v41, v30, 15, v41 | ||
| 272 | v_cmpx_ge_f16_e64 v10, 0 | ||
| 273 | s_mov_b32 s21, exec_lo | ||
| 274 | s_mov_b32 exec_lo, s20 | ||
| 275 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 276 | v_lshl_or_b32 v41, v30, 16, v41 | ||
| 277 | v_cmpx_ge_f16_e64 v11, v4 | ||
| 278 | s_mov_b32 s21, exec_lo | ||
| 279 | s_mov_b32 exec_lo, s20 | ||
| 280 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 281 | v_lshl_or_b32 v41, v30, 17, v41 | ||
| 282 | v_cmpx_ge_f16_e64 v12, v5 | ||
| 283 | s_mov_b32 s21, exec_lo | ||
| 284 | s_mov_b32 exec_lo, s20 | ||
| 285 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 286 | v_lshl_or_b32 v41, v30, 18, v41 | ||
| 287 | v_cmpx_ge_f16_e64 v13, v6 | ||
| 288 | s_mov_b32 s21, exec_lo | ||
| 289 | s_mov_b32 exec_lo, s20 | ||
| 290 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 291 | v_lshl_or_b32 v41, v30, 19, v41 | ||
| 292 | v_cmpx_ge_f16_e64 v14, v7 | ||
| 293 | s_mov_b32 s21, exec_lo | ||
| 294 | s_mov_b32 exec_lo, s20 | ||
| 295 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 296 | v_lshl_or_b32 v41, v30, 20, v41 | ||
| 297 | v_cmpx_o_f16_e64 v8, 1.0 | ||
| 298 | s_mov_b32 s21, exec_lo | ||
| 299 | s_mov_b32 exec_lo, s20 | ||
| 300 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 301 | v_lshl_or_b32 v41, v30, 21, v41 | ||
| 302 | v_cmpx_o_f16_e64 v9, 2.0 | ||
| 303 | s_mov_b32 s21, exec_lo | ||
| 304 | s_mov_b32 exec_lo, s20 | ||
| 305 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 306 | v_lshl_or_b32 v41, v30, 22, v41 | ||
| 307 | v_cmpx_o_f16_e64 v10, 0 | ||
| 308 | s_mov_b32 s21, exec_lo | ||
| 309 | s_mov_b32 exec_lo, s20 | ||
| 310 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 311 | v_lshl_or_b32 v41, v30, 23, v41 | ||
| 312 | v_cmpx_o_f16_e64 v11, v4 | ||
| 313 | s_mov_b32 s21, exec_lo | ||
| 314 | s_mov_b32 exec_lo, s20 | ||
| 315 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 316 | v_lshl_or_b32 v41, v30, 24, v41 | ||
| 317 | v_cmpx_o_f16_e64 v12, v5 | ||
| 318 | s_mov_b32 s21, exec_lo | ||
| 319 | s_mov_b32 exec_lo, s20 | ||
| 320 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 321 | v_lshl_or_b32 v41, v30, 25, v41 | ||
| 322 | v_cmpx_o_f16_e64 v13, v6 | ||
| 323 | s_mov_b32 s21, exec_lo | ||
| 324 | s_mov_b32 exec_lo, s20 | ||
| 325 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 326 | v_lshl_or_b32 v41, v30, 26, v41 | ||
| 327 | v_cmpx_o_f16_e64 v14, v7 | ||
| 328 | s_mov_b32 s21, exec_lo | ||
| 329 | s_mov_b32 exec_lo, s20 | ||
| 330 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 331 | v_lshl_or_b32 v41, v30, 27, v41 | ||
| 332 | v_mov_b32_e32 v42, 0x40000000 | ||
| 333 | v_cmp_tru_f16_e32 vcc_lo, v8, v8 | ||
| 334 | v_cmpx_f_f16_e64 v8, v8 | ||
| 335 | s_mov_b32 s21, exec_lo | ||
| 336 | s_mov_b32 exec_lo, s20 | ||
| 337 | v_cndmask_b32_e64 v30, 0, 1, vcc_lo | ||
| 338 | v_lshl_or_b32 v42, v30, 29, v42 | ||
| 339 | v_cmpx_f_f16_e64 v8, v8 | ||
| 340 | v_cmpx_tru_f16_e64 v8, v8 | ||
| 341 | s_mov_b32 s21, exec_lo | ||
| 342 | s_mov_b32 exec_lo, s20 | ||
| 343 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 344 | v_lshl_or_b32 v42, v30, 28, v42 | ||
| 345 | v_cmpx_u_f16_e64 v8, 1.0 | ||
| 346 | s_mov_b32 s21, exec_lo | ||
| 347 | s_mov_b32 exec_lo, s20 | ||
| 348 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 349 | v_lshl_or_b32 v42, v30, 0, v42 | ||
| 350 | v_cmpx_u_f16_e64 v9, 2.0 | ||
| 351 | s_mov_b32 s21, exec_lo | ||
| 352 | s_mov_b32 exec_lo, s20 | ||
| 353 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 354 | v_lshl_or_b32 v42, v30, 1, v42 | ||
| 355 | v_cmpx_u_f16_e64 v10, 0 | ||
| 356 | s_mov_b32 s21, exec_lo | ||
| 357 | s_mov_b32 exec_lo, s20 | ||
| 358 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 359 | v_lshl_or_b32 v42, v30, 2, v42 | ||
| 360 | v_cmpx_u_f16_e64 v11, v4 | ||
| 361 | s_mov_b32 s21, exec_lo | ||
| 362 | s_mov_b32 exec_lo, s20 | ||
| 363 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 364 | v_lshl_or_b32 v42, v30, 3, v42 | ||
| 365 | v_cmpx_u_f16_e64 v12, v5 | ||
| 366 | s_mov_b32 s21, exec_lo | ||
| 367 | s_mov_b32 exec_lo, s20 | ||
| 368 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 369 | v_lshl_or_b32 v42, v30, 4, v42 | ||
| 370 | v_cmpx_u_f16_e64 v13, v6 | ||
| 371 | s_mov_b32 s21, exec_lo | ||
| 372 | s_mov_b32 exec_lo, s20 | ||
| 373 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 374 | v_lshl_or_b32 v42, v30, 5, v42 | ||
| 375 | v_cmpx_u_f16_e64 v14, v7 | ||
| 376 | s_mov_b32 s21, exec_lo | ||
| 377 | s_mov_b32 exec_lo, s20 | ||
| 378 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 379 | v_lshl_or_b32 v42, v30, 6, v42 | ||
| 380 | v_cmpx_nge_f16_e64 v8, 1.0 | ||
| 381 | s_mov_b32 s21, exec_lo | ||
| 382 | s_mov_b32 exec_lo, s20 | ||
| 383 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 384 | v_lshl_or_b32 v42, v30, 7, v42 | ||
| 385 | v_cmpx_nge_f16_e64 v9, 2.0 | ||
| 386 | s_mov_b32 s21, exec_lo | ||
| 387 | s_mov_b32 exec_lo, s20 | ||
| 388 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 389 | v_lshl_or_b32 v42, v30, 8, v42 | ||
| 390 | v_cmpx_nge_f16_e64 v10, 0 | ||
| 391 | s_mov_b32 s21, exec_lo | ||
| 392 | s_mov_b32 exec_lo, s20 | ||
| 393 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 394 | v_lshl_or_b32 v42, v30, 9, v42 | ||
| 395 | v_cmpx_nge_f16_e64 v11, v4 | ||
| 396 | s_mov_b32 s21, exec_lo | ||
| 397 | s_mov_b32 exec_lo, s20 | ||
| 398 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 399 | v_lshl_or_b32 v42, v30, 10, v42 | ||
| 400 | v_cmpx_nge_f16_e64 v12, v5 | ||
| 401 | s_mov_b32 s21, exec_lo | ||
| 402 | s_mov_b32 exec_lo, s20 | ||
| 403 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 404 | v_lshl_or_b32 v42, v30, 11, v42 | ||
| 405 | v_cmpx_nge_f16_e64 v13, v6 | ||
| 406 | s_mov_b32 s21, exec_lo | ||
| 407 | s_mov_b32 exec_lo, s20 | ||
| 408 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 409 | v_lshl_or_b32 v42, v30, 12, v42 | ||
| 410 | v_cmpx_nge_f16_e64 v14, v7 | ||
| 411 | s_mov_b32 s21, exec_lo | ||
| 412 | s_mov_b32 exec_lo, s20 | ||
| 413 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 414 | v_lshl_or_b32 v42, v30, 13, v42 | ||
| 415 | v_cmpx_nlg_f16_e64 v8, 1.0 | ||
| 416 | s_mov_b32 s21, exec_lo | ||
| 417 | s_mov_b32 exec_lo, s20 | ||
| 418 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 419 | v_lshl_or_b32 v42, v30, 14, v42 | ||
| 420 | v_cmpx_nlg_f16_e64 v9, 2.0 | ||
| 421 | s_mov_b32 s21, exec_lo | ||
| 422 | s_mov_b32 exec_lo, s20 | ||
| 423 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 424 | v_lshl_or_b32 v42, v30, 15, v42 | ||
| 425 | v_cmpx_nlg_f16_e64 v10, 0 | ||
| 426 | s_mov_b32 s21, exec_lo | ||
| 427 | s_mov_b32 exec_lo, s20 | ||
| 428 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 429 | v_lshl_or_b32 v42, v30, 16, v42 | ||
| 430 | v_cmpx_nlg_f16_e64 v11, v4 | ||
| 431 | s_mov_b32 s21, exec_lo | ||
| 432 | s_mov_b32 exec_lo, s20 | ||
| 433 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 434 | v_lshl_or_b32 v42, v30, 17, v42 | ||
| 435 | v_cmpx_nlg_f16_e64 v12, v5 | ||
| 436 | s_mov_b32 s21, exec_lo | ||
| 437 | s_mov_b32 exec_lo, s20 | ||
| 438 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 439 | v_lshl_or_b32 v42, v30, 18, v42 | ||
| 440 | v_cmpx_nlg_f16_e64 v13, v6 | ||
| 441 | s_mov_b32 s21, exec_lo | ||
| 442 | s_mov_b32 exec_lo, s20 | ||
| 443 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 444 | v_lshl_or_b32 v42, v30, 19, v42 | ||
| 445 | v_cmpx_nlg_f16_e64 v14, v7 | ||
| 446 | s_mov_b32 s21, exec_lo | ||
| 447 | s_mov_b32 exec_lo, s20 | ||
| 448 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 449 | v_lshl_or_b32 v42, v30, 20, v42 | ||
| 450 | v_cmpx_ngt_f16_e64 v8, 1.0 | ||
| 451 | s_mov_b32 s21, exec_lo | ||
| 452 | s_mov_b32 exec_lo, s20 | ||
| 453 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 454 | v_lshl_or_b32 v42, v30, 21, v42 | ||
| 455 | v_cmpx_ngt_f16_e64 v9, 2.0 | ||
| 456 | s_mov_b32 s21, exec_lo | ||
| 457 | s_mov_b32 exec_lo, s20 | ||
| 458 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 459 | v_lshl_or_b32 v42, v30, 22, v42 | ||
| 460 | v_cmpx_ngt_f16_e64 v10, 0 | ||
| 461 | s_mov_b32 s21, exec_lo | ||
| 462 | s_mov_b32 exec_lo, s20 | ||
| 463 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 464 | v_lshl_or_b32 v42, v30, 23, v42 | ||
| 465 | v_cmpx_ngt_f16_e64 v11, v4 | ||
| 466 | s_mov_b32 s21, exec_lo | ||
| 467 | s_mov_b32 exec_lo, s20 | ||
| 468 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 469 | v_lshl_or_b32 v42, v30, 24, v42 | ||
| 470 | v_cmpx_ngt_f16_e64 v12, v5 | ||
| 471 | s_mov_b32 s21, exec_lo | ||
| 472 | s_mov_b32 exec_lo, s20 | ||
| 473 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 474 | v_lshl_or_b32 v42, v30, 25, v42 | ||
| 475 | v_cmpx_ngt_f16_e64 v13, v6 | ||
| 476 | s_mov_b32 s21, exec_lo | ||
| 477 | s_mov_b32 exec_lo, s20 | ||
| 478 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 479 | v_lshl_or_b32 v42, v30, 26, v42 | ||
| 480 | v_cmpx_ngt_f16_e64 v14, v7 | ||
| 481 | s_mov_b32 s21, exec_lo | ||
| 482 | s_mov_b32 exec_lo, s20 | ||
| 483 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 484 | v_lshl_or_b32 v42, v30, 27, v42 | ||
| 485 | v_mov_b32_e32 v43, 0x40000000 | ||
| 486 | v_cmp_tru_f16_e32 vcc_lo, v8, v8 | ||
| 487 | v_cmpx_f_f16_e64 v8, v8 | ||
| 488 | s_mov_b32 s21, exec_lo | ||
| 489 | s_mov_b32 exec_lo, s20 | ||
| 490 | v_cndmask_b32_e64 v30, 0, 1, vcc_lo | ||
| 491 | v_lshl_or_b32 v43, v30, 29, v43 | ||
| 492 | v_cmpx_f_f16_e64 v8, v8 | ||
| 493 | v_cmpx_tru_f16_e64 v8, v8 | ||
| 494 | s_mov_b32 s21, exec_lo | ||
| 495 | s_mov_b32 exec_lo, s20 | ||
| 496 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 497 | v_lshl_or_b32 v43, v30, 28, v43 | ||
| 498 | v_cmpx_nle_f16_e64 v8, 1.0 | ||
| 499 | s_mov_b32 s21, exec_lo | ||
| 500 | s_mov_b32 exec_lo, s20 | ||
| 501 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 502 | v_lshl_or_b32 v43, v30, 0, v43 | ||
| 503 | v_cmpx_nle_f16_e64 v9, 2.0 | ||
| 504 | s_mov_b32 s21, exec_lo | ||
| 505 | s_mov_b32 exec_lo, s20 | ||
| 506 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 507 | v_lshl_or_b32 v43, v30, 1, v43 | ||
| 508 | v_cmpx_nle_f16_e64 v10, 0 | ||
| 509 | s_mov_b32 s21, exec_lo | ||
| 510 | s_mov_b32 exec_lo, s20 | ||
| 511 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 512 | v_lshl_or_b32 v43, v30, 2, v43 | ||
| 513 | v_cmpx_nle_f16_e64 v11, v4 | ||
| 514 | s_mov_b32 s21, exec_lo | ||
| 515 | s_mov_b32 exec_lo, s20 | ||
| 516 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 517 | v_lshl_or_b32 v43, v30, 3, v43 | ||
| 518 | v_cmpx_nle_f16_e64 v12, v5 | ||
| 519 | s_mov_b32 s21, exec_lo | ||
| 520 | s_mov_b32 exec_lo, s20 | ||
| 521 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 522 | v_lshl_or_b32 v43, v30, 4, v43 | ||
| 523 | v_cmpx_nle_f16_e64 v13, v6 | ||
| 524 | s_mov_b32 s21, exec_lo | ||
| 525 | s_mov_b32 exec_lo, s20 | ||
| 526 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 527 | v_lshl_or_b32 v43, v30, 5, v43 | ||
| 528 | v_cmpx_nle_f16_e64 v14, v7 | ||
| 529 | s_mov_b32 s21, exec_lo | ||
| 530 | s_mov_b32 exec_lo, s20 | ||
| 531 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 532 | v_lshl_or_b32 v43, v30, 6, v43 | ||
| 533 | v_cmpx_neq_f16_e64 v8, 1.0 | ||
| 534 | s_mov_b32 s21, exec_lo | ||
| 535 | s_mov_b32 exec_lo, s20 | ||
| 536 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 537 | v_lshl_or_b32 v43, v30, 7, v43 | ||
| 538 | v_cmpx_neq_f16_e64 v9, 2.0 | ||
| 539 | s_mov_b32 s21, exec_lo | ||
| 540 | s_mov_b32 exec_lo, s20 | ||
| 541 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 542 | v_lshl_or_b32 v43, v30, 8, v43 | ||
| 543 | v_cmpx_neq_f16_e64 v10, 0 | ||
| 544 | s_mov_b32 s21, exec_lo | ||
| 545 | s_mov_b32 exec_lo, s20 | ||
| 546 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 547 | v_lshl_or_b32 v43, v30, 9, v43 | ||
| 548 | v_cmpx_neq_f16_e64 v11, v4 | ||
| 549 | s_mov_b32 s21, exec_lo | ||
| 550 | s_mov_b32 exec_lo, s20 | ||
| 551 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 552 | v_lshl_or_b32 v43, v30, 10, v43 | ||
| 553 | v_cmpx_neq_f16_e64 v12, v5 | ||
| 554 | s_mov_b32 s21, exec_lo | ||
| 555 | s_mov_b32 exec_lo, s20 | ||
| 556 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 557 | v_lshl_or_b32 v43, v30, 11, v43 | ||
| 558 | v_cmpx_neq_f16_e64 v13, v6 | ||
| 559 | s_mov_b32 s21, exec_lo | ||
| 560 | s_mov_b32 exec_lo, s20 | ||
| 561 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 562 | v_lshl_or_b32 v43, v30, 12, v43 | ||
| 563 | v_cmpx_neq_f16_e64 v14, v7 | ||
| 564 | s_mov_b32 s21, exec_lo | ||
| 565 | s_mov_b32 exec_lo, s20 | ||
| 566 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 567 | v_lshl_or_b32 v43, v30, 13, v43 | ||
| 568 | v_cmpx_nlt_f16_e64 v8, 1.0 | ||
| 569 | s_mov_b32 s21, exec_lo | ||
| 570 | s_mov_b32 exec_lo, s20 | ||
| 571 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 572 | v_lshl_or_b32 v43, v30, 14, v43 | ||
| 573 | v_cmpx_nlt_f16_e64 v9, 2.0 | ||
| 574 | s_mov_b32 s21, exec_lo | ||
| 575 | s_mov_b32 exec_lo, s20 | ||
| 576 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 577 | v_lshl_or_b32 v43, v30, 15, v43 | ||
| 578 | v_cmpx_nlt_f16_e64 v10, 0 | ||
| 579 | s_mov_b32 s21, exec_lo | ||
| 580 | s_mov_b32 exec_lo, s20 | ||
| 581 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 582 | v_lshl_or_b32 v43, v30, 16, v43 | ||
| 583 | v_cmpx_nlt_f16_e64 v11, v4 | ||
| 584 | s_mov_b32 s21, exec_lo | ||
| 585 | s_mov_b32 exec_lo, s20 | ||
| 586 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 587 | v_lshl_or_b32 v43, v30, 17, v43 | ||
| 588 | v_cmpx_nlt_f16_e64 v12, v5 | ||
| 589 | s_mov_b32 s21, exec_lo | ||
| 590 | s_mov_b32 exec_lo, s20 | ||
| 591 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 592 | v_lshl_or_b32 v43, v30, 18, v43 | ||
| 593 | v_cmpx_nlt_f16_e64 v13, v6 | ||
| 594 | s_mov_b32 s21, exec_lo | ||
| 595 | s_mov_b32 exec_lo, s20 | ||
| 596 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 597 | v_lshl_or_b32 v43, v30, 19, v43 | ||
| 598 | v_cmpx_nlt_f16_e64 v14, v7 | ||
| 599 | s_mov_b32 s21, exec_lo | ||
| 600 | s_mov_b32 exec_lo, s20 | ||
| 601 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 602 | v_lshl_or_b32 v43, v30, 20, v43 | ||
| 603 | v_cmpx_tru_f16_e64 v8, 1.0 | ||
| 604 | s_mov_b32 s21, exec_lo | ||
| 605 | s_mov_b32 exec_lo, s20 | ||
| 606 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 607 | v_lshl_or_b32 v43, v30, 21, v43 | ||
| 608 | v_cmpx_tru_f16_e64 v9, 2.0 | ||
| 609 | s_mov_b32 s21, exec_lo | ||
| 610 | s_mov_b32 exec_lo, s20 | ||
| 611 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 612 | v_lshl_or_b32 v43, v30, 22, v43 | ||
| 613 | v_cmpx_tru_f16_e64 v10, 0 | ||
| 614 | s_mov_b32 s21, exec_lo | ||
| 615 | s_mov_b32 exec_lo, s20 | ||
| 616 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 617 | v_lshl_or_b32 v43, v30, 23, v43 | ||
| 618 | v_cmpx_tru_f16_e64 v11, v4 | ||
| 619 | s_mov_b32 s21, exec_lo | ||
| 620 | s_mov_b32 exec_lo, s20 | ||
| 621 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 622 | v_lshl_or_b32 v43, v30, 24, v43 | ||
| 623 | v_cmpx_tru_f16_e64 v12, v5 | ||
| 624 | s_mov_b32 s21, exec_lo | ||
| 625 | s_mov_b32 exec_lo, s20 | ||
| 626 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 627 | v_lshl_or_b32 v43, v30, 25, v43 | ||
| 628 | v_cmpx_tru_f16_e64 v13, v6 | ||
| 629 | s_mov_b32 s21, exec_lo | ||
| 630 | s_mov_b32 exec_lo, s20 | ||
| 631 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 632 | v_lshl_or_b32 v43, v30, 26, v43 | ||
| 633 | v_cmpx_tru_f16_e64 v14, v7 | ||
| 634 | s_mov_b32 s21, exec_lo | ||
| 635 | s_mov_b32 exec_lo, s20 | ||
| 636 | v_cndmask_b32_e64 v30, 0, 1, s21 | ||
| 637 | v_lshl_or_b32 v43, v30, 27, v43 | ||
| 638 | exp mrt0 v40, v41, v42, v43 done vm | ||
| 639 | s_endpgm | ||
diff --git a/runtime/test/shaders/vs_base_ids.asm b/runtime/test/shaders/vs_base_ids.asm new file mode 100644 index 000000000..27e905aea --- /dev/null +++ b/runtime/test/shaders/vs_base_ids.asm | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | ; Vertex shader for the base-vertex / base-instance test. On AMD hardware the VS input VGPRs are zero-based: v0 is | ||
| 2 | ; the vertex id without the draw's first vertex (Mesa: ac.vertex_id = load_vertex_id_zero_base, the base comes in | ||
| 3 | ; the base_vertex SGPR), and v3 the instance id without its first instance (ac.instance_id = load_instance_id, the | ||
| 4 | ; base in start_instance). Vulkan's VertexIndex / InstanceIndex include firstVertex / firstInstance. | ||
| 5 | ; Same full-screen triangle as vs_ids (from v0's low bits), param0 = (u, v, 0, 1), and param1.x = | ||
| 6 | ; 0x101 + v0 + 0x1000 * v3 as raw bits, so ps_flat (attr1.x from the provoking vertex) shows both ids. | ||
| 7 | ; Run: VKH_DRAW=16,7 vk_harness vs_base_ids.spv ps_flat.spv out.raw | ||
| 8 | ; -> mrt0 bits = 0x101, 0x102 on every pixel (vertex 0 of instance 0); 0x7111 means firstVertex/firstInstance | ||
| 9 | ; leaked into v0 / v3. With VKH_DRAW unset (0,0) both read 0x101, as vs_ids. | ||
| 10 | v_lshlrev_b32_e32 v8, 12, v3 | ||
| 11 | v_lshlrev_b32_e32 v1, 1, v0 | ||
| 12 | v_and_b32_e32 v1, 2, v1 | ||
| 13 | v_and_b32_e32 v2, 2, v0 | ||
| 14 | v_cvt_f32_u32_e32 v1, v1 | ||
| 15 | v_cvt_f32_u32_e32 v2, v2 | ||
| 16 | v_fma_f32 v3, v1, 2.0, -1.0 | ||
| 17 | v_fma_f32 v4, v2, 2.0, -1.0 | ||
| 18 | v_mov_b32_e32 v5, 0 | ||
| 19 | v_mov_b32_e32 v6, 1.0 | ||
| 20 | exp pos0 v3, v4, v5, v6 done | ||
| 21 | exp param0 v1, v2, v5, v6 | ||
| 22 | v_add3_u32 v7, v0, v8, 0x101 | ||
| 23 | exp param1 v7, v7, v7, v7 | ||
| 24 | s_endpgm | ||
diff --git a/runtime/test/shaders/w64_graphics.py b/runtime/test/shaders/w64_graphics.py index efa21c752..988fa4a43 100644 --- a/runtime/test/shaders/w64_graphics.py +++ b/runtime/test/shaders/w64_graphics.py | |||
| @@ -355,6 +355,8 @@ def check(tools, spirv, name): | |||
| 355 | if size == 64: | 355 | if size == 64: |
| 356 | continue | 356 | continue |
| 357 | if tier == "C": | 357 | if tier == "C": |
| 358 | if comparable(name, ref_words, None) != comparable(name, words, None): | ||
| 359 | return "a word that must not depend on the partition differs from the 64-lane reference" | ||
| 358 | if not partition_dependent(name, ref_words, words): | 360 | if not partition_dependent(name, ref_words, words): |
| 359 | return "tier C but the run equals the 64-lane reference: the detector is wrong" | 361 | return "tier C but the run equals the 64-lane reference: the detector is wrong" |
| 360 | compared = True | 362 | compared = True |
diff --git a/runtime/test/spirv_f16_halves_test.cpp b/runtime/test/spirv_f16_halves_test.cpp new file mode 100644 index 000000000..29bb37113 --- /dev/null +++ b/runtime/test/spirv_f16_halves_test.cpp | |||
| @@ -0,0 +1,300 @@ | |||
| 1 | // Pure-CPU tests for runtime/src/spirv_f16_halves.h (SHADER-378): | ||
| 2 | // - fast path when PS has no f16_halves or VS already matches all PS half locations; | ||
| 3 | // - in-place relocation when VS already emits the requested params at different locations; | ||
| 4 | // - 16-param VS (param0..param15, static halves only for 0..6) paired with a corpus-style PS (raw 0..14, | ||
| 5 | // f16 on 0, 4, 5, 6, 7): unused static halves demoted to Private, reused halves relocated, missing param 7 | ||
| 6 | // synthesized with OpLoad + 4x UnpackHalf2x16 + OpStore before OpReturn; | ||
| 7 | // - PS relocation when a PS half location collides with an unread raw VS output; | ||
| 8 | // - SPIR-V 1.3 vs 1.4+ OpEntryPoint interface rules for demoted Private variables; | ||
| 9 | // - clean failure on genuine >30 location budget overflow (leaving input buffers untouched). | ||
| 10 | // No GPU or game files required. | ||
| 11 | #include "../src/spirv_f16_halves.h" | ||
| 12 | |||
| 13 | #include <cstdint> | ||
| 14 | #include <cstdio> | ||
| 15 | #include <map> | ||
| 16 | #include <set> | ||
| 17 | #include <string> | ||
| 18 | #include <vector> | ||
| 19 | |||
| 20 | #define CHECK(cond) do { \ | ||
| 21 | if (!(cond)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #cond); return 1; } \ | ||
| 22 | } while (0) | ||
| 23 | |||
| 24 | namespace { | ||
| 25 | |||
| 26 | using namespace leonida::spirv_detail; | ||
| 27 | |||
| 28 | void append_inst(std::vector<std::uint32_t>& w, std::uint16_t op, std::initializer_list<std::uint32_t> args) { | ||
| 29 | w.push_back((std::uint32_t(1 + args.size()) << 16) | op); | ||
| 30 | for (std::uint32_t a : args) w.push_back(a); | ||
| 31 | } | ||
| 32 | |||
| 33 | void append_inst_vec(std::vector<std::uint32_t>& w, std::uint16_t op, const std::vector<std::uint32_t>& args) { | ||
| 34 | w.push_back((std::uint32_t(1 + args.size()) << 16) | op); | ||
| 35 | w.insert(w.end(), args.begin(), args.end()); | ||
| 36 | } | ||
| 37 | |||
| 38 | // Build a minimal valid Vertex SPIR-V module with `num_raw_params` Output vec4 params (Location 0..num_raw_params-1) | ||
| 39 | // and optional static f16_halves Output vec4 vars at the given locations. | ||
| 40 | std::vector<std::uint32_t> build_vs(std::uint32_t version, std::uint32_t num_raw_params, | ||
| 41 | const std::map<std::uint32_t, std::array<std::uint32_t, 2>>& static_halves) { | ||
| 42 | // IDs: | ||
| 43 | // 1 = %void, 2 = %fn, 3 = %float, 4 = %v4float, 5 = %ptr_out_v4, 6 = %null_v4, 7 = %main, 8 = %entry | ||
| 44 | // 9 = %out_pos (BuiltIn Position) | ||
| 45 | // 10.. = raw param vars, then static half vars (lo, hi) | ||
| 46 | std::uint32_t next_id = 10; | ||
| 47 | std::vector<std::uint32_t> raw_vars; | ||
| 48 | for (std::uint32_t p = 0; p < num_raw_params; ++p) raw_vars.push_back(next_id++); | ||
| 49 | std::vector<std::pair<std::uint32_t, std::uint32_t>> half_vars; // (var_id, loc) | ||
| 50 | for (const auto& [param, pair] : static_halves) { | ||
| 51 | half_vars.push_back({next_id++, pair[0]}); | ||
| 52 | half_vars.push_back({next_id++, pair[1]}); | ||
| 53 | } | ||
| 54 | |||
| 55 | std::vector<std::uint32_t> w = {kSpirvMagic, version, 0, next_id, 0}; | ||
| 56 | append_inst(w, kOpCapability, {1}); // Shader | ||
| 57 | append_inst(w, kOpMemoryModel, {0, 1}); // Logical GLSL450 | ||
| 58 | std::vector<std::uint32_t> ep = {kExecModelVertex, 7, 0x6e69616du, 0x00000000u, 9}; // "main\0" | ||
| 59 | for (std::uint32_t v : raw_vars) ep.push_back(v); | ||
| 60 | for (const auto& [v, loc] : half_vars) ep.push_back(v); | ||
| 61 | append_inst_vec(w, kOpEntryPoint, ep); | ||
| 62 | |||
| 63 | append_inst(w, kOpDecorate, {9, 11, 0}); // BuiltIn Position | ||
| 64 | for (std::uint32_t p = 0; p < num_raw_params; ++p) append_inst(w, kOpDecorate, {raw_vars[p], kDecorationLocation, p}); | ||
| 65 | for (const auto& [v, loc] : half_vars) append_inst(w, kOpDecorate, {v, kDecorationLocation, loc}); | ||
| 66 | |||
| 67 | append_inst(w, 19, {1}); // OpTypeVoid | ||
| 68 | append_inst(w, 33, {2, 1}); // OpTypeFunction %void | ||
| 69 | append_inst(w, kOpTypeFloat, {3, 32}); | ||
| 70 | append_inst(w, kOpTypeVector, {4, 3, 4}); | ||
| 71 | append_inst(w, kOpTypePointer, {5, kStorageOutput, 4}); | ||
| 72 | append_inst(w, kOpConstantNull, {4, 6}); | ||
| 73 | append_inst(w, kOpVariable, {5, 9, kStorageOutput}); | ||
| 74 | for (std::uint32_t v : raw_vars) append_inst(w, kOpVariable, {5, v, kStorageOutput}); | ||
| 75 | for (const auto& [v, loc] : half_vars) append_inst(w, kOpVariable, {5, v, kStorageOutput}); | ||
| 76 | |||
| 77 | append_inst(w, kOpFunction, {1, 7, 0, 2}); | ||
| 78 | append_inst(w, 248, {8}); // OpLabel | ||
| 79 | append_inst(w, kOpStore, {9, 6}); | ||
| 80 | for (std::uint32_t v : raw_vars) append_inst(w, kOpStore, {v, 6}); | ||
| 81 | for (const auto& [v, loc] : half_vars) append_inst(w, kOpStore, {v, 6}); | ||
| 82 | append_inst(w, kOpReturn, {}); | ||
| 83 | append_inst(w, kOpFunctionEnd, {}); | ||
| 84 | return w; | ||
| 85 | } | ||
| 86 | |||
| 87 | // Build a minimal valid Fragment SPIR-V module with `raw_in_locs` and `half_in_locs` Input vec4 variables. | ||
| 88 | std::vector<std::uint32_t> build_ps(std::uint32_t version, const std::vector<std::uint32_t>& raw_in_locs, | ||
| 89 | const std::map<std::uint32_t, std::array<std::uint32_t, 2>>& f16_halves) { | ||
| 90 | // 1 = %void, 2 = %fn, 3 = %float, 4 = %v4float, 5 = %ptr_in_v4, 6 = %ptr_out_v4, 7 = %null_v4, 8 = %out0, | ||
| 91 | // 9 = %main, 10 = %entry | ||
| 92 | std::uint32_t next_id = 11; | ||
| 93 | std::vector<std::pair<std::uint32_t, std::uint32_t>> in_vars; // (var_id, loc) | ||
| 94 | for (std::uint32_t loc : raw_in_locs) in_vars.push_back({next_id++, loc}); | ||
| 95 | for (const auto& [param, pair] : f16_halves) { | ||
| 96 | in_vars.push_back({next_id++, pair[0]}); | ||
| 97 | in_vars.push_back({next_id++, pair[1]}); | ||
| 98 | } | ||
| 99 | |||
| 100 | std::vector<std::uint32_t> w = {kSpirvMagic, version, 0, next_id, 0}; | ||
| 101 | append_inst(w, kOpCapability, {1}); | ||
| 102 | append_inst(w, kOpMemoryModel, {0, 1}); | ||
| 103 | std::vector<std::uint32_t> ep = {kExecModelFragment, 9, 0x6e69616du, 0x00000000u, 8}; | ||
| 104 | for (const auto& [v, loc] : in_vars) ep.push_back(v); | ||
| 105 | append_inst_vec(w, kOpEntryPoint, ep); | ||
| 106 | append_inst(w, kOpExecutionMode, {9, 7}); // OriginUpperLeft | ||
| 107 | |||
| 108 | append_inst(w, kOpDecorate, {8, kDecorationLocation, 0}); | ||
| 109 | for (const auto& [v, loc] : in_vars) append_inst(w, kOpDecorate, {v, kDecorationLocation, loc}); | ||
| 110 | |||
| 111 | append_inst(w, 19, {1}); | ||
| 112 | append_inst(w, 33, {2, 1}); | ||
| 113 | append_inst(w, kOpTypeFloat, {3, 32}); | ||
| 114 | append_inst(w, kOpTypeVector, {4, 3, 4}); | ||
| 115 | append_inst(w, kOpTypePointer, {5, kStorageInput, 4}); | ||
| 116 | append_inst(w, kOpTypePointer, {6, kStorageOutput, 4}); | ||
| 117 | append_inst(w, kOpConstantNull, {4, 7}); | ||
| 118 | append_inst(w, kOpVariable, {6, 8, kStorageOutput}); | ||
| 119 | for (const auto& [v, loc] : in_vars) append_inst(w, kOpVariable, {5, v, kStorageInput}); | ||
| 120 | |||
| 121 | append_inst(w, kOpFunction, {1, 9, 0, 2}); | ||
| 122 | append_inst(w, 248, {10}); | ||
| 123 | append_inst(w, kOpStore, {8, 7}); | ||
| 124 | append_inst(w, kOpReturn, {}); | ||
| 125 | append_inst(w, kOpFunctionEnd, {}); | ||
| 126 | return w; | ||
| 127 | } | ||
| 128 | |||
| 129 | // Verify basic SPIR-V structural invariants: valid section ordering, all IDs < bound, unique Locations per storage. | ||
| 130 | bool verify_spirv_structure(const std::vector<std::uint32_t>& words, std::uint32_t storage_class, | ||
| 131 | std::map<std::uint32_t, std::uint32_t>& out_loc_to_var, int& out_unpack_count, | ||
| 132 | int& out_private_vars, std::set<std::uint32_t>& out_ep_iface) { | ||
| 133 | Module mod; | ||
| 134 | if (!mod.parse(words)) return false; | ||
| 135 | out_loc_to_var.clear(); | ||
| 136 | out_unpack_count = 0; | ||
| 137 | out_private_vars = 0; | ||
| 138 | out_ep_iface.clear(); | ||
| 139 | |||
| 140 | // Check section order: pre-type -> types/globals -> functions, and every defined type appears before its use. | ||
| 141 | int section = 0; // 0 = pre-type, 1 = types/globals, 2 = functions | ||
| 142 | std::set<std::uint32_t> defined_types; | ||
| 143 | std::map<std::uint32_t, std::uint32_t> var_storage; | ||
| 144 | std::uint32_t glsl_id = 0; | ||
| 145 | for (const Inst& inst : mod.insts) { | ||
| 146 | if (inst.opcode == kOpExtInstImport && inst.words.size() >= 3 && | ||
| 147 | decode_literal_string(std::span<const std::uint32_t>(inst.words).subspan(2)) == "GLSL.std.450") { | ||
| 148 | glsl_id = inst.words[1]; | ||
| 149 | } | ||
| 150 | if (inst.opcode == kOpEntryPoint) { | ||
| 151 | const std::size_t s = entry_point_interface_start(inst); | ||
| 152 | for (std::size_t i = s; i < inst.words.size(); ++i) out_ep_iface.insert(inst.words[i]); | ||
| 153 | } | ||
| 154 | if (inst.opcode == kOpFunction) { | ||
| 155 | section = 2; | ||
| 156 | } else if (section == 0 && !is_pre_type_opcode(inst.opcode)) { | ||
| 157 | section = 1; | ||
| 158 | } else if (section == 1 && is_pre_type_opcode(inst.opcode)) { | ||
| 159 | return false; // annotation/header appeared after types started | ||
| 160 | } | ||
| 161 | if (section == 1) { | ||
| 162 | if (inst.opcode == 19 || inst.opcode == 33 || inst.opcode == kOpTypeInt || inst.opcode == kOpTypeFloat || | ||
| 163 | inst.opcode == kOpTypeVector || inst.opcode == kOpTypePointer) { | ||
| 164 | defined_types.insert(inst.words[1]); | ||
| 165 | if (inst.words[1] >= mod.header[3]) return false; | ||
| 166 | } | ||
| 167 | if (inst.opcode == kOpVariable) { | ||
| 168 | if (!defined_types.count(inst.words[1])) return false; // pointer type must precede OpVariable | ||
| 169 | if (inst.words[2] >= mod.header[3]) return false; | ||
| 170 | var_storage[inst.words[2]] = inst.words[3]; | ||
| 171 | if (inst.words[3] == kStoragePrivate) ++out_private_vars; | ||
| 172 | } | ||
| 173 | } | ||
| 174 | if (inst.opcode == kOpExtInst && inst.words.size() >= 6 && inst.words[3] == glsl_id && | ||
| 175 | inst.words[4] == kGlslUnpackHalf2x16) { | ||
| 176 | ++out_unpack_count; | ||
| 177 | if (inst.words[2] >= mod.header[3]) return false; | ||
| 178 | } | ||
| 179 | } | ||
| 180 | for (const Inst& inst : mod.insts) { | ||
| 181 | if (inst.opcode == kOpDecorate && inst.words.size() >= 4 && inst.words[2] == kDecorationLocation) { | ||
| 182 | const auto it = var_storage.find(inst.words[1]); | ||
| 183 | if (it != var_storage.end() && it->second == storage_class) { | ||
| 184 | if (!out_loc_to_var.emplace(inst.words[3], inst.words[1]).second) return false; // duplicate Location | ||
| 185 | } | ||
| 186 | if (it != var_storage.end() && it->second == kStoragePrivate) return false; // Private cannot have Location | ||
| 187 | } | ||
| 188 | } | ||
| 189 | return true; | ||
| 190 | } | ||
| 191 | |||
| 192 | } // namespace | ||
| 193 | |||
| 194 | int main() { | ||
| 195 | using namespace leonida; | ||
| 196 | |||
| 197 | // 1. Fast path: already matching static f16_halves -> both modules untouched. | ||
| 198 | { | ||
| 199 | ShaderEntry vs_e, ps_e; | ||
| 200 | vs_e.f16_halves = {{0, {28, 29}}, {1, {26, 27}}}; | ||
| 201 | ps_e.f16_halves = {{0, {28, 29}}}; | ||
| 202 | auto vs_w = build_vs(0x00010500u, 2, vs_e.f16_halves); | ||
| 203 | auto ps_w = build_ps(0x00010500u, {0, 1}, ps_e.f16_halves); | ||
| 204 | const auto vs_orig = vs_w, ps_orig = ps_w; | ||
| 205 | std::string err; | ||
| 206 | CHECK(link_f16_halves(vs_w, vs_e, ps_w, ps_e, &err)); | ||
| 207 | CHECK(vs_w == vs_orig && ps_w == ps_orig); | ||
| 208 | } | ||
| 209 | |||
| 210 | // 2. Corpus pattern (SHADER-378): 16-param VS (param0..param15, static halves only for 0..6) paired with a PS | ||
| 211 | // reading raw attrs 0..14 and f16 attrs {0, 4, 5, 6, 7} packed at 20..29. | ||
| 212 | // Expected: params 1,2,3 demoted to Private (6 Private vars), params 0,4,5,6 relocated, param 7 synthesized | ||
| 213 | // with 4 UnpackHalf2x16 ops at Locations 20 & 21; PS unchanged. | ||
| 214 | { | ||
| 215 | ShaderEntry vs_e, ps_e; | ||
| 216 | for (std::uint32_t n = 0; n <= 6; ++n) vs_e.f16_halves[n] = {28 - 2 * n, 29 - 2 * n}; | ||
| 217 | ps_e.f16_halves = {{0, {28, 29}}, {4, {26, 27}}, {5, {24, 25}}, {6, {22, 23}}, {7, {20, 21}}}; | ||
| 218 | std::vector<std::uint32_t> ps_raw; | ||
| 219 | for (std::uint32_t a = 0; a < 15; ++a) ps_raw.push_back(a); | ||
| 220 | |||
| 221 | auto vs_w = build_vs(0x00010500u, 16, vs_e.f16_halves); | ||
| 222 | auto ps_w = build_ps(0x00010500u, ps_raw, ps_e.f16_halves); | ||
| 223 | const auto ps_orig = ps_w; | ||
| 224 | std::string err; | ||
| 225 | CHECK(link_f16_halves(vs_w, vs_e, ps_w, ps_e, &err)); | ||
| 226 | CHECK(ps_w == ps_orig); // PS locations 20..29 do not collide with VS raw 0..15 | ||
| 227 | |||
| 228 | std::map<std::uint32_t, std::uint32_t> vs_locs; | ||
| 229 | int unpacks = 0, privs = 0; | ||
| 230 | std::set<std::uint32_t> ep_iface; | ||
| 231 | CHECK(verify_spirv_structure(vs_w, kStorageOutput, vs_locs, unpacks, privs, ep_iface)); | ||
| 232 | CHECK(privs == 6); // 3 unneeded static half pairs (params 1, 2, 3) demoted to Private | ||
| 233 | CHECK(unpacks == 4); // 1 missing param (param 7) * 4 vec4 channels | ||
| 234 | for (std::uint32_t loc = 0; loc < 16; ++loc) CHECK(vs_locs.count(loc) == 1); | ||
| 235 | for (std::uint32_t loc = 20; loc <= 29; ++loc) { | ||
| 236 | CHECK(vs_locs.count(loc) == 1); | ||
| 237 | CHECK(ep_iface.count(vs_locs[loc]) == 1); | ||
| 238 | } | ||
| 239 | CHECK(vs_locs.size() == 26); // 16 raw + 10 decoded halves; all <= 29 | ||
| 240 | CHECK(vs_locs.rbegin()->first == 29); | ||
| 241 | } | ||
| 242 | |||
| 243 | // 3. PS relocation: VS exports raw param0..param15, PS only read raw attr0..13 so PS placed attr7 at [14, 15] | ||
| 244 | // (colliding with VS's raw param14/param15). Both VS and PS must relocate attr7 to [28, 29]. | ||
| 245 | { | ||
| 246 | ShaderEntry vs_e, ps_e; | ||
| 247 | ps_e.f16_halves = {{7, {14, 15}}}; | ||
| 248 | std::vector<std::uint32_t> ps_raw; | ||
| 249 | for (std::uint32_t a = 0; a < 14; ++a) ps_raw.push_back(a); | ||
| 250 | |||
| 251 | auto vs_w = build_vs(0x00010500u, 16, {}); | ||
| 252 | auto ps_w = build_ps(0x00010500u, ps_raw, ps_e.f16_halves); | ||
| 253 | std::string err; | ||
| 254 | CHECK(link_f16_halves(vs_w, vs_e, ps_w, ps_e, &err)); | ||
| 255 | |||
| 256 | std::map<std::uint32_t, std::uint32_t> vs_locs, ps_locs; | ||
| 257 | int vs_unpacks = 0, vs_privs = 0, ps_unpacks = 0, ps_privs = 0; | ||
| 258 | std::set<std::uint32_t> vs_ep, ps_ep; | ||
| 259 | CHECK(verify_spirv_structure(vs_w, kStorageOutput, vs_locs, vs_unpacks, vs_privs, vs_ep)); | ||
| 260 | CHECK(verify_spirv_structure(ps_w, kStorageInput, ps_locs, ps_unpacks, ps_privs, ps_ep)); | ||
| 261 | CHECK(vs_unpacks == 4); | ||
| 262 | CHECK(vs_locs.count(28) == 1 && vs_locs.count(29) == 1); | ||
| 263 | CHECK(ps_locs.count(28) == 1 && ps_locs.count(29) == 1); | ||
| 264 | CHECK(!ps_locs.count(14) && !ps_locs.count(15)); | ||
| 265 | } | ||
| 266 | |||
| 267 | // 4. SPIR-V 1.3 OpEntryPoint drops demoted Private variables from interface list (SPIR-V 1.4+ keeps them). | ||
| 268 | { | ||
| 269 | ShaderEntry vs_e, ps_e; | ||
| 270 | vs_e.f16_halves = {{0, {28, 29}}, {1, {26, 27}}}; | ||
| 271 | ps_e.f16_halves = {{0, {26, 27}}}; // force patching; param 1 is demoted | ||
| 272 | auto vs_13 = build_vs(0x00010300u, 2, vs_e.f16_halves); | ||
| 273 | auto ps_13 = build_ps(0x00010300u, {0, 1}, ps_e.f16_halves); | ||
| 274 | std::string err; | ||
| 275 | CHECK(link_f16_halves(vs_13, vs_e, ps_13, ps_e, &err)); | ||
| 276 | std::map<std::uint32_t, std::uint32_t> locs; | ||
| 277 | int unpacks = 0, privs = 0; | ||
| 278 | std::set<std::uint32_t> ep_iface; | ||
| 279 | CHECK(verify_spirv_structure(vs_13, kStorageOutput, locs, unpacks, privs, ep_iface)); | ||
| 280 | CHECK(privs == 2); | ||
| 281 | // Position (9) + 2 raw (10,11) + 2 reused halves (12,13) = 5 interface vars; demoted 14,15 dropped in v1.3. | ||
| 282 | CHECK(ep_iface.size() == 5); | ||
| 283 | } | ||
| 284 | |||
| 285 | // 5. Genuine budget overflow (>30 locations needed): returns false, leaves modules unchanged. | ||
| 286 | { | ||
| 287 | ShaderEntry vs_e, ps_e; | ||
| 288 | ps_e.f16_halves = {{0, {28, 29}}}; | ||
| 289 | auto vs_w = build_vs(0x00010500u, 29, {}); // 29 raw outputs (0..28) -> only location 29 is free (< 2 needed) | ||
| 290 | auto ps_w = build_ps(0x00010500u, {0}, ps_e.f16_halves); | ||
| 291 | const auto vs_orig = vs_w, ps_orig = ps_w; | ||
| 292 | std::string err; | ||
| 293 | CHECK(!link_f16_halves(vs_w, vs_e, ps_w, ps_e, &err)); | ||
| 294 | CHECK(!err.empty()); | ||
| 295 | CHECK(vs_w == vs_orig && ps_w == ps_orig); | ||
| 296 | } | ||
| 297 | |||
| 298 | std::printf("spirv_f16_halves_test: all checks passed\n"); | ||
| 299 | return 0; | ||
| 300 | } | ||
diff --git a/runtime/test/startup_trace_test.cpp b/runtime/test/startup_trace_test.cpp index 8df64680f..ca085a4cf 100644 --- a/runtime/test/startup_trace_test.cpp +++ b/runtime/test/startup_trace_test.cpp | |||
| @@ -139,6 +139,14 @@ bool call_faulting(void* fn) { | |||
| 139 | return false; | 139 | return false; |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | void raise_bad_dbg_print() { | ||
| 143 | __try { | ||
| 144 | ULONG_PTR args[2] = {5, 0x1000}; // invalid string pointer in DBG_PRINTEXCEPTION_C | ||
| 145 | RaiseException(0x40010006, 0, 2, args); | ||
| 146 | } __except (EXCEPTION_EXECUTE_HANDLER) { | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 142 | std::string hex_rva(uint32_t rva) { | 150 | std::string hex_rva(uint32_t rva) { |
| 143 | char b[16]; | 151 | char b[16]; |
| 144 | std::snprintf(b, sizeof b, "+0x%x", rva); | 152 | std::snprintf(b, sizeof b, "+0x%x", rva); |
| @@ -211,6 +219,8 @@ void test_trace(const fs::path& dir) { | |||
| 211 | reinterpret_cast<VoidFn>(m.base + caller_rva(0))(nullptr); // second call: no second event | 219 | reinterpret_cast<VoidFn>(m.base + caller_rva(0))(nullptr); // second call: no second event |
| 212 | reinterpret_cast<VoidFn>(m.base + caller_rva(1))(kDebugText); | 220 | reinterpret_cast<VoidFn>(m.base + caller_rva(1))(kDebugText); |
| 213 | reinterpret_cast<VoidFn>(m.base + caller_rva(1))(kAnsiText); | 221 | reinterpret_cast<VoidFn>(m.base + caller_rva(1))(kAnsiText); |
| 222 | raise_bad_dbg_print(); | ||
| 223 | OutputDebugStringA("after_bad_dbg_print"); | ||
| 214 | check(call_faulting(m.base + kFaultRva), "the access violation reached the test's handler"); | 224 | check(call_faulting(m.base + kFaultRva), "the access violation reached the test's handler"); |
| 215 | rt::startup_trace::event("exit", "\"code\":0"); | 225 | rt::startup_trace::event("exit", "\"code\":0"); |
| 216 | } | 226 | } |
| @@ -240,6 +250,11 @@ void test_trace(const fs::path& dir) { | |||
| 240 | bool ansi_found = false; | 250 | bool ansi_found = false; |
| 241 | for (auto& l : lines) ansi_found |= l.find("\"kind\":\"debug_string\"") != std::string::npos && l.find(ansi) != std::string::npos; | 251 | for (auto& l : lines) ansi_found |= l.find("\"kind\":\"debug_string\"") != std::string::npos && l.find(ansi) != std::string::npos; |
| 242 | check(ansi_found, "an ANSI debug string with a byte above 0x7f is written as UTF-8"); | 252 | check(ansi_found, "an ANSI debug string with a byte above 0x7f is written as UTF-8"); |
| 253 | bool after_bad_found = false; | ||
| 254 | for (auto& l : lines) | ||
| 255 | after_bad_found |= | ||
| 256 | l.find("\"kind\":\"debug_string\"") != std::string::npos && l.find("after_bad_dbg_print") != std::string::npos; | ||
| 257 | check(after_bad_found, "an SEH fault inside the VEH does not leave in_handler stuck true"); | ||
| 243 | check(valid_utf8(trace), "the whole trace is valid UTF-8"); | 258 | check(valid_utf8(trace), "the whole trace is valid UTF-8"); |
| 244 | 259 | ||
| 245 | const std::string* e = find_line(lines, "exception"); | 260 | const std::string* e = find_line(lines, "exception"); |
diff --git a/runtime/test/vk_bindless_test.cpp b/runtime/test/vk_bindless_test.cpp index 91f954cf3..6b72034e5 100644 --- a/runtime/test/vk_bindless_test.cpp +++ b/runtime/test/vk_bindless_test.cpp | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #include "vulkan_loader.h" | 22 | #include "vulkan_loader.h" |
| 23 | #include "vk_device_pick.h" | 23 | #include "vk_device_pick.h" |
| 24 | #include "vk_shader_fma.h" | 24 | #include "vk_shader_fma.h" |
| 25 | #include "vk_pc_tail.h" | ||
| 25 | #include "../src/vulkan_bindless.h" | 26 | #include "../src/vulkan_bindless.h" |
| 26 | 27 | ||
| 27 | #include <algorithm> | 28 | #include <algorithm> |
| @@ -192,7 +193,10 @@ int main(int argc, char** argv) { | |||
| 192 | std::printf("device: %s%s\n", props.properties.deviceName, validation ? " (validation on)" : ""); | 193 | std::printf("device: %s%s\n", props.properties.deviceName, validation ? " (validation on)" : ""); |
| 193 | // The pipeline layout pushes the 144-byte translated user-data block. A device with fewer push constant bytes | 194 | // The pipeline layout pushes the 144-byte translated user-data block. A device with fewer push constant bytes |
| 194 | // (128 on Intel Arc and some AMD drivers) can't create it: a device limit, not a wrong result (TEST-149). | 195 | // (128 on Intel Arc and some AMD drivers) can't create it: a device limit, not a wrong result (TEST-149). |
| 195 | constexpr std::uint32_t push_bytes = 144; | 196 | // LEONIDA_PC_TAIL_UBO=1 (rdna2spirv.py --pc-tail-ubo): s0..s31 only, 128 bytes; the heap base, if a stage reads |
| 197 | // it, is in a uniform block at set 1 (vk_pc_tail.h). | ||
| 198 | const bool pc_tail = leonida::vk_test::pc_tail_requested(); | ||
| 199 | const std::uint32_t push_bytes = pc_tail ? 128u : 144u; | ||
| 196 | if (props.properties.limits.maxPushConstantsSize < push_bytes) { | 200 | if (props.properties.limits.maxPushConstantsSize < push_bytes) { |
| 197 | std::printf("unsupported: need %u push constant bytes, device has %u\n", push_bytes, | 201 | std::printf("unsupported: need %u push constant bytes, device has %u\n", push_bytes, |
| 198 | props.properties.limits.maxPushConstantsSize); | 202 | props.properties.limits.maxPushConstantsSize); |
| @@ -201,7 +205,8 @@ int main(int argc, char** argv) { | |||
| 201 | 205 | ||
| 202 | // The features ps_tex's metadata names (bufferDeviceAddress, runtimeDescriptorArray, shaderInt64), dynamic | 206 | // The features ps_tex's metadata names (bufferDeviceAddress, runtimeDescriptorArray, shaderInt64), dynamic |
| 203 | // indexing of the image array, and whichever descriptor-indexing flags the set can use. | 207 | // indexing of the image array, and whichever descriptor-indexing flags the set can use. |
| 204 | VkPhysicalDeviceVulkan12Features have12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; | 208 | VkPhysicalDeviceVulkan11Features have11{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES}; |
| 209 | VkPhysicalDeviceVulkan12Features have12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, &have11}; | ||
| 205 | VkPhysicalDeviceFeatures2 have{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &have12}; | 210 | VkPhysicalDeviceFeatures2 have{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &have12}; |
| 206 | vkGetPhysicalDeviceFeatures2(pd, &have); | 211 | vkGetPhysicalDeviceFeatures2(pd, &have); |
| 207 | if (!have12.bufferDeviceAddress || !have12.runtimeDescriptorArray || !have.features.shaderInt64 || | 212 | if (!have12.bufferDeviceAddress || !have12.runtimeDescriptorArray || !have.features.shaderInt64 || |
| @@ -215,7 +220,10 @@ int main(int argc, char** argv) { | |||
| 215 | have12.descriptorBindingStorageImageUpdateAfterBind && | 220 | have12.descriptorBindingStorageImageUpdateAfterBind && |
| 216 | have12.descriptorBindingStorageBufferUpdateAfterBind; | 221 | have12.descriptorBindingStorageBufferUpdateAfterBind; |
| 217 | device_flags.partially_bound = have12.descriptorBindingPartiallyBound == VK_TRUE; | 222 | device_flags.partially_bound = have12.descriptorBindingPartiallyBound == VK_TRUE; |
| 218 | VkPhysicalDeviceVulkan12Features enable12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; | 223 | // Translated vertex shaders read BaseVertex / BaseInstance (DrawParameters) for the zero-based v0 / v3. |
| 224 | VkPhysicalDeviceVulkan11Features enable11{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES}; | ||
| 225 | enable11.shaderDrawParameters = have11.shaderDrawParameters; | ||
| 226 | VkPhysicalDeviceVulkan12Features enable12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, &enable11}; | ||
| 219 | enable12.bufferDeviceAddress = VK_TRUE; | 227 | enable12.bufferDeviceAddress = VK_TRUE; |
| 220 | enable12.runtimeDescriptorArray = VK_TRUE; | 228 | enable12.runtimeDescriptorArray = VK_TRUE; |
| 221 | enable12.descriptorIndexing = have12.descriptorIndexing; | 229 | enable12.descriptorIndexing = have12.descriptorIndexing; |
| @@ -419,17 +427,34 @@ int main(int argc, char** argv) { | |||
| 419 | CHECK(make_buffer(VkDeviceSize(W) * H * 16, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &readback, &readback_map)); | 427 | CHECK(make_buffer(VkDeviceSize(W) * H * 16, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &readback, &readback_map)); |
| 420 | 428 | ||
| 421 | VkShaderModule vs, fs; | 429 | VkShaderModule vs, fs; |
| 430 | bool tail_block = false; | ||
| 422 | for (int stage = 0; stage < 2; ++stage) { | 431 | for (int stage = 0; stage < 2; ++stage) { |
| 423 | const auto code = read_spv(argv[1 + stage]); | 432 | const auto code = read_spv(argv[1 + stage]); |
| 424 | if (code.empty()) { | 433 | if (code.empty()) { |
| 425 | std::fprintf(stderr, "cannot read %s\n", argv[1 + stage]); | 434 | std::fprintf(stderr, "cannot read %s\n", argv[1 + stage]); |
| 426 | return 1; | 435 | return 1; |
| 427 | } | 436 | } |
| 437 | if (pc_tail && leonida::vk_test::spirv_declares_set(code.data(), code.size() * 4, leonida::vk_test::pc_tail_set)) | ||
| 438 | tail_block = true; | ||
| 428 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; | 439 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 429 | smi.codeSize = code.size() * 4; | 440 | smi.codeSize = code.size() * 4; |
| 430 | smi.pCode = code.data(); | 441 | smi.pCode = code.data(); |
| 431 | CHECK(vkCreateShaderModule(dev, &smi, nullptr, stage ? &fs : &vs)); | 442 | CHECK(vkCreateShaderModule(dev, &smi, nullptr, stage ? &fs : &vs)); |
| 432 | } | 443 | } |
| 444 | // One tail block for every variant below: each draw's tail is the same heap base. | ||
| 445 | leonida::vk_test::PcTail tail; | ||
| 446 | if (tail_block && !tail.create(vkGetDeviceProcAddr, dev, mp, props.properties.limits.minUniformBufferOffsetAlignment, | ||
| 447 | VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 1)) { | ||
| 448 | std::fprintf(stderr, "FAILED creating the --pc-tail-ubo block\n"); | ||
| 449 | return 1; | ||
| 450 | } | ||
| 451 | auto bind_tail = [&](VkCommandBuffer cb, VkPipelineLayout layout, const std::uint32_t* block) { | ||
| 452 | if (!tail_block) return; | ||
| 453 | tail.write(0, block, 4); | ||
| 454 | const std::uint32_t offset = tail.offset(0); | ||
| 455 | vkCmdBindDescriptorSets(cb, VK_PIPELINE_BIND_POINT_GRAPHICS, layout, leonida::vk_test::pc_tail_set, 1, &tail.set, | ||
| 456 | 1, &offset); | ||
| 457 | }; | ||
| 433 | VkCommandPoolCreateInfo cpi{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; | 458 | VkCommandPoolCreateInfo cpi{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; |
| 434 | cpi.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; | 459 | cpi.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 435 | cpi.queueFamilyIndex = qi; | 460 | cpi.queueFamilyIndex = qi; |
| @@ -566,6 +591,8 @@ int main(int argc, char** argv) { | |||
| 566 | pli.pSetLayouts = &set_layout; | 591 | pli.pSetLayouts = &set_layout; |
| 567 | pli.pushConstantRangeCount = 1; | 592 | pli.pushConstantRangeCount = 1; |
| 568 | pli.pPushConstantRanges = &push; | 593 | pli.pPushConstantRanges = &push; |
| 594 | const VkDescriptorSetLayout set_layouts[] = {set_layout, tail.set_layout}; | ||
| 595 | if (tail_block) { pli.setLayoutCount = 2; pli.pSetLayouts = set_layouts; } | ||
| 569 | VkPipelineLayout pipeline_layout; | 596 | VkPipelineLayout pipeline_layout; |
| 570 | CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pipeline_layout)); | 597 | CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pipeline_layout)); |
| 571 | VkPipelineShaderStageCreateInfo stages[2]{{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}, | 598 | VkPipelineShaderStageCreateInfo stages[2]{{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}, |
| @@ -632,7 +659,8 @@ int main(int argc, char** argv) { | |||
| 632 | block[2] = table_va; // s2:s3 = console VA of the descriptor table | 659 | block[2] = table_va; // s2:s3 = console VA of the descriptor table |
| 633 | block[32] = std::uint32_t(heap_base); | 660 | block[32] = std::uint32_t(heap_base); |
| 634 | block[33] = std::uint32_t(heap_base >> 32); | 661 | block[33] = std::uint32_t(heap_base >> 32); |
| 635 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(block), block); | 662 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, push_bytes, block); |
| 663 | bind_tail(cmd, pipeline_layout, block); | ||
| 636 | vkCmdDraw(cmd, 3, 1, 0, 0); | 664 | vkCmdDraw(cmd, 3, 1, 0, 0); |
| 637 | vkCmdEndRenderPass(cmd); | 665 | vkCmdEndRenderPass(cmd); |
| 638 | VkBufferImageCopy rc{}; | 666 | VkBufferImageCopy rc{}; |
| @@ -780,7 +808,8 @@ int main(int argc, char** argv) { | |||
| 780 | block[32] = std::uint32_t(heap_base); | 808 | block[32] = std::uint32_t(heap_base); |
| 781 | block[33] = std::uint32_t(heap_base >> 32); | 809 | block[33] = std::uint32_t(heap_base >> 32); |
| 782 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, | 810 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, |
| 783 | sizeof(block), block); | 811 | push_bytes, block); |
| 812 | bind_tail(cmd, pipeline_layout, block); | ||
| 784 | vkCmdDraw(cmd, 3, 1, 0, 0); | 813 | vkCmdDraw(cmd, 3, 1, 0, 0); |
| 785 | vkCmdEndRenderPass(cmd); | 814 | vkCmdEndRenderPass(cmd); |
| 786 | VkMemoryBarrier after{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; | 815 | VkMemoryBarrier after{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; |
diff --git a/runtime/test/vk_compute_test.cpp b/runtime/test/vk_compute_test.cpp index bcc6683ef..f0f7c4605 100644 --- a/runtime/test/vk_compute_test.cpp +++ b/runtime/test/vk_compute_test.cpp | |||
| @@ -11,10 +11,12 @@ | |||
| 11 | // VKC_SGPRS=w4,w5,... (env): set s4, s5, ... (decimal or 0x hex, up to s31), the user SGPRs after the output V#, | 11 | // VKC_SGPRS=w4,w5,... (env): set s4, s5, ... (decimal or 0x hex, up to s31), the user SGPRs after the output V#, |
| 12 | // so a test can take input words (cs_user_sgprs.asm). They are zero otherwise. Same syntax as vk_harness's VKH_SGPRS. | 12 | // so a test can take input words (cs_user_sgprs.asm). They are zero otherwise. Same syntax as vk_harness's VKH_SGPRS. |
| 13 | // Contract (docs/design.md): push constants = s0..s31 (128 bytes), heap base lo/hi, code base lo/hi (144 bytes). | 13 | // Contract (docs/design.md): push constants = s0..s31 (128 bytes), heap base lo/hi, code base lo/hi (144 bytes). |
| 14 | // LEONIDA_PC_TAIL_UBO=1 (modules from rdna2spirv.py --pc-tail-ubo): s0..s31 only, the rest at set 1 (vk_pc_tail.h). | ||
| 14 | // The output buffer is the "heap": Xbox VA 0 maps to its device address, and s[0:3] hold a V# with base 0. | 15 | // The output buffer is the "heap": Xbox VA 0 maps to its device address, and s[0:3] hold a V# with base 0. |
| 15 | #include "vulkan_loader.h" | 16 | #include "vulkan_loader.h" |
| 16 | #include "vk_device_pick.h" | 17 | #include "vk_device_pick.h" |
| 17 | #include "vk_shader_fma.h" | 18 | #include "vk_shader_fma.h" |
| 19 | #include "vk_pc_tail.h" | ||
| 18 | 20 | ||
| 19 | #include <cctype> | 21 | #include <cctype> |
| 20 | #include <cmath> | 22 | #include <cmath> |
| @@ -151,6 +153,13 @@ int main(int argc, char** argv) { | |||
| 151 | std::fprintf(stderr, "full 64-wide compute subgroups unavailable\n"); | 153 | std::fprintf(stderr, "full 64-wide compute subgroups unavailable\n"); |
| 152 | return 77; | 154 | return 77; |
| 153 | } | 155 | } |
| 156 | std::ifstream f(argv[1], std::ios::binary); | ||
| 157 | std::vector<char> code((std::istreambuf_iterator<char>(f)), {}); | ||
| 158 | const bool needs_float64 = leonida::vk_test::spirv_declares_capability(code.data(), code.size(), 10); // Float64 | ||
| 159 | if (needs_float64 && !f2q.features.shaderFloat64) { | ||
| 160 | std::fprintf(stderr, "unsupported: %s uses Float64 and the device has no shaderFloat64\n", argv[1]); | ||
| 161 | return 77; | ||
| 162 | } | ||
| 154 | VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; | 163 | VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; |
| 155 | VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; | 164 | VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; |
| 156 | f12.bufferDeviceAddress = VK_TRUE; | 165 | f12.bufferDeviceAddress = VK_TRUE; |
| @@ -161,6 +170,7 @@ int main(int argc, char** argv) { | |||
| 161 | } | 170 | } |
| 162 | VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; | 171 | VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; |
| 163 | f2.features.shaderInt64 = VK_TRUE; | 172 | f2.features.shaderInt64 = VK_TRUE; |
| 173 | f2.features.shaderFloat64 = needs_float64; | ||
| 164 | f2.pNext = &f12; | 174 | f2.pNext = &f12; |
| 165 | // OpFmaKHR (rdna2spirv.py --fma khr): VK_KHR_shader_fma, when the device has it. | 175 | // OpFmaKHR (rdna2spirv.py --fma khr): VK_KHR_shader_fma, when the device has it. |
| 166 | leonida::vk_test::ShaderFma fma; | 176 | leonida::vk_test::ShaderFma fma; |
| @@ -178,7 +188,7 @@ int main(int argc, char** argv) { | |||
| 178 | LOADD(vkCreatePipelineLayout); LOADD(vkCreateComputePipelines); LOADD(vkCreateCommandPool); | 188 | LOADD(vkCreatePipelineLayout); LOADD(vkCreateComputePipelines); LOADD(vkCreateCommandPool); |
| 179 | LOADD(vkAllocateCommandBuffers); LOADD(vkBeginCommandBuffer); LOADD(vkCmdBindPipeline); | 189 | LOADD(vkAllocateCommandBuffers); LOADD(vkBeginCommandBuffer); LOADD(vkCmdBindPipeline); |
| 180 | LOADD(vkCmdPushConstants); LOADD(vkCmdDispatch); LOADD(vkEndCommandBuffer); LOADD(vkQueueSubmit); | 190 | LOADD(vkCmdPushConstants); LOADD(vkCmdDispatch); LOADD(vkEndCommandBuffer); LOADD(vkQueueSubmit); |
| 181 | LOADD(vkQueueWaitIdle); LOADD(vkCmdPipelineBarrier); LOADD(vkCmdDispatchBase); | 191 | LOADD(vkQueueWaitIdle); LOADD(vkCmdPipelineBarrier); LOADD(vkCmdDispatchBase); LOADD(vkCmdBindDescriptorSets); |
| 182 | VkQueue q; vkGetDeviceQueue(dev, qi, 0, &q); | 192 | VkQueue q; vkGetDeviceQueue(dev, qi, 0, &q); |
| 183 | 193 | ||
| 184 | // Output buffer = heap. Host-visible so the result can be read back directly. | 194 | // Output buffer = heap. Host-visible so the result can be read back directly. |
| @@ -227,15 +237,28 @@ int main(int argc, char** argv) { | |||
| 227 | bai.buffer = buf; | 237 | bai.buffer = buf; |
| 228 | const uint64_t heap = vkGetBufferDeviceAddress(dev, &bai); | 238 | const uint64_t heap = vkGetBufferDeviceAddress(dev, &bai); |
| 229 | 239 | ||
| 230 | std::ifstream f(argv[1], std::ios::binary); | ||
| 231 | std::vector<char> code((std::istreambuf_iterator<char>(f)), {}); | ||
| 232 | if (!fma.accepts(code.data(), code.size(), argv[1])) return 77; | 240 | if (!fma.accepts(code.data(), code.size(), argv[1])) return 77; |
| 233 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; | 241 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 234 | smi.codeSize = code.size(); smi.pCode = reinterpret_cast<const uint32_t*>(code.data()); | 242 | smi.codeSize = code.size(); smi.pCode = reinterpret_cast<const uint32_t*>(code.data()); |
| 235 | VkShaderModule sm; CHECK(vkCreateShaderModule(dev, &smi, nullptr, &sm)); | 243 | VkShaderModule sm; CHECK(vkCreateShaderModule(dev, &smi, nullptr, &sm)); |
| 236 | VkPushConstantRange pcr{VK_SHADER_STAGE_COMPUTE_BIT, 0, 144}; | 244 | // 144 push-constant bytes: s0..s31, heap base, code base. With LEONIDA_PC_TAIL_UBO=1 (rdna2spirv.py |
| 245 | // --pc-tail-ubo) only s0..s31; the tail, if the module reads it, is a uniform block at set 1 (vk_pc_tail.h), one | ||
| 246 | // slot for the dispatch and one per workgroup_yz origin. | ||
| 247 | const bool pc_tail = leonida::vk_test::pc_tail_requested(); | ||
| 248 | const uint32_t pc_bytes = pc_tail ? 128u : 144u; | ||
| 249 | leonida::vk_test::PcTail tail; | ||
| 250 | const bool tail_block = pc_tail && | ||
| 251 | leonida::vk_test::spirv_declares_set(code.data(), code.size(), leonida::vk_test::pc_tail_set); | ||
| 252 | if (tail_block && !tail.create(vkGetDeviceProcAddr, dev, mp, props.limits.minUniformBufferOffsetAlignment, | ||
| 253 | VK_SHADER_STAGE_COMPUTE_BIT, 1 + origins)) { | ||
| 254 | std::fprintf(stderr, "FAILED creating the --pc-tail-ubo block\n"); | ||
| 255 | return 1; | ||
| 256 | } | ||
| 257 | VkPushConstantRange pcr{VK_SHADER_STAGE_COMPUTE_BIT, 0, pc_bytes}; | ||
| 237 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; | 258 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; |
| 238 | pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; | 259 | pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; |
| 260 | const VkDescriptorSetLayout tail_layouts[] = {tail.empty_layout, tail.set_layout}; | ||
| 261 | if (tail_block) { pli.setLayoutCount = 2; pli.pSetLayouts = tail_layouts; } | ||
| 239 | VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); | 262 | VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); |
| 240 | VkComputePipelineCreateInfo cpi{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO}; | 263 | VkComputePipelineCreateInfo cpi{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO}; |
| 241 | if (workgroup_yz) cpi.flags |= VK_PIPELINE_CREATE_DISPATCH_BASE_BIT; | 264 | if (workgroup_yz) cpi.flags |= VK_PIPELINE_CREATE_DISPATCH_BASE_BIT; |
| @@ -270,14 +293,27 @@ int main(int argc, char** argv) { | |||
| 270 | VkCommandBufferBeginInfo cbi{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; | 293 | VkCommandBufferBeginInfo cbi{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; |
| 271 | CHECK(vkBeginCommandBuffer(cmd, &cbi)); | 294 | CHECK(vkBeginCommandBuffer(cmd, &cbi)); |
| 272 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipe); | 295 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipe); |
| 273 | vkCmdPushConstants(cmd, pl, VK_SHADER_STAGE_COMPUTE_BIT, 0, 144, pc); | 296 | vkCmdPushConstants(cmd, pl, VK_SHADER_STAGE_COMPUTE_BIT, 0, pc_bytes, pc); |
| 297 | auto bind_tail = [&](uint32_t slot) { | ||
| 298 | if (!tail_block) return; | ||
| 299 | tail.write(slot, pc, 4); | ||
| 300 | const uint32_t offset = tail.offset(slot); | ||
| 301 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pl, leonida::vk_test::pc_tail_set, 1, &tail.set, | ||
| 302 | 1, &offset); | ||
| 303 | }; | ||
| 304 | bind_tail(0); | ||
| 274 | vkCmdDispatch(cmd, groups, groups_y, groups_z); | 305 | vkCmdDispatch(cmd, groups, groups_y, groups_z); |
| 275 | // A permutation within one axis can leave the full-grid histogram unchanged. Dispatch one group at | 306 | // A permutation within one axis can leave the full-grid histogram unchanged. Dispatch one group at |
| 276 | // each known origin into its own histogram, selected by the host independently of the shader's SGPRs. | 307 | // each known origin into its own histogram, selected by the host independently of the shader's SGPRs. |
| 277 | for (uint32_t g = 0; g < origins; ++g) { | 308 | for (uint32_t g = 0; g < origins; ++g) { |
| 278 | const uint64_t base = heap + (g + 1) * yz_bins * sizeof(uint32_t); | 309 | const uint64_t base = heap + (g + 1) * yz_bins * sizeof(uint32_t); |
| 279 | const uint32_t address[] = {uint32_t(base), uint32_t(base >> 32)}; | 310 | const uint32_t address[] = {uint32_t(base), uint32_t(base >> 32)}; |
| 280 | vkCmdPushConstants(cmd, pl, VK_SHADER_STAGE_COMPUTE_BIT, 32 * sizeof(uint32_t), sizeof(address), address); | 311 | if (pc_tail) { |
| 312 | pc[32] = address[0]; pc[33] = address[1]; // the heap base is the tail's dwords 0..1 | ||
| 313 | bind_tail(g + 1); | ||
| 314 | } else { | ||
| 315 | vkCmdPushConstants(cmd, pl, VK_SHADER_STAGE_COMPUTE_BIT, 32 * sizeof(uint32_t), sizeof(address), address); | ||
| 316 | } | ||
| 281 | vkCmdDispatchBase(cmd, g % groups, (g / groups) % groups_y, g / (groups * groups_y), 1, 1, 1); | 317 | vkCmdDispatchBase(cmd, g % groups, (g / groups) % groups_y, g / (groups * groups_y), 1, 1, 1); |
| 282 | } | 318 | } |
| 283 | VkMemoryBarrier readback{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; | 319 | VkMemoryBarrier readback{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; |
diff --git a/runtime/test/vk_harness.cpp b/runtime/test/vk_harness.cpp index fe9ae194a..abaacb348 100644 --- a/runtime/test/vk_harness.cpp +++ b/runtime/test/vk_harness.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "vulkan_loader.h" | 23 | #include "vulkan_loader.h" |
| 24 | #include "vk_device_pick.h" | 24 | #include "vk_device_pick.h" |
| 25 | #include "vk_shader_fma.h" | 25 | #include "vk_shader_fma.h" |
| 26 | #include "vk_pc_tail.h" | ||
| 26 | 27 | ||
| 27 | #include <cctype> | 28 | #include <cctype> |
| 28 | #include <cstddef> | 29 | #include <cstddef> |
| @@ -296,7 +297,16 @@ int main(int argc, char** argv) { | |||
| 296 | // fewer bytes (128, the Vulkan minimum, as on some Intel Arc drivers and AMD's Windows driver for RDNA2 iGPUs) | 297 | // fewer bytes (128, the Vulkan minimum, as on some Intel Arc drivers and AMD's Windows driver for RDNA2 iGPUs) |
| 297 | // cannot take that range: declaring it anyway is invalid, and there a shader reading past the limit crashed or | 298 | // cannot take that range: declaring it anyway is invalid, and there a shader reading past the limit crashed or |
| 298 | // hung the device. 77, as vk_texture_test and vk_bindless_test: a device limit, not a wrong result (D3D-14). | 299 | // hung the device. 77, as vk_texture_test and vk_bindless_test: a device limit, not a wrong result (D3D-14). |
| 299 | const uint32_t pc_bytes = mesh_compute ? 152u : 144u; | 300 | // LEONIDA_PC_TAIL_UBO=1 (rdna2spirv.py --pc-tail-ubo): s0..s31 only, 128 bytes, which every device has; the |
| 301 | // tail is a uniform block at set 1 (vk_pc_tail.h). tools/mesh_compute_vs.py's vertex shader still reads the | ||
| 302 | // --mesh-compute output address from push constants, so that combination isn't run. | ||
| 303 | const bool pc_tail = leonida::vk_test::pc_tail_requested(); | ||
| 304 | if (pc_tail && mesh_compute) { | ||
| 305 | std::fprintf(stderr, "unsupported: --mesh-compute's vertex shader reads the output address from push " | ||
| 306 | "constants, not from the --pc-tail-ubo block\n"); | ||
| 307 | return 77; | ||
| 308 | } | ||
| 309 | const uint32_t pc_bytes = pc_tail ? 128u : mesh_compute ? 152u : 144u; | ||
| 300 | if (props.limits.maxPushConstantsSize < pc_bytes) { | 310 | if (props.limits.maxPushConstantsSize < pc_bytes) { |
| 301 | std::fprintf(stderr, "unsupported: need %u push constant bytes, device has %u\n", pc_bytes, | 311 | std::fprintf(stderr, "unsupported: need %u push constant bytes, device has %u\n", pc_bytes, |
| 302 | props.limits.maxPushConstantsSize); | 312 | props.limits.maxPushConstantsSize); |
| @@ -326,12 +336,22 @@ int main(int argc, char** argv) { | |||
| 326 | m8.maintenance8 = VK_TRUE; m8.pNext = chain; chain = &m8; | 336 | m8.maintenance8 = VK_TRUE; m8.pNext = chain; chain = &m8; |
| 327 | } | 337 | } |
| 328 | #endif | 338 | #endif |
| 339 | VkPhysicalDeviceVulkan11Features f11q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES}; | ||
| 329 | VkPhysicalDeviceVulkan12Features f12q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; | 340 | VkPhysicalDeviceVulkan12Features f12q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; |
| 341 | f12q.pNext = &f11q; | ||
| 330 | VkPhysicalDeviceVulkan13Features f13q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; | 342 | VkPhysicalDeviceVulkan13Features f13q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; |
| 331 | f13q.pNext = &f12q; | 343 | f13q.pNext = &f12q; |
| 332 | VkPhysicalDeviceFeatures2 f2q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; | 344 | VkPhysicalDeviceFeatures2 f2q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; |
| 333 | f2q.pNext = &f13q; | 345 | f2q.pNext = &f13q; |
| 334 | vkGetPhysicalDeviceFeatures2(pd, &f2q); | 346 | vkGetPhysicalDeviceFeatures2(pd, &f2q); |
| 347 | // Translated vertex shaders read BaseVertex / BaseInstance (DrawParameters) to give v0 / v3 the hardware's | ||
| 348 | // zero-based ids. | ||
| 349 | VkPhysicalDeviceVulkan11Features f11{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES}; | ||
| 350 | if (f11q.shaderDrawParameters) { | ||
| 351 | f11.shaderDrawParameters = VK_TRUE; | ||
| 352 | f11.pNext = chain; | ||
| 353 | chain = &f11; | ||
| 354 | } | ||
| 335 | VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; | 355 | VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; |
| 336 | if (f13q.subgroupSizeControl) { | 356 | if (f13q.subgroupSizeControl) { |
| 337 | f13.subgroupSizeControl = VK_TRUE; | 357 | f13.subgroupSizeControl = VK_TRUE; |
| @@ -390,6 +410,7 @@ int main(int argc, char** argv) { | |||
| 390 | LOADD(vkCreateCommandPool); LOADD(vkAllocateCommandBuffers); LOADD(vkBeginCommandBuffer); | 410 | LOADD(vkCreateCommandPool); LOADD(vkAllocateCommandBuffers); LOADD(vkBeginCommandBuffer); |
| 391 | LOADD(vkCmdBeginRenderPass); LOADD(vkCmdBindPipeline); LOADD(vkCmdDraw); LOADD(vkCmdEndRenderPass); | 411 | LOADD(vkCmdBeginRenderPass); LOADD(vkCmdBindPipeline); LOADD(vkCmdDraw); LOADD(vkCmdEndRenderPass); |
| 392 | LOADD(vkCmdBindVertexBuffers); LOADD(vkCmdBindIndexBuffer); LOADD(vkCmdDrawIndexed); | 412 | LOADD(vkCmdBindVertexBuffers); LOADD(vkCmdBindIndexBuffer); LOADD(vkCmdDrawIndexed); |
| 413 | LOADD(vkCmdPipelineBarrier); | ||
| 393 | LOADD(vkCmdCopyImageToBuffer); LOADD(vkEndCommandBuffer); LOADD(vkQueueSubmit); LOADD(vkQueueWaitIdle); | 414 | LOADD(vkCmdCopyImageToBuffer); LOADD(vkEndCommandBuffer); LOADD(vkQueueSubmit); LOADD(vkQueueWaitIdle); |
| 394 | LOADD(vkCreateBuffer); LOADD(vkGetBufferMemoryRequirements); LOADD(vkBindBufferMemory); LOADD(vkMapMemory); | 415 | LOADD(vkCreateBuffer); LOADD(vkGetBufferMemoryRequirements); LOADD(vkBindBufferMemory); LOADD(vkMapMemory); |
| 395 | VkQueue q; vkGetDeviceQueue(dev, qi, 0, &q); | 416 | VkQueue q; vkGetDeviceQueue(dev, qi, 0, &q); |
| @@ -462,8 +483,11 @@ int main(int argc, char** argv) { | |||
| 462 | VkFramebufferCreateInfo fbi{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO}; | 483 | VkFramebufferCreateInfo fbi{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO}; |
| 463 | fbi.renderPass = rp; fbi.attachmentCount = rpi.attachmentCount; fbi.pAttachments = views; fbi.width = W; fbi.height = H; fbi.layers = 1; | 484 | fbi.renderPass = rp; fbi.attachmentCount = rpi.attachmentCount; fbi.pAttachments = views; fbi.width = W; fbi.height = H; fbi.layers = 1; |
| 464 | VkFramebuffer fb; CHECK(vkCreateFramebuffer(dev, &fbi, nullptr, &fb)); | 485 | VkFramebuffer fb; CHECK(vkCreateFramebuffer(dev, &fbi, nullptr, &fb)); |
| 486 | bool tail_block = false; // some stage reads the --pc-tail-ubo block (declares set 1) | ||
| 465 | auto module = [&](const char* p, VkShaderModule* m) { | 487 | auto module = [&](const char* p, VkShaderModule* m) { |
| 466 | auto code = read_spv(p); | 488 | auto code = read_spv(p); |
| 489 | if (pc_tail && leonida::vk_test::spirv_declares_set(code.data(), code.size() * 4, leonida::vk_test::pc_tail_set)) | ||
| 490 | tail_block = true; | ||
| 467 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; | 491 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 468 | smi.codeSize = code.size() * 4; smi.pCode = code.data(); | 492 | smi.codeSize = code.size() * 4; smi.pCode = code.data(); |
| 469 | return vkCreateShaderModule(dev, &smi, nullptr, m); | 493 | return vkCreateShaderModule(dev, &smi, nullptr, m); |
| @@ -537,6 +561,14 @@ int main(int argc, char** argv) { | |||
| 537 | VkPushConstantRange pcr{pcs, 0, pc_bytes}; | 561 | VkPushConstantRange pcr{pcs, 0, pc_bytes}; |
| 538 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; | 562 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; |
| 539 | pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; | 563 | pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; |
| 564 | // --pc-tail-ubo: the tail block at set 1 (set 0 stays empty here), one slot for the one draw. | ||
| 565 | leonida::vk_test::PcTail tail; | ||
| 566 | if (tail_block && !tail.create(vkGetDeviceProcAddr, dev, mp, props.limits.minUniformBufferOffsetAlignment, pcs, 1)) { | ||
| 567 | std::fprintf(stderr, "FAILED creating the --pc-tail-ubo block\n"); | ||
| 568 | return 1; | ||
| 569 | } | ||
| 570 | const VkDescriptorSetLayout tail_layouts[] = {tail.empty_layout, tail.set_layout}; | ||
| 571 | if (tail_block) { pli.setLayoutCount = 2; pli.pSetLayouts = tail_layouts; } | ||
| 540 | VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); | 572 | VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); |
| 541 | VkGraphicsPipelineCreateInfo gpi{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; | 573 | VkGraphicsPipelineCreateInfo gpi{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; |
| 542 | gpi.stageCount = nstages; gpi.pStages = stages; | 574 | gpi.stageCount = nstages; gpi.pStages = stages; |
| @@ -674,7 +706,7 @@ int main(int argc, char** argv) { | |||
| 674 | auto push = reinterpret_cast<PFN_vkCmdPushConstants>(vkGetDeviceProcAddr(dev, "vkCmdPushConstants")); | 706 | auto push = reinterpret_cast<PFN_vkCmdPushConstants>(vkGetDeviceProcAddr(dev, "vkCmdPushConstants")); |
| 675 | if (mesh_compute) { | 707 | if (mesh_compute) { |
| 676 | // The mesh shader as compute, then make its stores visible to the vertex shader's reads. | 708 | // The mesh shader as compute, then make its stores visible to the vertex shader's reads. |
| 677 | LOADD(vkCmdDispatch); LOADD(vkCmdPipelineBarrier); | 709 | LOADD(vkCmdDispatch); |
| 678 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, cpipe); | 710 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, cpipe); |
| 679 | push(cmd, pl, pcs, 0, pc_bytes, pc); | 711 | push(cmd, pl, pcs, 0, pc_bytes, pc); |
| 680 | vkCmdDispatch(cmd, groups[0], groups[1], groups[2]); | 712 | vkCmdDispatch(cmd, groups[0], groups[1], groups[2]); |
| @@ -698,6 +730,13 @@ int main(int argc, char** argv) { | |||
| 698 | } | 730 | } |
| 699 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); | 731 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); |
| 700 | push(cmd, pl, pcs, 0, pc_bytes, pc); | 732 | push(cmd, pl, pcs, 0, pc_bytes, pc); |
| 733 | if (tail_block) { | ||
| 734 | LOADD(vkCmdBindDescriptorSets); | ||
| 735 | tail.write(0, pc, 4); // heap base (VKH_HEAP) and code base, as pc[32..35] are without the flag | ||
| 736 | const uint32_t offset = tail.offset(0); | ||
| 737 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pl, leonida::vk_test::pc_tail_set, 1, &tail.set, | ||
| 738 | 1, &offset); | ||
| 739 | } | ||
| 701 | // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251). | 740 | // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251). |
| 702 | const char* vertices_env = std::getenv("VKH_VERTICES"); | 741 | const char* vertices_env = std::getenv("VKH_VERTICES"); |
| 703 | if (draw_mesh_path) { | 742 | if (draw_mesh_path) { |
| @@ -712,11 +751,21 @@ int main(int argc, char** argv) { | |||
| 712 | vkCmdDraw(cmd, uint32_t(mesh_groups * mesh_prims * 3), 1, 0, 0); | 751 | vkCmdDraw(cmd, uint32_t(mesh_groups * mesh_prims * 3), 1, 0, 0); |
| 713 | else if (mesh) | 752 | else if (mesh) |
| 714 | reinterpret_cast<PFN_vkCmdDrawMeshTasksEXT>(vkGetDeviceProcAddr(dev, "vkCmdDrawMeshTasksEXT"))(cmd, groups[0], groups[1], groups[2]); | 753 | reinterpret_cast<PFN_vkCmdDrawMeshTasksEXT>(vkGetDeviceProcAddr(dev, "vkCmdDrawMeshTasksEXT"))(cmd, groups[0], groups[1], groups[2]); |
| 715 | else | 754 | else { |
| 716 | vkCmdDraw(cmd, 3, 1, 0, 0); | 755 | // VKH_DRAW=<firstVertex>,<firstInstance>: draw the triangle with non-zero bases (vs_base_ids). |
| 756 | unsigned first_vertex = 0, first_instance = 0; | ||
| 757 | if (const char* d = std::getenv("VKH_DRAW")) std::sscanf(d, "%u,%u", &first_vertex, &first_instance); | ||
| 758 | vkCmdDraw(cmd, 3, 1, first_vertex, first_instance); | ||
| 759 | } | ||
| 717 | vkCmdEndRenderPass(cmd); | 760 | vkCmdEndRenderPass(cmd); |
| 718 | VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1}; | 761 | VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1}; |
| 719 | vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, ®); | 762 | vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, ®); |
| 763 | // Make the image copy and any shader writes to the heap visible to the host after the queue wait. | ||
| 764 | VkMemoryBarrier readback{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; | ||
| 765 | readback.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT; | ||
| 766 | readback.dstAccessMask = VK_ACCESS_HOST_READ_BIT; | ||
| 767 | vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, | ||
| 768 | 1, &readback, 0, nullptr, 0, nullptr); | ||
| 720 | CHECK(vkEndCommandBuffer(cmd)); | 769 | CHECK(vkEndCommandBuffer(cmd)); |
| 721 | VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd; | 770 | VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd; |
| 722 | CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE)); | 771 | CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE)); |
diff --git a/runtime/test/vk_image_fuzz.cpp b/runtime/test/vk_image_fuzz.cpp index b38188b22..52b59d6e0 100644 --- a/runtime/test/vk_image_fuzz.cpp +++ b/runtime/test/vk_image_fuzz.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "../src/vulkan_device_filter.h" | 9 | #include "../src/vulkan_device_filter.h" |
| 10 | #include "../src/vulkan_bindless.h" | 10 | #include "../src/vulkan_bindless.h" |
| 11 | 11 | ||
| 12 | #include <cctype> | ||
| 12 | #include <cstdint> | 13 | #include <cstdint> |
| 13 | #include <cstdio> | 14 | #include <cstdio> |
| 14 | #include <cstdlib> | 15 | #include <cstdlib> |
| @@ -51,6 +52,14 @@ std::string trim(const std::string& s) { | |||
| 51 | std::size_t b = s.find_first_not_of(" \t\r\n"), e = s.find_last_not_of(" \t\r\n"); | 52 | std::size_t b = s.find_first_not_of(" \t\r\n"), e = s.find_last_not_of(" \t\r\n"); |
| 52 | return b == std::string::npos ? "" : s.substr(b, e - b + 1); | 53 | return b == std::string::npos ? "" : s.substr(b, e - b + 1); |
| 53 | } | 54 | } |
| 55 | // LEONIDA_PC_TAIL_UBO=1: shaders were translated with --pc-tail-ubo (128-byte push constants for s0..s31; the | ||
| 56 | // image_load fuzz shaders read neither heap base nor code base, so they declare no set-1 block). | ||
| 57 | bool pc_tail_requested() { | ||
| 58 | const char* v = std::getenv("LEONIDA_PC_TAIL_UBO"); | ||
| 59 | std::string s = trim(v ? v : ""); | ||
| 60 | for (char& c : s) c = char(std::tolower(static_cast<unsigned char>(c))); | ||
| 61 | return s == "1" || s == "true" || s == "yes" || s == "on"; | ||
| 62 | } | ||
| 54 | // Decimal or 0x-prefixed hex, whole string, no exceptions (strtoul with base 0 handles both). | 63 | // Decimal or 0x-prefixed hex, whole string, no exceptions (strtoul with base 0 handles both). |
| 55 | bool parse_u32(const std::string& text, std::uint32_t& out) { | 64 | bool parse_u32(const std::string& text, std::uint32_t& out) { |
| 56 | if (text.empty() || text.find_first_of(" \t\r\n") != std::string::npos) return false; | 65 | if (text.empty() || text.find_first_of(" \t\r\n") != std::string::npos) return false; |
| @@ -223,9 +232,11 @@ int main(int argc, char** argv) { | |||
| 223 | std::printf("unsupported: %s lacks the required image feature\n", spec.format_name.c_str()); | 232 | std::printf("unsupported: %s lacks the required image feature\n", spec.format_name.c_str()); |
| 224 | return unsupported; | 233 | return unsupported; |
| 225 | } | 234 | } |
| 226 | // The pipeline layout pushes the 144-byte translated user-data block. A device with fewer push constant bytes | 235 | // The pipeline layout pushes the translated user-data block (144 bytes by default, or 128 bytes under |
| 227 | // (128 on Intel Arc and some AMD drivers) can't create it: a device limit, not a wrong result (TEST-149). | 236 | // LEONIDA_PC_TAIL_UBO=1 for rdna2spirv.py --pc-tail-ubo). A device with fewer push constant bytes (128 on |
| 228 | constexpr std::uint32_t push_bytes = 144; | 237 | // Intel Arc and AMD's Windows driver for RDNA2 iGPUs) can't take 144: a device limit, not a wrong result (TEST-149). |
| 238 | const bool pc_tail = pc_tail_requested(); | ||
| 239 | const std::uint32_t push_bytes = pc_tail ? 128u : 144u; | ||
| 229 | if (props.properties.limits.maxPushConstantsSize < push_bytes) { | 240 | if (props.properties.limits.maxPushConstantsSize < push_bytes) { |
| 230 | std::printf("unsupported: need %u push constant bytes, device has %u\n", push_bytes, | 241 | std::printf("unsupported: need %u push constant bytes, device has %u\n", push_bytes, |
| 231 | props.properties.limits.maxPushConstantsSize); | 242 | props.properties.limits.maxPushConstantsSize); |
| @@ -561,7 +572,7 @@ int main(int argc, char** argv) { | |||
| 561 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bound, 0, nullptr); | 572 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bound, 0, nullptr); |
| 562 | std::uint32_t block[36] = {}; | 573 | std::uint32_t block[36] = {}; |
| 563 | std::memcpy(block + 8, spec.tsharp, sizeof(spec.tsharp)); // s[8:15]: the T# the fragment shader loads | 574 | std::memcpy(block + 8, spec.tsharp, sizeof(spec.tsharp)); // s[8:15]: the T# the fragment shader loads |
| 564 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(block), block); | 575 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, push_bytes, block); |
| 565 | vkCmdDraw(cmd, 3, 1, 0, 0); | 576 | vkCmdDraw(cmd, 3, 1, 0, 0); |
| 566 | vkCmdEndRenderPass(cmd); | 577 | vkCmdEndRenderPass(cmd); |
| 567 | VkBufferImageCopy rc{.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .imageExtent = {W, H, 1}}; | 578 | VkBufferImageCopy rc{.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .imageExtent = {W, H, 1}}; |
diff --git a/runtime/test/vk_overlapping_occlusion_test.cpp b/runtime/test/vk_overlapping_occlusion_test.cpp index 2a510d33a..43ffd5002 100644 --- a/runtime/test/vk_overlapping_occlusion_test.cpp +++ b/runtime/test/vk_overlapping_occlusion_test.cpp | |||
| @@ -16,8 +16,8 @@ namespace { | |||
| 16 | 16 | ||
| 17 | using namespace leonida; | 17 | using namespace leonida; |
| 18 | constexpr std::uint32_t side = 8; | 18 | constexpr std::uint32_t side = 8; |
| 19 | constexpr std::uint32_t query_count = 4; | 19 | constexpr std::uint32_t query_count = 10; |
| 20 | constexpr std::uint32_t statistics_count = 4; | 20 | constexpr std::uint32_t statistics_count = 9; |
| 21 | constexpr std::uint32_t statistics_words = 11; // D3D12_QUERY_DATA_PIPELINE_STATISTICS | 21 | constexpr std::uint32_t statistics_words = 11; // D3D12_QUERY_DATA_PIPELINE_STATISTICS |
| 22 | 22 | ||
| 23 | VkShaderModule load_shader(vktest::Device& d, const char* path) { | 23 | VkShaderModule load_shader(vktest::Device& d, const char* path) { |
| @@ -190,6 +190,10 @@ int run(vktest::Device& d, const char* vertex, const char* fragment, const Bisec | |||
| 190 | // The statistics lists below: a split query (two segments), two unsplit references and a second split query. | 190 | // The statistics lists below: a split query (two segments), two unsplit references and a second split query. |
| 191 | if (d.pipeline_statistics_query) schedule.extents.insert(schedule.extents.end(), {3, 5, 3, 5, 3, 5}); | 191 | if (d.pipeline_statistics_query) schedule.extents.insert(schedule.extents.end(), {3, 5, 3, 5, 3, 5}); |
| 192 | schedule.extents.insert(schedule.extents.end(), {2, 0, 0, 0, 1}); | 192 | schedule.extents.insert(schedule.extents.end(), {2, 0, 0, 0, 1}); |
| 193 | // The D3D-252 lists: three crossing statistics segment ends, three statistics references with the same draws, | ||
| 194 | // then the kind overlap's three segment ends and three occlusion references carrying the same draws. | ||
| 195 | if (d.pipeline_statistics_query) schedule.extents.insert(schedule.extents.end(), {7, 9, 11, 7, 9, 11}); | ||
| 196 | schedule.extents.insert(schedule.extents.end(), {19, 21, 23, 19, 21, 23}); | ||
| 193 | schedule.every = bisect.enabled; | 197 | schedule.every = bisect.enabled; |
| 194 | schedule.no_draw = bisect.no_draw; | 198 | schedule.no_draw = bisect.no_draw; |
| 195 | draws = &schedule; | 199 | draws = &schedule; |
| @@ -216,7 +220,7 @@ int run(vktest::Device& d, const char* vertex, const char* fragment, const Bisec | |||
| 216 | std::vector<bool>(query_count, false)}); | 220 | std::vector<bool>(query_count, false)}); |
| 217 | 221 | ||
| 218 | constexpr ResourceId dst_id = 4, predicate_id = 5; | 222 | constexpr ResourceId dst_id = 4, predicate_id = 5; |
| 219 | constexpr VkDeviceSize binding_offset = 24, size = 160; | 223 | constexpr VkDeviceSize binding_offset = 24, size = 256; |
| 220 | void* mapping = nullptr; | 224 | void* mapping = nullptr; |
| 221 | ResourceBinding dst{}; | 225 | ResourceBinding dst{}; |
| 222 | dst.buffer = d.buffer(size, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &mapping); | 226 | dst.buffer = d.buffer(size, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &mapping); |
| @@ -388,7 +392,7 @@ int run(vktest::Device& d, const char* vertex, const char* fragment, const Bisec | |||
| 388 | // gets one native draw before it ends (extents 3 and 5); two unsplit queries with the same draws are the | 392 | // gets one native draw before it ends (extents 3 and 5); two unsplit queries with the same draws are the |
| 389 | // reference, and CSInvocations stays 0 because no application compute runs. | 393 | // reference, and CSInvocations stays 0 because no application compute runs. |
| 390 | constexpr ResourceId stats_dst_id = 6; | 394 | constexpr ResourceId stats_dst_id = 6; |
| 391 | constexpr VkDeviceSize stats_result = statistics_words * sizeof(std::uint64_t), stats_slots = 5; | 395 | constexpr VkDeviceSize stats_result = statistics_words * sizeof(std::uint64_t), stats_slots = 10; |
| 392 | void* stats_mapping = nullptr; | 396 | void* stats_mapping = nullptr; |
| 393 | ResourceBinding stats_dst{}; | 397 | ResourceBinding stats_dst{}; |
| 394 | if (fixture.statistics) { | 398 | if (fixture.statistics) { |
| @@ -446,6 +450,43 @@ int run(vktest::Device& d, const char* vertex, const char* fragment, const Bisec | |||
| 446 | EXPECT(single.close()); | 450 | EXPECT(single.close()); |
| 447 | const CommandList* fifth[] = {&single}; | 451 | const CommandList* fifth[] = {&single}; |
| 448 | EXPECT(queue.execute(fifth) == ReplayResult::success); | 452 | EXPECT(queue.execute(fifth) == ReplayResult::success); |
| 453 | // D3D-252: overlapping pipeline-statistics queries and overlapping occlusion kinds. The hook's draw lands in | ||
| 454 | // the segment that is about to close, so each crossing query's sum covers its own intervals plus the shared | ||
| 455 | // intersection; the reference queries carry the same draws unsplit, and the sums must match them. | ||
| 456 | CommandList crossing_stats, stats_references, kind_overlap, kind_references; | ||
| 457 | if (d.pipeline_statistics_query) { | ||
| 458 | EXPECT(crossing_stats.begin_query({stats, d3d12_query::pipeline_statistics, 4})); | ||
| 459 | EXPECT(crossing_stats.begin_query({stats, d3d12_query::pipeline_statistics, 5})); | ||
| 460 | EXPECT(crossing_stats.end_query({stats, d3d12_query::pipeline_statistics, 4})); | ||
| 461 | EXPECT(crossing_stats.end_query({stats, d3d12_query::pipeline_statistics, 5})); | ||
| 462 | EXPECT(crossing_stats.resolve_queries({stats, d3d12_query::pipeline_statistics, 4, 1, stats_dst_id, | ||
| 463 | 5 * stats_result})); | ||
| 464 | EXPECT(crossing_stats.resolve_queries({stats, d3d12_query::pipeline_statistics, 5, 1, stats_dst_id, | ||
| 465 | 6 * stats_result})); | ||
| 466 | EXPECT(crossing_stats.close()); | ||
| 467 | for (std::uint32_t index : {6u, 7u, 8u}) { | ||
| 468 | EXPECT(stats_references.begin_query({stats, d3d12_query::pipeline_statistics, index})); | ||
| 469 | EXPECT(stats_references.end_query({stats, d3d12_query::pipeline_statistics, index})); | ||
| 470 | } | ||
| 471 | EXPECT(stats_references.resolve_queries({stats, d3d12_query::pipeline_statistics, 6, 3, stats_dst_id, | ||
| 472 | 7 * stats_result})); | ||
| 473 | EXPECT(stats_references.close()); | ||
| 474 | } | ||
| 475 | EXPECT(kind_overlap.begin_query({a, occ, 4})); | ||
| 476 | EXPECT(kind_overlap.begin_query({a, binary, 5})); | ||
| 477 | EXPECT(kind_overlap.end_query({a, binary, 5})); | ||
| 478 | EXPECT(kind_overlap.end_query({a, occ, 4})); | ||
| 479 | EXPECT(kind_overlap.resolve_queries({a, occ, 4, 1, dst_id, 168})); | ||
| 480 | EXPECT(kind_overlap.resolve_queries({a, binary, 5, 1, dst_id, 176})); | ||
| 481 | EXPECT(kind_overlap.close()); | ||
| 482 | for (std::uint32_t index : {6u, 7u, 8u}) { | ||
| 483 | EXPECT(kind_references.begin_query({b, occ, index})); | ||
| 484 | EXPECT(kind_references.end_query({b, occ, index})); | ||
| 485 | } | ||
| 486 | EXPECT(kind_references.resolve_queries({b, occ, 6, 3, dst_id, 184})); | ||
| 487 | EXPECT(kind_references.close()); | ||
| 488 | const CommandList* overlap_lists[] = {&crossing_stats, &stats_references, &kind_overlap, &kind_references}; | ||
| 489 | EXPECT(queue.execute(overlap_lists) == ReplayResult::success); | ||
| 449 | EXPECT(!schedule.overflow && schedule.next == schedule.extents.size()); | 490 | EXPECT(!schedule.overflow && schedule.next == schedule.extents.size()); |
| 450 | EXPECT(gate.signal(1)); | 491 | EXPECT(gate.signal(1)); |
| 451 | EXPECT(queue.idle()); | 492 | EXPECT(queue.idle()); |
| @@ -455,6 +496,21 @@ int run(vktest::Device& d, const char* vertex, const char* fragment, const Bisec | |||
| 455 | {88, 2 * bursts + 1}, {96, 1}, {112, 4}, {120, 0}, {128, 4}, | 496 | {88, 2 * bursts + 1}, {96, 1}, {112, 4}, {120, 0}, {128, 4}, |
| 456 | }; | 497 | }; |
| 457 | if (fixture.statistics) expected[0] = 2 * bursts + 1; // the sum resolved inside the statistics query | 498 | if (fixture.statistics) expected[0] = 2 * bursts + 1; // the sum resolved inside the statistics query |
| 499 | { // D3D-252: the ordinary result covers three segments (draws 19, 21 and 23); the binary result is the | ||
| 500 | // shared segment's count normalized to 1. The reference queries carry the same draws unsplit, and their | ||
| 501 | // own results at 184, 192 and 200 are the expectation for the sums. | ||
| 502 | const auto word_at = [&](VkDeviceSize at) { | ||
| 503 | std::uint64_t value = 0; | ||
| 504 | std::memcpy(&value, static_cast<const char*>(mapping) + binding_offset + at, sizeof(value)); | ||
| 505 | return value; | ||
| 506 | }; | ||
| 507 | const std::uint64_t first = word_at(184), shared = word_at(192), last = word_at(200); | ||
| 508 | expected[168] = first + shared + last; | ||
| 509 | expected[176] = 1; | ||
| 510 | expected[184] = first; | ||
| 511 | expected[192] = shared; | ||
| 512 | expected[200] = last; | ||
| 513 | } | ||
| 458 | for (VkDeviceSize offset = 0; offset < size; offset += 8) { | 514 | for (VkDeviceSize offset = 0; offset < size; offset += 8) { |
| 459 | const auto it = expected.find(offset - binding_offset); | 515 | const auto it = expected.find(offset - binding_offset); |
| 460 | const auto want = it == expected.end() ? 0xcdcdcdcdcdcdcdcdULL : it->second; | 516 | const auto want = it == expected.end() ? 0xcdcdcdcdcdcdcdcdULL : it->second; |
| @@ -487,9 +543,25 @@ int run(vktest::Device& d, const char* vertex, const char* fragment, const Bisec | |||
| 487 | } | 543 | } |
| 488 | } | 544 | } |
| 489 | EXPECT(word(0, cs_invocations) == 0 && word(1, 0) != 0 && word(2, 0) != 0); | 545 | EXPECT(word(0, cs_invocations) == 0 && word(1, 0) != 0 && word(2, 0) != 0); |
| 546 | // D3D-252: the crossing statistics queries (slots 5 and 6) each cover one private interval plus the shared | ||
| 547 | // intersection; slots 7 to 9 are the references with the same draws unsplit. | ||
| 548 | for (std::uint32_t counter = 0; counter < statistics_words; ++counter) { | ||
| 549 | if (word(5, counter) != word(7, counter) + word(8, counter) || | ||
| 550 | word(6, counter) != word(8, counter) + word(9, counter)) { | ||
| 551 | std::fprintf(stderr, "crossing statistics counter %u: got %llu/%llu, wanted %llu/%llu\n", counter, | ||
| 552 | static_cast<unsigned long long>(word(5, counter)), | ||
| 553 | static_cast<unsigned long long>(word(6, counter)), | ||
| 554 | static_cast<unsigned long long>(word(7, counter) + word(8, counter)), | ||
| 555 | static_cast<unsigned long long>(word(8, counter) + word(9, counter))); | ||
| 556 | return 1; | ||
| 557 | } | ||
| 558 | } | ||
| 559 | EXPECT(word(5, cs_invocations) == 0 && word(6, cs_invocations) == 0); | ||
| 490 | std::printf("statistics split around a sum: IA vertices %llu, PS invocations %llu, CS invocations 0, " | 560 | std::printf("statistics split around a sum: IA vertices %llu, PS invocations %llu, CS invocations 0, " |
| 491 | "equal to two unsplit queries\n", | 561 | "equal to two unsplit queries\n", |
| 492 | static_cast<unsigned long long>(word(0, 0)), static_cast<unsigned long long>(word(0, 7))); | 562 | static_cast<unsigned long long>(word(0, 0)), static_cast<unsigned long long>(word(0, 7))); |
| 563 | std::printf("crossing statistics: IA vertices %llu/%llu, CS invocations 0, equal to the unsplit references\n", | ||
| 564 | static_cast<unsigned long long>(word(5, 0)), static_cast<unsigned long long>(word(6, 0))); | ||
| 493 | } | 565 | } |
| 494 | std::printf("crossing 80/20; nested 84/16; %u segments summed; alternating binary results 1/1; " | 566 | std::printf("crossing 80/20; nested 84/16; %u segments summed; alternating binary results 1/1; " |
| 495 | "resolve inside an active query 4; offsets and gated overwrites exact\n", | 567 | "resolve inside an active query 4; offsets and gated overwrites exact\n", |
diff --git a/runtime/test/vk_pc_tail.h b/runtime/test/vk_pc_tail.h new file mode 100644 index 000000000..fa0509e68 --- /dev/null +++ b/runtime/test/vk_pc_tail.h | |||
| @@ -0,0 +1,125 @@ | |||
| 1 | // --pc-tail-ubo for the test programs: shaders translated with `rdna2spirv.py --pc-tail-ubo` keep s0..s31 (128 bytes) | ||
| 2 | // in push constants and read the tail (heap base, code base; the --mesh-compute output address) from a uniform block | ||
| 3 | // at set 1, binding 0 (docs/design.md, "Push-constant tail as a uniform block"). LEONIDA_PC_TAIL_UBO=1 says the | ||
| 4 | // shaders were translated that way (build.py and run_gpu_tests.py pass the flag then). A test program then declares | ||
| 5 | // 128 push-constant bytes and, when the module declares set 1, binds a PcTail: a host-visible buffer of one slot per | ||
| 6 | // dispatch or draw, bound as a dynamic uniform buffer so each one can select its own tail. | ||
| 7 | #pragma once | ||
| 8 | |||
| 9 | #include <vulkan/vulkan.h> | ||
| 10 | |||
| 11 | #include <cctype> | ||
| 12 | #include <cstddef> | ||
| 13 | #include <cstdint> | ||
| 14 | #include <cstdlib> | ||
| 15 | #include <cstring> | ||
| 16 | #include <string> | ||
| 17 | #include <vector> | ||
| 18 | |||
| 19 | namespace leonida::vk_test { | ||
| 20 | |||
| 21 | inline constexpr std::uint32_t pc_tail_set = 1; | ||
| 22 | inline constexpr std::uint32_t pc_tail_binding = 0; | ||
| 23 | |||
| 24 | // LEONIDA_PC_TAIL_UBO=1: the shaders were translated with --pc-tail-ubo. The values run_gpu_tests.py accepts: | ||
| 25 | // 1/true/yes/on, any case, with the trailing space cmd.exe's `set VAR=1 &` leaves. | ||
| 26 | inline bool pc_tail_requested() { | ||
| 27 | const char* v = std::getenv("LEONIDA_PC_TAIL_UBO"); | ||
| 28 | std::string s = v ? v : ""; | ||
| 29 | while (!s.empty() && std::isspace(static_cast<unsigned char>(s.back()))) s.pop_back(); | ||
| 30 | while (!s.empty() && std::isspace(static_cast<unsigned char>(s.front()))) s.erase(s.begin()); | ||
| 31 | for (char& c : s) c = char(std::tolower(static_cast<unsigned char>(c))); | ||
| 32 | return s == "1" || s == "true" || s == "yes" || s == "on"; | ||
| 33 | } | ||
| 34 | |||
| 35 | // OpDecorate (71) <id> DescriptorSet (34) <set>: a --pc-tail-ubo module declares set 1 only when it reads the tail. | ||
| 36 | inline bool spirv_declares_set(const void* data, std::size_t bytes, std::uint32_t set) { | ||
| 37 | if (bytes < 20 || bytes % 4) return false; | ||
| 38 | std::vector<std::uint32_t> words(bytes / 4); | ||
| 39 | std::memcpy(words.data(), data, bytes); | ||
| 40 | for (std::size_t i = 5; i < words.size() && (words[i] >> 16);) { | ||
| 41 | const std::uint32_t op = words[i] & 0xffff, count = words[i] >> 16; | ||
| 42 | if (op == 71 && count == 4 && i + 3 < words.size() && words[i + 2] == 34 && words[i + 3] == set) return true; | ||
| 43 | i += count; | ||
| 44 | } | ||
| 45 | return false; | ||
| 46 | } | ||
| 47 | |||
| 48 | // The tail block, `slots` slots of up to 6 dwords each (the 24-byte --mesh-compute tail), each at a multiple of the | ||
| 49 | // device's minUniformBufferOffsetAlignment. create() returns false (and leaves what it made to the device's | ||
| 50 | // destruction, as the test programs do) if any call fails. set_layout goes at index pc_tail_set of the pipeline | ||
| 51 | // layout; a program with no set 0 of its own puts empty_layout at index 0. | ||
| 52 | struct PcTail { | ||
| 53 | static constexpr VkDeviceSize slot_bytes = 6 * sizeof(std::uint32_t); | ||
| 54 | VkDescriptorSetLayout set_layout = VK_NULL_HANDLE; | ||
| 55 | VkDescriptorSetLayout empty_layout = VK_NULL_HANDLE; | ||
| 56 | VkDescriptorSet set = VK_NULL_HANDLE; | ||
| 57 | VkDeviceSize stride = 0; | ||
| 58 | std::uint32_t slots = 0; | ||
| 59 | std::uint8_t* map = nullptr; | ||
| 60 | |||
| 61 | bool create(PFN_vkGetDeviceProcAddr gdpa, VkDevice dev, const VkPhysicalDeviceMemoryProperties& memory, | ||
| 62 | VkDeviceSize min_offset_alignment, VkShaderStageFlags stages, std::uint32_t slot_count) { | ||
| 63 | #define PC_TAIL_LOAD(f) auto f = reinterpret_cast<PFN_##f>(gdpa(dev, #f)); if (!f) return false | ||
| 64 | PC_TAIL_LOAD(vkCreateDescriptorSetLayout); PC_TAIL_LOAD(vkCreateDescriptorPool); | ||
| 65 | PC_TAIL_LOAD(vkAllocateDescriptorSets); PC_TAIL_LOAD(vkUpdateDescriptorSets); PC_TAIL_LOAD(vkCreateBuffer); | ||
| 66 | PC_TAIL_LOAD(vkGetBufferMemoryRequirements); PC_TAIL_LOAD(vkAllocateMemory); PC_TAIL_LOAD(vkBindBufferMemory); | ||
| 67 | PC_TAIL_LOAD(vkMapMemory); | ||
| 68 | #undef PC_TAIL_LOAD | ||
| 69 | const VkDeviceSize align = min_offset_alignment ? min_offset_alignment : 1; | ||
| 70 | stride = (slot_bytes + align - 1) / align * align; | ||
| 71 | slots = slot_count ? slot_count : 1; | ||
| 72 | |||
| 73 | VkDescriptorSetLayoutBinding b{pc_tail_binding, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, stages, nullptr}; | ||
| 74 | VkDescriptorSetLayoutCreateInfo li{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO}; | ||
| 75 | li.bindingCount = 1; li.pBindings = &b; | ||
| 76 | if (vkCreateDescriptorSetLayout(dev, &li, nullptr, &set_layout) != VK_SUCCESS) return false; | ||
| 77 | VkDescriptorSetLayoutCreateInfo ei{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO}; | ||
| 78 | if (vkCreateDescriptorSetLayout(dev, &ei, nullptr, &empty_layout) != VK_SUCCESS) return false; | ||
| 79 | VkDescriptorPoolSize ps{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1}; | ||
| 80 | VkDescriptorPoolCreateInfo pi{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; | ||
| 81 | pi.maxSets = 1; pi.poolSizeCount = 1; pi.pPoolSizes = &ps; | ||
| 82 | VkDescriptorPool pool; | ||
| 83 | if (vkCreateDescriptorPool(dev, &pi, nullptr, &pool) != VK_SUCCESS) return false; | ||
| 84 | VkDescriptorSetAllocateInfo ai{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO}; | ||
| 85 | ai.descriptorPool = pool; ai.descriptorSetCount = 1; ai.pSetLayouts = &set_layout; | ||
| 86 | if (vkAllocateDescriptorSets(dev, &ai, &set) != VK_SUCCESS) return false; | ||
| 87 | |||
| 88 | VkBufferCreateInfo bi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; | ||
| 89 | bi.size = stride * slots; bi.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; | ||
| 90 | VkBuffer buffer; | ||
| 91 | if (vkCreateBuffer(dev, &bi, nullptr, &buffer) != VK_SUCCESS) return false; | ||
| 92 | VkMemoryRequirements mr; vkGetBufferMemoryRequirements(dev, buffer, &mr); | ||
| 93 | constexpr VkMemoryPropertyFlags host = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; | ||
| 94 | std::uint32_t type = 0; | ||
| 95 | while (type < memory.memoryTypeCount && | ||
| 96 | !((mr.memoryTypeBits >> type & 1) && (memory.memoryTypes[type].propertyFlags & host) == host)) ++type; | ||
| 97 | if (type == memory.memoryTypeCount) return false; | ||
| 98 | VkMemoryAllocateInfo mi{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; | ||
| 99 | mi.allocationSize = mr.size; mi.memoryTypeIndex = type; | ||
| 100 | VkDeviceMemory mem; | ||
| 101 | if (vkAllocateMemory(dev, &mi, nullptr, &mem) != VK_SUCCESS) return false; | ||
| 102 | if (vkBindBufferMemory(dev, buffer, mem, 0) != VK_SUCCESS) return false; | ||
| 103 | void* p; | ||
| 104 | if (vkMapMemory(dev, mem, 0, VK_WHOLE_SIZE, 0, &p) != VK_SUCCESS) return false; | ||
| 105 | map = static_cast<std::uint8_t*>(p); | ||
| 106 | std::memset(map, 0, std::size_t(stride * slots)); | ||
| 107 | |||
| 108 | VkDescriptorBufferInfo di{buffer, 0, slot_bytes}; | ||
| 109 | VkWriteDescriptorSet w{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}; | ||
| 110 | w.dstSet = set; w.dstBinding = pc_tail_binding; w.descriptorCount = 1; | ||
| 111 | w.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; w.pBufferInfo = &di; | ||
| 112 | vkUpdateDescriptorSets(dev, 1, &w, 0, nullptr); | ||
| 113 | return true; | ||
| 114 | } | ||
| 115 | |||
| 116 | // The tail of slot `slot` from a push-constant array laid out as without the flag: words 32.. of `pc`, `words` | ||
| 117 | // of them (4, or 6 with --mesh-compute). | ||
| 118 | void write(std::uint32_t slot, const std::uint32_t* pc, std::uint32_t words) { | ||
| 119 | std::memcpy(map + stride * slot, pc + 32, words * sizeof(std::uint32_t)); | ||
| 120 | } | ||
| 121 | |||
| 122 | std::uint32_t offset(std::uint32_t slot) const { return std::uint32_t(stride * slot); } | ||
| 123 | }; | ||
| 124 | |||
| 125 | } // namespace leonida::vk_test | ||
diff --git a/runtime/test/vk_pipeline_check.cpp b/runtime/test/vk_pipeline_check.cpp index 6e1e63eb8..65a53a5f3 100644 --- a/runtime/test/vk_pipeline_check.cpp +++ b/runtime/test/vk_pipeline_check.cpp | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | // Driver-level check of the translated corpus: vk_pipeline_check <spirv dir> [pipeline_cache.bin] | 1 | // Driver-level check of the translated corpus: vk_pipeline_check <spirv dir> [pipeline_cache.bin] |
| 2 | // Reads <spirv dir>/index.json (written by tools/rdna2spirv.py), creates a VkShaderModule for every entry and a real | 2 | // Reads <spirv dir>/index.json (written by tools/rdna2spirv.py), creates a VkShaderModule for every entry and a real |
| 3 | // pipeline with the translator's resource contract (set 0: sampled images 0, 3, 5, 6; samplers 1; descriptor hash | 3 | // pipeline with the translator's resource contract (set 0: sampled images 0, 3, 5, 6; samplers 1; descriptor hash |
| 4 | // table 2; storage images 4, 7 and 8..19; push constants 144 bytes): | 4 | // table 2; storage images 4, 7 and 8..19; set 1 binding 0 dynamic UBO for --pc-tail-ubo shaders; push constants |
| 5 | // sized from push_constant_bytes, default 144 or 128 with pc_tail): | ||
| 5 | // - cs: compute pipeline via vkCreateComputePipelines | 6 | // - cs: compute pipeline via vkCreateComputePipelines |
| 6 | // - ps/vs/ms/gs: graphics pipeline via vkCreateGraphicsPipelines (Vulkan 1.3 dynamic rendering, no render pass) | 7 | // - ps/vs/ms/gs: graphics pipeline via vkCreateGraphicsPipelines (Vulkan 1.3 dynamic rendering, no render pass) |
| 7 | // paired with minimal partner stubs from <spirv dir>/stubs/ (generated by tools/spirv_stubs.py) | 8 | // paired with minimal partner stubs from <spirv dir>/stubs/ (generated by tools/spirv_stubs.py) |
| @@ -41,6 +42,7 @@ | |||
| 41 | #include "vk_device_pick.h" | 42 | #include "vk_device_pick.h" |
| 42 | #include "pipeline_cache_file.h" | 43 | #include "pipeline_cache_file.h" |
| 43 | #include "pipeline_cache_snapshot.h" | 44 | #include "pipeline_cache_snapshot.h" |
| 45 | #include "../src/spirv_words.h" | ||
| 44 | 46 | ||
| 45 | #include <algorithm> | 47 | #include <algorithm> |
| 46 | #include <atomic> | 48 | #include <atomic> |
| @@ -84,6 +86,8 @@ struct ShaderMeta { | |||
| 84 | std::string stage; | 86 | std::string stage; |
| 85 | uint32_t subgroup_size = 0; | 87 | uint32_t subgroup_size = 0; |
| 86 | uint32_t lds_bytes = 0; | 88 | uint32_t lds_bytes = 0; |
| 89 | uint32_t push_constant_bytes = 0; // 0 = absent in index (128 with pc_tail, else 144) | ||
| 90 | uint32_t pc_tail_bytes = 0; // >0 = --pc-tail-ubo uniform block at set 1, binding 0 | ||
| 87 | bool writes_depth = false; | 91 | bool writes_depth = false; |
| 88 | bool needs_maintenance8 = false; | 92 | bool needs_maintenance8 = false; |
| 89 | std::vector<std::string> features; | 93 | std::vector<std::string> features; |
| @@ -263,6 +267,35 @@ struct JsonParser { | |||
| 263 | if (!error) fail("unterminated vertex_inputs array"); | 267 | if (!error) fail("unterminated vertex_inputs array"); |
| 264 | return out; | 268 | return out; |
| 265 | } | 269 | } |
| 270 | uint32_t parse_strict_u32(const char* what) { | ||
| 271 | ws(); | ||
| 272 | uint32_t v = 0; | ||
| 273 | const auto [end, ec] = std::from_chars(s.data() + i, s.data() + s.size(), v); | ||
| 274 | if (ec != std::errc{}) { fail(what); return 0u; } | ||
| 275 | i = static_cast<size_t>(end - s.data()); | ||
| 276 | if (i < s.size() && (s[i] == '.' || s[i] == 'e' || s[i] == 'E')) { fail(what); return 0u; } | ||
| 277 | return v; | ||
| 278 | } | ||
| 279 | uint32_t parse_pc_tail_bytes() { | ||
| 280 | ws(); | ||
| 281 | if (s.compare(i, 4, "null") == 0) { i += 4; return 0u; } | ||
| 282 | if (!consume('{')) { fail("expected object for pc_tail"); return 0u; } | ||
| 283 | uint32_t bytes = 0; | ||
| 284 | while (!error && i < s.size()) { | ||
| 285 | if (consume('}')) return bytes; | ||
| 286 | const size_t before = i; | ||
| 287 | std::string k = parse_string(); | ||
| 288 | if (error) return bytes; | ||
| 289 | if (!consume(':')) { fail("expected ':' in pc_tail"); return bytes; } | ||
| 290 | if (k == "bytes") bytes = parse_strict_u32("expected unsigned 32-bit pc_tail.bytes"); | ||
| 291 | else skip_value(); | ||
| 292 | if (error) return bytes; | ||
| 293 | if (consume('}')) return bytes; | ||
| 294 | if (!consume(',') || i == before) { fail("expected ',' or '}' in pc_tail"); return bytes; } | ||
| 295 | } | ||
| 296 | if (!error) fail("unterminated pc_tail object"); | ||
| 297 | return bytes; | ||
| 298 | } | ||
| 266 | ShaderMeta parse_meta() { | 299 | ShaderMeta parse_meta() { |
| 267 | ShaderMeta m; | 300 | ShaderMeta m; |
| 268 | if (!consume('{')) { skip_value(); return m; } | 301 | if (!consume('{')) { skip_value(); return m; } |
| @@ -279,12 +312,10 @@ struct JsonParser { | |||
| 279 | if (s.compare(i, 4, "null") == 0) { i += 4; m.subgroup_size = 0; } | 312 | if (s.compare(i, 4, "null") == 0) { i += 4; m.subgroup_size = 0; } |
| 280 | else m.subgroup_size = parse_u32(); | 313 | else m.subgroup_size = parse_u32(); |
| 281 | } | 314 | } |
| 282 | else if (k == "lds_bytes") { | 315 | else if (k == "lds_bytes") m.lds_bytes = parse_strict_u32("expected unsigned 32-bit lds_bytes"); |
| 283 | ws(); | 316 | else if (k == "push_constant_bytes") |
| 284 | const auto [end, ec] = std::from_chars(s.data() + i, s.data() + s.size(), m.lds_bytes); | 317 | m.push_constant_bytes = parse_strict_u32("expected unsigned 32-bit push_constant_bytes"); |
| 285 | if (ec != std::errc{}) fail("expected unsigned 32-bit lds_bytes"); | 318 | else if (k == "pc_tail") m.pc_tail_bytes = parse_pc_tail_bytes(); |
| 286 | else i = static_cast<size_t>(end - s.data()); | ||
| 287 | } | ||
| 288 | else if (k == "writes_depth") m.writes_depth = parse_bool(); | 319 | else if (k == "writes_depth") m.writes_depth = parse_bool(); |
| 289 | else if (k == "needs_maintenance8") m.needs_maintenance8 = parse_bool(); | 320 | else if (k == "needs_maintenance8") m.needs_maintenance8 = parse_bool(); |
| 290 | else if (k == "features") m.features = parse_str_array(); | 321 | else if (k == "features") m.features = parse_str_array(); |
| @@ -411,6 +442,21 @@ static_assert(shader_slice(7, 2, 0) == std::pair<size_t, size_t>{2, 7}); | |||
| 411 | static_assert(shader_slice(7, 8, 3) == std::pair<size_t, size_t>{7, 7}); | 442 | static_assert(shader_slice(7, 8, 3) == std::pair<size_t, size_t>{7, 7}); |
| 412 | static_assert(shader_slice(7, 2, std::numeric_limits<size_t>::max()) == std::pair<size_t, size_t>{2, 7}); | 443 | static_assert(shader_slice(7, 2, std::numeric_limits<size_t>::max()) == std::pair<size_t, size_t>{2, 7}); |
| 413 | 444 | ||
| 445 | // Push-constant range size a shader needs: its index push_constant_bytes when recorded (128 with --pc-tail-ubo, | ||
| 446 | // 144 by default, 152 with --mesh-compute), or 128 when pc_tail is present, else 144. Rounded up to 4 bytes | ||
| 447 | // (Vulkan requires VkPushConstantRange::size to be a positive multiple of 4). | ||
| 448 | constexpr uint32_t required_push_bytes(uint32_t push_constant_bytes, uint32_t pc_tail_bytes) { | ||
| 449 | const uint32_t raw = push_constant_bytes ? push_constant_bytes : (pc_tail_bytes ? 128u : 144u); | ||
| 450 | return raw > (std::numeric_limits<uint32_t>::max() - 3u) ? raw : ((raw + 3u) & ~3u); | ||
| 451 | } | ||
| 452 | |||
| 453 | static_assert(required_push_bytes(0, 0) == 144); | ||
| 454 | static_assert(required_push_bytes(0, 16) == 128); | ||
| 455 | static_assert(required_push_bytes(128, 0) == 128); | ||
| 456 | static_assert(required_push_bytes(128, 16) == 128); | ||
| 457 | static_assert(required_push_bytes(144, 0) == 144); | ||
| 458 | static_assert(required_push_bytes(152, 0) == 152); | ||
| 459 | |||
| 414 | // --cache-feedback class of a successful pipeline: 0 hit, 1 no hit reported, 2 unavailable. A hit counts only with | 460 | // --cache-feedback class of a successful pipeline: 0 hit, 1 no hit reported, 2 unavailable. A hit counts only with |
| 415 | // VALID; the duration and base-pipeline bits are not classified. | 461 | // VALID; the duration and base-pipeline bits are not classified. |
| 416 | constexpr int feedback_outcome(VkPipelineCreationFeedbackFlags f) { | 462 | constexpr int feedback_outcome(VkPipelineCreationFeedbackFlags f) { |
| @@ -547,6 +593,7 @@ int main(int argc, char** argv) { | |||
| 547 | } | 593 | } |
| 548 | std::setvbuf(stdout, nullptr, _IOLBF, 1 << 16); // failures reach a redirected log as they happen | 594 | std::setvbuf(stdout, nullptr, _IOLBF, 1 << 16); // failures reach a redirected log as they happen |
| 549 | std::string dir = argv[1], cache_path, stats_path, inflight_path, skip_path; | 595 | std::string dir = argv[1], cache_path, stats_path, inflight_path, skip_path; |
| 596 | bool cache_given = false; // an empty cache_path alone can't tell "not given" from an empty argument | ||
| 550 | uint32_t jobs = std::max(1u, std::thread::hardware_concurrency() / 2); | 597 | uint32_t jobs = std::max(1u, std::thread::hardware_concurrency() / 2); |
| 551 | size_t start = 0, count = 0, max_bytes = 0; | 598 | size_t start = 0, count = 0, max_bytes = 0; |
| 552 | size_t large_module_bytes = 4 * 1024 * 1024; | 599 | size_t large_module_bytes = 4 * 1024 * 1024; |
| @@ -592,9 +639,11 @@ int main(int argc, char** argv) { | |||
| 592 | else if (a.starts_with("--")) { // not a cache path: an option this build doesn't know | 639 | else if (a.starts_with("--")) { // not a cache path: an option this build doesn't know |
| 593 | std::fprintf(stderr, "unknown option %s\n", a.c_str()); | 640 | std::fprintf(stderr, "unknown option %s\n", a.c_str()); |
| 594 | return 2; | 641 | return 2; |
| 595 | } else if (cache_path.empty()) cache_path = a; | 642 | } else if (!cache_given) { |
| 596 | else { | 643 | cache_path = a; |
| 597 | std::fprintf(stderr, "unexpected argument %s (the cache path is already %s)\n", a.c_str(), | 644 | cache_given = true; |
| 645 | } else { | ||
| 646 | std::fprintf(stderr, "unexpected argument '%s' (a cache path was already given: '%s')\n", a.c_str(), | ||
| 598 | cache_path.c_str()); | 647 | cache_path.c_str()); |
| 599 | return 2; | 648 | return 2; |
| 600 | } | 649 | } |
| @@ -827,6 +876,7 @@ int main(int argc, char** argv) { | |||
| 827 | #endif | 876 | #endif |
| 828 | VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR exe{ | 877 | VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR exe{ |
| 829 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR}; | 878 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR}; |
| 879 | VkPhysicalDeviceVulkan11Features f11{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES}; | ||
| 830 | VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; | 880 | VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; |
| 831 | VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; | 881 | VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; |
| 832 | void* chain = nullptr; | 882 | void* chain = nullptr; |
| @@ -837,6 +887,7 @@ int main(int argc, char** argv) { | |||
| 837 | b->pNext = static_cast<VkBaseOutStructure*>(chain); chain = s; | 887 | b->pNext = static_cast<VkBaseOutStructure*>(chain); chain = s; |
| 838 | return true; | 888 | return true; |
| 839 | }; | 889 | }; |
| 890 | link(&f11, reinterpret_cast<VkBaseOutStructure*>(&f11), nullptr, true); // shaderDrawParameters (VS v0/v3) | ||
| 840 | link(&f12, reinterpret_cast<VkBaseOutStructure*>(&f12), nullptr, true); | 891 | link(&f12, reinterpret_cast<VkBaseOutStructure*>(&f12), nullptr, true); |
| 841 | link(&f13, reinterpret_cast<VkBaseOutStructure*>(&f13), nullptr, true); | 892 | link(&f13, reinterpret_cast<VkBaseOutStructure*>(&f13), nullptr, true); |
| 842 | const bool ext_mesh = link(&mesh, reinterpret_cast<VkBaseOutStructure*>(&mesh), VK_EXT_MESH_SHADER_EXTENSION_NAME, want_mesh); | 893 | const bool ext_mesh = link(&mesh, reinterpret_cast<VkBaseOutStructure*>(&mesh), VK_EXT_MESH_SHADER_EXTENSION_NAME, want_mesh); |
| @@ -872,6 +923,12 @@ int main(int argc, char** argv) { | |||
| 872 | VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; | 923 | VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; |
| 873 | f2.pNext = chain; | 924 | f2.pNext = chain; |
| 874 | vkGetPhysicalDeviceFeatures2(pd, &f2); // fills every linked struct with what's supported | 925 | vkGetPhysicalDeviceFeatures2(pd, &f2); // fills every linked struct with what's supported |
| 926 | VkPhysicalDeviceMeshShaderPropertiesEXT mesh_props{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_PROPERTIES_EXT}; | ||
| 927 | if (ext_mesh && mesh.meshShader) { | ||
| 928 | VkPhysicalDeviceProperties2 mesh_device_props{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2}; | ||
| 929 | mesh_device_props.pNext = &mesh_props; | ||
| 930 | vkGetPhysicalDeviceProperties2(pd, &mesh_device_props); | ||
| 931 | } | ||
| 875 | if (ext_mesh) { | 932 | if (ext_mesh) { |
| 876 | mesh.multiviewMeshShader = mesh.primitiveFragmentShadingRateMeshShader = mesh.meshShaderQueries = VK_FALSE; | 933 | mesh.multiviewMeshShader = mesh.primitiveFragmentShadingRateMeshShader = mesh.meshShaderQueries = VK_FALSE; |
| 877 | mesh.taskShader = VK_FALSE; | 934 | mesh.taskShader = VK_FALSE; |
| @@ -918,6 +975,12 @@ int main(int argc, char** argv) { | |||
| 918 | 975 | ||
| 919 | // Map enabled device features for per-shader compatibility checks. | 976 | // Map enabled device features for per-shader compatibility checks. |
| 920 | auto check_missing_feature = [&](const ShaderMeta& meta) -> std::string { | 977 | auto check_missing_feature = [&](const ShaderMeta& meta) -> std::string { |
| 978 | const uint32_t need_pc = required_push_bytes(meta.push_constant_bytes, meta.pc_tail_bytes); | ||
| 979 | if (need_pc > props.limits.maxPushConstantsSize) { | ||
| 980 | return "needs " + std::to_string(need_pc) + " push-constant bytes, device has " + | ||
| 981 | std::to_string(props.limits.maxPushConstantsSize) + | ||
| 982 | (need_pc > 128 ? " (translate with --pc-tail-ubo)" : ""); | ||
| 983 | } | ||
| 921 | if (is_graphics_stage(meta.stage) && !f13.dynamicRendering) return "no dynamicRendering"; | 984 | if (is_graphics_stage(meta.stage) && !f13.dynamicRendering) return "no dynamicRendering"; |
| 922 | if (meta.stage == "ms" && !(ext_mesh && mesh.meshShader)) return "no VK_EXT_mesh_shader"; | 985 | if (meta.stage == "ms" && !(ext_mesh && mesh.meshShader)) return "no VK_EXT_mesh_shader"; |
| 923 | if (meta.stage == "gs" && !f2.features.geometryShader) return "no geometryShader"; | 986 | if (meta.stage == "gs" && !f2.features.geometryShader) return "no geometryShader"; |
| @@ -950,6 +1013,7 @@ int main(int argc, char** argv) { | |||
| 950 | } | 1013 | } |
| 951 | if (feat == "shaderFloat64" && !f2.features.shaderFloat64) return "no shaderFloat64"; | 1014 | if (feat == "shaderFloat64" && !f2.features.shaderFloat64) return "no shaderFloat64"; |
| 952 | if (feat == "shaderInt64" && !f2.features.shaderInt64) return "no shaderInt64"; | 1015 | if (feat == "shaderInt64" && !f2.features.shaderInt64) return "no shaderInt64"; |
| 1016 | if (feat == "shaderDrawParameters" && !f11.shaderDrawParameters) return "no shaderDrawParameters"; | ||
| 953 | if (feat == "bufferDeviceAddress" && !f12.bufferDeviceAddress) return "no bufferDeviceAddress"; | 1017 | if (feat == "bufferDeviceAddress" && !f12.bufferDeviceAddress) return "no bufferDeviceAddress"; |
| 954 | if (feat == "runtimeDescriptorArray" && !f12.runtimeDescriptorArray) return "no runtimeDescriptorArray"; | 1018 | if (feat == "runtimeDescriptorArray" && !f12.runtimeDescriptorArray) return "no runtimeDescriptorArray"; |
| 955 | if (feat == "shaderImageGatherExtended" && !f2.features.shaderImageGatherExtended) return "no shaderImageGatherExtended"; | 1019 | if (feat == "shaderImageGatherExtended" && !f2.features.shaderImageGatherExtended) return "no shaderImageGatherExtended"; |
| @@ -976,10 +1040,41 @@ int main(int argc, char** argv) { | |||
| 976 | dli.bindingCount = uint32_t(b.size()); dli.pBindings = b.data(); | 1040 | dli.bindingCount = uint32_t(b.size()); dli.pBindings = b.data(); |
| 977 | VkDescriptorSetLayout dsl; | 1041 | VkDescriptorSetLayout dsl; |
| 978 | if (VkResult r = vkCreateDescriptorSetLayout(dev, &dli, nullptr, &dsl)) { std::fprintf(stderr, "layout %d\n", r); return 1; } | 1042 | if (VkResult r = vkCreateDescriptorSetLayout(dev, &dli, nullptr, &dsl)) { std::fprintf(stderr, "layout %d\n", r); return 1; } |
| 979 | VkPushConstantRange pcr{VK_SHADER_STAGE_ALL, 0, 144}; | 1043 | // Set 1 of --pc-tail-ubo shaders (docs/design.md): dynamic uniform block at binding 0 holding heap/code base. |
| 980 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; | 1044 | const VkDescriptorSetLayoutBinding tail_binding{0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, |
| 981 | pli.setLayoutCount = 1; pli.pSetLayouts = &dsl; pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; | 1045 | VK_SHADER_STAGE_ALL, nullptr}; |
| 982 | VkPipelineLayout pl; vkCreatePipelineLayout(dev, &pli, nullptr, &pl); | 1046 | VkDescriptorSetLayoutCreateInfo tail_dli{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO}; |
| 1047 | tail_dli.bindingCount = 1; tail_dli.pBindings = &tail_binding; | ||
| 1048 | VkDescriptorSetLayout dsl_tail = VK_NULL_HANDLE; | ||
| 1049 | if (VkResult r = vkCreateDescriptorSetLayout(dev, &tail_dli, nullptr, &dsl_tail)) { | ||
| 1050 | std::fprintf(stderr, "tail layout %d\n", r); return 1; | ||
| 1051 | } | ||
| 1052 | // One VkPipelineLayout per (push_constant_bytes, has_pc_tail) needed by the selected shaders that fits | ||
| 1053 | // maxPushConstantsSize; never declares a range above the device limit (VUID-VkPushConstantRange-size-00298). | ||
| 1054 | std::map<std::pair<uint32_t, bool>, VkPipelineLayout> layouts; | ||
| 1055 | for (const auto& [_, meta] : work) { | ||
| 1056 | const uint32_t need_pc = required_push_bytes(meta->push_constant_bytes, meta->pc_tail_bytes); | ||
| 1057 | if (need_pc > props.limits.maxPushConstantsSize) continue; | ||
| 1058 | const std::pair<uint32_t, bool> key{need_pc, meta->pc_tail_bytes != 0}; | ||
| 1059 | if (layouts.count(key)) continue; | ||
| 1060 | VkPushConstantRange pcr{VK_SHADER_STAGE_ALL, 0, need_pc}; | ||
| 1061 | VkDescriptorSetLayout sets[2] = {dsl, dsl_tail}; | ||
| 1062 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; | ||
| 1063 | pli.setLayoutCount = key.second ? 2u : 1u; | ||
| 1064 | pli.pSetLayouts = sets; | ||
| 1065 | pli.pushConstantRangeCount = 1; | ||
| 1066 | pli.pPushConstantRanges = &pcr; | ||
| 1067 | VkPipelineLayout pl = VK_NULL_HANDLE; | ||
| 1068 | if (VkResult r = vkCreatePipelineLayout(dev, &pli, nullptr, &pl)) { | ||
| 1069 | std::fprintf(stderr, "pipeline layout (%u bytes%s) %d\n", need_pc, key.second ? ", set 1" : "", r); | ||
| 1070 | return 1; | ||
| 1071 | } | ||
| 1072 | layouts.emplace(key, pl); | ||
| 1073 | } | ||
| 1074 | auto layout_for = [&](const ShaderMeta& meta) -> VkPipelineLayout { | ||
| 1075 | const uint32_t need_pc = required_push_bytes(meta.push_constant_bytes, meta.pc_tail_bytes); | ||
| 1076 | return layouts.at({need_pc, meta.pc_tail_bytes != 0}); | ||
| 1077 | }; | ||
| 983 | VkPipelineCacheCreateInfo pci{VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO}; | 1078 | VkPipelineCacheCreateInfo pci{VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO}; |
| 984 | std::vector<char> seed; | 1079 | std::vector<char> seed; |
| 985 | if (!cache_path.empty()) { // resume: pipelines already in the cache compile instantly | 1080 | if (!cache_path.empty()) { // resume: pipelines already in the cache compile instantly |
| @@ -1050,13 +1145,13 @@ int main(int argc, char** argv) { | |||
| 1050 | auto it = stub_cache.find(fname); | 1145 | auto it = stub_cache.find(fname); |
| 1051 | if (it != stub_cache.end()) return it->second; | 1146 | if (it != stub_cache.end()) return it->second; |
| 1052 | } | 1147 | } |
| 1053 | std::ifstream f(dir + "/stubs/" + fname, std::ios::binary); | 1148 | std::ifstream f(dir + "/stubs/" + fname, std::ios::binary | std::ios::ate); |
| 1054 | std::vector<char> code((std::istreambuf_iterator<char>(f)), {}); | 1149 | const auto code = leonida::read_spirv_words(f, f.tellg()); |
| 1055 | VkShaderModule mod = VK_NULL_HANDLE; | 1150 | VkShaderModule mod = VK_NULL_HANDLE; |
| 1056 | if (!code.empty()) { | 1151 | if (!code.empty()) { |
| 1057 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; | 1152 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 1058 | smi.codeSize = code.size(); | 1153 | smi.codeSize = code.size() * sizeof(code.front()); |
| 1059 | smi.pCode = reinterpret_cast<const uint32_t*>(code.data()); | 1154 | smi.pCode = code.data(); |
| 1060 | if (vkCreateShaderModule(dev, &smi, nullptr, &mod) != VK_SUCCESS) mod = VK_NULL_HANDLE; | 1155 | if (vkCreateShaderModule(dev, &smi, nullptr, &mod) != VK_SUCCESS) mod = VK_NULL_HANDLE; |
| 1061 | } | 1156 | } |
| 1062 | std::lock_guard<std::mutex> g(mu); | 1157 | std::lock_guard<std::mutex> g(mu); |
| @@ -1169,11 +1264,15 @@ int main(int argc, char** argv) { | |||
| 1169 | ++done; | 1264 | ++done; |
| 1170 | continue; | 1265 | continue; |
| 1171 | } | 1266 | } |
| 1172 | if (stage == "cs" && meta.lds_bytes > props.limits.maxComputeSharedMemorySize) { | 1267 | uint32_t shared_memory_limit = 0; |
| 1268 | if (stage == "cs") shared_memory_limit = props.limits.maxComputeSharedMemorySize; | ||
| 1269 | else if (stage == "ms") shared_memory_limit = mesh_props.maxMeshSharedMemorySize; | ||
| 1270 | if (shared_memory_limit && meta.lds_bytes > shared_memory_limit) { | ||
| 1271 | const char* limit_name = stage == "cs" ? "maxComputeSharedMemorySize" : "maxMeshSharedMemorySize"; | ||
| 1173 | std::lock_guard<std::mutex> g(mu); | 1272 | std::lock_guard<std::mutex> g(mu); |
| 1174 | modules_bad[stage]++; | 1273 | modules_bad[stage]++; |
| 1175 | std::printf("MODULE FAIL %s (workgroup memory %u bytes exceeds maxComputeSharedMemorySize %u)\n", | 1274 | std::printf("MODULE FAIL %s (workgroup memory %u bytes exceeds %s %u)\n", |
| 1176 | name.c_str(), meta.lds_bytes, props.limits.maxComputeSharedMemorySize); | 1275 | name.c_str(), meta.lds_bytes, limit_name, shared_memory_limit); |
| 1177 | ++done; | 1276 | ++done; |
| 1178 | continue; | 1277 | continue; |
| 1179 | } | 1278 | } |
| @@ -1190,13 +1289,13 @@ int main(int argc, char** argv) { | |||
| 1190 | if (isolated) write_inflight(); // alone in flight: the file names exactly this module | 1289 | if (isolated) write_inflight(); // alone in flight: the file names exactly this module |
| 1191 | } | 1290 | } |
| 1192 | 1291 | ||
| 1193 | f.seekg(0); | 1292 | const auto code = leonida::read_spirv_words(f, file_size); |
| 1194 | std::vector<char> code((std::istreambuf_iterator<char>(f)), {}); | ||
| 1195 | VkShaderModule sm = VK_NULL_HANDLE; | 1293 | VkShaderModule sm = VK_NULL_HANDLE; |
| 1196 | bool mod_ok = false; | 1294 | bool mod_ok = false; |
| 1197 | if (!code.empty()) { | 1295 | if (!code.empty()) { |
| 1198 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; | 1296 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 1199 | smi.codeSize = code.size(); smi.pCode = reinterpret_cast<const uint32_t*>(code.data()); | 1297 | smi.codeSize = code.size() * sizeof(code.front()); |
| 1298 | smi.pCode = code.data(); | ||
| 1200 | mod_ok = vkCreateShaderModule(dev, &smi, nullptr, &sm) == VK_SUCCESS; | 1299 | mod_ok = vkCreateShaderModule(dev, &smi, nullptr, &sm) == VK_SUCCESS; |
| 1201 | } | 1300 | } |
| 1202 | { | 1301 | { |
| @@ -1218,7 +1317,7 @@ int main(int argc, char** argv) { | |||
| 1218 | cpi.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; cpi.stage.module = sm; cpi.stage.pName = "main"; | 1317 | cpi.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; cpi.stage.module = sm; cpi.stage.pName = "main"; |
| 1219 | const bool sg_forced = can_require_sg(meta.subgroup_size, VK_SHADER_STAGE_COMPUTE_BIT); | 1318 | const bool sg_forced = can_require_sg(meta.subgroup_size, VK_SHADER_STAGE_COMPUTE_BIT); |
| 1220 | if (sg_forced) cpi.stage.pNext = &reqSg; | 1319 | if (sg_forced) cpi.stage.pNext = &reqSg; |
| 1221 | cpi.layout = pl; | 1320 | cpi.layout = layout_for(meta); |
| 1222 | cpi.flags = capture; | 1321 | cpi.flags = capture; |
| 1223 | // Only whole-pipeline feedback is reported. | 1322 | // Only whole-pipeline feedback is reported. |
| 1224 | VkPipelineCreationFeedback fb{}; | 1323 | VkPipelineCreationFeedback fb{}; |
| @@ -1390,7 +1489,7 @@ int main(int argc, char** argv) { | |||
| 1390 | gpci.pDepthStencilState = &ds; | 1489 | gpci.pDepthStencilState = &ds; |
| 1391 | gpci.pColorBlendState = &blend; | 1490 | gpci.pColorBlendState = &blend; |
| 1392 | gpci.pDynamicState = &dyn_state; | 1491 | gpci.pDynamicState = &dyn_state; |
| 1393 | gpci.layout = pl; | 1492 | gpci.layout = layout_for(meta); |
| 1394 | gpci.renderPass = VK_NULL_HANDLE; | 1493 | gpci.renderPass = VK_NULL_HANDLE; |
| 1395 | gpci.flags = capture; | 1494 | gpci.flags = capture; |
| 1396 | // Zeroed per call and read after it returns; per-stage entries are required but not reported. | 1495 | // Zeroed per call and read after it returns; per-stage entries are required but not reported. |
diff --git a/runtime/test/vk_queue_test.cpp b/runtime/test/vk_queue_test.cpp new file mode 100644 index 000000000..84289198c --- /dev/null +++ b/runtime/test/vk_queue_test.cpp | |||
| @@ -0,0 +1,210 @@ | |||
| 1 | // D3D12 copy and compute queues on their own Vulkan queues, with cross-queue fences. No shaders or game data. | ||
| 2 | // | ||
| 3 | // The device gets a queue per D3D12 type (dedicated families when the GPU has them). A copy queue uploads a buffer | ||
| 4 | // and a texture, the way asset streaming does, signals a fence, and the direct queue waits on that fence on the GPU | ||
| 5 | // before reading both back. The compute queue does the same handoff the other way. A copy queue must refuse a | ||
| 6 | // render-target clear. Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation; any validation error | ||
| 7 | // fails the test. | ||
| 8 | #include "vk_test_device.h" | ||
| 9 | #include "../src/vulkan_backend.h" | ||
| 10 | |||
| 11 | #include <array> | ||
| 12 | #include <cstdint> | ||
| 13 | #include <cstring> | ||
| 14 | #include <vector> | ||
| 15 | |||
| 16 | #define EXPECT(condition) do { \ | ||
| 17 | if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ | ||
| 18 | } while (0) | ||
| 19 | |||
| 20 | namespace { | ||
| 21 | |||
| 22 | using namespace leonida; | ||
| 23 | using Kind = VulkanQueue::QueueKind; | ||
| 24 | |||
| 25 | const char* flags_text(VkQueueFlags f) { | ||
| 26 | static char buf[32]; | ||
| 27 | std::snprintf(buf, sizeof buf, "%s%s%s", f & VK_QUEUE_GRAPHICS_BIT ? "G" : "", f & VK_QUEUE_COMPUTE_BIT ? "C" : "", | ||
| 28 | f & VK_QUEUE_TRANSFER_BIT ? "T" : ""); | ||
| 29 | return buf; | ||
| 30 | } | ||
| 31 | |||
| 32 | int check_picker() { | ||
| 33 | // Synthetic family layouts: the picker's choices don't depend on the GPU running the test. | ||
| 34 | auto fam = [](VkQueueFlags flags, std::uint32_t granularity = 1) { | ||
| 35 | VkQueueFamilyProperties p{}; | ||
| 36 | p.queueFlags = flags; | ||
| 37 | p.queueCount = 1; | ||
| 38 | p.minImageTransferGranularity = {granularity, granularity, granularity}; | ||
| 39 | return p; | ||
| 40 | }; | ||
| 41 | constexpr VkQueueFlags G = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT; | ||
| 42 | constexpr VkQueueFlags C = VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT; | ||
| 43 | constexpr VkQueueFlags T = VK_QUEUE_TRANSFER_BIT; | ||
| 44 | { | ||
| 45 | const std::array f{fam(G), fam(T), fam(C)}; // the common NVIDIA layout | ||
| 46 | const auto q = pick_queue_families(f, 0); | ||
| 47 | EXPECT(q.direct == 0 && q.compute == 2 && q.copy == 1); | ||
| 48 | } | ||
| 49 | { | ||
| 50 | const std::array f{fam(G)}; // one family for everything (integrated GPUs, llvmpipe) | ||
| 51 | const auto q = pick_queue_families(f, 0); | ||
| 52 | EXPECT(q.direct == 0 && q.compute == 0 && q.copy == 0); | ||
| 53 | } | ||
| 54 | { | ||
| 55 | const std::array f{fam(G), fam(C)}; // no DMA family: copies go to async compute | ||
| 56 | const auto q = pick_queue_families(f, 0); | ||
| 57 | EXPECT(q.compute == 1 && q.copy == 1); | ||
| 58 | } | ||
| 59 | { | ||
| 60 | const std::array f{fam(G), fam(T, 8), fam(C)}; // a coarse DMA family is skipped | ||
| 61 | const auto q = pick_queue_families(f, 0); | ||
| 62 | EXPECT(q.copy == 2); | ||
| 63 | } | ||
| 64 | std::printf("queue family picker: 4 layouts ok\n"); | ||
| 65 | return 0; | ||
| 66 | } | ||
| 67 | |||
| 68 | constexpr std::uint32_t kSize = 64 * 1024; | ||
| 69 | constexpr std::uint32_t kTex = 64; // 64x64 RGBA8: row pitch 256, already aligned | ||
| 70 | |||
| 71 | std::uint8_t pattern(std::uint32_t i, std::uint8_t seed) { return std::uint8_t(i * 31 + seed); } | ||
| 72 | |||
| 73 | } // namespace | ||
| 74 | |||
| 75 | int main() { | ||
| 76 | if (check_picker()) return 1; | ||
| 77 | |||
| 78 | vktest::Device d; | ||
| 79 | d.all_queue_types = true; | ||
| 80 | if (!d.create()) { | ||
| 81 | std::printf("SKIP: no usable Vulkan device\n"); | ||
| 82 | return 77; | ||
| 83 | } | ||
| 84 | std::printf("families: direct %u (%s)", d.family, flags_text(d.families[d.family].queueFlags)); | ||
| 85 | std::printf(", compute %u (%s)", d.compute_family, flags_text(d.families[d.compute_family].queueFlags)); | ||
| 86 | std::printf(", copy %u (%s)\n", d.copy_family, flags_text(d.families[d.copy_family].queueFlags)); | ||
| 87 | |||
| 88 | VulkanContext context(d.device_proc, d.device, true); | ||
| 89 | EXPECT(context.loaded()); | ||
| 90 | VulkanQueue direct(context, d.queue, d.family, Kind::direct); | ||
| 91 | VulkanQueue compute(context, d.compute_queue, d.compute_family, Kind::compute); | ||
| 92 | VulkanQueue copy(context, d.copy_queue, d.copy_family, Kind::copy); | ||
| 93 | EXPECT(direct.ok() && compute.ok() && copy.ok()); | ||
| 94 | |||
| 95 | // Buffers: an upload source, a GPU-side destination and a readback, all host-visible for the test. | ||
| 96 | void *upload_map = nullptr, *mid_map = nullptr, *readback_map = nullptr, *tex_readback_map = nullptr; | ||
| 97 | const VkBufferUsageFlags usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; | ||
| 98 | VkBuffer upload = d.buffer(kSize, usage, &upload_map); | ||
| 99 | VkBuffer mid = d.buffer(kSize, usage, &mid_map); | ||
| 100 | VkBuffer readback = d.buffer(kSize, usage, &readback_map); | ||
| 101 | VkBuffer tex_readback = d.buffer(kTex * kTex * 4, usage, &tex_readback_map); | ||
| 102 | VkImage texture = d.image(VK_FORMAT_R8G8B8A8_UNORM, kTex, kTex, 1, VK_IMAGE_USAGE_SAMPLED_BIT); | ||
| 103 | EXPECT(upload && mid && readback && tex_readback && texture); | ||
| 104 | auto* up = static_cast<std::uint8_t*>(upload_map); | ||
| 105 | for (std::uint32_t i = 0; i < kSize; ++i) up[i] = pattern(i, 7); | ||
| 106 | |||
| 107 | const ResourceId upload_id = 1, mid_id = 2, readback_id = 3, tex_id = 4, tex_readback_id = 5; | ||
| 108 | auto add_buffer = [&](ResourceId id, VkBuffer b, VkDeviceSize size) { | ||
| 109 | ResourceBinding r; | ||
| 110 | r.buffer = b; | ||
| 111 | r.size = size; | ||
| 112 | context.add_resource(id, r); | ||
| 113 | }; | ||
| 114 | add_buffer(upload_id, upload, kSize); | ||
| 115 | add_buffer(mid_id, mid, kSize); | ||
| 116 | add_buffer(readback_id, readback, kSize); | ||
| 117 | add_buffer(tex_readback_id, tex_readback, kTex * kTex * 4); | ||
| 118 | ResourceBinding tex; | ||
| 119 | tex.image = texture; | ||
| 120 | tex.format = VK_FORMAT_R8G8B8A8_UNORM; | ||
| 121 | tex.width = kTex; | ||
| 122 | tex.height = kTex; | ||
| 123 | // As the device registers a texture: tracked, still undefined, in D3D12's common state. Its first use is the | ||
| 124 | // copy-queue upload, which can't zero-fill it first. | ||
| 125 | context.add_resource(tex_id, tex, VK_IMAGE_LAYOUT_UNDEFINED); | ||
| 126 | |||
| 127 | VulkanFence fence(context, 0); | ||
| 128 | EXPECT(fence.semaphore()); | ||
| 129 | |||
| 130 | // 1. Copy queue: buffer upload and a texture upload from the same staging buffer (footprint copy), then signal. | ||
| 131 | CommandList on_copy; | ||
| 132 | EXPECT(on_copy.copy_buffer({mid_id, 0, upload_id, 0, kSize})); | ||
| 133 | CopyTexture upload_tex{}; | ||
| 134 | upload_tex.dst = {tex_id, false, 0, 0, 0, 0, 0, 0}; | ||
| 135 | upload_tex.src = {upload_id, true, 0, 0, kTex, kTex, 1, kTex * 4}; | ||
| 136 | EXPECT(on_copy.copy_texture(upload_tex)); | ||
| 137 | EXPECT(on_copy.close()); | ||
| 138 | const CommandList* copy_lists[] = {&on_copy}; | ||
| 139 | EXPECT(copy.execute(copy_lists) == ReplayResult::success); | ||
| 140 | EXPECT(copy.signal(fence.semaphore(), 1)); | ||
| 141 | |||
| 142 | // 2. Direct queue: wait for the copy queue on the GPU, then read both back. | ||
| 143 | direct.wait(fence.semaphore(), 1); | ||
| 144 | CommandList on_direct; | ||
| 145 | EXPECT(on_direct.copy_buffer({readback_id, 0, mid_id, 0, kSize})); | ||
| 146 | CopyTexture read_tex{}; | ||
| 147 | read_tex.dst = {tex_readback_id, true, 0, 0, kTex, kTex, 1, kTex * 4}; | ||
| 148 | read_tex.src = {tex_id, false, 0, 0, 0, 0, 0, 0}; | ||
| 149 | EXPECT(on_direct.copy_texture(read_tex)); | ||
| 150 | EXPECT(on_direct.close()); | ||
| 151 | const CommandList* direct_lists[] = {&on_direct}; | ||
| 152 | EXPECT(direct.execute(direct_lists) == ReplayResult::success); | ||
| 153 | EXPECT(direct.signal(fence.semaphore(), 2)); | ||
| 154 | EXPECT(fence.wait(2, 5'000'000'000ull)); | ||
| 155 | |||
| 156 | std::uint32_t bad = 0; | ||
| 157 | auto* rb = static_cast<std::uint8_t*>(readback_map); | ||
| 158 | for (std::uint32_t i = 0; i < kSize; ++i) bad += rb[i] != pattern(i, 7); | ||
| 159 | auto* tr = static_cast<std::uint8_t*>(tex_readback_map); | ||
| 160 | for (std::uint32_t i = 0; i < kTex * kTex * 4; ++i) bad += tr[i] != pattern(i, 7); | ||
| 161 | std::printf("copy -> direct: buffer and texture upload read back, %u bad bytes\n", bad); | ||
| 162 | EXPECT(bad == 0); | ||
| 163 | |||
| 164 | // 3. Compute queue the other way: wait for the direct queue, copy, signal; the host waits on the fence. | ||
| 165 | for (std::uint32_t i = 0; i < kSize; ++i) up[i] = pattern(i, 99); | ||
| 166 | CommandList on_direct2; | ||
| 167 | EXPECT(on_direct2.copy_buffer({mid_id, 0, upload_id, 0, kSize})); | ||
| 168 | EXPECT(on_direct2.close()); | ||
| 169 | const CommandList* direct_lists2[] = {&on_direct2}; | ||
| 170 | EXPECT(direct.execute(direct_lists2) == ReplayResult::success); | ||
| 171 | EXPECT(direct.signal(fence.semaphore(), 3)); | ||
| 172 | compute.wait(fence.semaphore(), 3); | ||
| 173 | CommandList on_compute; | ||
| 174 | EXPECT(on_compute.copy_buffer({readback_id, 0, mid_id, 0, kSize})); | ||
| 175 | EXPECT(on_compute.close()); | ||
| 176 | const CommandList* compute_lists[] = {&on_compute}; | ||
| 177 | EXPECT(compute.execute(compute_lists) == ReplayResult::success); | ||
| 178 | EXPECT(compute.signal(fence.semaphore(), 4)); | ||
| 179 | EXPECT(fence.wait(4, 5'000'000'000ull)); | ||
| 180 | bad = 0; | ||
| 181 | for (std::uint32_t i = 0; i < kSize; ++i) bad += rb[i] != pattern(i, 99); | ||
| 182 | std::printf("direct -> compute: %u bad bytes\n", bad); | ||
| 183 | EXPECT(bad == 0); | ||
| 184 | |||
| 185 | // 4. A copy queue refuses a render-target clear and submits nothing. | ||
| 186 | VkImage rt_image = d.image(VK_FORMAT_R8G8B8A8_UNORM, 8, 8, 1, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); | ||
| 187 | ResourceBinding rt; | ||
| 188 | rt.image = rt_image; | ||
| 189 | rt.format = VK_FORMAT_R8G8B8A8_UNORM; | ||
| 190 | rt.width = rt.height = 8; | ||
| 191 | context.add_resource(6, rt, VK_IMAGE_LAYOUT_UNDEFINED); | ||
| 192 | CommandList clear; | ||
| 193 | TargetView view{}; | ||
| 194 | view.resource = 6; | ||
| 195 | view.layer_count = 1; | ||
| 196 | EXPECT(clear.clear_render_target(view, ClearColor{})); | ||
| 197 | EXPECT(clear.close()); | ||
| 198 | const CommandList* clear_lists[] = {&clear}; | ||
| 199 | EXPECT(copy.execute(clear_lists) == ReplayResult::unsupported); | ||
| 200 | EXPECT(compute.execute(clear_lists) == ReplayResult::unsupported); | ||
| 201 | std::printf("copy and compute queues refuse a render-target clear\n"); | ||
| 202 | |||
| 203 | EXPECT(direct.idle() && compute.idle() && copy.idle()); | ||
| 204 | if (d.validation) { | ||
| 205 | std::printf("validation errors: %u\n", d.validation_errors()); | ||
| 206 | EXPECT(d.validation_errors() == 0); | ||
| 207 | } | ||
| 208 | std::printf("vk_queue_test: OK\n"); | ||
| 209 | return 0; | ||
| 210 | } | ||
diff --git a/runtime/test/vk_sampler_test.cpp b/runtime/test/vk_sampler_test.cpp index c1bc4b7e1..2adf4d629 100644 --- a/runtime/test/vk_sampler_test.cpp +++ b/runtime/test/vk_sampler_test.cpp | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #define VK_NO_PROTOTYPES | 13 | #define VK_NO_PROTOTYPES |
| 14 | #include "vulkan_loader.h" | 14 | #include "vulkan_loader.h" |
| 15 | #include "../src/vulkan_device_filter.h" | 15 | #include "../src/vulkan_device_filter.h" |
| 16 | #include "vk_pc_tail.h" | ||
| 16 | 17 | ||
| 17 | #include "../src/descriptor_table.h" | 18 | #include "../src/descriptor_table.h" |
| 18 | #include "../src/gfx10_descriptors.h" | 19 | #include "../src/gfx10_descriptors.h" |
| @@ -355,12 +356,19 @@ int main(int argc, char** argv) { | |||
| 355 | 356 | ||
| 356 | // Pipeline. | 357 | // Pipeline. |
| 357 | VkShaderModule modules[2]; | 358 | VkShaderModule modules[2]; |
| 359 | // LEONIDA_PC_TAIL_UBO=1 (rdna2spirv.py --pc-tail-ubo): s0..s31 in 128 push-constant bytes; the heap base, if a | ||
| 360 | // stage reads it, in a uniform block at set 1 (vk_pc_tail.h). | ||
| 361 | const bool pc_tail = leonida::vk_test::pc_tail_requested(); | ||
| 362 | const std::uint32_t push_bytes = pc_tail ? 128u : 144u; | ||
| 363 | bool tail_block = false; | ||
| 358 | for (int stage = 0; stage < 2; ++stage) { | 364 | for (int stage = 0; stage < 2; ++stage) { |
| 359 | const auto code = read_spv(argv[1 + stage]); | 365 | const auto code = read_spv(argv[1 + stage]); |
| 360 | if (code.empty()) { | 366 | if (code.empty()) { |
| 361 | std::fprintf(stderr, "cannot read %s\n", argv[1 + stage]); | 367 | std::fprintf(stderr, "cannot read %s\n", argv[1 + stage]); |
| 362 | return 1; | 368 | return 1; |
| 363 | } | 369 | } |
| 370 | if (pc_tail && leonida::vk_test::spirv_declares_set(code.data(), code.size() * 4, leonida::vk_test::pc_tail_set)) | ||
| 371 | tail_block = true; | ||
| 364 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; | 372 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 365 | smi.codeSize = code.size() * 4; | 373 | smi.codeSize = code.size() * 4; |
| 366 | smi.pCode = code.data(); | 374 | smi.pCode = code.data(); |
| @@ -374,12 +382,20 @@ int main(int argc, char** argv) { | |||
| 374 | stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; | 382 | stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 375 | stages[1].module = modules[1]; | 383 | stages[1].module = modules[1]; |
| 376 | stages[1].pName = "main"; | 384 | stages[1].pName = "main"; |
| 377 | const VkPushConstantRange push{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 144}; | 385 | const VkPushConstantRange push{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, push_bytes}; |
| 378 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; | 386 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; |
| 379 | pli.setLayoutCount = 1; | 387 | pli.setLayoutCount = 1; |
| 380 | pli.pSetLayouts = &dsl; | 388 | pli.pSetLayouts = &dsl; |
| 381 | pli.pushConstantRangeCount = 1; | 389 | pli.pushConstantRangeCount = 1; |
| 382 | pli.pPushConstantRanges = &push; | 390 | pli.pPushConstantRanges = &push; |
| 391 | leonida::vk_test::PcTail tail; | ||
| 392 | if (tail_block && !tail.create(vkGetDeviceProcAddr, dev, mp, props.limits.minUniformBufferOffsetAlignment, | ||
| 393 | VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 1)) { | ||
| 394 | std::fprintf(stderr, "FAILED creating the --pc-tail-ubo block\n"); | ||
| 395 | return 1; | ||
| 396 | } | ||
| 397 | const VkDescriptorSetLayout set_layouts[] = {dsl, tail.set_layout}; | ||
| 398 | if (tail_block) { pli.setLayoutCount = 2; pli.pSetLayouts = set_layouts; } | ||
| 383 | VkPipelineLayout pipeline_layout; | 399 | VkPipelineLayout pipeline_layout; |
| 384 | CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pipeline_layout)); | 400 | CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pipeline_layout)); |
| 385 | const VkPipelineVertexInputStateCreateInfo vertex_input{VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO}; | 401 | const VkPipelineVertexInputStateCreateInfo vertex_input{VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO}; |
| @@ -472,7 +488,13 @@ int main(int argc, char** argv) { | |||
| 472 | block[0] = table_va; // s0:s1 = console VA of the T# (the shader's s1 stays 0) | 488 | block[0] = table_va; // s0:s1 = console VA of the T# (the shader's s1 stays 0) |
| 473 | block[32] = std::uint32_t(heap_base); | 489 | block[32] = std::uint32_t(heap_base); |
| 474 | block[33] = std::uint32_t(heap_base >> 32); | 490 | block[33] = std::uint32_t(heap_base >> 32); |
| 475 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(block), block); | 491 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, push_bytes, block); |
| 492 | if (tail_block) { | ||
| 493 | tail.write(0, block, 4); | ||
| 494 | const std::uint32_t offset = tail.offset(0); | ||
| 495 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, leonida::vk_test::pc_tail_set, 1, | ||
| 496 | &tail.set, 1, &offset); | ||
| 497 | } | ||
| 476 | vkCmdDraw(cmd, 3, 1, 0, 0); | 498 | vkCmdDraw(cmd, 3, 1, 0, 0); |
| 477 | vkCmdEndRenderPass(cmd); | 499 | vkCmdEndRenderPass(cmd); |
| 478 | VkBufferImageCopy rc{}; | 500 | VkBufferImageCopy rc{}; |
diff --git a/runtime/test/vk_shader_fma.h b/runtime/test/vk_shader_fma.h index e66884f97..a740859dc 100644 --- a/runtime/test/vk_shader_fma.h +++ b/runtime/test/vk_shader_fma.h | |||
| @@ -21,14 +21,14 @@ inline constexpr bool shader_fma_in_headers = true; | |||
| 21 | inline constexpr bool shader_fma_in_headers = false; | 21 | inline constexpr bool shader_fma_in_headers = false; |
| 22 | #endif | 22 | #endif |
| 23 | 23 | ||
| 24 | // OpCapability (17) FMAKHR (6030; spirv/unified1/spirv.h). | 24 | // Find OpCapability (17) in a binary module. |
| 25 | inline bool spirv_needs_fma(const void* data, std::size_t bytes) { | 25 | inline bool spirv_declares_capability(const void* data, std::size_t bytes, std::uint32_t capability) { |
| 26 | if (bytes < 20 || bytes % 4) return false; | 26 | if (bytes < 20 || bytes % 4) return false; |
| 27 | std::vector<std::uint32_t> words(bytes / 4); | 27 | std::vector<std::uint32_t> words(bytes / 4); |
| 28 | std::memcpy(words.data(), data, bytes); | 28 | std::memcpy(words.data(), data, bytes); |
| 29 | for (std::size_t i = 5; i < words.size() && (words[i] >> 16);) { | 29 | for (std::size_t i = 5; i < words.size() && (words[i] >> 16);) { |
| 30 | const std::uint32_t op = words[i] & 0xffff, count = words[i] >> 16; | 30 | const std::uint32_t op = words[i] & 0xffff, count = words[i] >> 16; |
| 31 | if (op == 17 && count == 2 && i + 1 < words.size() && words[i + 1] == 6030) return true; | 31 | if (op == 17 && count == 2 && i + 1 < words.size() && words[i + 1] == capability) return true; |
| 32 | i += count; | 32 | i += count; |
| 33 | } | 33 | } |
| 34 | return false; | 34 | return false; |
| @@ -93,7 +93,7 @@ struct ShaderFma { | |||
| 93 | // True when the module can be used: it does not need FMAKHR, or the device enables shaderFmaFloat32. | 93 | // True when the module can be used: it does not need FMAKHR, or the device enables shaderFmaFloat32. |
| 94 | // Otherwise says so and the caller returns 77. | 94 | // Otherwise says so and the caller returns 77. |
| 95 | bool accepts(const void* code, std::size_t bytes, const char* name) const { | 95 | bool accepts(const void* code, std::size_t bytes, const char* name) const { |
| 96 | if (float32 || !spirv_needs_fma(code, bytes)) return true; | 96 | if (float32 || !spirv_declares_capability(code, bytes, 6030)) return true; // FMAKHR |
| 97 | std::fprintf(stderr, "unsupported: %s needs OpFmaKHR (VK_KHR_shader_fma, shaderFmaFloat32) and the device " | 97 | std::fprintf(stderr, "unsupported: %s needs OpFmaKHR (VK_KHR_shader_fma, shaderFmaFloat32) and the device " |
| 98 | "lacks it; translate with --fma glsl\n", name); | 98 | "lacks it; translate with --fma glsl\n", name); |
| 99 | return false; | 99 | return false; |
diff --git a/runtime/test/vk_store_test.cpp b/runtime/test/vk_store_test.cpp index 964266d1b..e6b76d363 100644 --- a/runtime/test/vk_store_test.cpp +++ b/runtime/test/vk_store_test.cpp | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "vulkan_loader.h" | 18 | #include "vulkan_loader.h" |
| 19 | #include "vk_device_pick.h" | 19 | #include "vk_device_pick.h" |
| 20 | #include "vk_shader_fma.h" | 20 | #include "vk_shader_fma.h" |
| 21 | #include "vk_pc_tail.h" | ||
| 21 | #include "../src/gfx10_descriptors.h" | 22 | #include "../src/gfx10_descriptors.h" |
| 22 | 23 | ||
| 23 | #include <cmath> | 24 | #include <cmath> |
| @@ -321,9 +322,23 @@ int main(int argc, char** argv) { | |||
| 321 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; | 322 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 322 | smi.codeSize = code.size(); smi.pCode = reinterpret_cast<const uint32_t*>(code.data()); | 323 | smi.codeSize = code.size(); smi.pCode = reinterpret_cast<const uint32_t*>(code.data()); |
| 323 | VkShaderModule sm; CHECK(vkCreateShaderModule(dev, &smi, nullptr, &sm)); | 324 | VkShaderModule sm; CHECK(vkCreateShaderModule(dev, &smi, nullptr, &sm)); |
| 324 | VkPushConstantRange pcr{VK_SHADER_STAGE_COMPUTE_BIT, 0, 144}; | 325 | // LEONIDA_PC_TAIL_UBO=1 (rdna2spirv.py --pc-tail-ubo): s0..s31 only, 128 bytes; a module that reads the tail |
| 326 | // gets it, all zero as without the flag, from a uniform block at set 1 (vk_pc_tail.h). | ||
| 327 | const bool pc_tail = leonida::vk_test::pc_tail_requested(); | ||
| 328 | const uint32_t pc_bytes = pc_tail ? 128u : 144u; | ||
| 329 | const bool tail_block = pc_tail && | ||
| 330 | leonida::vk_test::spirv_declares_set(code.data(), code.size(), leonida::vk_test::pc_tail_set); | ||
| 331 | leonida::vk_test::PcTail tail; | ||
| 332 | if (tail_block && !tail.create(vkGetDeviceProcAddr, dev, mp, props.limits.minUniformBufferOffsetAlignment, | ||
| 333 | VK_SHADER_STAGE_COMPUTE_BIT, 1)) { | ||
| 334 | std::fprintf(stderr, "FAILED creating the --pc-tail-ubo block\n"); | ||
| 335 | return 1; | ||
| 336 | } | ||
| 337 | VkPushConstantRange pcr{VK_SHADER_STAGE_COMPUTE_BIT, 0, pc_bytes}; | ||
| 325 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; | 338 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; |
| 326 | pli.setLayoutCount = 1; pli.pSetLayouts = &dsl; pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; | 339 | pli.setLayoutCount = 1; pli.pSetLayouts = &dsl; pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; |
| 340 | const VkDescriptorSetLayout set_layouts[] = {dsl, tail.set_layout}; | ||
| 341 | if (tail_block) { pli.setLayoutCount = 2; pli.pSetLayouts = set_layouts; } | ||
| 327 | VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); | 342 | VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); |
| 328 | VkComputePipelineCreateInfo cpi{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO}; | 343 | VkComputePipelineCreateInfo cpi{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO}; |
| 329 | cpi.stage = {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}; | 344 | cpi.stage = {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}; |
| @@ -420,7 +435,12 @@ int main(int argc, char** argv) { | |||
| 420 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipe); | 435 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipe); |
| 421 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pl, 0, 1, &ds, 0, nullptr); | 436 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pl, 0, 1, &ds, 0, nullptr); |
| 422 | uint32_t pc[36] = {}; | 437 | uint32_t pc[36] = {}; |
| 423 | vkCmdPushConstants(cmd, pl, VK_SHADER_STAGE_COMPUTE_BIT, 0, 144, pc); | 438 | vkCmdPushConstants(cmd, pl, VK_SHADER_STAGE_COMPUTE_BIT, 0, pc_bytes, pc); |
| 439 | if (tail_block) { | ||
| 440 | const uint32_t offset = tail.offset(0); // PcTail starts zeroed: the tail stays all zero, as pushed before | ||
| 441 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pl, leonida::vk_test::pc_tail_set, 1, &tail.set, | ||
| 442 | 1, &offset); | ||
| 443 | } | ||
| 424 | vkCmdDispatch(cmd, 1, 1, 1); | 444 | vkCmdDispatch(cmd, 1, 1, 1); |
| 425 | for (int k = 0; k < 3; k++) { | 445 | for (int k = 0; k < 3; k++) { |
| 426 | ib[k].oldLayout = VK_IMAGE_LAYOUT_GENERAL; ib[k].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; | 446 | ib[k].oldLayout = VK_IMAGE_LAYOUT_GENERAL; ib[k].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
diff --git a/runtime/test/vk_test_device.h b/runtime/test/vk_test_device.h index 84d9e7a7d..b1d5f8f73 100644 --- a/runtime/test/vk_test_device.h +++ b/runtime/test/vk_test_device.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "vulkan_loader.h" | 7 | #include "vulkan_loader.h" |
| 8 | #include "../src/queue_families.h" | ||
| 8 | #include "../src/vulkan_device_filter.h" | 9 | #include "../src/vulkan_device_filter.h" |
| 9 | #include "../src/vulkan13_features.h" | 10 | #include "../src/vulkan13_features.h" |
| 10 | #include "vk_device_pick.h" | 11 | #include "vk_device_pick.h" |
| @@ -92,6 +93,10 @@ public: | |||
| 92 | std::vector<VkQueue> queues; | 93 | std::vector<VkQueue> queues; |
| 93 | bool validation = false; | 94 | bool validation = false; |
| 94 | bool bc = false; // textureCompressionBC enabled | 95 | bool bc = false; // textureCompressionBC enabled |
| 96 | bool all_queue_types = false; | ||
| 97 | VkQueue compute_queue = VK_NULL_HANDLE, copy_queue = VK_NULL_HANDLE; | ||
| 98 | std::uint32_t compute_family = 0, copy_family = 0; | ||
| 99 | std::vector<VkQueueFamilyProperties> families; | ||
| 95 | VkPhysicalDeviceFeatures enabled{}; // the core features enabled on `device` | 100 | VkPhysicalDeviceFeatures enabled{}; // the core features enabled on `device` |
| 96 | bool bindless = false; // the features the bindless set 0 needs are enabled | 101 | bool bindless = false; // the features the bindless set 0 needs are enabled |
| 97 | bool partially_bound = false; // and its slots can stay empty | 102 | bool partially_bound = false; // and its slots can stay empty |
| @@ -211,6 +216,9 @@ public: | |||
| 211 | std::vector<VkExtensionProperties> available(count); | 216 | std::vector<VkExtensionProperties> available(count); |
| 212 | enumerate_instance(nullptr, &count, available.data()); | 217 | enumerate_instance(nullptr, &count, available.data()); |
| 213 | bool caps2 = false; | 218 | bool caps2 = false; |
| 219 | for (const auto& e : available) // lists the HDR10 (ST.2084) surface formats, when the display has them | ||
| 220 | if (std::strcmp(e.extensionName, "VK_EXT_swapchain_colorspace") == 0) | ||
| 221 | instance_extensions.push_back("VK_EXT_swapchain_colorspace"); | ||
| 214 | for (const auto& e : available) { | 222 | for (const auto& e : available) { |
| 215 | caps2 = caps2 || std::strcmp(e.extensionName, "VK_KHR_get_surface_capabilities2") == 0; | 223 | caps2 = caps2 || std::strcmp(e.extensionName, "VK_KHR_get_surface_capabilities2") == 0; |
| 216 | surface_m1_khr = surface_m1_khr || std::strcmp(e.extensionName, "VK_KHR_surface_maintenance1") == 0; | 224 | surface_m1_khr = surface_m1_khr || std::strcmp(e.extensionName, "VK_KHR_surface_maintenance1") == 0; |
| @@ -286,15 +294,15 @@ public: | |||
| 286 | if (!candidate13.usable()) continue; | 294 | if (!candidate13.usable()) continue; |
| 287 | std::uint32_t family_count = 0; | 295 | std::uint32_t family_count = 0; |
| 288 | families_of(candidate, &family_count, nullptr); | 296 | families_of(candidate, &family_count, nullptr); |
| 289 | std::vector<VkQueueFamilyProperties> families(family_count); | 297 | std::vector<VkQueueFamilyProperties> candidate_families(family_count); |
| 290 | families_of(candidate, &family_count, families.data()); | 298 | families_of(candidate, &family_count, candidate_families.data()); |
| 291 | for (std::uint32_t i = 0; i < family_count; ++i) { | 299 | for (std::uint32_t i = 0; i < family_count; ++i) { |
| 292 | if (!(families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)) continue; | 300 | if (!(candidate_families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)) continue; |
| 293 | if (const int rank = leonida::vk_test::device_rank(props.deviceType, props.vendorID); | 301 | if (const int rank = leonida::vk_test::device_rank(props.deviceType, props.vendorID); |
| 294 | rank > best_rank) { | 302 | rank > best_rank) { |
| 295 | physical = candidate; | 303 | physical = candidate; |
| 296 | family = i; | 304 | family = i; |
| 297 | family_queue_count = families[i].queueCount; | 305 | family_queue_count = candidate_families[i].queueCount; |
| 298 | chosen = props; | 306 | chosen = props; |
| 299 | best_rank = rank; | 307 | best_rank = rank; |
| 300 | v13_.choose(candidate13); | 308 | v13_.choose(candidate13); |
| @@ -386,11 +394,32 @@ public: | |||
| 386 | enable12.samplerFilterMinmax = sampler_filter_minmax; | 394 | enable12.samplerFilterMinmax = sampler_filter_minmax; |
| 387 | enable12.bufferDeviceAddress = VK_TRUE; | 395 | enable12.bufferDeviceAddress = VK_TRUE; |
| 388 | 396 | ||
| 389 | const std::vector<float> priority(std::max(1u, std::min(queue_count_wanted, family_queue_count)), 1.0f); | 397 | const std::uint32_t graphics_count = std::max(1u, std::min(queue_count_wanted, family_queue_count)); |
| 390 | VkDeviceQueueCreateInfo queue_info{VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO}; | 398 | const std::vector<float> priority(graphics_count, 1.0f); |
| 391 | queue_info.queueFamilyIndex = family; | 399 | { |
| 392 | queue_info.queueCount = std::max(1u, std::min(queue_count_wanted, family_queue_count)); | 400 | std::uint32_t family_count = 0; |
| 393 | queue_info.pQueuePriorities = priority.data(); | 401 | families_of(physical, &family_count, nullptr); |
| 402 | families.resize(family_count); | ||
| 403 | families_of(physical, &family_count, families.data()); | ||
| 404 | } | ||
| 405 | compute_family = copy_family = family; | ||
| 406 | if (all_queue_types) { | ||
| 407 | const auto picked = leonida::pick_queue_families(families, family); | ||
| 408 | compute_family = picked.compute; | ||
| 409 | copy_family = picked.copy; | ||
| 410 | } | ||
| 411 | std::vector<VkDeviceQueueCreateInfo> queue_infos; | ||
| 412 | for (std::uint32_t f : {family, compute_family, copy_family}) { | ||
| 413 | bool seen = false; | ||
| 414 | for (const auto& q : queue_infos) seen = seen || q.queueFamilyIndex == f; | ||
| 415 | if (seen) continue; | ||
| 416 | VkDeviceQueueCreateInfo q{VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO}; | ||
| 417 | q.queueFamilyIndex = f; | ||
| 418 | q.queueCount = f == family ? graphics_count : 1; | ||
| 419 | q.pQueuePriorities = priority.data(); | ||
| 420 | queue_infos.push_back(q); | ||
| 421 | sharing_.push_back(f); | ||
| 422 | } | ||
| 394 | VkPhysicalDeviceFeatures enable{}; | 423 | VkPhysicalDeviceFeatures enable{}; |
| 395 | enable.textureCompressionBC = features.features.textureCompressionBC; // BC uploads, where available | 424 | enable.textureCompressionBC = features.features.textureCompressionBC; // BC uploads, where available |
| 396 | enable.shaderInt64 = features.features.shaderInt64; // translated shaders declare Int64 (index features) | 425 | enable.shaderInt64 = features.features.shaderInt64; // translated shaders declare Int64 (index features) |
| @@ -398,6 +427,7 @@ public: | |||
| 398 | enable.shaderSampledImageArrayDynamicIndexing = bindless; | 427 | enable.shaderSampledImageArrayDynamicIndexing = bindless; |
| 399 | enable.shaderStorageImageArrayDynamicIndexing = bindless; | 428 | enable.shaderStorageImageArrayDynamicIndexing = bindless; |
| 400 | enable.logicOp = features.features.logicOp; // d3d12_draw_test's logic-op draw, where available | 429 | enable.logicOp = features.features.logicOp; // d3d12_draw_test's logic-op draw, where available |
| 430 | enable.geometryShader = features.features.geometryShader; // d3d12_geometry_test, where available | ||
| 401 | enable.shaderInt64 = features.features.shaderInt64; // translated shaders declare Int64 for their addresses | 431 | enable.shaderInt64 = features.features.shaderInt64; // translated shaders declare Int64 for their addresses |
| 402 | const char* conditional_extension = VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME; | 432 | const char* conditional_extension = VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME; |
| 403 | 433 | ||
| @@ -471,8 +501,8 @@ public: | |||
| 471 | } | 501 | } |
| 472 | 502 | ||
| 473 | VkDeviceCreateInfo device_info{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, &enable12}; | 503 | VkDeviceCreateInfo device_info{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, &enable12}; |
| 474 | device_info.queueCreateInfoCount = 1; | 504 | device_info.queueCreateInfoCount = std::uint32_t(queue_infos.size()); |
| 475 | device_info.pQueueCreateInfos = &queue_info; | 505 | device_info.pQueueCreateInfos = queue_infos.data(); |
| 476 | device_info.pEnabledFeatures = &enable; | 506 | device_info.pEnabledFeatures = &enable; |
| 477 | enabled = enable; | 507 | enabled = enable; |
| 478 | std::vector<const char*> device_extensions; | 508 | std::vector<const char*> device_extensions; |
| @@ -514,10 +544,12 @@ public: | |||
| 514 | result = instance_fn<PFN_vkCreateDevice>("vkCreateDevice")(physical, &device_info, nullptr, &device); | 544 | result = instance_fn<PFN_vkCreateDevice>("vkCreateDevice")(physical, &device_info, nullptr, &device); |
| 515 | if (result != VK_SUCCESS) return failure("vkCreateDevice", result); | 545 | if (result != VK_SUCCESS) return failure("vkCreateDevice", result); |
| 516 | device_proc = instance_fn<PFN_vkGetDeviceProcAddr>("vkGetDeviceProcAddr"); | 546 | device_proc = instance_fn<PFN_vkGetDeviceProcAddr>("vkGetDeviceProcAddr"); |
| 517 | queues.resize(queue_info.queueCount); | 547 | queues.resize(graphics_count); |
| 518 | for (std::uint32_t i = 0; i < queue_info.queueCount; ++i) | 548 | for (std::uint32_t i = 0; i < graphics_count; ++i) |
| 519 | fn<PFN_vkGetDeviceQueue>("vkGetDeviceQueue")(device, family, i, &queues[i]); | 549 | fn<PFN_vkGetDeviceQueue>("vkGetDeviceQueue")(device, family, i, &queues[i]); |
| 520 | queue = queues[0]; | 550 | queue = queues[0]; |
| 551 | fn<PFN_vkGetDeviceQueue>("vkGetDeviceQueue")(device, compute_family, 0, &compute_queue); | ||
| 552 | fn<PFN_vkGetDeviceQueue>("vkGetDeviceQueue")(device, copy_family, 0, ©_queue); | ||
| 521 | instance_fn<PFN_vkGetPhysicalDeviceMemoryProperties>("vkGetPhysicalDeviceMemoryProperties")(physical, | 553 | instance_fn<PFN_vkGetPhysicalDeviceMemoryProperties>("vkGetPhysicalDeviceMemoryProperties")(physical, |
| 522 | &memory_); | 554 | &memory_); |
| 523 | VkCommandPoolCreateInfo pool{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; | 555 | VkCommandPoolCreateInfo pool{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; |
| @@ -547,6 +579,7 @@ public: | |||
| 547 | info.arrayLayers = layers; | 579 | info.arrayLayers = layers; |
| 548 | info.samples = VkSampleCountFlagBits(samples); | 580 | info.samples = VkSampleCountFlagBits(samples); |
| 549 | info.usage = usage | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; | 581 | info.usage = usage | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 582 | share(info); | ||
| 550 | VkImage image = VK_NULL_HANDLE; | 583 | VkImage image = VK_NULL_HANDLE; |
| 551 | if (fn<PFN_vkCreateImage>("vkCreateImage")(device, &info, nullptr, &image) != VK_SUCCESS) return VK_NULL_HANDLE; | 584 | if (fn<PFN_vkCreateImage>("vkCreateImage")(device, &info, nullptr, &image) != VK_SUCCESS) return VK_NULL_HANDLE; |
| 552 | VkMemoryRequirements requirements{}; | 585 | VkMemoryRequirements requirements{}; |
| @@ -563,6 +596,7 @@ public: | |||
| 563 | VkBufferCreateInfo info{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; | 596 | VkBufferCreateInfo info{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; |
| 564 | info.size = size; | 597 | info.size = size; |
| 565 | info.usage = usage | (buffer_device_address ? VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT : 0u); | 598 | info.usage = usage | (buffer_device_address ? VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT : 0u); |
| 599 | share(info); | ||
| 566 | VkBuffer buffer = VK_NULL_HANDLE; | 600 | VkBuffer buffer = VK_NULL_HANDLE; |
| 567 | if (fn<PFN_vkCreateBuffer>("vkCreateBuffer")(device, &info, nullptr, &buffer) != VK_SUCCESS) | 601 | if (fn<PFN_vkCreateBuffer>("vkCreateBuffer")(device, &info, nullptr, &buffer) != VK_SUCCESS) |
| 568 | return VK_NULL_HANDLE; | 602 | return VK_NULL_HANDLE; |
| @@ -646,6 +680,16 @@ public: | |||
| 646 | } | 680 | } |
| 647 | 681 | ||
| 648 | private: | 682 | private: |
| 683 | std::vector<std::uint32_t> sharing_; | ||
| 684 | |||
| 685 | template<typename Info> | ||
| 686 | void share(Info& info) const { | ||
| 687 | if (sharing_.size() < 2) return; | ||
| 688 | info.sharingMode = VK_SHARING_MODE_CONCURRENT; | ||
| 689 | info.queueFamilyIndexCount = std::uint32_t(sharing_.size()); | ||
| 690 | info.pQueueFamilyIndices = sharing_.data(); | ||
| 691 | } | ||
| 692 | |||
| 649 | VkDeviceMemory allocate(const VkMemoryRequirements& requirements, VkMemoryPropertyFlags flags) { | 693 | VkDeviceMemory allocate(const VkMemoryRequirements& requirements, VkMemoryPropertyFlags flags) { |
| 650 | for (std::uint32_t i = 0; i < memory_.memoryTypeCount; ++i) { | 694 | for (std::uint32_t i = 0; i < memory_.memoryTypeCount; ++i) { |
| 651 | if (!(requirements.memoryTypeBits & (1u << i))) continue; | 695 | if (!(requirements.memoryTypeBits & (1u << i))) continue; |
diff --git a/runtime/test/vk_texture_test.cpp b/runtime/test/vk_texture_test.cpp index 69f4b5675..2deb3f812 100644 --- a/runtime/test/vk_texture_test.cpp +++ b/runtime/test/vk_texture_test.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "vulkan_loader.h" | 23 | #include "vulkan_loader.h" |
| 24 | #include "vk_device_pick.h" | 24 | #include "vk_device_pick.h" |
| 25 | #include "vk_shader_fma.h" | 25 | #include "vk_shader_fma.h" |
| 26 | #include "vk_pc_tail.h" | ||
| 26 | 27 | ||
| 27 | #include <algorithm> | 28 | #include <algorithm> |
| 28 | #include <cmath> | 29 | #include <cmath> |
| @@ -112,10 +113,11 @@ int main(int argc, char** argv) { | |||
| 112 | std::fprintf(stderr, "usage: vk_texture_test [cube|dref|dref_a16] [out] | vs fs out ptr_sgpr s0 s1 s2 s3 [--two-mip|--two-mip-sint]\n"); | 113 | std::fprintf(stderr, "usage: vk_texture_test [cube|dref|dref_a16] [out] | vs fs out ptr_sgpr s0 s1 s2 s3 [--two-mip|--two-mip-sint]\n"); |
| 113 | return 2; | 114 | return 2; |
| 114 | } | 115 | } |
| 115 | // Word 1 also selects the numeric type when the shader fetches through this key. | 116 | // Word 1 also selects the numeric type when the shader fetches through this key. Word 3 keeps BASE_LEVEL [15:12] |
| 117 | // at 0, as the views here start at level 0: image_get_resinfo minifies a 2D array's layers from BASE_LEVEL. | ||
| 116 | const VkFormat sampled_format = dref ? VK_FORMAT_D32_SFLOAT : | 118 | const VkFormat sampled_format = dref ? VK_FORMAT_D32_SFLOAT : |
| 117 | signed_mips ? VK_FORMAT_R8G8B8A8_SINT : VK_FORMAT_R8G8B8A8_UNORM; | 119 | signed_mips ? VK_FORMAT_R8G8B8A8_SINT : VK_FORMAT_R8G8B8A8_UNORM; |
| 118 | uint32_t tsharp[8] = {0x11111111, leonida::gfx10::format_from_vulkan(sampled_format) << 20, 0x33333333, 0x44444444, | 120 | uint32_t tsharp[8] = {0x11111111, leonida::gfx10::format_from_vulkan(sampled_format) << 20, 0x33333333, 0x44440444, |
| 119 | 0x55555555, 0x66666666, 0x77777777, 0x88888888}; | 121 | 0x55555555, 0x66666666, 0x77777777, 0x88888888}; |
| 120 | const uint32_t tsharp_va = 256; | 122 | const uint32_t tsharp_va = 256; |
| 121 | 123 | ||
| @@ -155,7 +157,10 @@ int main(int argc, char** argv) { | |||
| 155 | } | 157 | } |
| 156 | } | 158 | } |
| 157 | constexpr uint32_t push_words = 36; | 159 | constexpr uint32_t push_words = 36; |
| 158 | constexpr uint32_t push_bytes = push_words * sizeof(uint32_t); | 160 | // LEONIDA_PC_TAIL_UBO=1 (rdna2spirv.py --pc-tail-ubo): s0..s31 only; the heap base is in a uniform block at set 1 |
| 161 | // (vk_pc_tail.h), so a 128-byte device runs these tests too. | ||
| 162 | const bool pc_tail = leonida::vk_test::pc_tail_requested(); | ||
| 163 | const uint32_t push_bytes = pc_tail ? 128u : push_words * uint32_t(sizeof(uint32_t)); | ||
| 159 | if (properties.limits.maxPushConstantsSize < push_bytes) { | 164 | if (properties.limits.maxPushConstantsSize < push_bytes) { |
| 160 | std::fprintf(stderr, "unsupported: need %u push constant bytes, device has %u\n", | 165 | std::fprintf(stderr, "unsupported: need %u push constant bytes, device has %u\n", |
| 161 | push_bytes, properties.limits.maxPushConstantsSize); | 166 | push_bytes, properties.limits.maxPushConstantsSize); |
| @@ -172,7 +177,11 @@ int main(int argc, char** argv) { | |||
| 172 | float prio = 1; | 177 | float prio = 1; |
| 173 | VkDeviceQueueCreateInfo qci{VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO}; | 178 | VkDeviceQueueCreateInfo qci{VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO}; |
| 174 | qci.queueFamilyIndex = qi; qci.queueCount = 1; qci.pQueuePriorities = &prio; | 179 | qci.queueFamilyIndex = qi; qci.queueCount = 1; qci.pQueuePriorities = &prio; |
| 180 | // Translated vertex shaders read BaseVertex / BaseInstance (DrawParameters) for the zero-based v0 / v3. | ||
| 181 | VkPhysicalDeviceVulkan11Features f11{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES}; | ||
| 182 | f11.shaderDrawParameters = VK_TRUE; | ||
| 175 | VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; | 183 | VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; |
| 184 | f12.pNext = &f11; | ||
| 176 | f12.bufferDeviceAddress = VK_TRUE; f12.runtimeDescriptorArray = VK_TRUE; f12.descriptorIndexing = VK_TRUE; | 185 | f12.bufferDeviceAddress = VK_TRUE; f12.runtimeDescriptorArray = VK_TRUE; f12.descriptorIndexing = VK_TRUE; |
| 177 | VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; f2.pNext = &f12; | 186 | VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; f2.pNext = &f12; |
| 178 | f2.features.shaderInt64 = VK_TRUE; | 187 | f2.features.shaderInt64 = VK_TRUE; |
| @@ -413,12 +422,15 @@ int main(int argc, char** argv) { | |||
| 413 | wr[3].dstBinding = 3; wr[3].descriptorCount = 2; wr[3].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; wr[3].pImageInfo = ai2; | 422 | wr[3].dstBinding = 3; wr[3].descriptorCount = 2; wr[3].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; wr[3].pImageInfo = ai2; |
| 414 | vkUpdateDescriptorSets(dev, 4, wr, 0, nullptr); | 423 | vkUpdateDescriptorSets(dev, 4, wr, 0, nullptr); |
| 415 | // Pipeline. | 424 | // Pipeline. |
| 425 | bool tail_block = false; // a stage reads the --pc-tail-ubo block (declares set 1) | ||
| 416 | auto module = [&](const char* p, VkShaderModule* m) { | 426 | auto module = [&](const char* p, VkShaderModule* m) { |
| 417 | auto code = read_spv(p); | 427 | auto code = read_spv(p); |
| 418 | if (code.empty()) { | 428 | if (code.empty()) { |
| 419 | std::fprintf(stderr, "failed to read shader module: %s\n", p); | 429 | std::fprintf(stderr, "failed to read shader module: %s\n", p); |
| 420 | return VK_ERROR_INITIALIZATION_FAILED; | 430 | return VK_ERROR_INITIALIZATION_FAILED; |
| 421 | } | 431 | } |
| 432 | if (pc_tail && leonida::vk_test::spirv_declares_set(code.data(), code.size() * 4, leonida::vk_test::pc_tail_set)) | ||
| 433 | tail_block = true; | ||
| 422 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; smi.codeSize = code.size() * 4; smi.pCode = code.data(); | 434 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; smi.codeSize = code.size() * 4; smi.pCode = code.data(); |
| 423 | return vkCreateShaderModule(dev, &smi, nullptr, m); | 435 | return vkCreateShaderModule(dev, &smi, nullptr, m); |
| 424 | }; | 436 | }; |
| @@ -429,6 +441,14 @@ int main(int argc, char** argv) { | |||
| 429 | VkPushConstantRange pcr{VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_VERTEX_BIT, 0, push_bytes}; | 441 | VkPushConstantRange pcr{VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_VERTEX_BIT, 0, push_bytes}; |
| 430 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; | 442 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; |
| 431 | pli.setLayoutCount = 1; pli.pSetLayouts = &dsl; pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; | 443 | pli.setLayoutCount = 1; pli.pSetLayouts = &dsl; pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; |
| 444 | leonida::vk_test::PcTail tail; | ||
| 445 | if (tail_block && !tail.create(vkGetDeviceProcAddr, dev, mp, properties.limits.minUniformBufferOffsetAlignment, | ||
| 446 | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_VERTEX_BIT, 1)) { | ||
| 447 | std::fprintf(stderr, "FAILED creating the --pc-tail-ubo block\n"); | ||
| 448 | return 1; | ||
| 449 | } | ||
| 450 | const VkDescriptorSetLayout set_layouts[] = {dsl, tail.set_layout}; | ||
| 451 | if (tail_block) { pli.setLayoutCount = 2; pli.pSetLayouts = set_layouts; } | ||
| 432 | VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); | 452 | VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); |
| 433 | VkPipelineVertexInputStateCreateInfo vin{VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO}; | 453 | VkPipelineVertexInputStateCreateInfo vin{VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO}; |
| 434 | VkPipelineInputAssemblyStateCreateInfo ia{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO}; ia.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; | 454 | VkPipelineInputAssemblyStateCreateInfo ia{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO}; ia.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; |
| @@ -481,7 +501,13 @@ int main(int argc, char** argv) { | |||
| 481 | uint32_t pc[push_words] = {}; | 501 | uint32_t pc[push_words] = {}; |
| 482 | pc[ptr_sgpr] = tsharp_va; // pointer to the T# (low dword; the shader forces the high dword to 0) | 502 | pc[ptr_sgpr] = tsharp_va; // pointer to the T# (low dword; the shader forces the high dword to 0) |
| 483 | pc[32] = uint32_t(heap_base); pc[33] = uint32_t(heap_base >> 32); | 503 | pc[32] = uint32_t(heap_base); pc[33] = uint32_t(heap_base >> 32); |
| 484 | vkCmdPushConstants(cmd, pl, VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(pc), pc); | 504 | vkCmdPushConstants(cmd, pl, VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_VERTEX_BIT, 0, push_bytes, pc); |
| 505 | if (tail_block) { | ||
| 506 | tail.write(0, pc, 4); | ||
| 507 | const uint32_t offset = tail.offset(0); | ||
| 508 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pl, leonida::vk_test::pc_tail_set, 1, &tail.set, | ||
| 509 | 1, &offset); | ||
| 510 | } | ||
| 485 | vkCmdDraw(cmd, 3, 1, 0, 0); | 511 | vkCmdDraw(cmd, 3, 1, 0, 0); |
| 486 | vkCmdEndRenderPass(cmd); | 512 | vkCmdEndRenderPass(cmd); |
| 487 | VkBufferImageCopy rc{}; rc.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; rc.imageExtent = {W, H, 1}; | 513 | VkBufferImageCopy rc{}; rc.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; rc.imageExtent = {W, H, 1}; |
diff --git a/runtime/test/winhttp_offline_test.cpp b/runtime/test/winhttp_offline_test.cpp new file mode 100644 index 000000000..3d80c7f02 --- /dev/null +++ b/runtime/test/winhttp_offline_test.cpp | |||
| @@ -0,0 +1,296 @@ | |||
| 1 | // Checks the offline WinHTTP the shims give a mapped title (runtime/shims/winhttp_offline.cpp). | ||
| 2 | // | ||
| 3 | // Every function is resolved through rt::shims::find under winhttp.dll, so the test runs against the table the | ||
| 4 | // runtime installs. Nothing here touches the network: the server names use the reserved .invalid top-level domain, and | ||
| 5 | // the only host WinHTTP call the shims make is WinHttpCrackUrl, which parses a string. | ||
| 6 | #include <windows.h> | ||
| 7 | #include <winhttp.h> | ||
| 8 | |||
| 9 | #include <atomic> | ||
| 10 | #include <chrono> | ||
| 11 | #include <cstdio> | ||
| 12 | #include <cstring> | ||
| 13 | |||
| 14 | #include "shims.h" | ||
| 15 | |||
| 16 | namespace { | ||
| 17 | |||
| 18 | using OpenFn = HINTERNET(WINAPI*)(LPCWSTR, DWORD, LPCWSTR, LPCWSTR, DWORD); | ||
| 19 | using ConnectFn = HINTERNET(WINAPI*)(HINTERNET, LPCWSTR, INTERNET_PORT, DWORD); | ||
| 20 | using OpenRequestFn = HINTERNET(WINAPI*)(HINTERNET, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR*, DWORD); | ||
| 21 | using SendRequestFn = BOOL(WINAPI*)(HINTERNET, LPCWSTR, DWORD, LPVOID, DWORD, DWORD, DWORD_PTR); | ||
| 22 | using ReceiveResponseFn = BOOL(WINAPI*)(HINTERNET, LPVOID); | ||
| 23 | using ReadDataFn = BOOL(WINAPI*)(HINTERNET, LPVOID, DWORD, LPDWORD); | ||
| 24 | using QueryHeadersFn = BOOL(WINAPI*)(HINTERNET, DWORD, LPCWSTR, LPVOID, LPDWORD, LPDWORD); | ||
| 25 | using AddRequestHeadersFn = BOOL(WINAPI*)(HINTERNET, LPCWSTR, DWORD, DWORD); | ||
| 26 | using SetTimeoutsFn = BOOL(WINAPI*)(HINTERNET, int, int, int, int); | ||
| 27 | using SetOptionFn = BOOL(WINAPI*)(HINTERNET, DWORD, LPVOID, DWORD); | ||
| 28 | using QueryOptionFn = BOOL(WINAPI*)(HINTERNET, DWORD, LPVOID, LPDWORD); | ||
| 29 | using SetStatusCallbackFn = WINHTTP_STATUS_CALLBACK(WINAPI*)(HINTERNET, WINHTTP_STATUS_CALLBACK, DWORD, DWORD_PTR); | ||
| 30 | using CloseHandleFn = BOOL(WINAPI*)(HINTERNET); | ||
| 31 | using CrackUrlFn = BOOL(WINAPI*)(LPCWSTR, DWORD, DWORD, LPURL_COMPONENTS); | ||
| 32 | |||
| 33 | int g_checks = 0; | ||
| 34 | int g_failures = 0; | ||
| 35 | |||
| 36 | void check(bool condition, const char* what) { | ||
| 37 | ++g_checks; | ||
| 38 | std::printf("%s %s\n", condition ? "PASS" : "FAIL", what); | ||
| 39 | if (!condition) ++g_failures; | ||
| 40 | } | ||
| 41 | |||
| 42 | template <typename Fn> | ||
| 43 | Fn resolve(const char* name) { | ||
| 44 | return reinterpret_cast<Fn>(rt::shims::find("winhttp.dll", name)); | ||
| 45 | } | ||
| 46 | |||
| 47 | // What the status callback saw, for the asynchronous checks. | ||
| 48 | struct Seen { | ||
| 49 | std::atomic<int> request_errors{0}; | ||
| 50 | std::atomic<int> closing{0}; | ||
| 51 | std::atomic<int> created{0}; | ||
| 52 | std::atomic<DWORD> api{0}; | ||
| 53 | std::atomic<DWORD> error{0}; | ||
| 54 | std::atomic<DWORD_PTR> context{0}; | ||
| 55 | std::atomic<DWORD> thread{0}; | ||
| 56 | std::atomic<bool> closing_after_error{true}; | ||
| 57 | HANDLE error_event = nullptr; | ||
| 58 | HANDLE closing_event = nullptr; | ||
| 59 | CloseHandleFn close_in_callback = nullptr; // when set, the error callback closes the request itself | ||
| 60 | }; | ||
| 61 | Seen* g_seen = nullptr; | ||
| 62 | |||
| 63 | void CALLBACK on_status(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID info, DWORD length) { | ||
| 64 | Seen& s = *g_seen; | ||
| 65 | if (status == WINHTTP_CALLBACK_STATUS_HANDLE_CREATED) { | ||
| 66 | ++s.created; | ||
| 67 | } else if (status == WINHTTP_CALLBACK_STATUS_REQUEST_ERROR && info && length == sizeof(WINHTTP_ASYNC_RESULT)) { | ||
| 68 | const auto* result = static_cast<const WINHTTP_ASYNC_RESULT*>(info); | ||
| 69 | s.api = static_cast<DWORD>(result->dwResult); | ||
| 70 | s.error = result->dwError; | ||
| 71 | s.context = context; | ||
| 72 | s.thread = GetCurrentThreadId(); | ||
| 73 | ++s.request_errors; | ||
| 74 | if (s.close_in_callback) s.close_in_callback(handle); | ||
| 75 | SetEvent(s.error_event); | ||
| 76 | } else if (status == WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING) { | ||
| 77 | if (s.request_errors.load() == 0) s.closing_after_error = false; | ||
| 78 | if (info && length == sizeof(HINTERNET) && *static_cast<HINTERNET*>(info) == handle) ++s.closing; | ||
| 79 | SetEvent(s.closing_event); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | double ms_since(std::chrono::steady_clock::time_point start) { | ||
| 84 | return std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - start).count(); | ||
| 85 | } | ||
| 86 | |||
| 87 | } // namespace | ||
| 88 | |||
| 89 | int main() { | ||
| 90 | const auto open = resolve<OpenFn>("WinHttpOpen"); | ||
| 91 | const auto connect = resolve<ConnectFn>("WinHttpConnect"); | ||
| 92 | const auto open_request = resolve<OpenRequestFn>("WinHttpOpenRequest"); | ||
| 93 | const auto send = resolve<SendRequestFn>("WinHttpSendRequest"); | ||
| 94 | const auto receive = resolve<ReceiveResponseFn>("WinHttpReceiveResponse"); | ||
| 95 | const auto read = resolve<ReadDataFn>("WinHttpReadData"); | ||
| 96 | const auto query_headers = resolve<QueryHeadersFn>("WinHttpQueryHeaders"); | ||
| 97 | const auto add_headers = resolve<AddRequestHeadersFn>("WinHttpAddRequestHeaders"); | ||
| 98 | const auto set_timeouts = resolve<SetTimeoutsFn>("WinHttpSetTimeouts"); | ||
| 99 | const auto set_option = resolve<SetOptionFn>("WinHttpSetOption"); | ||
| 100 | const auto query_option = resolve<QueryOptionFn>("WinHttpQueryOption"); | ||
| 101 | const auto set_callback = resolve<SetStatusCallbackFn>("WinHttpSetStatusCallback"); | ||
| 102 | const auto close = resolve<CloseHandleFn>("WinHttpCloseHandle"); | ||
| 103 | const auto crack = resolve<CrackUrlFn>("WinHttpCrackUrl"); | ||
| 104 | check(open && connect && open_request && send && receive && read && query_headers && add_headers && | ||
| 105 | set_timeouts && set_option && query_option && set_callback && close && crack && | ||
| 106 | rt::shims::find("winhttp.dll", "WinHttpQueryDataAvailable") && | ||
| 107 | rt::shims::find("winhttp.dll", "WinHttpWriteData"), | ||
| 108 | "all 16 WinHTTP imports of the package resolve through the registry"); | ||
| 109 | check(rt::shims::owns_dll("winhttp.dll"), "winhttp.dll is a module the shims own (LoadLibrary gets a pseudo-handle)"); | ||
| 110 | if (!(open && connect && open_request && send && close && set_callback)) { | ||
| 111 | std::printf("%d check(s), %d failure(s)\n", g_checks, g_failures + 1); | ||
| 112 | return 1; | ||
| 113 | } | ||
| 114 | |||
| 115 | // Synchronous: the send fails at once, nothing is resolved or connected. | ||
| 116 | { | ||
| 117 | const HINTERNET session = open(L"test", WINHTTP_ACCESS_TYPE_NO_PROXY, nullptr, nullptr, 0); | ||
| 118 | check(session != nullptr, "WinHttpOpen returns a session"); | ||
| 119 | const HINTERNET connection = connect(session, L"example.invalid", INTERNET_DEFAULT_HTTPS_PORT, 0); | ||
| 120 | check(connection != nullptr, "WinHttpConnect returns a connection without resolving the name"); | ||
| 121 | const HINTERNET request = | ||
| 122 | open_request(connection, L"GET", L"/x", nullptr, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, | ||
| 123 | WINHTTP_FLAG_SECURE); | ||
| 124 | check(request != nullptr, "WinHttpOpenRequest returns a request"); | ||
| 125 | check(add_headers(request, L"X-Test: 1", static_cast<DWORD>(-1), WINHTTP_ADDREQ_FLAG_ADD) != FALSE, | ||
| 126 | "request headers are accepted"); | ||
| 127 | check(set_timeouts(request, 1000, 1000, 1000, 1000) != FALSE, "timeouts are accepted"); | ||
| 128 | |||
| 129 | SetLastError(0); | ||
| 130 | const auto start = std::chrono::steady_clock::now(); | ||
| 131 | const BOOL sent = send(request, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0); | ||
| 132 | const DWORD error = GetLastError(); | ||
| 133 | const double elapsed = ms_since(start); | ||
| 134 | check(sent == FALSE && error == ERROR_WINHTTP_CANNOT_CONNECT, | ||
| 135 | "WinHttpSendRequest fails with ERROR_WINHTTP_CANNOT_CONNECT"); | ||
| 136 | check(elapsed < 50.0, "and fails at once (under 50 ms)"); | ||
| 137 | SetLastError(0); | ||
| 138 | check(receive(request, nullptr) == FALSE && GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_STATE, | ||
| 139 | "there is no response to receive"); | ||
| 140 | char buffer[16]; | ||
| 141 | DWORD got = 0; | ||
| 142 | SetLastError(0); | ||
| 143 | check(read(request, buffer, sizeof(buffer), &got) == FALSE && | ||
| 144 | GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_STATE, | ||
| 145 | "and nothing to read"); | ||
| 146 | DWORD status = 0, size = sizeof(status); | ||
| 147 | SetLastError(0); | ||
| 148 | check(query_headers(request, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, WINHTTP_HEADER_NAME_BY_INDEX, | ||
| 149 | &status, &size, WINHTTP_NO_HEADER_INDEX) == FALSE && | ||
| 150 | GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_STATE, | ||
| 151 | "and no status code"); | ||
| 152 | |||
| 153 | // Options: the context value round-trips, the handle type is answered, the rest is refused when queried. | ||
| 154 | DWORD_PTR value = 0x1234; | ||
| 155 | check(set_option(request, WINHTTP_OPTION_CONTEXT_VALUE, &value, sizeof(value)) != FALSE, | ||
| 156 | "WINHTTP_OPTION_CONTEXT_VALUE can be set"); | ||
| 157 | DWORD_PTR back = 0; | ||
| 158 | DWORD back_size = sizeof(back); | ||
| 159 | check(query_option(request, WINHTTP_OPTION_CONTEXT_VALUE, &back, &back_size) != FALSE && back == 0x1234, | ||
| 160 | "and queried back"); | ||
| 161 | DWORD type = 0, type_size = sizeof(type); | ||
| 162 | check(query_option(connection, WINHTTP_OPTION_HANDLE_TYPE, &type, &type_size) != FALSE && | ||
| 163 | type == WINHTTP_HANDLE_TYPE_CONNECT, | ||
| 164 | "WINHTTP_OPTION_HANDLE_TYPE names a connection"); | ||
| 165 | DWORD needed = 0; | ||
| 166 | SetLastError(0); | ||
| 167 | check(query_option(request, WINHTTP_OPTION_CONTEXT_VALUE, nullptr, &needed) == FALSE && | ||
| 168 | GetLastError() == ERROR_INSUFFICIENT_BUFFER && needed == sizeof(DWORD_PTR), | ||
| 169 | "a query without a buffer reports the size it needs"); | ||
| 170 | DWORD flags = 0, flags_size = sizeof(flags); | ||
| 171 | SetLastError(0); | ||
| 172 | check(query_option(request, WINHTTP_OPTION_SECURITY_FLAGS, &flags, &flags_size) == FALSE && | ||
| 173 | GetLastError() == ERROR_WINHTTP_INVALID_OPTION, | ||
| 174 | "other options are not answered"); | ||
| 175 | DWORD protocols = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2; | ||
| 176 | check(set_option(session, WINHTTP_OPTION_SECURE_PROTOCOLS, &protocols, sizeof(protocols)) != FALSE, | ||
| 177 | "but setting them is accepted"); | ||
| 178 | |||
| 179 | // Wrong handles. | ||
| 180 | SetLastError(0); | ||
| 181 | check(connect(request, L"example.invalid", 80, 0) == nullptr && | ||
| 182 | GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE, | ||
| 183 | "a request is not a session"); | ||
| 184 | SetLastError(0); | ||
| 185 | check(send(connection, nullptr, 0, nullptr, 0, 0, 0) == FALSE && | ||
| 186 | GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE, | ||
| 187 | "a connection is not a request"); | ||
| 188 | SetLastError(0); | ||
| 189 | check(connect(session, nullptr, 80, 0) == nullptr && GetLastError() == ERROR_INVALID_PARAMETER, | ||
| 190 | "a connection needs a server name"); | ||
| 191 | |||
| 192 | check(close(request) != FALSE && close(connection) != FALSE && close(session) != FALSE, | ||
| 193 | "the handles close, children first"); | ||
| 194 | SetLastError(0); | ||
| 195 | check(close(request) == FALSE && GetLastError() == ERROR_INVALID_HANDLE, "a closed handle is gone"); | ||
| 196 | SetLastError(0); | ||
| 197 | check(send(request, nullptr, 0, nullptr, 0, 0, 0) == FALSE && GetLastError() == ERROR_INVALID_HANDLE, | ||
| 198 | "and cannot be used"); | ||
| 199 | } | ||
| 200 | |||
| 201 | // Asynchronous: the send returns TRUE, the failure arrives through the inherited callback on another thread with | ||
| 202 | // the request's context, and HANDLE_CLOSING comes last. | ||
| 203 | Seen seen; | ||
| 204 | seen.error_event = CreateEventW(nullptr, FALSE, FALSE, nullptr); | ||
| 205 | seen.closing_event = CreateEventW(nullptr, FALSE, FALSE, nullptr); | ||
| 206 | g_seen = &seen; | ||
| 207 | { | ||
| 208 | const HINTERNET session = open(L"test", WINHTTP_ACCESS_TYPE_NO_PROXY, nullptr, nullptr, WINHTTP_FLAG_ASYNC); | ||
| 209 | check(set_callback(session, &on_status, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS, 0) == nullptr, | ||
| 210 | "WinHttpSetStatusCallback returns the previous callback (none)"); | ||
| 211 | const HINTERNET connection = connect(session, L"example.invalid", 443, 0); | ||
| 212 | const HINTERNET request = open_request(connection, L"POST", L"/y", nullptr, WINHTTP_NO_REFERER, | ||
| 213 | WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE); | ||
| 214 | check(connection && request && seen.created.load() == 2, | ||
| 215 | "the callback is inherited and reports both new handles as created"); | ||
| 216 | |||
| 217 | const auto start = std::chrono::steady_clock::now(); | ||
| 218 | const BOOL sent = send(request, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0xC0FFEE); | ||
| 219 | check(sent != FALSE, "an asynchronous WinHttpSendRequest returns TRUE"); | ||
| 220 | const bool fired = WaitForSingleObject(seen.error_event, 2000) == WAIT_OBJECT_0; | ||
| 221 | const double elapsed = ms_since(start); | ||
| 222 | check(fired && seen.request_errors.load() == 1, "WINHTTP_CALLBACK_STATUS_REQUEST_ERROR arrives once"); | ||
| 223 | check(seen.api.load() == API_SEND_REQUEST && seen.error.load() == ERROR_WINHTTP_CANNOT_CONNECT, | ||
| 224 | "for API_SEND_REQUEST with ERROR_WINHTTP_CANNOT_CONNECT"); | ||
| 225 | check(seen.context.load() == 0xC0FFEE, "with the context the request was sent with"); | ||
| 226 | check(seen.thread.load() != GetCurrentThreadId(), "on another thread"); | ||
| 227 | check(elapsed < 500.0, "within 500 ms"); | ||
| 228 | |||
| 229 | check(close(request) != FALSE, "the request closes"); | ||
| 230 | check(WaitForSingleObject(seen.closing_event, 2000) == WAIT_OBJECT_0 && seen.closing.load() == 1 && | ||
| 231 | seen.closing_after_error.load(), | ||
| 232 | "and HANDLE_CLOSING follows once, after the error"); | ||
| 233 | close(connection); | ||
| 234 | close(session); | ||
| 235 | check(seen.closing.load() == 3, "every handle reports HANDLE_CLOSING once"); | ||
| 236 | } | ||
| 237 | |||
| 238 | // A callback that closes its request while handling the error, as libHttpClient-style code does. | ||
| 239 | { | ||
| 240 | seen.request_errors = 0; | ||
| 241 | seen.closing = 0; | ||
| 242 | seen.close_in_callback = close; | ||
| 243 | ResetEvent(seen.closing_event); | ||
| 244 | const HINTERNET session = open(L"test", WINHTTP_ACCESS_TYPE_NO_PROXY, nullptr, nullptr, WINHTTP_FLAG_ASYNC); | ||
| 245 | set_callback(session, &on_status, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS, 0); | ||
| 246 | const HINTERNET connection = connect(session, L"example.invalid", 443, 0); | ||
| 247 | const HINTERNET request = open_request(connection, L"GET", L"/z", nullptr, WINHTTP_NO_REFERER, | ||
| 248 | WINHTTP_DEFAULT_ACCEPT_TYPES, 0); | ||
| 249 | check(send(request, nullptr, 0, nullptr, 0, 0, 7) != FALSE, "a second asynchronous send is queued"); | ||
| 250 | check(WaitForSingleObject(seen.error_event, 2000) == WAIT_OBJECT_0, "its error arrives"); | ||
| 251 | check(WaitForSingleObject(seen.closing_event, 2000) == WAIT_OBJECT_0 && seen.closing.load() == 1, | ||
| 252 | "closing the request inside the callback reports HANDLE_CLOSING once"); | ||
| 253 | seen.close_in_callback = nullptr; | ||
| 254 | close(connection); | ||
| 255 | close(session); | ||
| 256 | } | ||
| 257 | |||
| 258 | // A request closed before its queued failure is delivered gets no error callback, only HANDLE_CLOSING. | ||
| 259 | { | ||
| 260 | seen.request_errors = 0; | ||
| 261 | seen.closing = 0; | ||
| 262 | const HINTERNET session = open(L"test", WINHTTP_ACCESS_TYPE_NO_PROXY, nullptr, nullptr, WINHTTP_FLAG_ASYNC); | ||
| 263 | set_callback(session, &on_status, WINHTTP_CALLBACK_FLAG_HANDLES, 0); // closing only | ||
| 264 | const HINTERNET connection = connect(session, L"example.invalid", 443, 0); | ||
| 265 | const HINTERNET request = open_request(connection, L"GET", L"/w", nullptr, WINHTTP_NO_REFERER, | ||
| 266 | WINHTTP_DEFAULT_ACCEPT_TYPES, 0); | ||
| 267 | send(request, nullptr, 0, nullptr, 0, 0, 0); | ||
| 268 | close(request); | ||
| 269 | close(connection); | ||
| 270 | close(session); | ||
| 271 | for (int i = 0; i < 100 && seen.closing.load() < 3; ++i) Sleep(10); | ||
| 272 | check(seen.request_errors.load() == 0 && seen.closing.load() == 3, | ||
| 273 | "notifications not asked for are not sent, and each handle still closes once"); | ||
| 274 | } | ||
| 275 | g_seen = nullptr; | ||
| 276 | CloseHandle(seen.error_event); | ||
| 277 | CloseHandle(seen.closing_event); | ||
| 278 | |||
| 279 | // WinHttpCrackUrl is parsing only and stays the host's. | ||
| 280 | { | ||
| 281 | wchar_t host[64] = {}, path[64] = {}; | ||
| 282 | URL_COMPONENTS parts{}; | ||
| 283 | parts.dwStructSize = sizeof(parts); | ||
| 284 | parts.lpszHostName = host; | ||
| 285 | parts.dwHostNameLength = 64; | ||
| 286 | parts.lpszUrlPath = path; | ||
| 287 | parts.dwUrlPathLength = 64; | ||
| 288 | check(crack(L"https://example.invalid:8443/a/b", 0, 0, &parts) != FALSE && parts.nPort == 8443 && | ||
| 289 | parts.nScheme == INTERNET_SCHEME_HTTPS && std::wcscmp(host, L"example.invalid") == 0 && | ||
| 290 | std::wcscmp(path, L"/a/b") == 0, | ||
| 291 | "WinHttpCrackUrl parses a URL"); | ||
| 292 | } | ||
| 293 | |||
| 294 | std::printf("%d check(s), %d failure(s)\n", g_checks, g_failures); | ||
| 295 | return g_failures == 0 ? 0 : 1; | ||
| 296 | } | ||
diff --git a/runtime/test/xbox_present_test.cpp b/runtime/test/xbox_present_test.cpp index 2e3afcaea..6d8860c99 100644 --- a/runtime/test/xbox_present_test.cpp +++ b/runtime/test/xbox_present_test.cpp | |||
| @@ -3,8 +3,11 @@ | |||
| 3 | // fake clock, so the test is fast and the order of tokens and presents is exact. | 3 | // fake clock, so the test is fast and the order of tokens and presents is exact. |
| 4 | // | 4 | // |
| 5 | // Cases: 0 planes (blank), 1 plane (solid colour, two colours side by side, a source rectangle, an RGBA and a BGRA | 5 | // Cases: 0 planes (blank), 1 plane (solid colour, two colours side by side, a source rectangle, an RGBA and a BGRA |
| 6 | // source, an sRGB source), 2 planes (plane 0 shown), token errors (null, unknown, stale, repeated), suspend/resume | 6 | // source, an sRGB source), 2 planes (SDR overlay), plane composition (placement, point/bilinear, premultiplied and |
| 7 | // with re-registration, statistics, and a real-time loop at 60 Hz. Needs a window and a Vulkan GPU with presentation. | 7 | // straight alpha, HDR10 and PQ conversions, refusals) against a CPU model with the tolerances stated at each case, token |
| 8 | // errors (null, unknown, stale, repeated), suspend/resume with re-registration, statistics, and a real-time loop at | ||
| 9 | // 60 Hz. An HDR10 swapchain is only checked where the surface lists an ST.2084 format (else logged as skipped). | ||
| 10 | // Needs a window and a Vulkan GPU with presentation. | ||
| 8 | // Set LEONIDA_VK_VALIDATION=1 for VK_LAYER_KHRONOS_validation; any validation error fails the test, except that | 11 | // Set LEONIDA_VK_VALIDATION=1 for VK_LAYER_KHRONOS_validation; any validation error fails the test, except that |
| 9 | // the NVIDIA layer's known sRGB-swapchain STORAGE check makes the run skip rather than pass or fail. | 12 | // the NVIDIA layer's known sRGB-swapchain STORAGE check makes the run skip rather than pass or fail. |
| 10 | #include "vk_test_device.h" | 13 | #include "vk_test_device.h" |
| @@ -12,10 +15,15 @@ | |||
| 12 | #include "../shims/d3d12_xs_device.h" | 15 | #include "../shims/d3d12_xs_device.h" |
| 13 | #include "../shims/xbox_present.h" | 16 | #include "../shims/xbox_present.h" |
| 14 | 17 | ||
| 18 | #include <algorithm> | ||
| 15 | #include <chrono> | 19 | #include <chrono> |
| 16 | #include <cmath> | 20 | #include <cmath> |
| 21 | #include <cstring> | ||
| 22 | #include <limits> | ||
| 17 | #include <cstdint> | 23 | #include <cstdint> |
| 18 | #include <cstdlib> | 24 | #include <cstdlib> |
| 25 | #include <array> | ||
| 26 | #include <vector> | ||
| 19 | 27 | ||
| 20 | #define EXPECT(condition) do { \ | 28 | #define EXPECT(condition) do { \ |
| 21 | if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ | 29 | if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ |
| @@ -85,6 +93,126 @@ bool region_is(const Frame& frame, UINT x0, UINT y0, UINT x1, UINT y1, Px want, | |||
| 85 | return true; | 93 | return true; |
| 86 | } | 94 | } |
| 87 | 95 | ||
| 96 | // A CPU model of runtime/src/present_compose.comp, in double precision, written from the documented behaviour | ||
| 97 | // (docs/d3d12_vulkan.md section 4.5), not from the shader's code: planes scaled from a source rectangle to a | ||
| 98 | // destination rectangle (point: the texel containing the sample; bilinear: four texels clamped inside the source | ||
| 99 | // rectangle), SDR = G2.2 Rec.709, HDR10 = PQ Rec.2020, conversions through linear light and `white` nits, plane 1 blended | ||
| 100 | // over plane 0 in the output's encoded space, premultiplied or straight. | ||
| 101 | namespace xbox_present_ref { | ||
| 102 | |||
| 103 | struct Tex { | ||
| 104 | UINT w = 0, h = 0; | ||
| 105 | std::vector<std::array<double, 4>> px; // 0..1, as stored | ||
| 106 | }; | ||
| 107 | struct Ref_plane { | ||
| 108 | const Tex* tex = nullptr; | ||
| 109 | double src[4]{}, dest[4]{}; // texels; output pixels | ||
| 110 | bool point = false, hdr = false, straight = false; | ||
| 111 | }; | ||
| 112 | using V3 = std::array<double, 3>; | ||
| 113 | |||
| 114 | double pq_encode(double nits) { | ||
| 115 | const double m1 = 0.1593017578125, m2 = 78.84375, c1 = 0.8359375, c2 = 18.8515625, c3 = 18.6875; | ||
| 116 | const double y = std::pow(std::clamp(nits / 10000.0, 0.0, 1.0), m1); | ||
| 117 | return std::pow((c1 + c2 * y) / (1.0 + c3 * y), m2); | ||
| 118 | } | ||
| 119 | double pq_decode(double e) { | ||
| 120 | const double m1 = 0.1593017578125, m2 = 78.84375, c1 = 0.8359375, c2 = 18.8515625, c3 = 18.6875; | ||
| 121 | const double ep = std::pow(std::clamp(e, 0.0, 1.0), 1.0 / m2); | ||
| 122 | return 10000.0 * std::pow(std::max(ep - c1, 0.0) / (c2 - c3 * ep), 1.0 / m1); | ||
| 123 | } | ||
| 124 | V3 convert(V3 c, bool plane_hdr, bool out_hdr, double white) { | ||
| 125 | if (plane_hdr == out_hdr) return c; | ||
| 126 | if (!plane_hdr) { // SDR -> PQ | ||
| 127 | const double r = std::pow(std::clamp(c[0], 0.0, 1.0), 2.2), g = std::pow(std::clamp(c[1], 0.0, 1.0), 2.2), | ||
| 128 | b = std::pow(std::clamp(c[2], 0.0, 1.0), 2.2); | ||
| 129 | return {pq_encode((0.627404 * r + 0.329283 * g + 0.043313 * b) * white), | ||
| 130 | pq_encode((0.069097 * r + 0.919540 * g + 0.011362 * b) * white), | ||
| 131 | pq_encode((0.016391 * r + 0.088013 * g + 0.895595 * b) * white)}; | ||
| 132 | } | ||
| 133 | const double r = pq_decode(c[0]), g = pq_decode(c[1]), b = pq_decode(c[2]); | ||
| 134 | const auto sdr = [&](double v) { return std::pow(std::clamp(v / white, 0.0, 1.0), 1.0 / 2.2); }; | ||
| 135 | return {sdr(1.660491 * r - 0.587641 * g - 0.072850 * b), sdr(-0.124550 * r + 1.132900 * g - 0.008349 * b), | ||
| 136 | sdr(-0.018151 * r - 0.100579 * g + 1.118730 * b)}; | ||
| 137 | } | ||
| 138 | std::array<double, 4> sample(const Ref_plane& p, int x, int y) { | ||
| 139 | const Tex& t = *p.tex; | ||
| 140 | const double u = (x + 0.5 - p.dest[0]) / (p.dest[2] - p.dest[0]), v = (y + 0.5 - p.dest[1]) / (p.dest[3] - p.dest[1]); | ||
| 141 | const double sx = p.src[0] + u * (p.src[2] - p.src[0]), sy = p.src[1] + v * (p.src[3] - p.src[1]); | ||
| 142 | const auto at = [&](int ix, int iy) { return t.px[std::size_t(iy) * t.w + ix]; }; | ||
| 143 | if (p.point) | ||
| 144 | return at(int(std::clamp(std::floor(sx), p.src[0], p.src[2] - 1)), int(std::clamp(std::floor(sy), p.src[1], p.src[3] - 1))); | ||
| 145 | const double fx = std::clamp(sx - 0.5, p.src[0], p.src[2] - 1), fy = std::clamp(sy - 0.5, p.src[1], p.src[3] - 1); | ||
| 146 | const int x0 = int(std::floor(fx)), y0 = int(std::floor(fy)); | ||
| 147 | const int x1 = int(std::min(double(x0) + 1, p.src[2] - 1)), y1 = int(std::min(double(y0) + 1, p.src[3] - 1)); | ||
| 148 | const double wx = fx - x0, wy = fy - y0; | ||
| 149 | // Four texels with their bilinear weights. Straight-alpha colour is weighted by its alpha (filtering associated colour), | ||
| 150 | // then divided by the filtered alpha: a transparent texel contributes no colour of its own. | ||
| 151 | const double weight[4] = {(1 - wx) * (1 - wy), wx * (1 - wy), (1 - wx) * wy, wx * wy}; | ||
| 152 | const std::array<double, 4> texel[4] = {at(x0, y0), at(x1, y0), at(x0, y1), at(x1, y1)}; | ||
| 153 | std::array<double, 4> out{}; | ||
| 154 | for (int i = 0; i < 4; ++i) { | ||
| 155 | const double colour_weight = p.straight ? weight[i] * texel[i][3] : weight[i]; | ||
| 156 | for (int c = 0; c < 3; ++c) out[c] += texel[i][c] * colour_weight; | ||
| 157 | out[3] += texel[i][3] * weight[i]; | ||
| 158 | } | ||
| 159 | if (p.straight) | ||
| 160 | for (int c = 0; c < 3; ++c) out[c] = out[3] > 0.0 ? out[c] / out[3] : 0.0; | ||
| 161 | return out; | ||
| 162 | } | ||
| 163 | V3 compose(const Ref_plane* planes, int count, bool out_hdr, double white, int x, int y) { | ||
| 164 | const auto inside = [&](const Ref_plane& p) { | ||
| 165 | return x + 0.5 >= p.dest[0] && x + 0.5 < p.dest[2] && y + 0.5 >= p.dest[1] && y + 0.5 < p.dest[3]; | ||
| 166 | }; | ||
| 167 | V3 base{0, 0, 0}; | ||
| 168 | if (inside(planes[0])) { | ||
| 169 | const auto c = sample(planes[0], x, y); | ||
| 170 | base = convert({c[0], c[1], c[2]}, planes[0].hdr, out_hdr, white); | ||
| 171 | } | ||
| 172 | if (count > 1 && inside(planes[1])) { | ||
| 173 | const Ref_plane& p = planes[1]; | ||
| 174 | const auto c = sample(p, x, y); | ||
| 175 | const double a = std::clamp(c[3], 0.0, 1.0); | ||
| 176 | V3 over{c[0], c[1], c[2]}; | ||
| 177 | if (p.hdr != out_hdr) { // converted as unassociated colour, premultiplied again afterwards | ||
| 178 | if (!p.straight && a > 0.0) over = {c[0] / a, c[1] / a, c[2] / a}; | ||
| 179 | over = convert(over, p.hdr, out_hdr, white); | ||
| 180 | if (!p.straight) over = {over[0] * a, over[1] * a, over[2] * a}; | ||
| 181 | } | ||
| 182 | for (int i = 0; i < 3; ++i) base[i] = p.straight ? base[i] * (1 - a) + over[i] * a : over[i] + (1 - a) * base[i]; | ||
| 183 | } | ||
| 184 | return base; | ||
| 185 | } | ||
| 186 | |||
| 187 | // The whole swapchain frame against the model; prints the first pixel that is off by more than `tolerance` levels. | ||
| 188 | bool frame_matches(const Frame& frame, const Ref_plane* planes, int count, bool out_hdr, double white, int tolerance) { | ||
| 189 | int worst = 0; | ||
| 190 | UINT bad = 0, first_x = 0, first_y = 0; | ||
| 191 | Px first_got{}, first_want{}; | ||
| 192 | for (UINT y = 0; y < frame.extent.height; ++y) | ||
| 193 | for (UINT x = 0; x < frame.extent.width; ++x) { | ||
| 194 | const V3 v = compose(planes, count, out_hdr, white, int(x), int(y)); | ||
| 195 | const Px want{int(std::lround(std::clamp(v[0], 0.0, 1.0) * 255)), int(std::lround(std::clamp(v[1], 0.0, 1.0) * 255)), | ||
| 196 | int(std::lround(std::clamp(v[2], 0.0, 1.0) * 255))}; | ||
| 197 | const Px got = frame.at(x, y); | ||
| 198 | const int err = std::max({std::abs(got.r - want.r), std::abs(got.g - want.g), std::abs(got.b - want.b)}); | ||
| 199 | worst = std::max(worst, err); | ||
| 200 | if (err > tolerance && bad++ == 0) { | ||
| 201 | first_x = x; | ||
| 202 | first_y = y; | ||
| 203 | first_got = got; | ||
| 204 | first_want = want; | ||
| 205 | } | ||
| 206 | } | ||
| 207 | if (bad) | ||
| 208 | std::fprintf(stderr, "%u pixels differ from the model by more than %d (worst %d); first at %u,%u is %d,%d,%d, model %d,%d,%d\n", bad, | ||
| 209 | tolerance, worst, first_x, first_y, first_got.r, first_got.g, first_got.b, first_want.r, first_want.g, | ||
| 210 | first_want.b); | ||
| 211 | return bad == 0; | ||
| 212 | } | ||
| 213 | |||
| 214 | } // namespace xbox_present_ref | ||
| 215 | |||
| 88 | } // namespace | 216 | } // namespace |
| 89 | 217 | ||
| 90 | int main() { | 218 | int main() { |
| @@ -123,6 +251,33 @@ int main() { | |||
| 123 | pump(); | 251 | pump(); |
| 124 | 252 | ||
| 125 | { | 253 | { |
| 254 | // The real runtime's instance path (create_vulkan_device_standalone, not the test device): it must enable | ||
| 255 | // VK_EXT_swapchain_colorspace when the loader has it, or the HDR10 surface formats can never be listed. | ||
| 256 | Ref<ID3D12Device> standalone; | ||
| 257 | if (SUCCEEDED(rt::d3d12::create_vulkan_device_standalone(IID_PPV_ARGS(&standalone.p)))) { | ||
| 258 | const auto enumerate = reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>( | ||
| 259 | d.instance_proc(nullptr, "vkEnumerateInstanceExtensionProperties")); | ||
| 260 | std::uint32_t count = 0; | ||
| 261 | enumerate(nullptr, &count, nullptr); | ||
| 262 | std::vector<VkExtensionProperties> available(count); | ||
| 263 | enumerate(nullptr, &count, available.data()); | ||
| 264 | bool loader_has = false; | ||
| 265 | for (const auto& e : available) loader_has = loader_has || !std::strcmp(e.extensionName, "VK_EXT_swapchain_colorspace"); | ||
| 266 | auto standalone_presenter = rt::d3d12::create_window_presenter(standalone.p, window); | ||
| 267 | if (standalone_presenter) { | ||
| 268 | EXPECT(rt::d3d12::device_has_swapchain_colorspace(standalone.p) == loader_has); | ||
| 269 | EXPECT(standalone_presenter->enable_capture()); | ||
| 270 | EXPECT(SUCCEEDED(standalone_presenter->present_blank(1))); | ||
| 271 | std::printf("standalone device (real instance path): VK_EXT_swapchain_colorspace %s on the instance (loader has it: %s)\n", | ||
| 272 | rt::d3d12::device_has_swapchain_colorspace(standalone.p) ? "enabled" : "not enabled", | ||
| 273 | loader_has ? "yes" : "no"); | ||
| 274 | } else { | ||
| 275 | std::printf("standalone device: no window presenter (skipped the instance-extension check)\n"); | ||
| 276 | } | ||
| 277 | } | ||
| 278 | } | ||
| 279 | |||
| 280 | { | ||
| 126 | rt::d3d12::VulkanDeviceInfo info{}; | 281 | rt::d3d12::VulkanDeviceInfo info{}; |
| 127 | info.get_instance_proc = d.instance_proc; | 282 | info.get_instance_proc = d.instance_proc; |
| 128 | info.instance = d.instance; | 283 | info.instance = d.instance; |
| @@ -158,7 +313,7 @@ int main() { | |||
| 158 | IID_PPV_ARGS(&list.p)))); | 313 | IID_PPV_ARGS(&list.p)))); |
| 159 | EXPECT(SUCCEEDED(list->Close())); | 314 | EXPECT(SUCCEEDED(list->Close())); |
| 160 | EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence.p)))); | 315 | EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence.p)))); |
| 161 | constexpr UINT rtv_slots = 8; | 316 | constexpr UINT rtv_slots = 24; |
| 162 | const D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_RTV, rtv_slots, | 317 | const D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_RTV, rtv_slots, |
| 163 | D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0}; | 318 | D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0}; |
| 164 | EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&rtv_heap.p)))); | 319 | EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&rtv_heap.p)))); |
| @@ -172,12 +327,12 @@ int main() { | |||
| 172 | Ref<ID3D12Resource> resource; | 327 | Ref<ID3D12Resource> resource; |
| 173 | D3D12_CPU_DESCRIPTOR_HANDLE rtv{}; | 328 | D3D12_CPU_DESCRIPTOR_HANDLE rtv{}; |
| 174 | }; | 329 | }; |
| 175 | const auto make_source = [&](DXGI_FORMAT format, Source& out) -> bool { | 330 | const auto make_source = [&](DXGI_FORMAT format, Source& out, UINT w = width, UINT h = height) -> bool { |
| 176 | const D3D12_HEAP_PROPERTIES default_heap{D3D12_HEAP_TYPE_DEFAULT}; | 331 | const D3D12_HEAP_PROPERTIES default_heap{D3D12_HEAP_TYPE_DEFAULT}; |
| 177 | D3D12_RESOURCE_DESC desc{}; | 332 | D3D12_RESOURCE_DESC desc{}; |
| 178 | desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; | 333 | desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; |
| 179 | desc.Width = width; | 334 | desc.Width = w; |
| 180 | desc.Height = height; | 335 | desc.Height = h; |
| 181 | desc.DepthOrArraySize = 1; | 336 | desc.DepthOrArraySize = 1; |
| 182 | desc.MipLevels = 1; | 337 | desc.MipLevels = 1; |
| 183 | desc.Format = format; | 338 | desc.Format = format; |
| @@ -223,9 +378,10 @@ int main() { | |||
| 223 | clock.advance_us(period); | 378 | clock.advance_us(period); |
| 224 | return xbox.WaitFrameEventX(rt::d3d12::xbox_frame_event_origin, 0, 0, &token) == S_OK; | 379 | return xbox.WaitFrameEventX(rt::d3d12::xbox_frame_event_origin, 0, 0, &token) == S_OK; |
| 225 | }; | 380 | }; |
| 381 | UINT want_w = width, want_h = height; // the client size the frames are expected at (the resize case changes it) | ||
| 226 | const auto grab = [&](Frame& frame) -> bool { | 382 | const auto grab = [&](Frame& frame) -> bool { |
| 227 | return xbox.presenter().read_back(frame.bytes, &frame.extent, &frame.format) && | 383 | return xbox.presenter().read_back(frame.bytes, &frame.extent, &frame.format) && |
| 228 | frame.extent.width == width && frame.extent.height == height; | 384 | (want_w == 0 || (frame.extent.width == want_w && frame.extent.height == want_h)); |
| 229 | }; | 385 | }; |
| 230 | 386 | ||
| 231 | const FLOAT blue_ish[4] = {0.2f, 0.6f, 0.9f, 1.0f}; // 51, 153, 230 | 387 | const FLOAT blue_ish[4] = {0.2f, 0.6f, 0.9f, 1.0f}; // 51, 153, 230 |
| @@ -331,15 +487,18 @@ int main() { | |||
| 331 | EXPECT(region_is(frame, 0, 0, width, height, {51, 153, 230})); | 487 | EXPECT(region_is(frame, 0, 0, width, height, {51, 153, 230})); |
| 332 | std::printf("1 plane, sRGB source (swapchain follows): ok\n"); | 488 | std::printf("1 plane, sRGB source (swapchain follows): ok\n"); |
| 333 | 489 | ||
| 334 | // 2 planes sharing a token: plane 0 is shown. | 490 | // 2 planes sharing a token, both SDR: plane 1 is an overlay (section 4.5), and an opaque one covers plane 0. |
| 491 | // (The plane composition has its own checks further down.) | ||
| 335 | Source second; | 492 | Source second; |
| 336 | EXPECT(make_source(DXGI_FORMAT_R8G8B8A8_UNORM, second)); | 493 | EXPECT(make_source(DXGI_FORMAT_R8G8B8A8_UNORM, second)); |
| 337 | EXPECT(fill(second, green)); | 494 | EXPECT(fill(second, green)); |
| 338 | EXPECT(next_token(token)); | 495 | EXPECT(next_token(token)); |
| 339 | rt::d3d12::XboxPresentPlaneParameters two[2] = {plane_of(rgba, token), plane_of(second, token)}; | 496 | rt::d3d12::XboxPresentPlaneParameters two[2] = {plane_of(rgba, token), plane_of(second, token)}; |
| 497 | const std::uint64_t composed_before = xbox.presenter().composed_presents(); | ||
| 340 | EXPECT(xbox.PresentX(2, two, nullptr) == S_OK); | 498 | EXPECT(xbox.PresentX(2, two, nullptr) == S_OK); |
| 499 | EXPECT(xbox.presenter().composed_presents() == composed_before); // plane 1 without the overlay flag: not composed | ||
| 341 | EXPECT(grab(frame)); | 500 | EXPECT(grab(frame)); |
| 342 | EXPECT(region_is(frame, 0, 0, width, height, {51, 153, 230})); | 501 | EXPECT(region_is(frame, 0, 0, width, height, {51, 153, 230})); // plane 0 only, by the plain blit |
| 343 | // Planes with different tokens, or more than two planes, are refused. | 502 | // Planes with different tokens, or more than two planes, are refused. |
| 344 | EXPECT(next_token(token)); | 503 | EXPECT(next_token(token)); |
| 345 | two[0] = plane_of(rgba, token); | 504 | two[0] = plane_of(rgba, token); |
| @@ -348,7 +507,25 @@ int main() { | |||
| 348 | rt::d3d12::XboxPresentPlaneParameters three[3] = {plane_of(rgba, token), plane_of(second, token), plane_of(second, token)}; | 507 | rt::d3d12::XboxPresentPlaneParameters three[3] = {plane_of(rgba, token), plane_of(second, token), plane_of(second, token)}; |
| 349 | EXPECT(xbox.PresentX(3, three, nullptr) == E_INVALIDARG); | 508 | EXPECT(xbox.PresentX(3, three, nullptr) == E_INVALIDARG); |
| 350 | EXPECT(xbox.PresentX(1, nullptr, nullptr) == E_INVALIDARG); | 509 | EXPECT(xbox.PresentX(1, nullptr, nullptr) == E_INVALIDARG); |
| 351 | std::printf("2 planes (plane 0 shown) and refused plane sets: ok\n"); | 510 | { // ResourceCount above 1 (either plane, either path) is refused, nothing presented, the frame stays |
| 511 | ID3D12Resource* both[2] = {rgba.resource.p, second.resource.p}; | ||
| 512 | const std::uint64_t presents_before_count = xbox.presents(); | ||
| 513 | const auto count_two = [&](int color_space, UINT flags) { | ||
| 514 | rt::d3d12::XboxPresentPlaneParameters p{token, 2, both, nullptr, 0}; | ||
| 515 | p.ColorSpace = color_space; | ||
| 516 | p.Flags = flags; | ||
| 517 | return p; | ||
| 518 | }; | ||
| 519 | auto one_count = count_two(0, 0); | ||
| 520 | EXPECT(xbox.PresentX(1, &one_count, nullptr) == DXGI_ERROR_UNSUPPORTED); // plain blit path | ||
| 521 | one_count = count_two(rt::d3d12::xbox_color_space_g2084_p2020, 0); | ||
| 522 | EXPECT(xbox.PresentX(1, &one_count, nullptr) == DXGI_ERROR_UNSUPPORTED); // compose path | ||
| 523 | rt::d3d12::XboxPresentPlaneParameters pair_count[2] = {plane_of(rgba, token), count_two(0, rt::d3d12::xbox_plane_flag_overlay)}; | ||
| 524 | EXPECT(xbox.PresentX(2, pair_count, nullptr) == DXGI_ERROR_UNSUPPORTED); // plane 1 | ||
| 525 | EXPECT(xbox.presents() == presents_before_count); | ||
| 526 | std::printf("ResourceCount above 1 refused (plain, compose, plane 1): ok\n"); | ||
| 527 | } | ||
| 528 | std::printf("2 planes (SDR overlay over plane 0) and refused plane sets: ok\n"); | ||
| 352 | 529 | ||
| 353 | // The parameters struct is accepted (ImmediateThresholdPercent is ignored). | 530 | // The parameters struct is accepted (ImmediateThresholdPercent is ignored). |
| 354 | const rt::d3d12::XboxPresentParameters params{50.0f}; | 531 | const rt::d3d12::XboxPresentParameters params{50.0f}; |
| @@ -421,6 +598,330 @@ int main() { | |||
| 421 | std::printf("unsupported sources (MSAA, integer, BC) refused: ok\n"); | 598 | std::printf("unsupported sources (MSAA, integer, BC) refused: ok\n"); |
| 422 | } | 599 | } |
| 423 | 600 | ||
| 601 | // ---- Plane composition (docs section 4.5), against a CPU model of the compose pass (xbox_present_ref below). ---- | ||
| 602 | // Exact (tolerance 0) for point filtering between SDR planes without alpha; 1 level for bilinear filtering and | ||
| 603 | // alpha blending (the pass works in float, stores RGBA16F and the copy rounds to 8 bits); 2 levels where PQ and | ||
| 604 | // gamma conversions are involved (GPU pow is not correctly rounded). | ||
| 605 | { | ||
| 606 | using namespace xbox_present_ref; | ||
| 607 | using rt::d3d12::XboxViewRect; | ||
| 608 | struct Painted { | ||
| 609 | Source source; | ||
| 610 | Tex tex; | ||
| 611 | }; | ||
| 612 | const auto make_painted = [&](Painted& p, UINT w, UINT h, DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM) { | ||
| 613 | p.tex = Tex{w, h, std::vector<std::array<double, 4>>(std::size_t(w) * h, {0, 0, 0, 0})}; | ||
| 614 | const FLOAT zero[4] = {0, 0, 0, 0}; | ||
| 615 | return make_source(format, p.source, w, h) && fill(p.source, zero); | ||
| 616 | }; | ||
| 617 | // Paints a rectangle with 8-bit values (R8G8B8A8) in the texture and in the model. | ||
| 618 | const auto paint = [&](Painted& p, D3D12_RECT r, int R, int G, int B, int A) { | ||
| 619 | const FLOAT c[4] = {R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f}; | ||
| 620 | if (!fill(p.source, c, 1, &r)) return false; | ||
| 621 | for (LONG y = r.top; y < r.bottom; ++y) | ||
| 622 | for (LONG x = r.left; x < r.right; ++x) | ||
| 623 | p.tex.px[std::size_t(y) * p.tex.w + x] = {R / 255.0, G / 255.0, B / 255.0, A / 255.0}; | ||
| 624 | return true; | ||
| 625 | }; | ||
| 626 | // The same for R10G10B10A2 (10-bit codes; alpha 2 bits): the model keeps the quantised value. | ||
| 627 | const auto paint10 = [&](Painted& p, D3D12_RECT r, int R, int G, int B) { | ||
| 628 | const FLOAT c[4] = {R / 1023.0f, G / 1023.0f, B / 1023.0f, 1.0f}; | ||
| 629 | if (!fill(p.source, c, 1, &r)) return false; | ||
| 630 | for (LONG y = r.top; y < r.bottom; ++y) | ||
| 631 | for (LONG x = r.left; x < r.right; ++x) | ||
| 632 | p.tex.px[std::size_t(y) * p.tex.w + x] = {R / 1023.0, G / 1023.0, B / 1023.0, 1.0}; | ||
| 633 | return true; | ||
| 634 | }; | ||
| 635 | // One PresentX of `count` planes, a fresh token for all; the swapchain frame is read back into `frame`. | ||
| 636 | const auto present_planes = [&](rt::d3d12::XboxPresentPlaneParameters* planes_, UINT count_, HRESULT want = S_OK) { | ||
| 637 | clock.advance_us(4 * period); | ||
| 638 | if (!next_token(token)) return false; | ||
| 639 | for (UINT i = 0; i < count_; ++i) planes_[i].Token = token; | ||
| 640 | if (xbox.PresentX(count_, planes_, nullptr) != want) return false; | ||
| 641 | return want != S_OK || grab(frame); | ||
| 642 | }; | ||
| 643 | const auto parameters = [&](Source& s, const XboxViewRect* place, int filter, int color_space = 0, | ||
| 644 | UINT flags = 0, const D3D12_RECT* rect = nullptr) { | ||
| 645 | rt::d3d12::XboxPresentPlaneParameters p = plane_of(s, 0, rect); | ||
| 646 | p.ColorSpace = color_space; | ||
| 647 | p.pDestPlacementBase = place; | ||
| 648 | p.ScaleFilter = filter; | ||
| 649 | p.Flags = flags; | ||
| 650 | return p; | ||
| 651 | }; | ||
| 652 | const auto model = [&](const Painted& p, const XboxViewRect* place, bool point, const D3D12_RECT* rect = nullptr, | ||
| 653 | bool hdr = false, bool straight = false) { | ||
| 654 | Ref_plane r; | ||
| 655 | r.tex = &p.tex; | ||
| 656 | r.src[0] = rect ? rect->left : 0; | ||
| 657 | r.src[1] = rect ? rect->top : 0; | ||
| 658 | r.src[2] = rect ? rect->right : double(p.tex.w); | ||
| 659 | r.src[3] = rect ? rect->bottom : double(p.tex.h); | ||
| 660 | const XboxViewRect whole{0, 0, 1, 1}; | ||
| 661 | const XboxViewRect& v = place ? *place : whole; | ||
| 662 | r.dest[0] = v.left * width; | ||
| 663 | r.dest[1] = v.top * height; | ||
| 664 | r.dest[2] = v.right * width; | ||
| 665 | r.dest[3] = v.bottom * height; | ||
| 666 | r.point = point; | ||
| 667 | r.hdr = hdr; | ||
| 668 | r.straight = straight; | ||
| 669 | return r; | ||
| 670 | }; | ||
| 671 | using rt::d3d12::xbox_scale_filter_linear; | ||
| 672 | using rt::d3d12::xbox_scale_filter_point; | ||
| 673 | const std::uint64_t composed_start = xbox.presenter().composed_presents(); | ||
| 674 | std::uint64_t composed_expected = composed_start; | ||
| 675 | const auto composed_ok = [&] { return xbox.presenter().composed_presents() == ++composed_expected; }; | ||
| 676 | |||
| 677 | // A: one plane, scaled 2x to the middle of the output, point and linear; the rest of the output is black. | ||
| 678 | Painted quad; | ||
| 679 | EXPECT(make_painted(quad, 80, 60)); | ||
| 680 | EXPECT(paint(quad, {0, 0, 40, 30}, 255, 0, 0, 255) && paint(quad, {40, 0, 80, 30}, 0, 255, 0, 255)); | ||
| 681 | EXPECT(paint(quad, {0, 30, 40, 60}, 0, 0, 255, 255) && paint(quad, {40, 30, 80, 60}, 255, 255, 255, 255)); | ||
| 682 | const XboxViewRect middle_half{0.25f, 0.25f, 0.75f, 0.75f}; | ||
| 683 | auto one = parameters(quad.source, &middle_half, xbox_scale_filter_point); | ||
| 684 | EXPECT(present_planes(&one, 1) && composed_ok()); | ||
| 685 | EXPECT(frame.format == VK_FORMAT_B8G8R8A8_UNORM || frame.format == VK_FORMAT_R8G8B8A8_UNORM); | ||
| 686 | Ref_plane ref0 = model(quad, &middle_half, true); | ||
| 687 | EXPECT(frame_matches(frame, &ref0, 1, false, 203.0, 0)); | ||
| 688 | std::printf("compose: 1 plane, 80x60 -> dest placement 160x120, point: exact\n"); | ||
| 689 | one = parameters(quad.source, &middle_half, xbox_scale_filter_linear); | ||
| 690 | EXPECT(present_planes(&one, 1) && composed_ok()); | ||
| 691 | ref0 = model(quad, &middle_half, false); | ||
| 692 | EXPECT(frame_matches(frame, &ref0, 1, false, 203.0, 1)); | ||
| 693 | std::printf("compose: same, bilinear: within 1 level of the model\n"); | ||
| 694 | // A source rectangle (the right half) onto the whole output, point: no placement. | ||
| 695 | const D3D12_RECT right_half_of_quad{40, 0, 80, 60}; | ||
| 696 | one = parameters(quad.source, nullptr, xbox_scale_filter_point, 0, 0, &right_half_of_quad); | ||
| 697 | EXPECT(present_planes(&one, 1) && composed_ok()); | ||
| 698 | ref0 = model(quad, nullptr, true, &right_half_of_quad); | ||
| 699 | EXPECT(frame_matches(frame, &ref0, 1, false, 203.0, 0)); | ||
| 700 | // Bilinear with a source rectangle must not read outside it: the right half shows only green over white. | ||
| 701 | one = parameters(quad.source, nullptr, xbox_scale_filter_linear, 0, 0, &right_half_of_quad); | ||
| 702 | EXPECT(present_planes(&one, 1) && composed_ok()); | ||
| 703 | ref0 = model(quad, nullptr, false, &right_half_of_quad); | ||
| 704 | EXPECT(frame_matches(frame, &ref0, 1, false, 203.0, 1)); | ||
| 705 | std::printf("compose: source rectangle, point and bilinear (clamped inside it): ok\n"); | ||
| 706 | |||
| 707 | // The compose pass with point filtering at 1:1 gives the very bytes of the plain blit. | ||
| 708 | plane = plane_of(split, 0); | ||
| 709 | clock.advance_us(4 * period); | ||
| 710 | EXPECT(next_token(token)); | ||
| 711 | plane.Token = token; | ||
| 712 | const std::uint64_t blits = xbox.presenter().composed_presents(); | ||
| 713 | EXPECT(xbox.PresentX(1, &plane, nullptr) == S_OK && xbox.presenter().composed_presents() == blits); | ||
| 714 | Frame blit_frame; | ||
| 715 | EXPECT(grab(blit_frame)); | ||
| 716 | one = parameters(split, nullptr, xbox_scale_filter_point); | ||
| 717 | EXPECT(present_planes(&one, 1) && composed_ok()); | ||
| 718 | EXPECT(frame.bytes == blit_frame.bytes); | ||
| 719 | std::printf("compose at 1:1 equals the plain blit byte for byte: ok\n"); | ||
| 720 | |||
| 721 | // An sRGB source (0.5 linear is byte 188): the pass encodes it again, so the bytes come out as stored. | ||
| 722 | one = parameters(srgb, nullptr, xbox_scale_filter_point); | ||
| 723 | EXPECT(present_planes(&one, 1) && composed_ok()); | ||
| 724 | EXPECT(!frame.srgb()); | ||
| 725 | EXPECT(region_is(frame, 0, 0, width, height, {188, 188, 188}, 1)); | ||
| 726 | std::printf("compose: sRGB source, UNORM swapchain: ok\n"); | ||
| 727 | |||
| 728 | // B: plane 1 over plane 0. Plane 0 is a solid; plane 1 (80x60, scaled 2x into the middle) has a half | ||
| 729 | // transparent red (premultiplied: 128,0,0 alpha 128), nothing, opaque green and 25% blue (0,0,64, alpha 64). | ||
| 730 | Painted solid; | ||
| 731 | EXPECT(make_painted(solid, width, height)); | ||
| 732 | EXPECT(paint(solid, {0, 0, LONG(width), LONG(height)}, 51, 153, 230, 255)); | ||
| 733 | Painted ui; | ||
| 734 | EXPECT(make_painted(ui, 80, 60)); | ||
| 735 | EXPECT(paint(ui, {0, 0, 40, 30}, 128, 0, 0, 128) && paint(ui, {0, 30, 40, 60}, 0, 255, 0, 255)); | ||
| 736 | EXPECT(paint(ui, {40, 30, 80, 60}, 0, 0, 64, 64)); | ||
| 737 | rt::d3d12::XboxPresentPlaneParameters pair[2]; | ||
| 738 | pair[0] = parameters(solid.source, nullptr, xbox_scale_filter_point); | ||
| 739 | pair[1] = parameters(ui.source, &middle_half, xbox_scale_filter_point, 0, rt::d3d12::xbox_plane_flag_overlay); | ||
| 740 | EXPECT(present_planes(pair, 2) && composed_ok()); | ||
| 741 | Ref_plane refs[2] = {model(solid, nullptr, true), model(ui, &middle_half, true)}; | ||
| 742 | EXPECT(frame_matches(frame, refs, 2, false, 203.0, 1)); | ||
| 743 | std::printf("compose: 2 planes, premultiplied alpha overlay, point: within 1 level of the model\n"); | ||
| 744 | pair[1] = parameters(ui.source, &middle_half, xbox_scale_filter_point, 0, rt::d3d12::xbox_plane_flag_overlay | rt::d3d12::xbox_plane_flag_straight_alpha); | ||
| 745 | EXPECT(present_planes(pair, 2) && composed_ok()); | ||
| 746 | refs[1] = model(ui, &middle_half, true, nullptr, false, true); | ||
| 747 | EXPECT(frame_matches(frame, refs, 2, false, 203.0, 1)); | ||
| 748 | std::printf("compose: 2 planes, straight alpha overlay: within 1 level of the model\n"); | ||
| 749 | pair[1] = parameters(ui.source, &middle_half, xbox_scale_filter_linear, 0, rt::d3d12::xbox_plane_flag_overlay); | ||
| 750 | EXPECT(present_planes(pair, 2) && composed_ok()); | ||
| 751 | refs[1] = model(ui, &middle_half, false); | ||
| 752 | EXPECT(frame_matches(frame, refs, 2, false, 203.0, 1)); | ||
| 753 | std::printf("compose: 2 planes, bilinear overlay: within 1 level of the model\n"); | ||
| 754 | // Straight alpha with bilinear filtering across a transparent edge: opaque white on the left, transparent black on the | ||
| 755 | // right. Colour is filtered premultiplied, so the edge is white at partial alpha, not grey (filtering the | ||
| 756 | // unassociated colour would also quarter the colour and quarter it again by the alpha). At output x=160 the sample | ||
| 757 | // is 0.75 of the way from the white texel to the transparent one: alpha 0.25, colour white: | ||
| 758 | // base 51 + 0.25 * (255 - 51) = 102. | ||
| 759 | Painted edge; | ||
| 760 | EXPECT(make_painted(edge, 80, 60)); | ||
| 761 | EXPECT(paint(edge, {0, 0, 40, 60}, 255, 255, 255, 255) && paint(edge, {40, 0, 80, 60}, 0, 0, 0, 0)); | ||
| 762 | pair[1] = parameters(edge.source, &middle_half, xbox_scale_filter_linear, 0, | ||
| 763 | rt::d3d12::xbox_plane_flag_overlay | rt::d3d12::xbox_plane_flag_straight_alpha); | ||
| 764 | EXPECT(present_planes(pair, 2) && composed_ok()); | ||
| 765 | refs[1] = model(edge, &middle_half, false, nullptr, false, true); | ||
| 766 | EXPECT(frame_matches(frame, refs, 2, false, 203.0, 1)); | ||
| 767 | { | ||
| 768 | const Px edge_px = frame.at(160, 120); | ||
| 769 | // red: 51 + 0.25 * 204 = 102 (blue: 230 + 0.25 * 25 = 236); the unfiltered-colour result would be near 54 | ||
| 770 | EXPECT(std::abs(edge_px.r - 102) <= 1 && std::abs(edge_px.b - 236) <= 1); | ||
| 771 | } | ||
| 772 | std::printf("compose: straight alpha, bilinear across a transparent edge (premultiplied filtering): ok\n"); | ||
| 773 | |||
| 774 | // C: HDR10 (PQ, Rec.2020) planes. Plane 0 is 80x60 R10G10B10A2 (three bands: SDR white level, a bright | ||
| 775 | // colour above it, and a dim colour), shown 4x on the whole output. | ||
| 776 | Painted hdr; | ||
| 777 | EXPECT(make_painted(hdr, 80, 60, DXGI_FORMAT_R10G10B10A2_UNORM)); | ||
| 778 | const auto code = [](double nits) { return int(std::lround(pq_encode(nits) * 1023.0)); }; | ||
| 779 | EXPECT(paint10(hdr, {0, 0, 27, 60}, code(203), code(203), code(203))); | ||
| 780 | EXPECT(paint10(hdr, {27, 0, 54, 60}, code(600), code(150), code(20))); | ||
| 781 | EXPECT(paint10(hdr, {54, 0, 80, 60}, code(40), code(80), code(120))); | ||
| 782 | one = parameters(hdr.source, nullptr, xbox_scale_filter_point, rt::d3d12::xbox_color_space_g2084_p2020); | ||
| 783 | EXPECT(present_planes(&one, 1) && composed_ok()); | ||
| 784 | Ref_plane href = model(hdr, nullptr, true, nullptr, true); | ||
| 785 | const bool surface_hdr = xbox.presenter().hdr_active(); | ||
| 786 | if (!surface_hdr) { | ||
| 787 | EXPECT(frame_matches(frame, &href, 1, false, 203.0, 2)); | ||
| 788 | std::printf("compose: HDR10 plane to an SDR swapchain (clipped to SDR, white = 203 nits): within 2 levels of the model\n"); | ||
| 789 | } else { | ||
| 790 | // A real HDR10 swapchain: the 10-bit codes come out as they went in (plane 0, point, 1:1 PQ). | ||
| 791 | EXPECT(frame.format == VK_FORMAT_A2B10G10R10_UNORM_PACK32 || frame.format == VK_FORMAT_A2R10G10B10_UNORM_PACK32); | ||
| 792 | bool ok = true; | ||
| 793 | for (UINT y = 0; y < height && ok; y += 7) | ||
| 794 | for (UINT x = 0; x < width && ok; x += 5) { | ||
| 795 | std::uint32_t word; | ||
| 796 | std::memcpy(&word, &frame.bytes[(std::size_t(y) * frame.extent.width + x) * 4], 4); | ||
| 797 | const bool abgr = frame.format == VK_FORMAT_A2B10G10R10_UNORM_PACK32; | ||
| 798 | const int r = int(abgr ? (word & 1023) : ((word >> 20) & 1023)); | ||
| 799 | const auto want = hdr.tex.px[std::size_t(y / 4) * 80 + x / 4]; | ||
| 800 | ok = std::abs(r - int(std::lround(want[0] * 1023.0))) <= 1; | ||
| 801 | } | ||
| 802 | EXPECT(ok); | ||
| 803 | std::printf("compose: HDR10 plane to an HDR10 (ST.2084) swapchain: codes within 1 of the source: ok\n"); | ||
| 804 | } | ||
| 805 | // Same plane, conversions to the PQ encoding of an 8-bit swapchain (test hook): an SDR overlay over it. | ||
| 806 | xbox.presenter().force_hdr_encoding(true); | ||
| 807 | pair[0] = parameters(hdr.source, nullptr, xbox_scale_filter_point, rt::d3d12::xbox_color_space_g2084_p2020); | ||
| 808 | pair[1] = parameters(ui.source, &middle_half, xbox_scale_filter_point, 0, rt::d3d12::xbox_plane_flag_overlay); | ||
| 809 | EXPECT(present_planes(pair, 2) && composed_ok()); | ||
| 810 | Ref_plane hrefs[2] = {model(hdr, nullptr, true, nullptr, true), model(ui, &middle_half, true)}; | ||
| 811 | if (!surface_hdr) { | ||
| 812 | EXPECT(frame_matches(frame, hrefs, 2, true, 203.0, 2)); | ||
| 813 | std::printf("compose: HDR10 plane + SDR overlay in PQ encoding (8-bit, forced): within 2 levels of the model\n"); | ||
| 814 | } | ||
| 815 | // SDR planes into PQ: the SDR white of the quad's white corner goes to 203 nits. | ||
| 816 | pair[0] = parameters(quad.source, nullptr, xbox_scale_filter_point); | ||
| 817 | pair[1] = parameters(ui.source, &middle_half, xbox_scale_filter_point, 0, rt::d3d12::xbox_plane_flag_overlay); | ||
| 818 | EXPECT(present_planes(pair, 2) && composed_ok()); | ||
| 819 | Ref_plane srefs[2] = {model(quad, nullptr, true), model(ui, &middle_half, true)}; | ||
| 820 | if (!surface_hdr) { | ||
| 821 | EXPECT(frame_matches(frame, srefs, 2, true, 203.0, 2)); | ||
| 822 | std::printf("compose: SDR planes converted to PQ (forced): within 2 levels of the model\n"); | ||
| 823 | } | ||
| 824 | xbox.presenter().force_hdr_encoding(false); | ||
| 825 | // The HDR plane reaches the SDR swapchain again after an HDR request on a surface that has none. | ||
| 826 | if (!surface_hdr) { | ||
| 827 | xbox.set_sdr_white_nits(100.0f); | ||
| 828 | one = parameters(hdr.source, nullptr, xbox_scale_filter_point, rt::d3d12::xbox_color_space_g2084_p2020); | ||
| 829 | EXPECT(present_planes(&one, 1) && composed_ok()); | ||
| 830 | EXPECT(frame_matches(frame, &href, 1, false, 100.0, 2)); | ||
| 831 | xbox.set_sdr_white_nits(203.0f); | ||
| 832 | std::printf("compose: SDR white level 100 nits applies: ok\n"); | ||
| 833 | } else { | ||
| 834 | std::printf("compose: the surface has HDR10: the forced-encoding checks are skipped on it\n"); | ||
| 835 | } | ||
| 836 | if (!surface_hdr) | ||
| 837 | std::printf("compose: HDR10 swapchain: this surface/display lists no ST.2084 format, so only the SDR clip and " | ||
| 838 | "the PQ encoder were run (HDR10 swapchain case skipped)\n"); | ||
| 839 | |||
| 840 | // D: an SDR plane 1 next to an HDR10 plane 0 that is not flagged an overlay is the GameDVR copy: not shown. | ||
| 841 | pair[0] = parameters(hdr.source, nullptr, xbox_scale_filter_point, rt::d3d12::xbox_color_space_g2084_p2020); | ||
| 842 | pair[1] = parameters(second, nullptr, xbox_scale_filter_point, 0); | ||
| 843 | EXPECT(present_planes(pair, 2) && composed_ok()); | ||
| 844 | if (!surface_hdr) EXPECT(frame_matches(frame, &href, 1, false, 203.0, 2)); | ||
| 845 | std::printf("compose: HDR10 plane 0 + unflagged SDR plane 1 (GameDVR copy) shows plane 0 only: ok\n"); | ||
| 846 | |||
| 847 | // E: a placement that is not a sub-rectangle of the output (empty, inverted, outside, NaN), an unknown filter and | ||
| 848 | // extended descriptors are ignored (logged once): the plane is shown over the whole output, point filtered. | ||
| 849 | const float nan = std::numeric_limits<float>::quiet_NaN(); | ||
| 850 | const XboxViewRect bad_places[] = {{0.5f, 0, 0.5f, 1}, {-0.1f, 0, 1, 1}, {0, 0, 1.5f, 1}, {0, 0.75f, 1, 0.25f}, {nan, 0, 1, 1}}; | ||
| 851 | for (const XboxViewRect& bad : bad_places) { | ||
| 852 | one = parameters(quad.source, &bad, xbox_scale_filter_point); | ||
| 853 | EXPECT(present_planes(&one, 1) && composed_ok()); | ||
| 854 | Ref_plane whole = model(quad, nullptr, true); | ||
| 855 | EXPECT(frame_matches(frame, &whole, 1, false, 203.0, 0)); | ||
| 856 | } | ||
| 857 | one = parameters(quad.source, nullptr, 77); // unknown filter: default (bilinear), plain blit path | ||
| 858 | one.ExtendedDescCount = 2; | ||
| 859 | EXPECT(present_planes(&one, 1)); | ||
| 860 | std::printf("compose: implausible placement, unknown filter, extended descriptors ignored (shown, not refused): ok\n"); | ||
| 861 | // Sources the pass cannot read (depth, multisampled) are refused: nothing is presented, the token still works. | ||
| 862 | const std::uint64_t presents_before = xbox.presents(); | ||
| 863 | { | ||
| 864 | const D3D12_HEAP_PROPERTIES default_heap{D3D12_HEAP_TYPE_DEFAULT}; | ||
| 865 | const auto make_special = [&](DXGI_FORMAT format, UINT samples, D3D12_RESOURCE_FLAGS flags, Ref<ID3D12Resource>& out) { | ||
| 866 | D3D12_RESOURCE_DESC desc{}; | ||
| 867 | desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; | ||
| 868 | desc.Width = width; | ||
| 869 | desc.Height = height; | ||
| 870 | desc.DepthOrArraySize = 1; | ||
| 871 | desc.MipLevels = 1; | ||
| 872 | desc.Format = format; | ||
| 873 | desc.SampleDesc.Count = samples; | ||
| 874 | desc.Flags = flags; | ||
| 875 | return SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_ALLOW_DISPLAY, &desc, | ||
| 876 | D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&out.p))); | ||
| 877 | }; | ||
| 878 | Ref<ID3D12Resource> depth_plane, msaa_plane; | ||
| 879 | EXPECT(make_special(DXGI_FORMAT_D32_FLOAT, 1, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE, depth_plane)); | ||
| 880 | EXPECT(make_special(DXGI_FORMAT_R8G8B8A8_UNORM, 4, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, msaa_plane)); | ||
| 881 | ID3D12Resource* cannot[2] = {depth_plane.p, msaa_plane.p}; | ||
| 882 | for (ID3D12Resource* resource : cannot) { | ||
| 883 | rt::d3d12::XboxPresentPlaneParameters p{0, 1, &resource, nullptr, 0}; | ||
| 884 | p.ScaleFilter = xbox_scale_filter_point; | ||
| 885 | EXPECT(present_planes(&p, 1, DXGI_ERROR_UNSUPPORTED)); | ||
| 886 | } | ||
| 887 | } | ||
| 888 | EXPECT(xbox.presents() == presents_before); | ||
| 889 | EXPECT(xbox.presenter().composed_presents() == composed_expected); | ||
| 890 | one = parameters(quad.source, &middle_half, xbox_scale_filter_point); | ||
| 891 | EXPECT(present_planes(&one, 1) && composed_ok()); // still working after the refusals | ||
| 892 | std::printf("compose: bad placements, depth and multisampled sources refused: ok\n"); | ||
| 893 | |||
| 894 | // F: the window changes size between composed presents (the swapchain is recreated, possibly in the middle of a | ||
| 895 | // present after an out-of-date acquire): the compose target follows, pixels match the model at the new size. | ||
| 896 | const UINT sizes[][2] = {{400, 300}, {200, 150}, {width, height}}; | ||
| 897 | for (const auto& size : sizes) { | ||
| 898 | RECT outer{0, 0, LONG(size[0]), LONG(size[1])}; | ||
| 899 | AdjustWindowRect(&outer, WS_OVERLAPPEDWINDOW, FALSE); | ||
| 900 | SetWindowPos(window, nullptr, 0, 0, outer.right - outer.left, outer.bottom - outer.top, | ||
| 901 | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); | ||
| 902 | pump(); | ||
| 903 | want_w = want_h = 0; // the first present after a resize may still be at the old size (suboptimal swapchain) | ||
| 904 | for (int round = 0; round < 3; ++round) { | ||
| 905 | one = parameters(quad.source, &middle_half, xbox_scale_filter_point); | ||
| 906 | // (A present the driver reports out of date right after the resize is not counted as shown, so the counter | ||
| 907 | // is not checked here; the frame is still composed and read back.) | ||
| 908 | EXPECT(present_planes(&one, 1)); | ||
| 909 | // Whatever size the frame has, it must be the composition at that size (no stale or mis-sized target). | ||
| 910 | Ref_plane resized = model(quad, &middle_half, true); | ||
| 911 | resized.dest[0] = middle_half.left * double(frame.extent.width); | ||
| 912 | resized.dest[1] = middle_half.top * double(frame.extent.height); | ||
| 913 | resized.dest[2] = middle_half.right * double(frame.extent.width); | ||
| 914 | resized.dest[3] = middle_half.bottom * double(frame.extent.height); | ||
| 915 | EXPECT(frame_matches(frame, &resized, 1, false, 203.0, 0)); | ||
| 916 | if (round == 2) EXPECT(frame.extent.width == size[0] && frame.extent.height == size[1]); | ||
| 917 | } | ||
| 918 | } | ||
| 919 | want_w = width; | ||
| 920 | want_h = height; | ||
| 921 | composed_expected = xbox.presenter().composed_presents(); | ||
| 922 | std::printf("compose: window resized 320x240 -> 400x300 -> 200x150 -> 320x240 between composed presents: ok\n"); | ||
| 923 | } | ||
| 924 | |||
| 424 | // Skipping a frame (waiting twice, presenting the second token) is fine. | 925 | // Skipping a frame (waiting twice, presenting the second token) is fine. |
| 425 | std::uint64_t skipped = 0; | 926 | std::uint64_t skipped = 0; |
| 426 | clock.advance_us(4 * period); | 927 | clock.advance_us(4 * period); |
diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp index 504f0f74d..c5a0e988e 100644 --- a/runtime/test/xgameruntime_test.cpp +++ b/runtime/test/xgameruntime_test.cpp | |||
| @@ -51,16 +51,11 @@ using AsyncCompleteFn = void(__stdcall*)(XAsyncBlock*, HRESULT, size_t); | |||
| 51 | using AsyncResultSizeFn = HRESULT(__stdcall*)(XAsyncBlock*, size_t*); | 51 | using AsyncResultSizeFn = HRESULT(__stdcall*)(XAsyncBlock*, size_t*); |
| 52 | using AsyncResultFn = HRESULT(__stdcall*)(XAsyncBlock*, const void*, size_t, void*, size_t*); | 52 | using AsyncResultFn = HRESULT(__stdcall*)(XAsyncBlock*, const void*, size_t, void*, size_t*); |
| 53 | 53 | ||
| 54 | struct XVersion { | 54 | struct alignas(8) XVersion { |
| 55 | union { | 55 | uint16_t major; |
| 56 | struct { | 56 | uint16_t minor; |
| 57 | uint16_t major; | 57 | uint16_t build; |
| 58 | uint16_t minor; | 58 | uint16_t revision; |
| 59 | uint16_t build; | ||
| 60 | uint16_t revision; | ||
| 61 | }; | ||
| 62 | uint64_t Value; | ||
| 63 | }; | ||
| 64 | }; | 59 | }; |
| 65 | static_assert(sizeof(XVersion) == 8, "XVersion must be 8 bytes per GDK spec"); | 60 | static_assert(sizeof(XVersion) == 8, "XVersion must be 8 bytes per GDK spec"); |
| 66 | 61 | ||
| @@ -72,14 +67,22 @@ struct XSystemAnalyticsInfo { | |||
| 72 | }; | 67 | }; |
| 73 | static_assert(sizeof(XSystemAnalyticsInfo) == 144, "XSystemAnalyticsInfo must be 144 bytes per GDK spec"); | 68 | static_assert(sizeof(XSystemAnalyticsInfo) == 144, "XSystemAnalyticsInfo must be 144 bytes per GDK spec"); |
| 74 | 69 | ||
| 70 | struct XPackageMountHandle { | ||
| 71 | uint64_t handle; | ||
| 72 | }; | ||
| 73 | |||
| 75 | using AnalyticsInfoFn = XSystemAnalyticsInfo(__stdcall*)(); | 74 | using AnalyticsInfoFn = XSystemAnalyticsInfo(__stdcall*)(); |
| 76 | using PackageIdentifierFn = HRESULT(__stdcall*)(size_t, char*); | 75 | using PackageIdentifierFn = HRESULT(__stdcall*)(size_t, char*); |
| 77 | using PackageMountPathFn = HRESULT(__stdcall*)(void*, size_t, char*); | 76 | using PackageMountFn = HRESULT(__stdcall*)(const char*, XPackageMountHandle*); |
| 77 | using PackageCloseMountHandleFn = void(__stdcall*)(XPackageMountHandle); | ||
| 78 | using PackageMountPathSizeFn = HRESULT(__stdcall*)(XPackageMountHandle, size_t*); | ||
| 79 | using PackageMountPathFn = HRESULT(__stdcall*)(XPackageMountHandle, size_t, char*); | ||
| 78 | using PackagedProcessFn = bool(__stdcall*)(); | 80 | using PackagedProcessFn = bool(__stdcall*)(); |
| 79 | 81 | ||
| 80 | const char* const kNames[] = { | 82 | const char* const kNames[] = { |
| 81 | "XGameRuntimeInitialize", "XGameRuntimeUninitialize", "XSystemGetDeviceType", "XSystemGetConsoleId", | 83 | "XGameRuntimeInitialize", "XGameRuntimeUninitialize", "XSystemGetDeviceType", "XSystemGetConsoleId", |
| 82 | "XSystemGetAnalyticsInfo", "XPackageGetCurrentProcessPackageIdentifier", "XPackageGetMountPath", | 84 | "XSystemGetAnalyticsInfo", "XPackageGetCurrentProcessPackageIdentifier", "XPackageMount", |
| 85 | "XPackageCloseMountHandle", "XPackageGetMountPathSize", "XPackageGetMountPath", | ||
| 83 | "XPackageIsPackagedProcess", | 86 | "XPackageIsPackagedProcess", |
| 84 | "XTaskQueueCreate", "XTaskQueueCreateComposite", "XTaskQueueGetPort", "XTaskQueueDuplicateHandle", | 87 | "XTaskQueueCreate", "XTaskQueueCreateComposite", "XTaskQueueGetPort", "XTaskQueueDuplicateHandle", |
| 85 | "XTaskQueueCloseHandle", "XTaskQueueTerminate", "XTaskQueueDispatch", "XTaskQueueSubmitCallback", | 88 | "XTaskQueueCloseHandle", "XTaskQueueTerminate", "XTaskQueueDispatch", "XTaskQueueSubmitCallback", |
| @@ -194,6 +197,23 @@ void check_run_time_load() { | |||
| 194 | check(get_proc(rt_mod, nullptr) == nullptr && GetLastError() == ERROR_PROC_NOT_FOUND, | 197 | check(get_proc(rt_mod, nullptr) == nullptr && GetLastError() == ERROR_PROC_NOT_FOUND, |
| 195 | "a null proc name is NULL with ERROR_PROC_NOT_FOUND"); | 198 | "a null proc name is NULL with ERROR_PROC_NOT_FOUND"); |
| 196 | 199 | ||
| 200 | // XCurl.dll's other way in: LoadLibraryExW(L"gameplatformservices.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32), | ||
| 201 | // then GetApiVersionImpl(uint64_t*, uint64_t*) and QueryApiImpl. Served by the shims, never the PC's own. | ||
| 202 | using LoadExW = HMODULE(WINAPI*)(LPCWSTR, HANDLE, DWORD); | ||
| 203 | auto load_ex_w = reinterpret_cast<LoadExW>(rt::shims::find(set, "LoadLibraryExW")); | ||
| 204 | HMODULE gps = load_ex_w ? load_ex_w(L"gameplatformservices.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32) : nullptr; | ||
| 205 | check(rt::shims::owns_dll("gameplatformservices.dll") && gps != nullptr && gps != rt_mod, | ||
| 206 | "LoadLibraryExW(gameplatformservices.dll, SEARCH_SYSTEM32) is served by the shims"); | ||
| 207 | using ApiVersion = HRESULT(WINAPI*)(uint64_t*, uint64_t*); | ||
| 208 | auto api_version = gps ? reinterpret_cast<ApiVersion>(get_proc(gps, "GetApiVersionImpl")) : nullptr; | ||
| 209 | uint64_t v1 = 0, v2 = 0, w1 = 0, w2 = 0; | ||
| 210 | check(api_version && api_version(&v1, &v2) == S_OK && api_version(&w1, &w2) == S_OK && v1 && v2 && v1 == w1 && | ||
| 211 | v2 == w2, | ||
| 212 | "GetApiVersionImpl writes the same two non-zero versions on every call"); | ||
| 213 | check(gps && reinterpret_cast<void*>(get_proc(gps, "QueryApiImpl")) == | ||
| 214 | rt::shims::find("xgameruntime.dll", "QueryApiImpl"), | ||
| 215 | "its QueryApiImpl is the offline runtime's"); | ||
| 216 | |||
| 197 | struct Options { | 217 | struct Options { |
| 198 | uint32_t unknown; | 218 | uint32_t unknown; |
| 199 | BOOL is_inline; | 219 | BOOL is_inline; |
| @@ -283,76 +303,123 @@ void check_run_time_load() { | |||
| 283 | return true; | 303 | return true; |
| 284 | }; | 304 | }; |
| 285 | using SetCallback = void(STDMETHODCALLTYPE*)(void*, Callback, void*); | 305 | using SetCallback = void(STDMETHODCALLTYPE*)(void*, Callback, void*); |
| 286 | using Report = void(STDMETHODCALLTYPE*)(void*, HRESULT, const char*); | 306 | using Report = HRESULT(STDMETHODCALLTYPE*)(void*, HRESULT, const char*); |
| 287 | reinterpret_cast<SetCallback>(slot(e, 4))(e, on_error, &seen); | 307 | reinterpret_cast<SetCallback>(slot(e, 4))(e, on_error, &seen); |
| 288 | reinterpret_cast<Report>(slot(e, 3))(e, E_FAIL, "offline test"); | 308 | const HRESULT reported = reinterpret_cast<Report>(slot(e, 3))(e, E_FAIL, "offline test"); |
| 289 | check(seen.hr == E_FAIL && std::strcmp(seen.msg, "offline test") == 0, | 309 | check(reported == S_OK && seen.hr == E_FAIL && std::strcmp(seen.msg, "offline test") == 0, |
| 290 | "slot 3 is XErrorReport and reaches the callback slot 4 (XErrorSetCallback) set"); | 310 | "slot 3 is XErrorReport and reaches the callback slot 4 (XErrorSetCallback) set"); |
| 291 | reinterpret_cast<SetCallback>(slot(e, 4))(e, nullptr, nullptr); | 311 | reinterpret_cast<SetCallback>(slot(e, 4))(e, nullptr, nullptr); |
| 292 | using SetOptions = HRESULT(STDMETHODCALLTYPE*)(void*, uint32_t, uint32_t); | 312 | using SetOptions = void(STDMETHODCALLTYPE*)(void*, uint32_t, uint32_t); // void, per Microsoft's page |
| 293 | check(reinterpret_cast<SetOptions>(slot(e, 5))(e, 0, 0) == S_OK, "slot 5 is XErrorSetOptions"); | 313 | reinterpret_cast<SetOptions>(slot(e, 5))(e, 0x01, 0x00); // OutputDebugStringOnError / None |
| 294 | release(e); | 314 | release(e); |
| 295 | } | 315 | } |
| 296 | 316 | ||
| 297 | const GUID networking_cls = {0x37e56907, 0x2f10, 0x41e8, {0xb7, 0x2f, 0x36, 0xed, 0xb1, 0x85, 0x33, 0x1a}}; | 317 | // XNetworkingImpl, asked for as XCurl.dll does: the class id with IXNetworkingImpl2's interface id. |
| 298 | void* n = get(networking_cls); | 318 | const GUID networking = {0x37e56907, 0x2f10, 0x41e8, {0xb7, 0x2f, 0x36, 0xed, 0xb1, 0x85, 0x33, 0x1a}}; |
| 299 | check(n != nullptr, "QueryApiImpl hands out XNetworkingImpl for its class id"); | 319 | const GUID networking2 = {0xbf2346b2, 0x39af, 0x4658, {0xb5, 0xea, 0x44, 0x71, 0x3c, 0x7e, 0x83, 0xb3}}; |
| 320 | const HRESULT no_network = HRESULT_FROM_WIN32(ERROR_NETWORK_UNREACHABLE); | ||
| 321 | void* n = nullptr; | ||
| 322 | check(query(&networking, networking2, &n) == S_OK && n, "QueryApiImpl hands out XNetworkingImpl for IXNetworkingImpl2"); | ||
| 323 | void* n1 = nullptr; | ||
| 324 | check(query(&networking, networking, &n1) == S_OK && n1 == n, "and the same object for IXNetworkingImpl"); | ||
| 325 | if (n1) release(n1); | ||
| 300 | if (n) { | 326 | if (n) { |
| 301 | void* again = get(networking_cls); | 327 | struct Hint { |
| 302 | check(again == n, "XNetworkingImpl is one process-wide object"); | 328 | uint32_t level, cost, iana; |
| 303 | release(again); | 329 | bool initialized, approaching, over, roaming; |
| 304 | 330 | } hint{9, 9, 9, false, true, true, true}; | |
| 305 | // Slot 15: XNetworkingGetConnectivityHint | 331 | using GetHint = HRESULT(STDMETHODCALLTYPE*)(void*, Hint*); |
| 306 | struct ConnectivityHint { | 332 | check(reinterpret_cast<GetHint>(slot(n, 15))(n, &hint) == S_OK && hint.level == 1 && hint.cost == 0 && |
| 307 | uint32_t level; | 333 | hint.initialized && !hint.approaching && !hint.over && !hint.roaming, |
| 308 | uint32_t cost; | 334 | "slot 15 (XNetworkingGetConnectivityHint): initialized, no connectivity"); |
| 309 | uint32_t iana_type; | 335 | XAsyncBlock block{}; |
| 310 | bool network_initialized; | 336 | using SecurityAsync = HRESULT(STDMETHODCALLTYPE*)(void*, const wchar_t*, XAsyncBlock*); |
| 311 | bool approaching_limit; | 337 | using ResultSize = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, size_t*); |
| 312 | bool over_limit; | 338 | size_t size = 99; |
| 313 | bool roaming; | 339 | check(reinterpret_cast<SecurityAsync>(slot(n, 11))(n, L"https://example.invalid/", &block) == S_OK && |
| 314 | } hint{}; | 340 | XAsyncGetStatus(&block, true) == no_network && |
| 315 | using GetHint = HRESULT(STDMETHODCALLTYPE*)(void*, ConnectivityHint*); | 341 | reinterpret_cast<ResultSize>(slot(n, 12))(n, &block, &size) == no_network && size == 0, |
| 316 | check(reinterpret_cast<GetHint>(slot(n, 15))(n, nullptr) == E_POINTER, | 342 | "slots 11/12 (UTF-16 URL security info): the async call completes with no network"); |
| 317 | "slot 15 rejects null pointer with E_POINTER"); | 343 | // Slots 10/13 in Microsoft's order: (async, bufferByteCount, bufferByteCountUsed*, buffer*, information**). |
| 318 | check(reinterpret_cast<GetHint>(slot(n, 15))(n, &hint) == S_OK && hint.network_initialized && | 344 | // A sentinel buffer must stay untouched; the two outputs are written where they are, not into the buffer. |
| 319 | hint.level == 3 && hint.cost == 1, | 345 | using SecurityResult = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, size_t, size_t*, uint8_t*, void**); |
| 320 | "slot 15 is XNetworkingGetConnectivityHint reporting initialized network and internet access"); | 346 | for (int s : {10, 13}) { |
| 321 | 347 | uint8_t buffer[32]; | |
| 322 | // Slot 14: XNetworkingVerifyServerCertificate | 348 | std::memset(buffer, 0xA5, sizeof(buffer)); |
| 323 | using VerifyCert = HRESULT(STDMETHODCALLTYPE*)(void*, void*, const void*); | 349 | size_t used = 77; |
| 324 | check(reinterpret_cast<VerifyCert>(slot(n, 14))(n, nullptr, nullptr) == S_OK, | 350 | void* info = &used; |
| 325 | "slot 14 is XNetworkingVerifyServerCertificate returning S_OK offline"); | 351 | const HRESULT hr = reinterpret_cast<SecurityResult>(slot(n, s))(n, &block, sizeof(buffer), &used, buffer, &info); |
| 326 | 352 | bool untouched = true; | |
| 327 | // Slot 16 & 17: XNetworkingRegisterConnectivityHintChanged and Unregister | 353 | for (uint8_t byte : buffer) untouched = untouched && byte == 0xA5; |
| 328 | using RegisterHint = HRESULT(STDMETHODCALLTYPE*)(void*, XTaskQueueHandle, void*, void*, XTaskQueueRegistrationToken*); | 354 | check(hr == no_network && used == 0 && info == nullptr && untouched, |
| 329 | using UnregisterHint = bool(STDMETHODCALLTYPE*)(void*, XTaskQueueRegistrationToken, bool); | 355 | s == 10 ? "slot 10 (ANSI result): outputs zeroed in place, the caller's buffer untouched" |
| 330 | XTaskQueueRegistrationToken tok1{0}, tok2{0}; | 356 | : "slot 13 (UTF-16 result): outputs zeroed in place, the caller's buffer untouched"); |
| 331 | check(reinterpret_cast<RegisterHint>(slot(n, 16))(n, nullptr, nullptr, nullptr, &tok1) == S_OK && | 357 | } |
| 332 | reinterpret_cast<RegisterHint>(slot(n, 16))(n, nullptr, nullptr, nullptr, &tok2) == S_OK && | 358 | using Verify = HRESULT(STDMETHODCALLTYPE*)(void*, void*, const void*); |
| 333 | tok1.token != tok2.token && tok1.token > 0, | 359 | check(reinterpret_cast<Verify>(slot(n, 14))(n, nullptr, nullptr) == no_network, |
| 334 | "slot 16 registers connectivity hint callbacks and hands out tokens"); | 360 | "slot 14 (XNetworkingVerifyServerCertificate) fails offline"); |
| 335 | check(reinterpret_cast<UnregisterHint>(slot(n, 17))(n, tok1, false) == true && | 361 | XTaskQueueRegistrationToken token{}; |
| 336 | reinterpret_cast<UnregisterHint>(slot(n, 17))(n, tok2, true) == true, | 362 | using Register = HRESULT(STDMETHODCALLTYPE*)(void*, XTaskQueueHandle, void*, void*, XTaskQueueRegistrationToken*); |
| 337 | "slot 17 unregisters connectivity hint callbacks"); | 363 | using Unregister = bool(STDMETHODCALLTYPE*)(void*, XTaskQueueRegistrationToken, bool); |
| 338 | 364 | check(reinterpret_cast<Register>(slot(n, 16))(n, nullptr, nullptr, nullptr, &token) == S_OK && token.token && | |
| 339 | // Slots 11-13: Async security info query | 365 | reinterpret_cast<Unregister>(slot(n, 17))(n, token, true), |
| 340 | using QuerySecAsync = HRESULT(STDMETHODCALLTYPE*)(void*, const wchar_t*, XAsyncBlock*); | 366 | "slots 16/17 register and unregister a connectivity-hint callback"); |
| 341 | using QuerySecSize = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, size_t*); | 367 | uint16_t port = 7; |
| 342 | using QuerySecResult = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, size_t, size_t*, uint8_t*, void**); | 368 | using QueryPort = HRESULT(STDMETHODCALLTYPE*)(void*, uint16_t*); |
| 343 | check(reinterpret_cast<QuerySecAsync>(slot(n, 11))(n, L"https://example.com", nullptr) == S_OK, | 369 | using NotImpl = HRESULT(STDMETHODCALLTYPE*)(void*); |
| 344 | "slot 11 is XNetworkingQuerySecurityInformationForUrlUtf16Async"); | 370 | check(reinterpret_cast<QueryPort>(slot(n, 3))(n, &port) == no_network && port == 0 && |
| 345 | size_t sec_size = 42; | 371 | reinterpret_cast<NotImpl>(slot(n, 20))(n) == E_NOTIMPL, |
| 346 | check(reinterpret_cast<QuerySecSize>(slot(n, 12))(n, nullptr, &sec_size) == S_OK && sec_size == 0, | 372 | "slot 3 (preferred UDP port) has no answer offline; slot 20 (IXNetworkingImpl2) is E_NOTIMPL"); |
| 347 | "slot 12 is XNetworkingQuerySecurityInformationForUrlUtf16AsyncResultSize returning 0 bytes"); | ||
| 348 | size_t used = 42; | ||
| 349 | void* sec_info = reinterpret_cast<void*>(1); | ||
| 350 | check(reinterpret_cast<QuerySecResult>(slot(n, 13))(n, nullptr, 0, &used, nullptr, &sec_info) == S_OK && | ||
| 351 | used == 0 && sec_info == nullptr, | ||
| 352 | "slot 13 is XNetworkingQuerySecurityInformationForUrlUtf16AsyncResult returning S_OK with null result"); | ||
| 353 | |||
| 354 | release(n); | 373 | release(n); |
| 355 | } | 374 | } |
| 375 | |||
| 376 | // XSystemImpl, asked for as libHttpClient.GDK.dll does: the class id with IXSystemImpl5's interface id. | ||
| 377 | const GUID system_cls = {0xe349bd1a, 0xfc20, 0x4e40, {0xb9, 0x9c, 0x41, 0x78, 0xcc, 0x6b, 0x40, 0x9f}}; | ||
| 378 | const GUID system5 = {0x1861cf2e, 0xe18b, 0x4834, {0xa9, 0xf5, 0xb4, 0xa4, 0xe6, 0xef, 0xb4, 0xcf}}; | ||
| 379 | void* sy = nullptr; | ||
| 380 | check(query(&system_cls, system5, &sy) == S_OK && sy, "QueryApiImpl hands out XSystemImpl for IXSystemImpl5"); | ||
| 381 | if (sy) { | ||
| 382 | using IdQuery = HRESULT(STDMETHODCALLTYPE*)(void*, size_t, char*, size_t*); | ||
| 383 | char buf[64] = {}; | ||
| 384 | size_t used = 0; | ||
| 385 | check(reinterpret_cast<IdQuery>(slot(sy, 3))(sy, sizeof(buf), buf, &used) == S_OK && used == 39 && | ||
| 386 | std::strlen(buf) == 38, | ||
| 387 | "slot 3 (XSystemGetConsoleId): the 39-byte placeholder"); | ||
| 388 | check(reinterpret_cast<IdQuery>(slot(sy, 4))(sy, sizeof(buf), buf, &used) == S_OK && | ||
| 389 | std::strcmp(buf, "RETAIL") == 0 && used == 7, | ||
| 390 | "slot 4 (XSystemGetXboxLiveSandboxId): RETAIL"); | ||
| 391 | check(reinterpret_cast<IdQuery>(slot(sy, 4))(sy, 15, buf, &used) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) && | ||
| 392 | reinterpret_cast<IdQuery>(slot(sy, 4))(sy, 16, buf, &used) == S_OK, | ||
| 393 | "slot 4 needs XSystemXboxLiveSandboxIdMaxBytes (16), not just the id's 7 bytes"); | ||
| 394 | const GUID chain[] = { | ||
| 395 | system_cls, | ||
| 396 | {0x6fd71f09, 0x7513, 0x49f0, {0x89, 0xbc, 0xbf, 0xaf, 0x5d, 0xf6, 0xf8, 0x52}}, | ||
| 397 | {0x67ce4bfc, 0xb1d1, 0x4ac7, {0xbc, 0x3a, 0xcb, 0x92, 0x19, 0xa9, 0x7a, 0x85}}, | ||
| 398 | {0xdadc2895, 0x34b0, 0x4ef5, {0xa8, 0x3e, 0x45, 0x11, 0x4d, 0x62, 0x9b, 0x80}}, | ||
| 399 | system5}; | ||
| 400 | bool all = true; | ||
| 401 | for (const GUID& iid : chain) { | ||
| 402 | void* same = nullptr; | ||
| 403 | all = all && query(&system_cls, iid, &same) == S_OK && same == sy; | ||
| 404 | if (same) release(same); | ||
| 405 | } | ||
| 406 | check(all, "IXSystemImpl5 answers for every interface it inherits (IXSystemImpl .. IXSystemImpl4)"); | ||
| 407 | check(reinterpret_cast<IdQuery>(slot(sy, 5))(sy, sizeof(buf), buf, &used) == S_OK && used == 45 && | ||
| 408 | reinterpret_cast<IdQuery>(slot(sy, 5))(sy, 44, buf, &used) == | ||
| 409 | HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) && | ||
| 410 | reinterpret_cast<IdQuery>(slot(sy, 5))(sy, 45, nullptr, &used) == E_INVALIDARG, | ||
| 411 | "slot 5 (XSystemGetAppSpecificDeviceId): 45 bytes; a short or null buffer is refused"); | ||
| 412 | using Track = HRESULT(STDMETHODCALLTYPE*)(void*, void*, void*); | ||
| 413 | using IsValid = bool(STDMETHODCALLTYPE*)(void*, void*); // bool, per Microsoft's reference page | ||
| 414 | using Bandwidth = void(STDMETHODCALLTYPE*)(void*, bool); | ||
| 415 | int ctx = 0; | ||
| 416 | reinterpret_cast<Bandwidth>(slot(sy, 8))(sy, true); | ||
| 417 | check(reinterpret_cast<Track>(slot(sy, 6))(sy, &ctx, &ctx) == S_OK && | ||
| 418 | reinterpret_cast<IsValid>(slot(sy, 7))(sy, &ctx) && | ||
| 419 | !reinterpret_cast<IsValid>(slot(sy, 7))(sy, nullptr), | ||
| 420 | "slots 6-8 (handle tracking, handle check, download bandwidth) answer offline"); | ||
| 421 | release(sy); | ||
| 422 | } | ||
| 356 | check(uninit_api() == S_OK, "UninitializeApiImpl succeeds"); | 423 | check(uninit_api() == S_OK, "UninitializeApiImpl succeeds"); |
| 357 | 424 | ||
| 358 | HMODULE k32 = load_w(L"kernel32.dll"); | 425 | HMODULE k32 = load_w(L"kernel32.dll"); |
| @@ -426,20 +493,63 @@ int main() { | |||
| 426 | std::strcmp(pkg_id, "CustomTestPackageId_123456789012") == 0, | 493 | std::strcmp(pkg_id, "CustomTestPackageId_123456789012") == 0, |
| 427 | "XPackageGetCurrentProcessPackageIdentifier respects LEONIDA_PACKAGE_ID override"); | 494 | "XPackageGetCurrentProcessPackageIdentifier respects LEONIDA_PACKAGE_ID override"); |
| 428 | SetEnvironmentVariableA("LEONIDA_PACKAGE_ID", nullptr); | 495 | SetEnvironmentVariableA("LEONIDA_PACKAGE_ID", nullptr); |
| 496 | // pkg_id still holds the override; the mount checks below need the game's own identifier again. | ||
| 497 | check(package_id(sizeof(pkg_id), pkg_id) == S_OK && std::strlen(pkg_id) == 32, | ||
| 498 | "XPackageGetCurrentProcessPackageIdentifier returns the default again once the override is cleared"); | ||
| 429 | 499 | ||
| 500 | auto mount_pkg = get<PackageMountFn>("XPackageMount"); | ||
| 501 | auto close_mount = get<PackageCloseMountHandleFn>("XPackageCloseMountHandle"); | ||
| 502 | auto mount_path_size = get<PackageMountPathSizeFn>("XPackageGetMountPathSize"); | ||
| 430 | auto mount_path = get<PackageMountPathFn>("XPackageGetMountPath"); | 503 | auto mount_path = get<PackageMountPathFn>("XPackageGetMountPath"); |
| 431 | check(mount_path(nullptr, 0, nullptr) == E_INVALIDARG, "XPackageGetMountPath rejects null buffer and size 0"); | ||
| 432 | char mnt_path[MAX_PATH] = {}; | ||
| 433 | check(mount_path(nullptr, 0, mnt_path) == E_INVALIDARG, "XPackageGetMountPath rejects size 0 with buffer"); | ||
| 434 | check(mount_path(nullptr, 10, nullptr) == E_INVALIDARG, "XPackageGetMountPath rejects null pointer with size"); | ||
| 435 | 504 | ||
| 436 | SetEnvironmentVariableA("LEONIDA_GAME_DIR", "C:\\LeonidaGameDir"); | 505 | const XPackageMountHandle kInvalidMount{0}; |
| 437 | check(mount_path(nullptr, 5, mnt_path) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), | 506 | const XPackageMountHandle kStaleMount{999}; |
| 507 | |||
| 508 | XPackageMountHandle test_out{0}; | ||
| 509 | check(mount_pkg(nullptr, nullptr) == E_INVALIDARG, "XPackageMount rejects null identifier and null out pointer"); | ||
| 510 | check(mount_pkg(pkg_id, nullptr) == E_INVALIDARG, "XPackageMount rejects null out pointer with identifier"); | ||
| 511 | check(mount_pkg(nullptr, &test_out) == E_INVALIDARG, "XPackageMount rejects null identifier with out pointer"); | ||
| 512 | check(mount_pkg(pkg_id, &test_out) == E_ACCESSDENIED, | ||
| 513 | "XPackageMount rejects game package identifier with E_ACCESSDENIED"); | ||
| 514 | check(mount_pkg("UninstalledPackage_0000000000000", &test_out) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), | ||
| 515 | "XPackageMount rejects uninstalled package identifier with ERROR_NOT_FOUND"); | ||
| 516 | |||
| 517 | size_t req_size = 0; | ||
| 518 | check(mount_path_size(kInvalidMount, &req_size) == E_INVALIDARG, | ||
| 519 | "XPackageGetMountPathSize rejects invalid mount handle 0"); | ||
| 520 | check(mount_path_size(kStaleMount, &req_size) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), | ||
| 521 | "XPackageGetMountPathSize rejects unknown mount handle"); | ||
| 522 | |||
| 523 | char mnt_path[MAX_PATH] = {}; | ||
| 524 | check(mount_path(kInvalidMount, 0, nullptr) == E_INVALIDARG, | ||
| 525 | "XPackageGetMountPath rejects invalid mount handle 0"); | ||
| 526 | check(mount_path(kStaleMount, sizeof(mnt_path), mnt_path) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), | ||
| 527 | "XPackageGetMountPath rejects unknown mount handle"); | ||
| 528 | |||
| 529 | SetEnvironmentVariableA("LEONIDA_CONTENT_PACKAGES", "DLC1_123456789012345678901234567=C:\\LeonidaDLC1"); | ||
| 530 | XPackageMountHandle dlc_mount{0}; | ||
| 531 | check(mount_pkg("DLC1_123456789012345678901234567", &dlc_mount) == S_OK && dlc_mount.handle != 0, | ||
| 532 | "XPackageMount mounts content package from LEONIDA_CONTENT_PACKAGES"); | ||
| 533 | check(mount_path_size(dlc_mount, nullptr) == E_INVALIDARG, | ||
| 534 | "XPackageGetMountPathSize rejects null size pointer"); | ||
| 535 | check(mount_path_size(dlc_mount, &req_size) == S_OK && req_size == std::strlen("C:\\LeonidaDLC1") + 1, | ||
| 536 | "XPackageGetMountPathSize returns required buffer size including null terminator for mounted handle"); | ||
| 537 | check(mount_path(dlc_mount, 0, mnt_path) == E_INVALIDARG, | ||
| 538 | "XPackageGetMountPath rejects size 0 with buffer"); | ||
| 539 | check(mount_path(dlc_mount, 10, nullptr) == E_INVALIDARG, | ||
| 540 | "XPackageGetMountPath rejects null pointer with size"); | ||
| 541 | check(mount_path(dlc_mount, 5, mnt_path) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), | ||
| 438 | "XPackageGetMountPath rejects insufficient buffer"); | 542 | "XPackageGetMountPath rejects insufficient buffer"); |
| 439 | check(mount_path(nullptr, sizeof(mnt_path), mnt_path) == S_OK && | 543 | check(mount_path(dlc_mount, sizeof(mnt_path), mnt_path) == S_OK && |
| 440 | std::strcmp(mnt_path, "C:\\LeonidaGameDir") == 0, | 544 | std::strcmp(mnt_path, "C:\\LeonidaDLC1") == 0, |
| 441 | "XPackageGetMountPath returns configured game directory"); | 545 | "XPackageGetMountPath returns configured content directory for mounted handle"); |
| 442 | SetEnvironmentVariableA("LEONIDA_GAME_DIR", nullptr); | 546 | |
| 547 | close_mount(dlc_mount); | ||
| 548 | check(mount_path_size(dlc_mount, &req_size) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), | ||
| 549 | "XPackageGetMountPathSize rejects closed/stale mount handle"); | ||
| 550 | check(mount_path(dlc_mount, sizeof(mnt_path), mnt_path) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), | ||
| 551 | "XPackageGetMountPath rejects closed/stale mount handle"); | ||
| 552 | SetEnvironmentVariableA("LEONIDA_CONTENT_PACKAGES", nullptr); | ||
| 443 | 553 | ||
| 444 | auto is_packaged = get<PackagedProcessFn>("XPackageIsPackagedProcess"); | 554 | auto is_packaged = get<PackagedProcessFn>("XPackageIsPackagedProcess"); |
| 445 | check(is_packaged() == true, "XPackageIsPackagedProcess returns true by default"); | 555 | check(is_packaged() == true, "XPackageIsPackagedProcess returns true by default"); |
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp index 4087df4d7..7e4948f1f 100644 --- a/runtime/test/xmem_test.cpp +++ b/runtime/test/xmem_test.cpp | |||
| @@ -20,6 +20,9 @@ using XMemFreeFn = void(__stdcall*)(void*, uint64_t); | |||
| 20 | using XMemVirtualQueryFn = SIZE_T(__stdcall*)(HANDLE, const void*, void*); | 20 | using XMemVirtualQueryFn = SIZE_T(__stdcall*)(HANDLE, const void*, void*); |
| 21 | // BOOL XMemGetWorkingSetStatistics(UINT32 kind, stats*): the FSR DLL passes kind 0x20000001 at every call site. | 21 | // BOOL XMemGetWorkingSetStatistics(UINT32 kind, stats*): the FSR DLL passes kind 0x20000001 at every call site. |
| 22 | using XMemGetWorkingSetStatisticsFn = BOOL(__stdcall*)(uint32_t, void*); | 22 | using XMemGetWorkingSetStatisticsFn = BOOL(__stdcall*)(uint32_t, void*); |
| 23 | using XMemVirtualAllocFn = void*(WINAPI*)(void*, SIZE_T, DWORD, ULONGLONG, DWORD); | ||
| 24 | using XMemGetWriteWatchFn = UINT(WINAPI*)(DWORD, void*, SIZE_T, void**, ULONG_PTR*, ULONG*); | ||
| 25 | using XMemResetWriteWatchFn = UINT(WINAPI*)(void*, SIZE_T); | ||
| 23 | constexpr uint32_t kMeasuredKind = 0x20000001; | 26 | constexpr uint32_t kMeasuredKind = 0x20000001; |
| 24 | 27 | ||
| 25 | int g_checks = 0; | 28 | int g_checks = 0; |
| @@ -129,6 +132,78 @@ void test_virtual_query(XMemVirtualQueryFn query) { | |||
| 129 | check(bad == 0, "XMemVirtualQuery on an invalid address returns 0 without crashing"); | 132 | check(bad == 0, "XMemVirtualQuery on an invalid address returns 0 without crashing"); |
| 130 | } | 133 | } |
| 131 | 134 | ||
| 135 | void test_virtual_alloc(XMemVirtualAllocFn virtual_alloc, XMemGetWriteWatchFn get_write_watch, | ||
| 136 | XMemResetWriteWatchFn reset_write_watch) { | ||
| 137 | SYSTEM_INFO system_info{}; | ||
| 138 | GetSystemInfo(&system_info); | ||
| 139 | const SIZE_T page_size = system_info.dwPageSize; | ||
| 140 | check(page_size != 0, "GetSystemInfo reports a non-zero page size"); | ||
| 141 | if (page_size == 0) return; | ||
| 142 | |||
| 143 | const SIZE_T region_size = page_size * 3; | ||
| 144 | void* const base = virtual_alloc(nullptr, region_size, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, 0, | ||
| 145 | PAGE_READWRITE); | ||
| 146 | check(base != nullptr, "XMemVirtualAlloc creates a synthetic write-watch region"); | ||
| 147 | if (!base) return; | ||
| 148 | |||
| 149 | void* watched[4]{}; | ||
| 150 | ULONG_PTR count = 4; | ||
| 151 | ULONG granularity = 0; | ||
| 152 | UINT status = get_write_watch(0, base, region_size, watched, &count, &granularity); | ||
| 153 | check(status == NO_ERROR && count == 0, "new write-watch region starts with no dirty pages"); | ||
| 154 | check(status == NO_ERROR && granularity == page_size, "write-watch reports the host page granularity"); | ||
| 155 | |||
| 156 | auto* const bytes = static_cast<volatile uint8_t*>(base); | ||
| 157 | bytes[0] = 0xa1; | ||
| 158 | bytes[page_size * 2] = 0xb2; | ||
| 159 | |||
| 160 | count = 4; | ||
| 161 | status = get_write_watch(0, base, region_size, watched, &count, &granularity); | ||
| 162 | bool saw_first_page = false; | ||
| 163 | bool saw_third_page = false; | ||
| 164 | bool all_addresses_are_page_aligned = count <= 4; | ||
| 165 | for (ULONG_PTR i = 0; i < count && i < 4; ++i) { | ||
| 166 | const uintptr_t address = reinterpret_cast<uintptr_t>(watched[i]); | ||
| 167 | const uintptr_t start = reinterpret_cast<uintptr_t>(base); | ||
| 168 | all_addresses_are_page_aligned &= address >= start && (address - start) % page_size == 0; | ||
| 169 | saw_first_page |= address == start; | ||
| 170 | saw_third_page |= address == start + page_size * 2; | ||
| 171 | } | ||
| 172 | check(status == NO_ERROR && count == 2 && saw_first_page && saw_third_page, | ||
| 173 | "write-watch reports each written page by its relative address"); | ||
| 174 | check(all_addresses_are_page_aligned, "write-watch addresses are page aligned and within the region"); | ||
| 175 | |||
| 176 | count = 4; | ||
| 177 | status = get_write_watch(0, base, region_size, watched, &count, &granularity); | ||
| 178 | check(status == NO_ERROR && count == 2, "query-only write-watch leaves dirty pages recorded"); | ||
| 179 | |||
| 180 | status = reset_write_watch(base, region_size); | ||
| 181 | check(status == NO_ERROR, "XMemResetWriteWatch clears the synthetic region"); | ||
| 182 | count = 4; | ||
| 183 | status = get_write_watch(0, base, region_size, watched, &count, &granularity); | ||
| 184 | check(status == NO_ERROR && count == 0, "reset write-watch query returns no dirty pages"); | ||
| 185 | |||
| 186 | bytes[page_size] = 0xc3; | ||
| 187 | count = 4; | ||
| 188 | status = get_write_watch(0, base, region_size, watched, &count, &granularity); | ||
| 189 | check(status == NO_ERROR && count == 1 && | ||
| 190 | reinterpret_cast<uintptr_t>(watched[0]) == reinterpret_cast<uintptr_t>(base) + page_size, | ||
| 191 | "write-watch records writes again after reset"); | ||
| 192 | |||
| 193 | check(VirtualFree(base, 0, MEM_RELEASE), "release the synthetic write-watch region"); | ||
| 194 | |||
| 195 | SetLastError(ERROR_SUCCESS); | ||
| 196 | void* const large_page = virtual_alloc(nullptr, page_size, MEM_RESERVE | MEM_COMMIT | 0x20000000, 0, | ||
| 197 | PAGE_READWRITE); | ||
| 198 | check(large_page == nullptr && GetLastError() == ERROR_NOT_SUPPORTED, | ||
| 199 | "unsupported large-page allocation is rejected before host allocation"); | ||
| 200 | |||
| 201 | SetLastError(ERROR_SUCCESS); | ||
| 202 | void* const attributed = virtual_alloc(nullptr, page_size, MEM_RESERVE | MEM_COMMIT, 1, PAGE_READWRITE); | ||
| 203 | check(attributed == nullptr && GetLastError() == ERROR_NOT_SUPPORTED, | ||
| 204 | "nonzero XMem allocation attributes are rejected before host allocation"); | ||
| 205 | } | ||
| 206 | |||
| 132 | void print_result() { | 207 | void print_result() { |
| 133 | if (g_failures == 0) { | 208 | if (g_failures == 0) { |
| 134 | std::printf("xmem_test: OK (%d checks)\n", g_checks); | 209 | std::printf("xmem_test: OK (%d checks)\n", g_checks); |
| @@ -148,11 +223,20 @@ int main() { | |||
| 148 | const auto query = reinterpret_cast<XMemVirtualQueryFn>(rt::shims::find("xmem.dll", "XMemVirtualQuery")); | 223 | const auto query = reinterpret_cast<XMemVirtualQueryFn>(rt::shims::find("xmem.dll", "XMemVirtualQuery")); |
| 149 | const auto get_stats = | 224 | const auto get_stats = |
| 150 | reinterpret_cast<XMemGetWorkingSetStatisticsFn>(rt::shims::find("xmem.dll", "XMemGetWorkingSetStatistics")); | 225 | reinterpret_cast<XMemGetWorkingSetStatisticsFn>(rt::shims::find("xmem.dll", "XMemGetWorkingSetStatistics")); |
| 226 | const auto virtual_alloc = | ||
| 227 | reinterpret_cast<XMemVirtualAllocFn>(rt::shims::find("xmem.dll", "XMemVirtualAlloc")); | ||
| 228 | const auto get_write_watch = | ||
| 229 | reinterpret_cast<XMemGetWriteWatchFn>(rt::shims::find("xmem.dll", "XMemGetWriteWatch")); | ||
| 230 | const auto reset_write_watch = | ||
| 231 | reinterpret_cast<XMemResetWriteWatchFn>(rt::shims::find("xmem.dll", "XMemResetWriteWatch")); | ||
| 151 | 232 | ||
| 152 | check(alloc != nullptr, "registry exposes xmem.dll!XMemAlloc"); | 233 | check(alloc != nullptr, "registry exposes xmem.dll!XMemAlloc"); |
| 153 | check(free_mem != nullptr, "registry exposes xmem.dll!XMemFree"); | 234 | check(free_mem != nullptr, "registry exposes xmem.dll!XMemFree"); |
| 154 | check(query != nullptr, "registry exposes xmem.dll!XMemVirtualQuery"); | 235 | check(query != nullptr, "registry exposes xmem.dll!XMemVirtualQuery"); |
| 155 | check(get_stats != nullptr, "registry exposes xmem.dll!XMemGetWorkingSetStatistics"); | 236 | check(get_stats != nullptr, "registry exposes xmem.dll!XMemGetWorkingSetStatistics"); |
| 237 | check(virtual_alloc != nullptr, "registry exposes xmem.dll!XMemVirtualAlloc"); | ||
| 238 | check(get_write_watch != nullptr, "registry exposes xmem.dll!XMemGetWriteWatch"); | ||
| 239 | check(reset_write_watch != nullptr, "registry exposes xmem.dll!XMemResetWriteWatch"); | ||
| 156 | 240 | ||
| 157 | if (!alloc || !free_mem || !query || !get_stats) { | 241 | if (!alloc || !free_mem || !query || !get_stats) { |
| 158 | print_result(); | 242 | print_result(); |
| @@ -162,6 +246,9 @@ int main() { | |||
| 162 | test_alloc(alloc, free_mem); | 246 | test_alloc(alloc, free_mem); |
| 163 | test_working_set(get_stats); | 247 | test_working_set(get_stats); |
| 164 | test_virtual_query(query); | 248 | test_virtual_query(query); |
| 249 | if (virtual_alloc && get_write_watch && reset_write_watch) { | ||
| 250 | test_virtual_alloc(virtual_alloc, get_write_watch, reset_write_watch); | ||
| 251 | } | ||
| 165 | 252 | ||
| 166 | print_result(); | 253 | print_result(); |
| 167 | return g_failures ? 1 : 0; | 254 | return g_failures ? 1 : 0; |