From d3710613092c32f1bec112ec183555e08d5a03a1 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Thu, 6 Nov 2025 16:18:41 +0100 Subject: [PATCH] radv/tests: use vkGetPipelineKeyKHR() instead of compiling pipelines Getting the pipeline key is enough for this set of tests. Signed-off-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/tests/drirc.cpp | 28 +++++++++--------- src/amd/vulkan/tests/helpers.cpp | 49 ++++++++++++++++++++++++++++++++ src/amd/vulkan/tests/helpers.h | 6 +++- src/amd/vulkan/tests/misc.cpp | 24 +++++++--------- 4 files changed, 79 insertions(+), 28 deletions(-) diff --git a/src/amd/vulkan/tests/drirc.cpp b/src/amd/vulkan/tests/drirc.cpp index b26b4c9bb62..9f916a6e51e 100644 --- a/src/amd/vulkan/tests/drirc.cpp +++ b/src/amd/vulkan/tests/drirc.cpp @@ -105,18 +105,17 @@ TEST_F(drirc, override_compute_shader_version) 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00}; - uint64_t pipeline_hash; + VkPipelineBinaryKeyKHR pipeline_keys[3]; - /* Create a simple compute pipeline to get the pipeline hash. */ - create_compute_pipeline(ARRAY_SIZE(code), (uint32_t *)code, VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR); - pipeline_hash = get_pipeline_hash(VK_SHADER_STAGE_COMPUTE_BIT); - EXPECT_NE(pipeline_hash, 0); - destroy_pipeline(); + /* Create a simple compute pipeline to get the pipeline key. */ + get_pipeline_key(ARRAY_SIZE(code), (uint32_t *)code, &pipeline_keys[0], + VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR); - /* Verify that re-creating the exact same pipeline returns the same pipeline hash. */ - create_compute_pipeline(ARRAY_SIZE(code), (uint32_t *)code, VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR); - EXPECT_EQ(pipeline_hash, get_pipeline_hash(VK_SHADER_STAGE_COMPUTE_BIT)); - destroy_pipeline(); + /* Verify that re-creating the exact same pipeline returns the same pipeline key. */ + get_pipeline_key(ARRAY_SIZE(code), (uint32_t *)code, &pipeline_keys[1], + VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR); + EXPECT_EQ(pipeline_keys[0].keySize, pipeline_keys[1].keySize); + EXPECT_FALSE(memcmp(pipeline_keys[0].key, pipeline_keys[1].key, pipeline_keys[0].keySize)); destroy_device(); @@ -124,10 +123,11 @@ TEST_F(drirc, override_compute_shader_version) create_device(); - /* Verify that overwriting the compute pipeline version returns a different hash. */ - create_compute_pipeline(ARRAY_SIZE(code), (uint32_t *)code, VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR); - EXPECT_NE(pipeline_hash, get_pipeline_hash(VK_SHADER_STAGE_COMPUTE_BIT)); - destroy_pipeline(); + /* Verify that overwriting the compute pipeline version returns a different key. */ + get_pipeline_key(ARRAY_SIZE(code), (uint32_t *)code, &pipeline_keys[2], + VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR); + EXPECT_EQ(pipeline_keys[1].keySize, pipeline_keys[2].keySize); + EXPECT_TRUE(memcmp(pipeline_keys[1].key, pipeline_keys[2].key, pipeline_keys[1].keySize)); destroy_device(); } diff --git a/src/amd/vulkan/tests/helpers.cpp b/src/amd/vulkan/tests/helpers.cpp index ec5d8e43e56..bf5e4554224 100644 --- a/src/amd/vulkan/tests/helpers.cpp +++ b/src/amd/vulkan/tests/helpers.cpp @@ -204,3 +204,52 @@ radv_test::get_pipeline_hash(VkShaderStageFlags stage) UNREACHABLE("Driver pipeline hash not found"); } + +void +radv_test::get_pipeline_key(uint32_t code_size, const uint32_t *code, VkPipelineBinaryKeyKHR *pipeline_key, + VkPipelineCreateFlags flags) +{ + VkResult result; + + VkShaderModuleCreateInfo shader_module_create_info = { + .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, + .codeSize = code_size, + .pCode = code, + }; + VkShaderModule shader_module; + + result = CreateShaderModule(device, &shader_module_create_info, NULL, &shader_module); + assert(result == VK_SUCCESS); + + VkPipelineLayoutCreateInfo pipeline_layout_info = { + .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, + }; + + result = CreatePipelineLayout(device, &pipeline_layout_info, NULL, &pipeline_layout); + assert(result == VK_SUCCESS); + + VkPipelineShaderStageCreateInfo stage_create_info = { + .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + .stage = VK_SHADER_STAGE_COMPUTE_BIT, + .module = shader_module, + .pName = "main", + }; + + VkComputePipelineCreateInfo compute_pipeline_create_info = { + .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, + .flags = flags, + .stage = stage_create_info, + .layout = pipeline_layout, + }; + + VkPipelineCreateInfoKHR pipeline_create_info = { + .sType = VK_STRUCTURE_TYPE_PIPELINE_CREATE_INFO_KHR, + .pNext = &compute_pipeline_create_info, + }; + + result = GetPipelineKeyKHR(device, &pipeline_create_info, pipeline_key); + assert(result == VK_SUCCESS); + + DestroyPipelineLayout(device, pipeline_layout, NULL); + DestroyShaderModule(device, shader_module, NULL); +} diff --git a/src/amd/vulkan/tests/helpers.h b/src/amd/vulkan/tests/helpers.h index 1a39450b5b8..ffdd7a67912 100644 --- a/src/amd/vulkan/tests/helpers.h +++ b/src/amd/vulkan/tests/helpers.h @@ -29,7 +29,8 @@ ITEM(CreatePipelineLayout) \ ITEM(DestroyPipelineLayout) \ ITEM(GetPipelineExecutableStatisticsKHR) \ - ITEM(GetPipelineExecutablePropertiesKHR) + ITEM(GetPipelineExecutablePropertiesKHR) \ + ITEM(GetPipelineKeyKHR) class radv_test : public testing::Test { public: @@ -47,6 +48,9 @@ public: void create_compute_pipeline(uint32_t code_size, const uint32_t *code, VkPipelineCreateFlags flags = 0); void destroy_pipeline(); + void get_pipeline_key(uint32_t code_size, const uint32_t *code, VkPipelineBinaryKeyKHR *pipeline_key, + VkPipelineCreateFlags flags = 0); + uint64_t get_pipeline_hash(VkShaderStageFlags stage); void add_envvar(std::string name, std::string value) diff --git a/src/amd/vulkan/tests/misc.cpp b/src/amd/vulkan/tests/misc.cpp index 7d0d85744ec..019eed09f27 100644 --- a/src/amd/vulkan/tests/misc.cpp +++ b/src/amd/vulkan/tests/misc.cpp @@ -47,10 +47,10 @@ TEST_F(misc, invariant_pipeline_cache_uuid) } /** - * This test verifies that the pipeline hash returned when shader stats are captured (eg. Fossilize) - * matches the pipeline hash returned when RGP is enabled. + * This test verifies that the pipeline key returned when shader stats are captured (eg. Fossilize) + * matches the pipeline key returned when RGP is enabled. */ -TEST_F(misc, pipeline_hash_rgp_fossilize) +TEST_F(misc, pipeline_key_rgp_fossilize) { create_device(); @@ -92,13 +92,11 @@ TEST_F(misc, pipeline_hash_rgp_fossilize) 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00}; - uint64_t pipeline_hash; + VkPipelineBinaryKeyKHR pipeline_keys[2]; - /* Create a simple compute pipeline that captures shader statistics (like Fossilize) and get the pipeline hash. */ - create_compute_pipeline(ARRAY_SIZE(code), (uint32_t *)code, VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR); - pipeline_hash = get_pipeline_hash(VK_SHADER_STAGE_COMPUTE_BIT); - EXPECT_NE(pipeline_hash, 0); - destroy_pipeline(); + /* Get the pipeline key for a simple compute pipeline that captures shader statistics (like Fossilize). */ + get_pipeline_key(ARRAY_SIZE(code), (uint32_t *)code, &pipeline_keys[0], + VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR); destroy_device(); @@ -108,10 +106,10 @@ TEST_F(misc, pipeline_hash_rgp_fossilize) create_device(); - /* Verify the pipeline hash matches. */ - create_compute_pipeline(ARRAY_SIZE(code), (uint32_t *)code); - EXPECT_EQ(pipeline_hash, get_pipeline_hash(VK_SHADER_STAGE_COMPUTE_BIT)); - destroy_pipeline(); + /* Verify the pipeline keys match. */ + get_pipeline_key(ARRAY_SIZE(code), (uint32_t *)code, &pipeline_keys[1]); + EXPECT_EQ(pipeline_keys[0].keySize, pipeline_keys[1].keySize); + EXPECT_FALSE(memcmp(pipeline_keys[0].key, pipeline_keys[1].key, pipeline_keys[0].keySize)); destroy_device(); }