meat: use bindings from meat file
also compare them with currently hardcoded values to make sure there are no regressions next: - remove old hardcoded semantic/binding tables - remove comparisons - extract formats from spirv
This commit is contained in:
parent
c2e4f199ec
commit
a5d5167f1d
|
@ -53,6 +53,11 @@ static void finalizePassDescriptors( ray_pass_t *header, const ray_pass_layout_t
|
|||
header->desc.binding_semantics = Mem_Malloc(vk_core.pool, semantics_size);
|
||||
memcpy(header->desc.binding_semantics, layout->bindings_semantics, semantics_size);
|
||||
|
||||
const size_t bindings_size = sizeof(layout->bindings[0]) * layout->bindings_count;
|
||||
VkDescriptorSetLayoutBinding *bindings = Mem_Malloc(vk_core.pool, bindings_size);
|
||||
memcpy(bindings, layout->bindings, bindings_size);
|
||||
header->desc.riptors.bindings = bindings;
|
||||
|
||||
header->desc.riptors.values = Mem_Malloc(vk_core.pool, sizeof(header->desc.riptors.values[0]) * layout->bindings_count);
|
||||
}
|
||||
|
||||
|
@ -224,6 +229,7 @@ void RayPassDestroy( struct ray_pass_s *pass ) {
|
|||
VK_DescriptorsDestroy(&pass->desc.riptors);
|
||||
Mem_Free(pass->desc.riptors.values);
|
||||
Mem_Free(pass->desc.binding_semantics);
|
||||
Mem_Free((void*)pass->desc.riptors.bindings);
|
||||
Mem_Free(pass);
|
||||
}
|
||||
|
||||
|
|
|
@ -95,3 +95,76 @@ void RayResourcesFill(VkCommandBuffer cmdbuf, ray_resources_fill_t fill) {
|
|||
0, 0, NULL, 0, NULL, image_barriers_count, image_barriers);
|
||||
}
|
||||
}
|
||||
|
||||
#define FIXME_DESC(name_, semantic_, type_, count_) \
|
||||
{ .name = name_, \
|
||||
.desc.semantic = semantic_, \
|
||||
.desc.type = VK_DESCRIPTOR_TYPE_##type_, \
|
||||
.desc.count = count_, \
|
||||
}
|
||||
|
||||
#define FIXME_DESC_IN(name_, semantic_, type_, count_) \
|
||||
{ .name = name_, \
|
||||
.desc.semantic = (RayResource_##semantic_ + 1), \
|
||||
.desc.type = VK_DESCRIPTOR_TYPE_##type_, \
|
||||
.desc.count = count_, \
|
||||
}
|
||||
|
||||
#define FIXME_DESC_OUT(name_, semantic_, type_, count_) \
|
||||
{ .name = name_, \
|
||||
.desc.semantic = -(RayResource_##semantic_ + 1), \
|
||||
.desc.type = VK_DESCRIPTOR_TYPE_##type_, \
|
||||
.desc.count = count_, \
|
||||
}
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
ray_resource_binding_desc_fixme_t desc;
|
||||
} fixme_descs[] = {
|
||||
FIXME_DESC_IN("ubo", ubo, UNIFORM_BUFFER, 1),
|
||||
FIXME_DESC_IN("tlas", tlas, ACCELERATION_STRUCTURE_KHR, 1),
|
||||
FIXME_DESC_IN("kusochki", kusochki, STORAGE_BUFFER, 1),
|
||||
FIXME_DESC_IN("indices", indices, STORAGE_BUFFER, 1),
|
||||
FIXME_DESC_IN("vertices", vertices, STORAGE_BUFFER, 1),
|
||||
FIXME_DESC_IN("textures", all_textures, COMBINED_IMAGE_SAMPLER, MAX_TEXTURES),
|
||||
FIXME_DESC_IN("skybox", skybox, COMBINED_IMAGE_SAMPLER, 1),
|
||||
FIXME_DESC_IN("lights", lights, STORAGE_BUFFER, 1),
|
||||
FIXME_DESC_IN("light_clusters", light_clusters, STORAGE_BUFFER, 1),
|
||||
|
||||
FIXME_DESC_OUT("out_image_base_color_a", base_color_a, STORAGE_IMAGE, 1),
|
||||
FIXME_DESC_IN("src_base_color", base_color_a, STORAGE_IMAGE, 1),
|
||||
|
||||
FIXME_DESC_OUT("out_image_position_t", position_t, STORAGE_IMAGE, 1),
|
||||
FIXME_DESC_IN("position_t", position_t, STORAGE_IMAGE, 1),
|
||||
|
||||
FIXME_DESC_OUT("out_image_normals_gs", normals_gs, STORAGE_IMAGE, 1),
|
||||
FIXME_DESC_IN("normals_gs", normals_gs, STORAGE_IMAGE, 1),
|
||||
|
||||
FIXME_DESC_OUT("out_image_material_rmxx", material_rmxx, STORAGE_IMAGE, 1),
|
||||
FIXME_DESC_IN("material_rmxx", material_rmxx, STORAGE_IMAGE, 1),
|
||||
|
||||
FIXME_DESC_OUT("out_image_emissive", emissive, STORAGE_IMAGE, 1),
|
||||
FIXME_DESC_IN("src_emissive", emissive, STORAGE_IMAGE, 1),
|
||||
|
||||
FIXME_DESC_OUT("out_image_light_poly_diffuse", light_poly_diffuse, STORAGE_IMAGE, 1),
|
||||
FIXME_DESC_IN("src_light_direct_poly_diffuse", light_poly_diffuse, STORAGE_IMAGE, 1),
|
||||
|
||||
FIXME_DESC_OUT("out_image_light_poly_specular", light_poly_specular, STORAGE_IMAGE, 1),
|
||||
FIXME_DESC_IN("src_light_direct_poly_specular", light_poly_specular, STORAGE_IMAGE, 1),
|
||||
|
||||
FIXME_DESC_OUT("out_image_light_point_diffuse", light_point_diffuse, STORAGE_IMAGE, 1),
|
||||
FIXME_DESC_IN("src_light_direct_point_diffuse", light_point_diffuse, STORAGE_IMAGE, 1),
|
||||
|
||||
FIXME_DESC_OUT("out_image_light_point_specular", light_point_specular, STORAGE_IMAGE, 1),
|
||||
FIXME_DESC_IN("src_light_direct_point_specular", light_point_specular, STORAGE_IMAGE, 1),
|
||||
|
||||
FIXME_DESC_OUT("dest", denoised, STORAGE_IMAGE, 1),
|
||||
};
|
||||
|
||||
const ray_resource_binding_desc_fixme_t *RayResouceGetBindingForName_FIXME(const char *name) {
|
||||
for (int i = 0; i < COUNTOF(fixme_descs); ++i) {
|
||||
if (strcmp(name, fixme_descs[i].name) == 0)
|
||||
return &fixme_descs[i].desc;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -59,3 +59,11 @@ typedef struct {
|
|||
} ray_resources_fill_t;
|
||||
|
||||
void RayResourcesFill(VkCommandBuffer cmdbuf, ray_resources_fill_t fill);
|
||||
|
||||
typedef struct {
|
||||
int semantic;
|
||||
VkDescriptorType type;
|
||||
int count;
|
||||
} ray_resource_binding_desc_fixme_t;
|
||||
|
||||
const ray_resource_binding_desc_fixme_t *RayResouceGetBindingForName_FIXME(const char *name);
|
||||
|
|
|
@ -17,8 +17,8 @@ layout(set = 0, binding = 4, rgba16f) uniform readonly image2D src_light_direct_
|
|||
layout(set = 0, binding = 5, rgba16f) uniform readonly image2D src_light_direct_point_specular;
|
||||
layout(set = 0, binding = 6, rgba16f) uniform readonly image2D src_emissive;
|
||||
|
||||
layout(set = 0, binding = 7, rgba32f) uniform readonly image2D src_position_t;
|
||||
layout(set = 0, binding = 8, rgba16f) uniform readonly image2D src_normals_gs;
|
||||
//layout(set = 0, binding = 7, rgba32f) uniform readonly image2D src_position_t;
|
||||
//layout(set = 0, binding = 8, rgba16f) uniform readonly image2D src_normals_gs;
|
||||
|
||||
//layout(set = 0, binding = 2, rgba16f) uniform readonly image2D src_light_direct_poly_diffuse;
|
||||
/* layout(set = 0, binding = 3, rgba16f) uniform readonly image2D src_specular; */
|
||||
|
@ -56,11 +56,13 @@ vec3 reinhard02(vec3 c, vec3 Cwhite2) {
|
|||
float normpdf2(in float x2, in float sigma) { return 0.39894*exp(-0.5*x2/(sigma*sigma))/sigma; }
|
||||
float normpdf(in float x, in float sigma) { return normpdf2(x*x, sigma); }
|
||||
|
||||
/*
|
||||
void readNormals(ivec2 uv, out vec3 geometry_normal, out vec3 shading_normal) {
|
||||
const vec4 n = imageLoad(src_normals_gs, uv);
|
||||
geometry_normal = normalDecode(n.xy);
|
||||
shading_normal = normalDecode(n.zw);
|
||||
}
|
||||
*/
|
||||
|
||||
void main() {
|
||||
ivec2 res = ivec2(imageSize(src_base_color));
|
||||
|
@ -90,8 +92,10 @@ void main() {
|
|||
//imageStore(dest, pix, vec4(aces_tonemap(imageLoad(src_light_direct_poly, pix).rgb), 0.)); return;
|
||||
//imageStore(dest, pix, vec4(aces_tonemap(imageLoad(src_specular, pix).rgb), 0.)); return;
|
||||
|
||||
/*
|
||||
vec3 geometry_normal, shading_normal;
|
||||
readNormals(pix, geometry_normal, shading_normal);
|
||||
*/
|
||||
|
||||
//imageStore(dest, pix, vec4(.5 + geometry_normal * .5, 0.)); return;
|
||||
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
X(4, light_point_diffuse) \
|
||||
X(5, light_point_specular) \
|
||||
X(6, emissive) \
|
||||
X(7, position_t) \
|
||||
X(8, normals_gs) \
|
||||
|
||||
//X(7, position_t) \
|
||||
//X(8, normals_gs) \
|
||||
|
||||
static const VkDescriptorSetLayoutBinding bindings[] = {
|
||||
#define BIND_IMAGE(index, name) \
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "vk_meatpipe.h"
|
||||
|
||||
#include "vk_pipeline.h"
|
||||
#include "ray_resources.h"
|
||||
|
||||
#include "ray_pass.h"
|
||||
#include "vk_common.h"
|
||||
|
@ -107,7 +108,31 @@ static ray_pass_layout_t FIXME_getLayoutFor(const char *name) {
|
|||
return (ray_pass_layout_t){0};
|
||||
}
|
||||
|
||||
static struct ray_pass_s *pipelineLoadCompute(load_context_t *ctx, int i, const char *name) {
|
||||
static qboolean FIXME_compareLayouts(const ray_pass_layout_t *a, const ray_pass_layout_t *b) {
|
||||
ASSERT(a->bindings_count == b->bindings_count);
|
||||
|
||||
for (int i = 0; i < a->bindings_count; ++i) {
|
||||
qboolean found = false;
|
||||
const VkDescriptorSetLayoutBinding *ab = a->bindings + i;
|
||||
for (int j = 0; j < b->bindings_count; ++j) {
|
||||
const VkDescriptorSetLayoutBinding *bb = b->bindings + j;
|
||||
if (ab->binding == bb->binding) {
|
||||
ASSERT(!found);
|
||||
found = true;
|
||||
ASSERT(ab->descriptorType == bb->descriptorType);
|
||||
ASSERT(ab->descriptorCount == bb->descriptorCount);
|
||||
ASSERT(ab->stageFlags == bb->stageFlags);
|
||||
ASSERT(ab->pImmutableSamplers == bb->pImmutableSamplers);
|
||||
ASSERT(a->bindings_semantics[i] == b->bindings_semantics[j]);
|
||||
}
|
||||
}
|
||||
ASSERT(found);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct ray_pass_s *pipelineLoadCompute(load_context_t *ctx, int i, const char *name, const ray_pass_layout_t *layout) {
|
||||
const uint32_t shader_comp = READ_U32_RETURN(NULL, "Couldn't read comp shader for %d %s", i, name);
|
||||
|
||||
if (shader_comp >= ctx->shaders_count) {
|
||||
|
@ -115,20 +140,23 @@ static struct ray_pass_s *pipelineLoadCompute(load_context_t *ctx, int i, const
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const ray_pass_layout_t known_layout = FIXME_getLayoutFor(name);
|
||||
ASSERT(FIXME_compareLayouts(&known_layout, layout));
|
||||
|
||||
const ray_pass_create_compute_t rpcc = {
|
||||
.debug_name = name,
|
||||
.layout = FIXME_getLayoutFor(name),
|
||||
.layout = *layout,
|
||||
.shader_module = ctx->shaders[shader_comp],
|
||||
};
|
||||
|
||||
return RayPassCreateCompute(&rpcc);
|
||||
}
|
||||
|
||||
static struct ray_pass_s *pipelineLoadRT(load_context_t *ctx, int i, const char *name) {
|
||||
static struct ray_pass_s *pipelineLoadRT(load_context_t *ctx, int i, const char *name, const ray_pass_layout_t *layout) {
|
||||
ray_pass_p ret = NULL;
|
||||
ray_pass_create_tracing_t rpct = {
|
||||
.debug_name = name,
|
||||
.layout = FIXME_getLayoutFor(name),
|
||||
.layout = *layout,
|
||||
};
|
||||
|
||||
// FIXME bounds check shader indices
|
||||
|
@ -172,9 +200,15 @@ finalize:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static qboolean readBindings(load_context_t *ctx) {
|
||||
#define MAX_BINDINGS 32
|
||||
static int readBindings(load_context_t *ctx, VkDescriptorSetLayoutBinding *bindings, int* semantics) {
|
||||
const int count = READ_U32_RETURN(false, "Coulnd't read bindings count");
|
||||
|
||||
if (count > MAX_BINDINGS) {
|
||||
gEngine.Con_Printf(S_ERROR "Too many binding (%d), max: %d\n", count, MAX_BINDINGS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
char name[64];
|
||||
READ_STR_RETURN(false, name, "Couldn't read binding name");
|
||||
|
@ -182,10 +216,23 @@ static qboolean readBindings(load_context_t *ctx) {
|
|||
const uint32_t binding = READ_U32_RETURN(false, "Couldn't read binding for binding %s", name);
|
||||
const uint32_t stages = READ_U32_RETURN(false, "Couldn't read stages for binding %s", name);
|
||||
|
||||
gEngine.Con_Reportf("Binding %d: %s ds=%d b=%d s=%08x\n", i, name, descriptor_set, binding, stages);
|
||||
const ray_resource_binding_desc_fixme_t *binding_fixme = RayResouceGetBindingForName_FIXME(name);
|
||||
if (!binding_fixme)
|
||||
return 0;
|
||||
|
||||
bindings[i] = (VkDescriptorSetLayoutBinding){
|
||||
.binding = binding,
|
||||
.descriptorType = binding_fixme->type,
|
||||
.descriptorCount = binding_fixme->count,
|
||||
.stageFlags = stages,
|
||||
.pImmutableSamplers = NULL,
|
||||
};
|
||||
semantics[i] = binding_fixme->semantic;
|
||||
|
||||
gEngine.Con_Reportf("Binding %d: %s ds=%d b=%d s=%08x type=%d semantic=%d\n", i, name, descriptor_set, binding, stages, binding_fixme->type, binding_fixme->semantic);
|
||||
}
|
||||
|
||||
return true;
|
||||
return count;
|
||||
}
|
||||
|
||||
static struct ray_pass_s *pipelineLoad(load_context_t *ctx, int i) {
|
||||
|
@ -196,7 +243,17 @@ static struct ray_pass_s *pipelineLoad(load_context_t *ctx, int i) {
|
|||
|
||||
gEngine.Con_Reportf("%d: loading pipeline %s\n", i, name);
|
||||
|
||||
if (!readBindings(ctx)) {
|
||||
int semantics[MAX_BINDINGS];
|
||||
VkDescriptorSetLayoutBinding bindings[MAX_BINDINGS];
|
||||
|
||||
const ray_pass_layout_t layout = {
|
||||
.bindings_semantics = semantics,
|
||||
.bindings = bindings,
|
||||
.bindings_count = readBindings(ctx, bindings, semantics),
|
||||
.push_constants = {0},
|
||||
};
|
||||
|
||||
if (!layout.bindings_count) {
|
||||
gEngine.Con_Printf(S_ERROR "Couldn't read bindings for pipeline %s\n", name);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -206,9 +263,9 @@ static struct ray_pass_s *pipelineLoad(load_context_t *ctx, int i) {
|
|||
|
||||
switch (type) {
|
||||
case PIPELINE_COMPUTE:
|
||||
return pipelineLoadCompute(ctx, i, name);
|
||||
return pipelineLoadCompute(ctx, i, name, &layout);
|
||||
case PIPELINE_RAYTRACING:
|
||||
return pipelineLoadRT(ctx, i, name);
|
||||
return pipelineLoadRT(ctx, i, name, &layout);
|
||||
default:
|
||||
gEngine.Con_Printf(S_ERROR "Unexpected pipeline type %d\n", type);
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in New Issue