Skip to content

Commit 659ed59

Browse files
committed
rework gpl vertex swap case
this should more accurately simulate real app usage of doing the hash-n-cache to find pipelines
1 parent 43a54e4 commit 659ed59

File tree

3 files changed

+63
-18
lines changed

3 files changed

+63
-18
lines changed

src/pipeline.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ create_gpl_basic_pipeline(VkRenderPass render_pass, VkPipelineLayout layout)
498498
}
499499

500500
VkPipeline
501-
create_gpl_vert_pipeline(VkRenderPass render_pass, VkPipelineLayout layout)
501+
create_gpl_vert_pipeline(VkRenderPass render_pass, VkPipelineLayout layout, VkPipelineVertexInputStateCreateInfo *vertex_input_state)
502502
{
503503
VkShaderModule modules[5] = {
504504
create_shader_module(vattrib_vert_spirv, vattrib_vert_spirv_len),
@@ -508,21 +508,15 @@ create_gpl_vert_pipeline(VkRenderPass render_pass, VkPipelineLayout layout)
508508
create_shader_module(basic_frag_spirv, basic_frag_spirv_len),
509509
};
510510

511-
VkVertexInputBindingDescription vbinding[16];
512-
VkVertexInputAttributeDescription vattr[16];
513-
VkPipelineVertexInputStateCreateInfo vertex_input_state = {0};
514-
vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
515-
vertex_input_state.pVertexBindingDescriptions = vbinding;
516-
vertex_input_state.vertexBindingDescriptionCount = 16;
517-
vertex_input_state.pVertexAttributeDescriptions = vattr;
518-
vertex_input_state.vertexAttributeDescriptionCount = 16;
519-
generate_vattribs(vbinding, vattr, 16);
511+
VkVertexInputBindingDescription *vattrs = (void*)vertex_input_state->pVertexBindingDescriptions;
512+
VkVertexInputAttributeDescription *vbindings = (void*)vertex_input_state->pVertexAttributeDescriptions;
513+
generate_vattribs(vattrs, vbindings, 16);
520514

521515
VkGraphicsPipelineLibraryCreateInfoEXT gplci = {
522516
VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT,
523517
NULL,
524518
VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT
525519
};
526520

527-
return create_pipeline(layout, render_pass, modules, &vertex_input_state, 1, false, &gplci);
521+
return create_pipeline(layout, render_pass, modules, vertex_input_state, 1, false, &gplci);
528522
}

src/vkoverhead.c

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
* USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
*/
2323

24-
24+
#define XXH_INLINE_ALL
2525
#include "vkoverhead.h"
2626
#include "common.h"
27+
#include "hash_table.h"
28+
#include "u_memory.h"
2729
#include "u_queue.h"
2830
#include "u_cpu_detect.h"
31+
#include "xxhash.h"
2932
#include <inttypes.h>
3033

3134
struct vk_device *dev;
@@ -684,13 +687,48 @@ draw_16vattrib_change_gpl(unsigned iterations)
684687
cleanup_func = NULL;
685688
}
686689

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+
687717
static void
688-
draw_16vattrib_change_gpl_precompile(unsigned iterations)
718+
draw_16vattrib_change_gpl_hashncache(unsigned iterations)
689719
{
690-
iterations = filter_overflow(draw_16vattrib_change_gpl_precompile, iterations, 1);
720+
iterations = filter_overflow(draw_16vattrib_change_gpl_hashncache, iterations, 1);
691721
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;
692726
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);
694732
VK(CmdDrawIndexed)(cmdbuf, 3, 1, 0, 0, 0);
695733
}
696734
}
@@ -1305,7 +1343,7 @@ static struct perf_case cases_draw[] = {
13051343
CASE_VATTRIB(draw_16vattrib_change),
13061344
CASE_VATTRIB_DYNAMIC(draw_16vattrib_change_dynamic, check_dynamic_vertex_input),
13071345
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),
13091347
CASE_BASIC(draw_1ubo_change),
13101348
CASE_UBO(draw_12ubo_change),
13111349
CASE_SAMPLER(draw_1sampler_change),
@@ -2169,11 +2207,24 @@ main(int argc, char *argv[])
21692207
};
21702208
pci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
21712209
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;
21722215
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);
21742219
libraries[1] = pipeline_gpl_vert[i];
21752220
result = VK(CreateGraphicsPipelines)(dev->dev, VK_NULL_HANDLE, 1, &pci, NULL, &pipeline_gpl_vert_final[i]);
21762221
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+
}
21772228
}
21782229
}
21792230

src/vkoverhead.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ VkPipeline create_ssbo_pipeline(VkRenderPass render_pass, VkPipelineLayout layou
5656
VkPipeline create_ssbo_many_pipeline(VkRenderPass render_pass, VkPipelineLayout layout);
5757
VkPipeline create_vattrib_pipeline_dynamic(VkRenderPass render_pass, VkPipelineLayout layout);
5858
VkPipeline create_gpl_basic_pipeline(VkRenderPass render_pass, VkPipelineLayout layout);
59-
VkPipeline create_gpl_vert_pipeline(VkRenderPass render_pass, VkPipelineLayout layout);
59+
VkPipeline create_gpl_vert_pipeline(VkRenderPass render_pass, VkPipelineLayout layout, VkPipelineVertexInputStateCreateInfo *vertex_input_state);
6060

6161
VkBuffer create_vertex_buffer(void);
6262
VkBuffer create_uniform_buffer(void);

0 commit comments

Comments
 (0)