rt: allocate as many desc sets as frames in flight

still not fully correct or robust, but passes validation

missing correctness things:
- Nx light data buffers
- Nx dynamic model buffers
- Nx dynamic BLASes

quite likely will also need (depending on update strategy, direct vs upload):
- Nx light data buffers
- Nx UBOs

probably fine since frames don't really overlap:
- single TLAS
This commit is contained in:
Ivan 'provod' Avdeev 2022-02-20 23:30:23 -08:00
parent 955f36a423
commit e35e2aa043
5 changed files with 26 additions and 22 deletions

View File

@ -3,6 +3,9 @@
#include "vk_pipeline.h"
#include "vk_descriptor.h"
// FIXME this is only needed for MAX_CONCURRENT_FRAMES
#include "vk_framectl.h"
#define MAX_STAGES 16
#define MAX_MISS_GROUPS 8
#define MAX_HIT_GROUPS 8
@ -18,7 +21,7 @@ typedef struct ray_pass_s {
struct {
vk_descriptors_t riptors;
VkDescriptorSet sets[1];
VkDescriptorSet sets[MAX_CONCURRENT_FRAMES];
int *binding_semantics;
} desc;
} ray_pass_t;
@ -202,22 +205,22 @@ void RayPassDestroy( struct ray_pass_s *pass ) {
Mem_Free(pass);
}
static void performTracing( VkCommandBuffer cmdbuf, const ray_pass_tracing_impl_t *tracing, const struct vk_ray_resources_s *res) {
static void performTracing( VkCommandBuffer cmdbuf, int set_slot, const ray_pass_tracing_impl_t *tracing, const struct vk_ray_resources_s *res) {
vkCmdBindPipeline(cmdbuf, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, tracing->pipeline.pipeline);
vkCmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, tracing->header.desc.riptors.pipeline_layout, 0, 1, tracing->header.desc.riptors.desc_sets + 0, 0, NULL);
vkCmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, tracing->header.desc.riptors.pipeline_layout, 0, 1, tracing->header.desc.riptors.desc_sets + set_slot, 0, NULL);
VK_PipelineRayTracingTrace(cmdbuf, &tracing->pipeline, res->width, res->height);
}
static void performCompute( VkCommandBuffer cmdbuf, const ray_pass_compute_impl_t *compute, const struct vk_ray_resources_s *res) {
static void performCompute( VkCommandBuffer cmdbuf, int set_slot, const ray_pass_compute_impl_t *compute, const struct vk_ray_resources_s *res) {
const uint32_t WG_W = 8;
const uint32_t WG_H = 8;
vkCmdBindPipeline(cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, compute->pipeline);
vkCmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, compute->header.desc.riptors.pipeline_layout, 0, 1, compute->header.desc.riptors.desc_sets + 0, 0, NULL);
vkCmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, compute->header.desc.riptors.pipeline_layout, 0, 1, compute->header.desc.riptors.desc_sets + set_slot, 0, NULL);
vkCmdDispatch(cmdbuf, (res->width + WG_W - 1) / WG_W, (res->height + WG_H - 1) / WG_H, 1);
}
void RayPassPerform( VkCommandBuffer cmdbuf, struct ray_pass_s *pass, struct vk_ray_resources_s *res) {
void RayPassPerform( VkCommandBuffer cmdbuf, int frame_set_slot, struct ray_pass_s *pass, struct vk_ray_resources_s *res) {
{
ray_resources_fill_t fill = {
.resources = res,
@ -239,7 +242,7 @@ void RayPassPerform( VkCommandBuffer cmdbuf, struct ray_pass_s *pass, struct vk_
RayResourcesFill(cmdbuf, fill);
VK_DescriptorsWrite(&pass->desc.riptors);
VK_DescriptorsWrite(&pass->desc.riptors, frame_set_slot);
}
DEBUG_BEGIN(cmdbuf, pass->debug_name);
@ -248,13 +251,13 @@ void RayPassPerform( VkCommandBuffer cmdbuf, struct ray_pass_s *pass, struct vk_
case RayPassType_Tracing:
{
ray_pass_tracing_impl_t *tracing = (ray_pass_tracing_impl_t*)pass;
performTracing(cmdbuf, tracing, res);
performTracing(cmdbuf, frame_set_slot, tracing, res);
break;
}
case RayPassType_Compute:
{
ray_pass_compute_impl_t *compute = (ray_pass_compute_impl_t*)pass;
performCompute(cmdbuf, compute, res);
performCompute(cmdbuf, frame_set_slot, compute, res);
break;
}
}

View File

@ -56,4 +56,4 @@ struct ray_pass_s *RayPassCreateTracing( const ray_pass_create_tracing_t *create
void RayPassDestroy( struct ray_pass_s *pass );
struct vk_ray_resources_s;
void RayPassPerform( VkCommandBuffer cmdbuf, struct ray_pass_s *pass, struct vk_ray_resources_s *res);
void RayPassPerform( VkCommandBuffer cmdbuf, int frame_set_slot, struct ray_pass_s *pass, struct vk_ray_resources_s *res);

View File

@ -143,14 +143,14 @@ void VK_DescriptorsCreate(vk_descriptors_t *desc)
int j;
for (j = 0; j < dpci.poolSizeCount; ++j) {
if (pools[j].type == bind->descriptorType) {
pools[j].descriptorCount += bind->descriptorCount;
pools[j].descriptorCount += bind->descriptorCount * desc->num_sets;
break;
}
}
if (j == dpci.poolSizeCount) {
ASSERT(dpci.poolSizeCount < ARRAYSIZE(pools));
pools[j].descriptorCount = bind->descriptorCount;
pools[j].descriptorCount = bind->descriptorCount * desc->num_sets;
pools[j].type = bind->descriptorType;
++dpci.poolSizeCount;
}
@ -159,18 +159,19 @@ void VK_DescriptorsCreate(vk_descriptors_t *desc)
XVK_CHECK(vkCreateDescriptorPool(vk_core.device, &dpci, NULL, &desc->desc_pool));
}
for (int i = 0; i < desc->num_sets; ++i)
{
VkDescriptorSetAllocateInfo dsai = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.descriptorPool = desc->desc_pool,
.descriptorSetCount = desc->num_sets,
.descriptorSetCount = 1,
.pSetLayouts = &desc->desc_layout,
};
XVK_CHECK(vkAllocateDescriptorSets(vk_core.device, &dsai, desc->desc_sets));
XVK_CHECK(vkAllocateDescriptorSets(vk_core.device, &dsai, desc->desc_sets + i));
}
}
void VK_DescriptorsWrite(const vk_descriptors_t *desc)
void VK_DescriptorsWrite(const vk_descriptors_t *desc, int set_slot)
{
VkWriteDescriptorSet wds[16];
ASSERT(ARRAYSIZE(wds) >= desc->num_bindings);
@ -180,7 +181,7 @@ void VK_DescriptorsWrite(const vk_descriptors_t *desc)
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.descriptorCount = binding->descriptorCount,
.descriptorType = binding->descriptorType,
.dstSet = /* TODO */ desc->desc_sets[0],
.dstSet = desc->desc_sets[set_slot],
.dstBinding = binding->binding,
.dstArrayElement = 0,
};

View File

@ -51,7 +51,7 @@ typedef struct {
} vk_descriptors_t;
void VK_DescriptorsCreate(vk_descriptors_t *desc);
void VK_DescriptorsWrite(const vk_descriptors_t *desc);
void VK_DescriptorsWrite(const vk_descriptors_t *desc, int set_slot);
void VK_DescriptorsDestroy(const vk_descriptors_t *desc);
// typedef enum {

View File

@ -733,7 +733,7 @@ static void updateDescriptors( const vk_ray_frame_render_args_t *args, int frame
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
};
VK_DescriptorsWrite(&g_rtx.descriptors);
VK_DescriptorsWrite(&g_rtx.descriptors, 0);
}
static qboolean rayTrace( VkCommandBuffer cmdbuf, const xvk_ray_frame_images_t *current_frame, float fov_angle_y ) {
@ -1066,10 +1066,10 @@ static void performTracing( VkCommandBuffer cmdbuf, const vk_ray_frame_render_ar
0, 0, NULL, ARRAYSIZE(bmb), bmb, 0, NULL);
}
RayPassPerform( cmdbuf, g_rtx.pass.primary_ray, &res );
RayPassPerform( cmdbuf, g_rtx.pass.light_direct_poly, &res );
RayPassPerform( cmdbuf, g_rtx.pass.light_direct_point, &res );
RayPassPerform( cmdbuf, g_rtx.pass.denoiser, &res );
RayPassPerform( cmdbuf, frame_index, g_rtx.pass.primary_ray, &res );
RayPassPerform( cmdbuf, frame_index, g_rtx.pass.light_direct_poly, &res );
RayPassPerform( cmdbuf, frame_index, g_rtx.pass.light_direct_point, &res );
RayPassPerform( cmdbuf, frame_index, g_rtx.pass.denoiser, &res );
{
const xvk_blit_args blit_args = {