rt: flatten pass bindings a bit

This commit is contained in:
Ivan Avdeev 2022-01-31 20:50:39 -08:00
parent b6c96ddebd
commit 6b381c8970
8 changed files with 50 additions and 129 deletions

View File

@ -1,7 +1,7 @@
#include "ray_pass.h"
#include "ray_resources.h"
#include "vk_pipeline.h"
#include "vk_descriptor.h"
#include "vk_ray_resources.h"
#define MAX_STAGES 16
#define MAX_MISS_GROUPS 8

View File

@ -1,4 +1,4 @@
#include "vk_ray_resources.h"
#include "ray_resources.h"
#include "vk_core.h"
#include <stdlib.h>

View File

@ -2,6 +2,7 @@
#include "vk_rtx.h"
#include "vk_const.h"
#include "vk_image.h"
#include "vk_descriptor.h"
#include "shaders/ray_interop.h"
@ -36,19 +37,15 @@ typedef struct {
typedef struct {
VkDescriptorType type;
ray_resource_state_t write, read;
vk_descriptor_value_t value;
union {
vk_descriptor_value_t value;
const xvk_image_t *image;
};
} ray_resource_t;
#define RAY_RESOURCE_DEFAULT_STATE \
(ray_resource_state_t) { \
.access_mask = 0, \
.image_layout = VK_IMAGE_LAYOUT_UNDEFINED, \
.pipelines = 0, \
}
typedef struct vk_ray_resources_s {
uint32_t width, height;
ray_resource_t values[RayResource__COUNT];
ray_resource_t resources[RayResource__COUNT];
} vk_ray_resources_t;
typedef struct {
@ -60,4 +57,4 @@ typedef struct {
vk_descriptor_value_t *out_values;
} ray_resources_fill_t;
void RayResourcesFill(ray_resources_fill_t fill);
void RayResourcesFill(VkCommandBuffer cmdbuf, ray_resources_fill_t fill);

View File

@ -1,6 +1,6 @@
#include "vk_denoiser.h"
#include "vk_ray_resources.h"
#include "ray_resources.h"
#include "ray_pass.h"
#define LIST_OUTPUTS(X) \

View File

@ -1,6 +1,6 @@
#include "vk_ray_light_direct.h"
#include "vk_ray_resources.h"
#include "ray_resources.h"
#include "ray_pass.h"
#define LIST_SCENE_BINDINGS(X) \
@ -17,17 +17,29 @@
LIST_SCENE_BINDINGS(X) \
RAY_LIGHT_DIRECT_INPUTS(X)
enum {
#define X(index, name, ...) Binding_##name,
LIST_COMMON_BINDINGS(X)
// FIXME more conservative shader stages
#define INIT_BINDING(index, name, type, count) \
{ \
.binding = index, \
.descriptorType = type, \
.descriptorCount = count, \
.stageFlags = VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR, \
},
#define INIT_IMAGE(index, name, ...) INIT_BINDING(index, name, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1)
static const VkDescriptorSetLayoutBinding bindings[] = {
LIST_SCENE_BINDINGS(INIT_BINDING)
RAY_LIGHT_DIRECT_INPUTS(INIT_IMAGE)
// FIXME it's an artifact that point and poly outputs have same bindings indices
RAY_LIGHT_DIRECT_POLY_OUTPUTS(X)
#undef X
Binding__COUNT
RAY_LIGHT_DIRECT_POLY_OUTPUTS(INIT_IMAGE)
};
static VkDescriptorSetLayoutBinding bindings[Binding__COUNT];
static const int semantics_poly[Binding__COUNT] = {
#undef INIT_IMAGE
#undef INIT_BINDING
static const int semantics_poly[] = {
#define IN(index, name, ...) (RayResource_##name + 1),
#define OUT(index, name, ...) -(RayResource_##name + 1),
LIST_COMMON_BINDINGS(IN)
@ -36,7 +48,7 @@ static const int semantics_poly[Binding__COUNT] = {
#undef OUT
};
static const int semantics_point[Binding__COUNT] = {
static const int semantics_point[] = {
#define IN(index, name, ...) (RayResource_##name + 1),
#define OUT(index, name, ...) -(RayResource_##name + 1),
LIST_COMMON_BINDINGS(IN)
@ -45,23 +57,6 @@ static const int semantics_point[Binding__COUNT] = {
#undef OUT
};
static void initDescriptors( void ) {
// FIXME more conservative shader stages
#define INIT_BINDING(index, name, type, count) \
bindings[Binding_##name] = (VkDescriptorSetLayoutBinding){ \
.binding = index, \
.descriptorType = type, \
.descriptorCount = count, \
.stageFlags = VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR, \
};
LIST_SCENE_BINDINGS(INIT_BINDING)
#define X(index, name, ...) INIT_BINDING(index, name, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1);
RAY_LIGHT_DIRECT_INPUTS(X)
RAY_LIGHT_DIRECT_POLY_OUTPUTS(X)
#undef X
#undef INIT_BINDING
}
struct ray_pass_s *R_VkRayLightDirectPolyPassCreate( void ) {
// FIXME move this into vk_pipeline
const struct SpecializationData {
@ -105,7 +100,6 @@ struct ray_pass_s *R_VkRayLightDirectPolyPassCreate( void ) {
.specialization = &spec,
};
initDescriptors();
return RayPassCreateTracing( &rpc );
}
@ -152,6 +146,5 @@ struct ray_pass_s *R_VkRayLightDirectPointPassCreate( void ) {
.specialization = &spec,
};
initDescriptors();
return RayPassCreateTracing( &rpc );
}

View File

@ -1,6 +1,6 @@
#include "vk_ray_primary.h"
#include "vk_ray_resources.h"
#include "ray_resources.h"
#include "ray_pass.h"
#define LIST_COMMON_BINDINGS(X) \
@ -11,17 +11,25 @@
X(5, vertices, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR) \
X(6, all_textures, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, MAX_TEXTURES, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR) \
enum {
#define X(index, name, ...) RtPrim_Desc_##name,
LIST_COMMON_BINDINGS(X)
RAY_PRIMARY_OUTPUTS(X)
#undef X
static const VkDescriptorSetLayoutBinding bindings[] = {
#define INIT_BINDING(index, name, type, count, stages) \
{ \
.binding = index, \
.descriptorType = type, \
.descriptorCount = count, \
.stageFlags = stages, \
},
#define INIT_IMAGE(index, name, ...) \
INIT_BINDING(index, name, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_RAYGEN_BIT_KHR)
RtPrim_Desc_COUNT
LIST_COMMON_BINDINGS(INIT_BINDING)
RAY_PRIMARY_OUTPUTS(INIT_IMAGE)
#undef INIT_IMAGE
#undef INIT_BINDING
};
static VkDescriptorSetLayoutBinding bindings[RtPrim_Desc_COUNT];
static const int semantics[RtPrim_Desc_COUNT] = {
static const int semantics[] = {
#define IN(index, name, ...) (RayResource_##name + 1),
#define OUT(index, name, ...) -(RayResource_##name + 1),
LIST_COMMON_BINDINGS(IN)
@ -30,22 +38,6 @@ static const int semantics[RtPrim_Desc_COUNT] = {
#undef OUT
};
static void initDescriptors( void ) {
#define INIT_BINDING(index, name, type, count, stages) \
bindings[RtPrim_Desc_##name] = (VkDescriptorSetLayoutBinding){ \
.binding = index, \
.descriptorType = type, \
.descriptorCount = count, \
.stageFlags = stages, \
};
LIST_COMMON_BINDINGS(INIT_BINDING)
#define X(index, name, ...) \
INIT_BINDING(index, name, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
RAY_PRIMARY_OUTPUTS(X)
#undef X
#undef INIT_BINDING
}
struct ray_pass_s *R_VkRayPrimaryPassCreate( void ) {
// FIXME move this into vk_pipeline or something
const struct SpecializationData {
@ -92,6 +84,5 @@ struct ray_pass_s *R_VkRayPrimaryPassCreate( void ) {
.specialization = &spec,
};
initDescriptors();
return RayPassCreateTracing( &rpc );
}

View File

@ -1,60 +0,0 @@
#pragma once
#include "vk_rtx.h"
#include "vk_const.h"
#include "vk_image.h"
#include "vk_descriptor.h"
#include "shaders/ray_interop.h"
#define RAY_SCENE_RESOURCES(X) \
X(TLAS, tlas) \
X(Buffer, ubo) \
X(Buffer, kusochki) \
X(Buffer, indices) \
X(Buffer, vertices) \
X(Buffer, lights) \
X(Buffer, light_clusters) \
X(Texture, all_textures) \
enum {
#define X(type, name, ...) RayResource_##name,
RAY_SCENE_RESOURCES(X)
RAY_PRIMARY_OUTPUTS(X)
RAY_LIGHT_DIRECT_POLY_OUTPUTS(X)
RAY_LIGHT_DIRECT_POINT_OUTPUTS(X)
X(-1, denoised)
#undef X
RayResource__COUNT
};
typedef struct {
VkAccessFlags access_mask;
VkImageLayout image_layout;
VkPipelineStageFlagBits pipelines;
} ray_resource_state_t;
typedef struct {
VkDescriptorType type;
ray_resource_state_t write, read;
union {
vk_descriptor_value_t value;
const xvk_image_t *image;
};
} ray_resource_t;
typedef struct vk_ray_resources_s {
uint32_t width, height;
ray_resource_t resources[RayResource__COUNT];
} vk_ray_resources_t;
typedef struct {
vk_ray_resources_t *resources;
const int *indices;
int count;
VkPipelineStageFlagBits dest_pipeline;
vk_descriptor_value_t *out_values;
} ray_resources_fill_t;
void RayResourcesFill(VkCommandBuffer cmdbuf, ray_resources_fill_t fill);

View File

@ -1,7 +1,7 @@
#include "vk_rtx.h"
#include "ray_pass.h"
#include "vk_ray_resources.h"
#include "ray_resources.h"
#include "vk_ray_primary.h"
#include "vk_ray_light_direct.h"