Compare commits
1 Commits
tmp-gpu-sh
...
gpu-shader
Author | SHA1 | Date | |
---|---|---|---|
f240ac1673 |
@@ -269,5 +269,9 @@ StatementMacros:
|
||||
- PyObject_HEAD
|
||||
- PyObject_VAR_HEAD
|
||||
|
||||
StatementMacros:
|
||||
- GPU_STAGE_INTERFACE_CREATE
|
||||
- GPU_SHADER_DESCRIPTOR
|
||||
|
||||
MacroBlockBegin: "^BSDF_CLOSURE_CLASS_BEGIN$"
|
||||
MacroBlockEnd: "^BSDF_CLOSURE_CLASS_END$"
|
||||
|
@@ -1,26 +1,25 @@
|
||||
|
||||
#include "gpu_shader_descriptor.h"
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(
|
||||
workbench_effect_cavity,
|
||||
{
|
||||
.do_static_compilation = true,
|
||||
.fragment_outputs =
|
||||
{
|
||||
[0] = FRAGMENT_OUTPUT(VEC4, "fragColor"),
|
||||
},
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_1] =
|
||||
{
|
||||
[0] = SAMPLER(FLOAT_2D, "depthBuffer", GPU_SAMPLER_DEFAULT),
|
||||
[1] = SAMPLER(FLOAT_2D, "normalBuffer", GPU_SAMPLER_DEFAULT),
|
||||
[2] = SAMPLER(UINT_2D, "objectIdBuffer", GPU_SAMPLER_DEFAULT),
|
||||
},
|
||||
},
|
||||
.fragment_source = "workbench_effect_cavity_frag.glsl",
|
||||
.additional_descriptors =
|
||||
{
|
||||
&draw_fullscreen,
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_effect_cavity)
|
||||
{
|
||||
.do_static_compilation = true,
|
||||
.fragment_outputs =
|
||||
{
|
||||
[0] = FRAGMENT_OUTPUT(VEC4, "fragColor"),
|
||||
},
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_1] =
|
||||
{
|
||||
[0] = SAMPLER(FLOAT_2D, "depthBuffer", GPU_SAMPLER_DEFAULT),
|
||||
[1] = SAMPLER(FLOAT_2D, "normalBuffer", GPU_SAMPLER_DEFAULT),
|
||||
[2] = SAMPLER(UINT_2D, "objectIdBuffer", GPU_SAMPLER_DEFAULT),
|
||||
},
|
||||
},
|
||||
.fragment_source = "workbench_effect_cavity_frag.glsl",
|
||||
.additional_descriptors =
|
||||
{
|
||||
"draw_fullscreen",
|
||||
},
|
||||
};
|
||||
|
@@ -5,54 +5,46 @@
|
||||
/** \name Object Type
|
||||
* \{ */
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_mesh,
|
||||
{
|
||||
.vertex_inputs =
|
||||
{
|
||||
[0] = VERTEX_INPUT(VEC3, "pos"),
|
||||
[1] = VERTEX_INPUT(VEC3, "nor"),
|
||||
[2] = VERTEX_INPUT(VEC4, "ac"),
|
||||
[3] = VERTEX_INPUT(VEC2, "au"),
|
||||
},
|
||||
.vertex_source = "workbench_prepass_vert.glsl",
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_mesh)
|
||||
{
|
||||
.vertex_inputs =
|
||||
{
|
||||
[0] = VERTEX_INPUT(VEC3, "pos"),
|
||||
[1] = VERTEX_INPUT(VEC3, "nor"),
|
||||
[2] = VERTEX_INPUT(VEC4, "ac"),
|
||||
[3] = VERTEX_INPUT(VEC2, "au"),
|
||||
},
|
||||
.vertex_source = "workbench_prepass_vert.glsl",
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_hair,
|
||||
{
|
||||
.vertex_source = "workbench_prepass_hair_vert.glsl",
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_0] =
|
||||
{
|
||||
[0] = SAMPLER(FLOAT_BUFFER, "ac", GPU_SAMPLER_DEFAULT),
|
||||
[1] = SAMPLER(FLOAT_BUFFER, "au", GPU_SAMPLER_DEFAULT),
|
||||
},
|
||||
},
|
||||
.additional_descriptors =
|
||||
{
|
||||
0,
|
||||
/* TODO */
|
||||
// &draw_hair,
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_hair)
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_0] =
|
||||
{
|
||||
[0] = SAMPLER(FLOAT_BUFFER, "ac", GPU_SAMPLER_DEFAULT),
|
||||
[1] = SAMPLER(FLOAT_BUFFER, "au", GPU_SAMPLER_DEFAULT),
|
||||
},
|
||||
},
|
||||
.vertex_source = "workbench_prepass_hair_vert.glsl",
|
||||
/* TODO */
|
||||
// .additional_descriptors = { "draw_hair", },
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_pointcloud,
|
||||
{
|
||||
.vertex_inputs =
|
||||
{
|
||||
[0] = VERTEX_INPUT(VEC4, "pos"),
|
||||
/* ---- Instanced attribs ---- */
|
||||
[1] = VERTEX_INPUT(VEC3, "pos_inst"),
|
||||
[2] = VERTEX_INPUT(VEC3, "nor"),
|
||||
},
|
||||
.vertex_source = "workbench_prepass_pointcloud_vert.glsl",
|
||||
.additional_descriptors =
|
||||
{
|
||||
0,
|
||||
/* TODO */
|
||||
// &draw_pointcloud,
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_pointcloud)
|
||||
{
|
||||
.vertex_inputs =
|
||||
{
|
||||
[0] = VERTEX_INPUT(VEC4, "pos"),
|
||||
/* ---- Instanced attribs ---- */
|
||||
[1] = VERTEX_INPUT(VEC3, "pos_inst"),
|
||||
[2] = VERTEX_INPUT(VEC3, "nor"),
|
||||
},
|
||||
.vertex_source = "workbench_prepass_pointcloud_vert.glsl",
|
||||
/* TODO */
|
||||
// .additional_descriptors = { "draw_pointcloud", },
|
||||
};
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -60,52 +52,50 @@ GPU_SHADER_DESCRIPTOR(workbench_pointcloud,
|
||||
/** \name Texture Type
|
||||
* \{ */
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_texture_none,
|
||||
{
|
||||
.defines =
|
||||
{
|
||||
[0] = "#define TEXTURE_NONE\n",
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_texture_none)
|
||||
{
|
||||
.defines =
|
||||
{
|
||||
[0] = "#define TEXTURE_NONE\n",
|
||||
},
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(
|
||||
workbench_texture_single,
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_0] =
|
||||
{
|
||||
/* ---- Hair buffers ---- */
|
||||
// [0] = SAMPLER(FLOAT_BUFFER, "ac", GPU_SAMPLER_DEFAULT),
|
||||
// [1] = SAMPLER(FLOAT_BUFFER, "au", GPU_SAMPLER_DEFAULT),
|
||||
[2] = SAMPLER(FLOAT_2D, "imageTexture", GPU_SAMPLER_DEFAULT),
|
||||
},
|
||||
},
|
||||
.defines =
|
||||
{
|
||||
[0] = "#define V3D_SHADING_TEXTURE_COLOR\n",
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_texture_single)
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_0] =
|
||||
{
|
||||
/* ---- Hair buffers ---- */
|
||||
// [0] = SAMPLER(FLOAT_BUFFER, "ac", GPU_SAMPLER_DEFAULT),
|
||||
// [1] = SAMPLER(FLOAT_BUFFER, "au", GPU_SAMPLER_DEFAULT),
|
||||
[2] = SAMPLER(FLOAT_2D, "imageTexture", GPU_SAMPLER_DEFAULT),
|
||||
},
|
||||
},
|
||||
.defines =
|
||||
{
|
||||
[0] = "#define V3D_SHADING_TEXTURE_COLOR\n",
|
||||
},
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(
|
||||
workbench_texture_tile,
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_0] =
|
||||
{
|
||||
/* ---- Hair buffers ---- */
|
||||
// [0] = SAMPLER(FLOAT_BUFFER, "ac", GPU_SAMPLER_DEFAULT),
|
||||
// [1] = SAMPLER(FLOAT_BUFFER, "au", GPU_SAMPLER_DEFAULT),
|
||||
[2] = SAMPLER(FLOAT_2D_ARRAY, "imageTileArray", GPU_SAMPLER_DEFAULT),
|
||||
[3] = SAMPLER(FLOAT_1D_ARRAY, "imageTileData", GPU_SAMPLER_DEFAULT),
|
||||
},
|
||||
},
|
||||
.defines =
|
||||
{
|
||||
[0] = "#define TEXTURE_IMAGE_ARRAY\n",
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_texture_tile)
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_0] =
|
||||
{
|
||||
/* ---- Hair buffers ---- */
|
||||
// [0] = SAMPLER(FLOAT_BUFFER, "ac", GPU_SAMPLER_DEFAULT),
|
||||
// [1] = SAMPLER(FLOAT_BUFFER, "au", GPU_SAMPLER_DEFAULT),
|
||||
[2] = SAMPLER(FLOAT_2D_ARRAY, "imageTileArray", GPU_SAMPLER_DEFAULT),
|
||||
[3] = SAMPLER(FLOAT_1D_ARRAY, "imageTileData", GPU_SAMPLER_DEFAULT),
|
||||
},
|
||||
},
|
||||
.defines =
|
||||
{
|
||||
[0] = "#define TEXTURE_IMAGE_ARRAY\n",
|
||||
},
|
||||
};
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -113,29 +103,29 @@ GPU_SHADER_DESCRIPTOR(
|
||||
/** \name Lighting Type
|
||||
* \{ */
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_lighting_studio,
|
||||
{
|
||||
.defines =
|
||||
{
|
||||
[1] = "#define V3D_LIGHTING_STUDIO\n",
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_lighting_studio)
|
||||
{
|
||||
.defines =
|
||||
{
|
||||
[1] = "#define V3D_LIGHTING_STUDIO\n",
|
||||
},
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_lighting_matcap,
|
||||
{
|
||||
.defines =
|
||||
{
|
||||
[1] = "#define V3D_LIGHTING_MATCAP\n",
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_lighting_matcap)
|
||||
{
|
||||
.defines =
|
||||
{
|
||||
[1] = "#define V3D_LIGHTING_MATCAP\n",
|
||||
},
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_lighting_flat,
|
||||
{
|
||||
.defines =
|
||||
{
|
||||
[1] = "#define V3D_LIGHTING_FLAT\n",
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_lighting_flat)
|
||||
{
|
||||
.defines =
|
||||
{
|
||||
[1] = "#define V3D_LIGHTING_FLAT\n",
|
||||
},
|
||||
};
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -143,28 +133,28 @@ GPU_SHADER_DESCRIPTOR(workbench_lighting_flat,
|
||||
/** \name Material Interface
|
||||
* \{ */
|
||||
|
||||
GPU_STAGE_INTERFACE_CREATE(workbench_material_iface,
|
||||
{
|
||||
{VEC3, "normal_interp"},
|
||||
{VEC3, "color_interp"},
|
||||
{FLOAT, "alpha_interp"},
|
||||
{VEC2, "uv_interp"},
|
||||
{INT, "object_id", FLAT},
|
||||
{FLOAT, "roughness", FLAT},
|
||||
{FLOAT, "metallic", FLAT},
|
||||
})
|
||||
GPU_STAGE_INTERFACE_CREATE(workbench_material_iface)
|
||||
{
|
||||
{VEC3, "normal_interp"},
|
||||
{VEC3, "color_interp"},
|
||||
{FLOAT, "alpha_interp"},
|
||||
{VEC2, "uv_interp"},
|
||||
{INT, "object_id", FLAT},
|
||||
{FLOAT, "roughness", FLAT},
|
||||
{FLOAT, "metallic", FLAT},
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_material,
|
||||
{
|
||||
.vertex_out_interfaces =
|
||||
{
|
||||
[0] = STAGE_INTERFACE("", workbench_material_iface),
|
||||
},
|
||||
.additional_descriptors =
|
||||
{
|
||||
&draw_view,
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_material)
|
||||
{
|
||||
.vertex_out_interfaces =
|
||||
{
|
||||
[0] = STAGE_INTERFACE("", workbench_material_iface),
|
||||
},
|
||||
.additional_descriptors =
|
||||
{
|
||||
"draw_view",
|
||||
},
|
||||
};
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -172,46 +162,48 @@ GPU_SHADER_DESCRIPTOR(workbench_material,
|
||||
/** \name Pipeline Type
|
||||
* \{ */
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_transparent_accum,
|
||||
{
|
||||
.fragment_outputs =
|
||||
{
|
||||
/* Note: Blending will be skipped on objectId because output is a
|
||||
non-normalized integer buffer. */
|
||||
[0] = FRAGMENT_OUTPUT(VEC4, "transparentAccum"),
|
||||
[1] = FRAGMENT_OUTPUT(VEC4, "revealageAccum"),
|
||||
[2] = FRAGMENT_OUTPUT(UINT, "objectId"),
|
||||
},
|
||||
.fragment_source = "workbench_effect_cavity_frag.glsl",
|
||||
.additional_descriptors =
|
||||
{
|
||||
&workbench_material,
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(workbench_transparent_accum)
|
||||
{
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_opaque,
|
||||
{
|
||||
.fragment_outputs =
|
||||
{
|
||||
/* Note: Blending will be skipped on objectId because output is a
|
||||
non-normalized integer buffer. */
|
||||
[0] = FRAGMENT_OUTPUT(VEC4, "materialData"),
|
||||
[1] = FRAGMENT_OUTPUT(VEC2, "normalData"),
|
||||
[2] = FRAGMENT_OUTPUT(UINT, "objectId"),
|
||||
},
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_0] =
|
||||
{
|
||||
[4] = UNIFORM_BUFFER("WB_Scene", "scene"),
|
||||
},
|
||||
},
|
||||
.fragment_source = "workbench_effect_cavity_frag.glsl",
|
||||
.additional_descriptors =
|
||||
{
|
||||
&workbench_material,
|
||||
},
|
||||
})
|
||||
.fragment_outputs =
|
||||
{
|
||||
/* Note: Blending will be skipped on objectId because output is a
|
||||
non-normalized integer buffer. */
|
||||
[0] = FRAGMENT_OUTPUT(VEC4, "transparentAccum"),
|
||||
[1] = FRAGMENT_OUTPUT(VEC4, "revealageAccum"),
|
||||
[2] = FRAGMENT_OUTPUT(UINT, "objectId"),
|
||||
},
|
||||
.fragment_source = "workbench_effect_cavity_frag.glsl",
|
||||
.additional_descriptors =
|
||||
{
|
||||
"workbench_material",
|
||||
},
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(workbench_opaque)
|
||||
{
|
||||
|
||||
.fragment_outputs =
|
||||
{
|
||||
/* Note: Blending will be skipped on objectId because output is a
|
||||
non-normalized integer buffer. */
|
||||
[0] = FRAGMENT_OUTPUT(VEC4, "materialData"),
|
||||
[1] = FRAGMENT_OUTPUT(VEC2, "normalData"),
|
||||
[2] = FRAGMENT_OUTPUT(UINT, "objectId"),
|
||||
},
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_0] =
|
||||
{
|
||||
[4] = UNIFORM_BUFFER("WB_Scene", "scene"),
|
||||
},
|
||||
},
|
||||
.fragment_source = "workbench_effect_cavity_frag.glsl",
|
||||
.additional_descriptors =
|
||||
{
|
||||
"workbench_material",
|
||||
},
|
||||
};
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -220,46 +212,48 @@ GPU_SHADER_DESCRIPTOR(workbench_opaque,
|
||||
* \{ */
|
||||
|
||||
#define WORKBENCH_SURFACETYPE_VARIATIONS(prefix, ...) \
|
||||
GPU_SHADER_DESCRIPTOR(prefix##_mesh, \
|
||||
{ \
|
||||
.additional_descriptors = \
|
||||
{ \
|
||||
&workbench_mesh, \
|
||||
__VA_ARGS__, \
|
||||
}, \
|
||||
}) \
|
||||
GPU_SHADER_DESCRIPTOR(prefix##_hair, \
|
||||
{ \
|
||||
.additional_descriptors = \
|
||||
{ \
|
||||
&workbench_hair, \
|
||||
__VA_ARGS__, \
|
||||
}, \
|
||||
}) \
|
||||
GPU_SHADER_DESCRIPTOR(prefix##_pointcloud, \
|
||||
{ \
|
||||
.additional_descriptors = \
|
||||
{ \
|
||||
&workbench_pointcloud, \
|
||||
__VA_ARGS__, \
|
||||
}, \
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(prefix##_mesh) \
|
||||
{ \
|
||||
.additional_descriptors = \
|
||||
{ \
|
||||
"workbench_mesh", \
|
||||
__VA_ARGS__, \
|
||||
}, \
|
||||
}; \
|
||||
GPU_SHADER_DESCRIPTOR(prefix##_hair) \
|
||||
{ \
|
||||
.additional_descriptors = \
|
||||
{ \
|
||||
"workbench_hair", \
|
||||
__VA_ARGS__, \
|
||||
}, \
|
||||
}; \
|
||||
GPU_SHADER_DESCRIPTOR(prefix##_ptcloud) \
|
||||
{ \
|
||||
.additional_descriptors = \
|
||||
{ \
|
||||
"workbench_pointcloud", \
|
||||
__VA_ARGS__, \
|
||||
}, \
|
||||
};
|
||||
|
||||
#define WORKBENCH_PIPELINE_VARIATIONS(prefix, ...) \
|
||||
WORKBENCH_SURFACETYPE_VARIATIONS(prefix##_transp_studio, \
|
||||
&workbench_transparent_accum, \
|
||||
&workbench_lighting_studio, \
|
||||
"workbench_transparent_accum", \
|
||||
"workbench_lighting_studio", \
|
||||
__VA_ARGS__) \
|
||||
WORKBENCH_SURFACETYPE_VARIATIONS(prefix##_transp_matcap, \
|
||||
&workbench_transparent_accum, \
|
||||
&workbench_lighting_matcap, \
|
||||
"workbench_transparent_accum", \
|
||||
"workbench_lighting_matcap", \
|
||||
__VA_ARGS__) \
|
||||
WORKBENCH_SURFACETYPE_VARIATIONS( \
|
||||
prefix##_transp_flat, &workbench_transparent_accum, &workbench_lighting_flat, __VA_ARGS__) \
|
||||
WORKBENCH_SURFACETYPE_VARIATIONS(prefix##_opaque, &workbench_opaque, __VA_ARGS__)
|
||||
WORKBENCH_SURFACETYPE_VARIATIONS(prefix##_transp_flat, \
|
||||
"workbench_transparent_accum", \
|
||||
"workbench_lighting_flat", \
|
||||
__VA_ARGS__) \
|
||||
WORKBENCH_SURFACETYPE_VARIATIONS(prefix##_opaque, "workbench_opaque", __VA_ARGS__)
|
||||
|
||||
WORKBENCH_PIPELINE_VARIATIONS(workbench_tex_none, &workbench_texture_none)
|
||||
WORKBENCH_PIPELINE_VARIATIONS(workbench_tex_single, &workbench_texture_single)
|
||||
WORKBENCH_PIPELINE_VARIATIONS(workbench_tex_tile, &workbench_texture_tile)
|
||||
WORKBENCH_PIPELINE_VARIATIONS(workbench_tex_none, "workbench_texture_none")
|
||||
WORKBENCH_PIPELINE_VARIATIONS(workbench_tex_single, "workbench_texture_single")
|
||||
WORKBENCH_PIPELINE_VARIATIONS(workbench_tex_tile, "workbench_texture_tile")
|
||||
|
||||
/** \} */
|
||||
|
@@ -1,16 +1,16 @@
|
||||
|
||||
#include "gpu_shader_descriptor.h"
|
||||
|
||||
GPU_STAGE_INTERFACE_CREATE(fullscreen_iface,
|
||||
{
|
||||
{VEC4, "uvcoordsvar"},
|
||||
})
|
||||
GPU_STAGE_INTERFACE_CREATE(fullscreen_iface)
|
||||
{
|
||||
{VEC4, "uvcoordsvar"},
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(draw_fullscreen,
|
||||
{
|
||||
.vertex_out_interfaces =
|
||||
{
|
||||
[0] = STAGE_INTERFACE("", fullscreen_iface),
|
||||
},
|
||||
.vertex_source = "common_fullscreen_vert.glsl",
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(draw_fullscreen)
|
||||
{
|
||||
.vertex_out_interfaces =
|
||||
{
|
||||
[0] = STAGE_INTERFACE("", fullscreen_iface),
|
||||
},
|
||||
.vertex_source = "common_fullscreen_vert.glsl",
|
||||
};
|
||||
|
@@ -1,14 +1,13 @@
|
||||
|
||||
#include "gpu_shader_descriptor.h"
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(
|
||||
draw_object_infos,
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_1] =
|
||||
{
|
||||
[2] = UNIFORM_BUFFER("ObjectInfos", "drw_infos[DRW_RESOURCE_CHUNK_LEN]"),
|
||||
},
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(draw_object_infos)
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_1] =
|
||||
{
|
||||
[2] = UNIFORM_BUFFER("ObjectInfos", "drw_infos[DRW_RESOURCE_CHUNK_LEN]"),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@@ -1,16 +1,14 @@
|
||||
|
||||
#include "gpu_shader_descriptor.h"
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(
|
||||
draw_view,
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_1] =
|
||||
{
|
||||
[0] = UNIFORM_BUFFER("ViewInfos", "drw_view"),
|
||||
[1] = UNIFORM_BUFFER("ObjectMatrices",
|
||||
"drw_matrices[DRW_RESOURCE_CHUNK_LEN]"),
|
||||
},
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(draw_view)
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_1] =
|
||||
{
|
||||
[0] = UNIFORM_BUFFER("ViewInfos", "drw_view"),
|
||||
[1] = UNIFORM_BUFFER("ObjectMatrices", "drw_matrices[DRW_RESOURCE_CHUNK_LEN]"),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@@ -34,8 +34,23 @@
|
||||
#undef GPU_STAGE_INTERFACE_CREATE
|
||||
#undef GPU_SHADER_DESCRIPTOR
|
||||
|
||||
static const GPUShaderDescriptor *find_descriptor_by_name(const GPUShaderDescriptor **descriptors,
|
||||
const char *name)
|
||||
{
|
||||
const GPUShaderDescriptor **result = descriptors;
|
||||
while (*result) {
|
||||
if (strcmp((*result)->name, name) == 0) {
|
||||
return *result;
|
||||
}
|
||||
result++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Return 0 on success. (Recursive). */
|
||||
static bool descriptor_flatten(const GPUShaderDescriptor *input, GPUShaderDescriptor *output)
|
||||
static bool descriptor_flatten(const GPUShaderDescriptor **descriptors,
|
||||
const GPUShaderDescriptor *input,
|
||||
GPUShaderDescriptor *output)
|
||||
{
|
||||
int errors = 0;
|
||||
|
||||
@@ -192,7 +207,17 @@ static bool descriptor_flatten(const GPUShaderDescriptor *input, GPUShaderDescri
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(input->additional_descriptors); i++) {
|
||||
if (input->additional_descriptors[i]) {
|
||||
errors += descriptor_flatten(input->additional_descriptors[i], output);
|
||||
const GPUShaderDescriptor *deps = find_descriptor_by_name(descriptors,
|
||||
input->additional_descriptors[i]);
|
||||
if (deps) {
|
||||
errors += descriptor_flatten(descriptors, deps, output);
|
||||
}
|
||||
else {
|
||||
printf("Error: %s : Could not find dependency %s.\n",
|
||||
input->name,
|
||||
input->additional_descriptors[i]);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
@@ -418,32 +443,39 @@ int main(int argc, char const *argv[])
|
||||
}
|
||||
|
||||
size_t descriptors_len = 0;
|
||||
/* Count number of descriptors. */
|
||||
#define GPU_STAGE_INTERFACE_CREATE(_interface, ...)
|
||||
#define GPU_SHADER_DESCRIPTOR(_descriptor, ...) descriptors_len++;
|
||||
/* Count number of descriptors. Define interfaces. */
|
||||
#define GPU_STAGE_INTERFACE_CREATE(_interface) GPUInOut _interface[] =
|
||||
#define GPU_SHADER_DESCRIPTOR(_descriptor) \
|
||||
descriptors_len++; \
|
||||
(void)(GPUShaderDescriptor)
|
||||
#include "gpu_shader_descriptor_list.h"
|
||||
#undef GPU_STAGE_INTERFACE_CREATE
|
||||
#undef GPU_SHADER_DESCRIPTOR
|
||||
/* Discard interfaces then. */
|
||||
#define GPU_STAGE_INTERFACE_CREATE(_interface) (void)(GPUInOut[])
|
||||
|
||||
GPUShaderDescriptor **descriptors = calloc(descriptors_len, sizeof(void *));
|
||||
/* Null ended array. */
|
||||
GPUShaderDescriptor **descriptors = calloc(descriptors_len + 1, sizeof(void *));
|
||||
|
||||
size_t index = 0;
|
||||
/* Declare everything first to be able to avoid dependency for references. */
|
||||
#define GPU_STAGE_INTERFACE_CREATE(_interface, ...) GPUInOut _interface[] = __VA_ARGS__;
|
||||
#define GPU_SHADER_DESCRIPTOR(_descriptor, ...) \
|
||||
#define GPU_SHADER_DESCRIPTOR(_descriptor) \
|
||||
GPUShaderDescriptor _descriptor; \
|
||||
descriptors[index++] = &_descriptor;
|
||||
descriptors[index++] = &_descriptor; \
|
||||
(void)(GPUShaderDescriptor)
|
||||
#include "gpu_shader_descriptor_list.h"
|
||||
#undef GPU_STAGE_INTERFACE_CREATE
|
||||
#undef GPU_SHADER_DESCRIPTOR
|
||||
|
||||
/* Set values. */
|
||||
#define GPU_STAGE_INTERFACE_CREATE(_interface, ...)
|
||||
#define GPU_SHADER_DESCRIPTOR(_descriptor, ...) \
|
||||
_descriptor = (GPUShaderDescriptor)__VA_ARGS__; \
|
||||
_descriptor.name = #_descriptor;
|
||||
#define GPU_SHADER_DESCRIPTOR(_descriptor) _descriptor = (GPUShaderDescriptor)
|
||||
#include "gpu_shader_descriptor_list.h"
|
||||
#undef GPU_SHADER_DESCRIPTOR
|
||||
|
||||
/* Set name. */
|
||||
#define GPU_SHADER_DESCRIPTOR(_descriptor) \
|
||||
_descriptor.name = #_descriptor; \
|
||||
(void)(GPUShaderDescriptor)
|
||||
#include "gpu_shader_descriptor_list.h"
|
||||
#undef GPU_STAGE_INTERFACE_CREATE
|
||||
#undef GPU_SHADER_DESCRIPTOR
|
||||
|
||||
FILE *fp = fopen(argv[1], "w");
|
||||
@@ -460,7 +492,7 @@ int main(int argc, char const *argv[])
|
||||
|
||||
GPUShaderDescriptor flattened_descriptor = {0};
|
||||
|
||||
int errors = descriptor_flatten(descriptor, &flattened_descriptor);
|
||||
int errors = descriptor_flatten(descriptors, descriptor, &flattened_descriptor);
|
||||
if (errors != 0) {
|
||||
result = 1;
|
||||
continue;
|
||||
|
@@ -24,18 +24,16 @@
|
||||
*
|
||||
* Some rule of thumb:
|
||||
* - Do not include anything else than this file in each descriptor file.
|
||||
* - You can assume all descriptors will be defined and you can reference any of them in
|
||||
* additional_descriptors.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/* For helping code suggestion. */
|
||||
/* For helping intellisense. */
|
||||
#ifndef GPU_SHADER_DESCRIPTOR
|
||||
# define GPU_STAGE_INTERFACE_CREATE(_interface, ...) GPUInOut _interface[] = __VA_ARGS__;
|
||||
# define GPU_SHADER_DESCRIPTOR(_descriptor, ...) GPUShaderDescriptor _descriptor = __VA_ARGS__;
|
||||
# define GPU_STAGE_INTERFACE_CREATE(_interface) GPUInOut _interface[] =
|
||||
# define GPU_SHADER_DESCRIPTOR(_descriptor) GPUShaderDescriptor _descriptor =
|
||||
#endif
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
@@ -238,8 +236,8 @@ typedef struct GPUShaderDescriptor {
|
||||
const char *defines[8];
|
||||
|
||||
/**
|
||||
* Link to other descriptors to recursively merge with this one.
|
||||
* Name of other descriptors to recursively merge with this one.
|
||||
* No data slot must overlap otherwise we throw an error.
|
||||
*/
|
||||
struct GPUShaderDescriptor *additional_descriptors[4];
|
||||
const char *additional_descriptors[4];
|
||||
} GPUShaderDescriptor;
|
||||
|
@@ -1,17 +1,17 @@
|
||||
|
||||
#include "gpu_shader_descriptor.h"
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(gpu_clip_planes,
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_0] =
|
||||
{
|
||||
[1] = UNIFORM_BUFFER("GPUClipPlanes", "clipPlanes"),
|
||||
},
|
||||
},
|
||||
.defines =
|
||||
{
|
||||
[5] = "#define USE_WORLD_CLIP_PLANES\n",
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(gpu_clip_planes)
|
||||
{
|
||||
.resources =
|
||||
{
|
||||
[DESCRIPTOR_SET_0] =
|
||||
{
|
||||
[1] = UNIFORM_BUFFER("GPUClipPlanes", "clipPlanes"),
|
||||
},
|
||||
},
|
||||
.defines =
|
||||
{
|
||||
[5] = "#define USE_WORLD_CLIP_PLANES\n",
|
||||
},
|
||||
};
|
||||
|
@@ -1,39 +1,39 @@
|
||||
|
||||
#include "gpu_shader_descriptor.h"
|
||||
|
||||
GPU_STAGE_INTERFACE_CREATE(flat_color_iface,
|
||||
{
|
||||
{VEC4, "finalColor", FLAT},
|
||||
})
|
||||
GPU_STAGE_INTERFACE_CREATE(flat_color_iface)
|
||||
{
|
||||
{VEC4, "finalColor", FLAT},
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(gpu_shader_3D_flat_color,
|
||||
{
|
||||
.vertex_inputs =
|
||||
{
|
||||
[0] = VERTEX_INPUT(VEC3, "pos"),
|
||||
[1] = VERTEX_INPUT(VEC4, "col"),
|
||||
},
|
||||
.vertex_out_interfaces =
|
||||
{
|
||||
[0] = STAGE_INTERFACE("", flat_color_iface),
|
||||
},
|
||||
.fragment_outputs =
|
||||
{
|
||||
[0] = FRAGMENT_OUTPUT(VEC4, "fragColor"),
|
||||
},
|
||||
.push_constants =
|
||||
{
|
||||
[1] = PUSH_CONSTANT(BOOL, "srgbTarget"),
|
||||
},
|
||||
.vertex_source = "gpu_shader_3D_flat_color_vert.glsl",
|
||||
.fragment_source = "gpu_shader_flat_color_frag.glsl",
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(gpu_shader_3D_flat_color)
|
||||
{
|
||||
.vertex_inputs =
|
||||
{
|
||||
[0] = VERTEX_INPUT(VEC3, "pos"),
|
||||
[1] = VERTEX_INPUT(VEC4, "col"),
|
||||
},
|
||||
.vertex_out_interfaces =
|
||||
{
|
||||
[0] = STAGE_INTERFACE("", flat_color_iface),
|
||||
},
|
||||
.fragment_outputs =
|
||||
{
|
||||
[0] = FRAGMENT_OUTPUT(VEC4, "fragColor"),
|
||||
},
|
||||
.push_constants =
|
||||
{
|
||||
[1] = PUSH_CONSTANT(BOOL, "srgbTarget"),
|
||||
},
|
||||
.vertex_source = "gpu_shader_3D_flat_color_vert.glsl",
|
||||
.fragment_source = "gpu_shader_flat_color_frag.glsl",
|
||||
};
|
||||
|
||||
GPU_SHADER_DESCRIPTOR(gpu_shader_3D_flat_color_clipped,
|
||||
{
|
||||
.additional_descriptors =
|
||||
{
|
||||
&gpu_shader_3D_flat_color,
|
||||
&gpu_clip_planes,
|
||||
},
|
||||
})
|
||||
GPU_SHADER_DESCRIPTOR(gpu_shader_3D_flat_color_clipped)
|
||||
{
|
||||
.additional_descriptors =
|
||||
{
|
||||
"gpu_shader_3D_flat_color",
|
||||
"gpu_clip_planes",
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user