|
21 | 21 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | 22 | */ |
23 | 23 |
|
24 | | - |
| 24 | +#define XXH_INLINE_ALL |
25 | 25 | #include "vkoverhead.h" |
26 | 26 | #include "common.h" |
| 27 | +#include "hash_table.h" |
| 28 | +#include "u_memory.h" |
27 | 29 | #include "u_queue.h" |
28 | 30 | #include "u_cpu_detect.h" |
| 31 | +#include "xxhash.h" |
29 | 32 | #include <inttypes.h> |
30 | 33 |
|
31 | 34 | struct vk_device *dev; |
@@ -684,13 +687,48 @@ draw_16vattrib_change_gpl(unsigned iterations) |
684 | 687 | cleanup_func = NULL; |
685 | 688 | } |
686 | 689 |
|
| 690 | +static VkVertexInputBindingDescription gpl_vbinding[2][16]; |
| 691 | +static VkVertexInputAttributeDescription gpl_vattr[2][16]; |
| 692 | +struct hash_table gpl_pipeline_table; |
| 693 | + |
| 694 | +static uint32_t |
| 695 | +gpl_hash_vi(const void *data) |
| 696 | +{ |
| 697 | + uint32_t hash = 0; |
| 698 | + const VkPipelineVertexInputStateCreateInfo *key = data; |
| 699 | + hash = XXH32(&key->vertexBindingDescriptionCount, sizeof(key->vertexBindingDescriptionCount), hash); |
| 700 | + hash = XXH32(&key->vertexAttributeDescriptionCount, sizeof(key->vertexAttributeDescriptionCount), hash); |
| 701 | + hash = XXH32(key->pVertexBindingDescriptions, key->vertexBindingDescriptionCount * sizeof(VkVertexInputBindingDescription), hash); |
| 702 | + hash = XXH32(key->pVertexAttributeDescriptions, key->vertexAttributeDescriptionCount * sizeof(VkVertexInputAttributeDescription), hash); |
| 703 | + return hash; |
| 704 | +} |
| 705 | + |
| 706 | +static bool |
| 707 | +gpl_equals_vi(const void *a, const void *b) |
| 708 | +{ |
| 709 | + const VkPipelineVertexInputStateCreateInfo *key_a = a; |
| 710 | + const VkPipelineVertexInputStateCreateInfo *key_b = b; |
| 711 | + return key_a->vertexBindingDescriptionCount == key_b->vertexBindingDescriptionCount && |
| 712 | + key_a->vertexAttributeDescriptionCount == key_b->vertexAttributeDescriptionCount && |
| 713 | + !memcmp(key_a->pVertexBindingDescriptions, key_b->pVertexBindingDescriptions, key_a->vertexBindingDescriptionCount * sizeof(VkVertexInputBindingDescription)) && |
| 714 | + !memcmp(key_a->pVertexAttributeDescriptions, key_b->pVertexAttributeDescriptions, key_a->vertexAttributeDescriptionCount * sizeof(VkVertexInputAttributeDescription)); |
| 715 | +} |
| 716 | + |
687 | 717 | static void |
688 | | -draw_16vattrib_change_gpl_precompile(unsigned iterations) |
| 718 | +draw_16vattrib_change_gpl_hashncache(unsigned iterations) |
689 | 719 | { |
690 | | - iterations = filter_overflow(draw_16vattrib_change_gpl_precompile, iterations, 1); |
| 720 | + iterations = filter_overflow(draw_16vattrib_change_gpl_hashncache, iterations, 1); |
691 | 721 | begin_rp(); |
| 722 | + VkPipelineVertexInputStateCreateInfo vertex_input_state = {0}; |
| 723 | + vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 724 | + vertex_input_state.vertexBindingDescriptionCount = 16; |
| 725 | + vertex_input_state.vertexAttributeDescriptionCount = 16; |
692 | 726 | for (unsigned i = 0; i < iterations; i++, count++) { |
693 | | - VK(CmdBindPipeline)(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_gpl_vert_final[i % 1]); |
| 727 | + vertex_input_state.pVertexBindingDescriptions = gpl_vbinding[i & 1]; |
| 728 | + vertex_input_state.pVertexAttributeDescriptions = gpl_vattr[i & 1]; |
| 729 | + struct hash_entry *he = _mesa_hash_table_search(&gpl_pipeline_table, &vertex_input_state); |
| 730 | + VkPipeline pipeline = he->data; |
| 731 | + VK(CmdBindPipeline)(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
694 | 732 | VK(CmdDrawIndexed)(cmdbuf, 3, 1, 0, 0, 0); |
695 | 733 | } |
696 | 734 | } |
@@ -1305,7 +1343,7 @@ static struct perf_case cases_draw[] = { |
1305 | 1343 | CASE_VATTRIB(draw_16vattrib_change), |
1306 | 1344 | CASE_VATTRIB_DYNAMIC(draw_16vattrib_change_dynamic, check_dynamic_vertex_input), |
1307 | 1345 | CASE_VATTRIB_GPL(draw_16vattrib_change_gpl, check_graphics_pipeline_library), |
1308 | | - CASE_VATTRIB_GPL(draw_16vattrib_change_gpl_precompile, check_graphics_pipeline_library), |
| 1346 | + CASE_VATTRIB_GPL(draw_16vattrib_change_gpl_hashncache, check_graphics_pipeline_library), |
1309 | 1347 | CASE_BASIC(draw_1ubo_change), |
1310 | 1348 | CASE_UBO(draw_12ubo_change), |
1311 | 1349 | CASE_SAMPLER(draw_1sampler_change), |
@@ -2169,11 +2207,24 @@ main(int argc, char *argv[]) |
2169 | 2207 | }; |
2170 | 2208 | pci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
2171 | 2209 | pci.pNext = &libstate; |
| 2210 | + _mesa_hash_table_init(&gpl_pipeline_table, NULL, gpl_hash_vi, gpl_equals_vi); |
| 2211 | + VkPipelineVertexInputStateCreateInfo vertex_input_state = {0}; |
| 2212 | + vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 2213 | + vertex_input_state.vertexBindingDescriptionCount = 16; |
| 2214 | + vertex_input_state.vertexAttributeDescriptionCount = 16; |
2172 | 2215 | for (unsigned i = 0; i < ARRAY_SIZE(pipeline_gpl_vert); i++) { |
2173 | | - pipeline_gpl_vert[i] = create_gpl_vert_pipeline(render_pass_clear, layout_basic); |
| 2216 | + vertex_input_state.pVertexBindingDescriptions = gpl_vbinding[i]; |
| 2217 | + vertex_input_state.pVertexAttributeDescriptions = gpl_vattr[i]; |
| 2218 | + pipeline_gpl_vert[i] = create_gpl_vert_pipeline(render_pass_clear, layout_basic, &vertex_input_state); |
2174 | 2219 | libraries[1] = pipeline_gpl_vert[i]; |
2175 | 2220 | result = VK(CreateGraphicsPipelines)(dev->dev, VK_NULL_HANDLE, 1, &pci, NULL, &pipeline_gpl_vert_final[i]); |
2176 | 2221 | VK_CHECK("CreateGraphicsPipelines", result); |
| 2222 | + { |
| 2223 | + VkPipelineVertexInputStateCreateInfo *key = mem_dup(&vertex_input_state, sizeof(VkPipelineVertexInputStateCreateInfo)); |
| 2224 | + key->pVertexBindingDescriptions = mem_dup(vertex_input_state.pVertexBindingDescriptions, vertex_input_state.vertexBindingDescriptionCount * sizeof(VkVertexInputBindingDescription)); |
| 2225 | + key->pVertexAttributeDescriptions = mem_dup(vertex_input_state.pVertexAttributeDescriptions, vertex_input_state.vertexAttributeDescriptionCount * sizeof(VkVertexInputAttributeDescription)); |
| 2226 | + _mesa_hash_table_insert(&gpl_pipeline_table, key, pipeline_gpl_vert_final[i]); |
| 2227 | + } |
2177 | 2228 | } |
2178 | 2229 | } |
2179 | 2230 |
|
|
0 commit comments