Skip to content

Commit 9ebaca1

Browse files
committed
Draw moving brush entities through the indirect path using per-submodel transforms
1 parent 918b3cc commit 9ebaca1

7 files changed

Lines changed: 288 additions & 19 deletions

File tree

Quake/gl_rmisc.c

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ void R_CreateDescriptorSetLayouts ()
14881488
}
14891489

14901490
{
1491-
ZEROED_STRUCT_ARRAY (VkDescriptorSetLayoutBinding, indirect_compute_layout_bindings, 4);
1491+
ZEROED_STRUCT_ARRAY (VkDescriptorSetLayoutBinding, indirect_compute_layout_bindings, 6);
14921492
indirect_compute_layout_bindings[0].binding = 0;
14931493
indirect_compute_layout_bindings[0].descriptorCount = 1;
14941494
indirect_compute_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
@@ -1505,19 +1505,50 @@ void R_CreateDescriptorSetLayouts ()
15051505
indirect_compute_layout_bindings[3].descriptorCount = 1;
15061506
indirect_compute_layout_bindings[3].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
15071507
indirect_compute_layout_bindings[3].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;
1508+
indirect_compute_layout_bindings[4].binding = 4;
1509+
indirect_compute_layout_bindings[4].descriptorCount = 1;
1510+
indirect_compute_layout_bindings[4].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
1511+
indirect_compute_layout_bindings[4].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;
1512+
indirect_compute_layout_bindings[5].binding = 5;
1513+
indirect_compute_layout_bindings[5].descriptorCount = 1;
1514+
indirect_compute_layout_bindings[5].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
1515+
indirect_compute_layout_bindings[5].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;
15081516

15091517
descriptor_set_layout_create_info.bindingCount = countof (indirect_compute_layout_bindings);
15101518
descriptor_set_layout_create_info.pBindings = indirect_compute_layout_bindings;
15111519

15121520
memset (&vulkan_globals.indirect_compute_set_layout, 0, sizeof (vulkan_globals.indirect_compute_set_layout));
1513-
vulkan_globals.indirect_compute_set_layout.num_storage_buffers = 4;
1521+
vulkan_globals.indirect_compute_set_layout.num_storage_buffers = 6;
15141522

15151523
err = vkCreateDescriptorSetLayout (vulkan_globals.device, &descriptor_set_layout_create_info, NULL, &vulkan_globals.indirect_compute_set_layout.handle);
15161524
if (err != VK_SUCCESS)
15171525
Sys_Error ("vkCreateDescriptorSetLayout failed with code %i", (int)err);
15181526
GL_SetObjectName ((uint64_t)vulkan_globals.indirect_compute_set_layout.handle, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, "indirect compute");
15191527
}
15201528

1529+
{
1530+
ZEROED_STRUCT_ARRAY (VkDescriptorSetLayoutBinding, bmodel_instances_layout_bindings, 2);
1531+
bmodel_instances_layout_bindings[0].binding = 0;
1532+
bmodel_instances_layout_bindings[0].descriptorCount = 1;
1533+
bmodel_instances_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
1534+
bmodel_instances_layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
1535+
bmodel_instances_layout_bindings[1].binding = 1;
1536+
bmodel_instances_layout_bindings[1].descriptorCount = 1;
1537+
bmodel_instances_layout_bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
1538+
bmodel_instances_layout_bindings[1].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
1539+
1540+
descriptor_set_layout_create_info.bindingCount = countof (bmodel_instances_layout_bindings);
1541+
descriptor_set_layout_create_info.pBindings = bmodel_instances_layout_bindings;
1542+
1543+
memset (&vulkan_globals.bmodel_instances_set_layout, 0, sizeof (vulkan_globals.bmodel_instances_set_layout));
1544+
vulkan_globals.bmodel_instances_set_layout.num_storage_buffers = 2;
1545+
1546+
err = vkCreateDescriptorSetLayout (vulkan_globals.device, &descriptor_set_layout_create_info, NULL, &vulkan_globals.bmodel_instances_set_layout.handle);
1547+
if (err != VK_SUCCESS)
1548+
Sys_Error ("vkCreateDescriptorSetLayout failed with code %i", (int)err);
1549+
GL_SetObjectName ((uint64_t)vulkan_globals.bmodel_instances_set_layout.handle, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, "bmodel instances");
1550+
}
1551+
15211552
if (vulkan_globals.ray_query)
15221553
{
15231554
ZEROED_STRUCT (VkDescriptorSetLayoutBinding, ray_query_push_layout_binding);
@@ -1616,7 +1647,7 @@ void R_CreatePipelineLayouts ()
16161647

16171648
ZEROED_STRUCT (VkPushConstantRange, push_constant_range);
16181649
push_constant_range.offset = 0;
1619-
push_constant_range.size = 21 * sizeof (float);
1650+
push_constant_range.size = 22 * sizeof (float);
16201651
push_constant_range.stageFlags = VK_SHADER_STAGE_ALL_GRAPHICS;
16211652

16221653
ZEROED_STRUCT (VkPipelineLayoutCreateInfo, pipeline_layout_create_info);
@@ -1636,13 +1667,13 @@ void R_CreatePipelineLayouts ()
16361667

16371668
{
16381669
// World
1639-
VkDescriptorSetLayout world_descriptor_set_layouts[4] = {
1670+
VkDescriptorSetLayout world_descriptor_set_layouts[5] = {
16401671
vulkan_globals.single_texture_set_layout.handle, vulkan_globals.single_texture_set_layout.handle, vulkan_globals.single_texture_set_layout.handle,
1641-
vulkan_globals.mboit_input_attachment_set_layout.handle};
1672+
vulkan_globals.mboit_input_attachment_set_layout.handle, vulkan_globals.bmodel_instances_set_layout.handle};
16421673

16431674
ZEROED_STRUCT (VkPushConstantRange, push_constant_range);
16441675
push_constant_range.offset = 0;
1645-
push_constant_range.size = 21 * sizeof (float);
1676+
push_constant_range.size = 22 * sizeof (float);
16461677
push_constant_range.stageFlags = VK_SHADER_STAGE_ALL_GRAPHICS;
16471678

16481679
ZEROED_STRUCT (VkPipelineLayoutCreateInfo, pipeline_layout_create_info);
@@ -1668,7 +1699,7 @@ void R_CreatePipelineLayouts ()
16681699

16691700
ZEROED_STRUCT (VkPushConstantRange, push_constant_range);
16701701
push_constant_range.offset = 0;
1671-
push_constant_range.size = 21 * sizeof (float);
1702+
push_constant_range.size = 22 * sizeof (float);
16721703
push_constant_range.stageFlags = VK_SHADER_STAGE_ALL_GRAPHICS;
16731704

16741705
ZEROED_STRUCT (VkPipelineLayoutCreateInfo, pipeline_layout_create_info);
@@ -1696,7 +1727,7 @@ void R_CreatePipelineLayouts ()
16961727

16971728
ZEROED_STRUCT (VkPushConstantRange, push_constant_range);
16981729
push_constant_range.offset = 0;
1699-
push_constant_range.size = 21 * sizeof (float);
1730+
push_constant_range.size = 22 * sizeof (float);
17001731
push_constant_range.stageFlags = VK_SHADER_STAGE_ALL_GRAPHICS;
17011732

17021733
ZEROED_STRUCT (VkPipelineLayoutCreateInfo, pipeline_layout_create_info);
@@ -1953,7 +1984,7 @@ void R_CreatePipelineLayouts ()
19531984

19541985
ZEROED_STRUCT (VkPushConstantRange, push_constant_range);
19551986
push_constant_range.offset = 0;
1956-
push_constant_range.size = 6 * sizeof (uint32_t);
1987+
push_constant_range.size = 7 * sizeof (uint32_t);
19571988
push_constant_range.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;
19581989

19591990
ZEROED_STRUCT (VkPipelineLayoutCreateInfo, pipeline_layout_create_info);
@@ -3168,17 +3199,20 @@ static void R_CreateShowTrisPipelines ()
31683199
infos.input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
31693200
R_CreateGraphicsPipeline (&vulkan_globals.showbboxes_pipeline[variant], &infos, vulkan_globals.basic_pipeline_layout, va ("showbboxes%s", pass_suffix));
31703201

3202+
// indirect showtris uses the world vertex shader so moved submodels get their instance transform applied
31713203
R_CopyPipelineCreateInfos (&infos, &base);
31723204
infos.graphics_pipeline.renderPass = render_pass;
3205+
infos.shader_stages[0].module = world_vert_module;
31733206
infos.vertex_input_state.vertexAttributeDescriptionCount = 3;
31743207
infos.vertex_input_state.pVertexAttributeDescriptions = world_vertex_input_attribute_descriptions;
31753208
infos.vertex_input_state.vertexBindingDescriptionCount = 1;
31763209
infos.vertex_input_state.pVertexBindingDescriptions = &world_vertex_binding_description;
31773210
R_CreateGraphicsPipeline (
3178-
&vulkan_globals.showtris_indirect_pipeline[variant], &infos, vulkan_globals.basic_pipeline_layout, va ("showtris_indirect%s", pass_suffix));
3211+
&vulkan_globals.showtris_indirect_pipeline[variant], &infos, vulkan_globals.world_pipeline_layout, va ("showtris_indirect%s", pass_suffix));
31793212

31803213
R_CopyPipelineCreateInfos (&infos, &base);
31813214
infos.graphics_pipeline.renderPass = render_pass;
3215+
infos.shader_stages[0].module = world_vert_module;
31823216
infos.vertex_input_state.vertexAttributeDescriptionCount = 3;
31833217
infos.vertex_input_state.pVertexAttributeDescriptions = world_vertex_input_attribute_descriptions;
31843218
infos.vertex_input_state.vertexBindingDescriptionCount = 1;
@@ -3188,7 +3222,7 @@ static void R_CreateShowTrisPipelines ()
31883222
infos.rasterization_state.depthBiasConstantFactor = 500.0f;
31893223
infos.rasterization_state.depthBiasSlopeFactor = 0.0f;
31903224
R_CreateGraphicsPipeline (
3191-
&vulkan_globals.showtris_indirect_depth_test_pipeline[variant], &infos, vulkan_globals.basic_pipeline_layout,
3225+
&vulkan_globals.showtris_indirect_depth_test_pipeline[variant], &infos, vulkan_globals.world_pipeline_layout,
31923226
va ("showtris_indirect_depth_test%s", pass_suffix));
31933227
}
31943228
}

Quake/glquake.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ typedef struct
474474
vulkan_desc_set_layout_t lightmap_compute_set_layout;
475475
VkDescriptorSet indirect_compute_desc_set;
476476
vulkan_desc_set_layout_t indirect_compute_set_layout;
477+
VkDescriptorSet bmodel_instances_desc_set;
478+
vulkan_desc_set_layout_t bmodel_instances_set_layout;
477479
vulkan_desc_set_layout_t ray_query_push_set_layout;
478480
VkDescriptorSet ray_debug_desc_set;
479481
vulkan_desc_set_layout_t ray_debug_set_layout;
@@ -732,6 +734,7 @@ void R_UpdateWarpTextures (void *unused);
732734
void R_MarkDeps (int combined_deps, int worker_index);
733735

734736
qboolean R_IndirectBrush (entity_t *e);
737+
void R_ClearBModelInstanceClaims (void);
735738

736739
void R_DrawWorld (cb_context_t *cbx, int index);
737740

0 commit comments

Comments
 (0)