radv/tests: use vkGetPipelineKeyKHR() instead of compiling pipelines

Getting the pipeline key is enough for this set of tests.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38285>
This commit is contained in:
Samuel Pitoiset
2025-11-06 16:18:41 +01:00
parent fda0490784
commit d371061309
4 changed files with 79 additions and 28 deletions

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -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)

View File

@@ -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();
}