[vulkan] Create the non-C side of the sprite pipeline

This adds the shaders and the pipeline specs. I'm not sure that the
deferred rendering side of the render pass is appropriate, but I thought
I'd give it a go, since quake sprites are really cutoff rather than
translucent.
This commit is contained in:
Bill Currie 2021-12-14 14:44:16 +09:00
parent 2db8d11dd0
commit 36e0d857a2
7 changed files with 239 additions and 0 deletions

View file

@ -287,6 +287,14 @@ vkparse_plist = \
vkshaderpath = libs/video/renderer/vulkan/shader
sprite_gbufv_src = $(vkshaderpath)/sprite_gbuf.vert
sprite_gbufv_c = $(vkshaderpath)/sprite_gbuf.vert.spvc
sprite_gbuff_src = $(vkshaderpath)/sprite_gbuf.frag
sprite_gbuff_c = $(vkshaderpath)/sprite_gbuf.frag.spvc
sprite_depthv_src = $(vkshaderpath)/sprite_depth.vert
sprite_depthv_c = $(vkshaderpath)/sprite_depth.vert.spvc
sprite_depthf_src = $(vkshaderpath)/sprite_depth.frag
sprite_depthf_c = $(vkshaderpath)/sprite_depth.frag.spvc
twodv_src = $(vkshaderpath)/twod.vert
twodv_c = $(vkshaderpath)/twod.vert.spvc
twodf_src = $(vkshaderpath)/twod.frag
@ -331,6 +339,14 @@ pushcolor_c = $(vkshaderpath)/pushcolor.frag.spvc
shadow_src = $(vkshaderpath)/shadow.geom
shadow_c = $(vkshaderpath)/shadow.geom.spvc
$(sprite_gbufv_c): $(sprite_gbufv_src)
$(sprite_gbuff_c): $(sprite_gbuff_src)
$(sprite_depthv_c): $(sprite_depthv_src)
$(sprite_depthf_c): $(sprite_depthf_src)
$(twodv_c): $(twodv_src)
$(twodf_c): $(twodf_src)
@ -374,6 +390,10 @@ $(pushcolor_c): $(pushcolor_src)
$(shadow_c): $(shadow_src)
vkshader_c = \
$(sprite_gbufv_c) \
$(sprite_gbuff_c) \
$(sprite_depthv_c) \
$(sprite_depthf_c) \
$(twodv_c) \
$(twodf_c) \
$(quakebspv_c) \

View file

@ -299,6 +299,26 @@
},
);
};
sprite_layout = {
setLayouts = (matrix_set, spritevrt_set, texture_set);
pushConstantRanges = (
{
stageFlags = vertex;
offset = 0;
size = "16 * 4";
},
{
stageFlags = vertex|fragment;
offset = 64;
size = "4";
},
{
stageFlags = fragment;
offset = 68;
size = "2 * 4 + 2 * 4 + 4 * 4";
},
);
};
lighting_layout = {
setLayouts = (lighting_attach, lighting_lights, lighting_shadow);
};
@ -344,6 +364,10 @@
topology = triangle_strip;
primitiveRestartEnable = true;
};
sprite = {
topology = triangle_strip;
primitiveRestartEnable = true;
};
};
vertexInput = {
@ -802,6 +826,58 @@
layout = quakebsp_layout;
renderPass = renderpass;
};
sprite_gbuf = {
subpass = 2;
stages = (
{
stage = vertex;
name = main;
module = $builtin/sprite_gbuf.vert;
},
{
stage = fragment;
name = main;
module = $builtin/sprite_gbuf.frag;
},
);
inputAssembly = $properties.inputAssembly.sprite;
viewport = $properties.viewport;
rasterization = $properties.rasterization.cw_cull_back;
multisample = $properties.multisample;
depthStencil = $properties.depthStencil.test_only;
colorBlend = $properties.pipelines.alias_gbuf.colorBlend;
dynamic = {
dynamicState = ( viewport, scissor, blend_constants );
};
layout = sprite_layout;
renderPass = renderpass;
};
sprite_depth = {
subpass = 0;
stages = (
{
stage = vertex;
name = main;
module = $builtin/sprite_depth.vert;
},
{
stage = fragment;
name = main;
module = $builtin/sprite_depth.frag;
},
);
inputAssembly = $properties.inputAssembly.alias;
viewport = $properties.viewport;
rasterization = $properties.rasterization.cw_cull_back;
multisample = $properties.multisample;
depthStencil = $properties.depthStencil.test_and_write;
colorBlend = $properties.pipelines.alias_gbuf.colorBlend;
dynamic = {
dynamicState = ( viewport, scissor );
};
layout = alias_layout;
renderPass = renderpass;
};
twod = {
subpass = 1;
stages = (

View file

@ -54,6 +54,14 @@
#include "vid_vulkan.h"
static
#include "libs/video/renderer/vulkan/shader/sprite_gbuf.vert.spvc"
static
#include "libs/video/renderer/vulkan/shader/sprite_gbuf.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/sprite_depth.vert.spvc"
static
#include "libs/video/renderer/vulkan/shader/sprite_depth.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/twod.vert.spvc"
static
@ -104,6 +112,10 @@ typedef struct shaderdata_s {
} shaderdata_t;
static shaderdata_t builtin_shaders[] = {
{ "sprite_gbuf.vert", sprite_gbuf_vert, sizeof (sprite_gbuf_vert) },
{ "sprite_gbuf.frag", sprite_gbuf_frag, sizeof (sprite_gbuf_frag) },
{ "sprite_depth.vert", sprite_depth_vert, sizeof (sprite_depth_vert) },
{ "sprite_depth.frag", sprite_depth_frag, sizeof (sprite_depth_frag) },
{ "twod.vert", twod_vert, sizeof (twod_vert) },
{ "twod.frag", twod_frag, sizeof (twod_frag) },
{ "quakebsp.vert", quakebsp_vert, sizeof (quakebsp_vert) },

View file

@ -0,0 +1,27 @@
#version 450
layout (constant_id = 0) const int MaxTextures = 256;
layout (set = 2, binding = 0) uniform sampler samp;
layout (set = 2, binding = 1) uniform texture2DArray sprites[MaxTextures];
layout (push_constant) uniform PushConstants {
layout (offset = 64)
int frame;
int spriteind;
// two slots
vec4 fog;
};
layout (location = 0) in vec2 st;
void
main (void)
{
vec4 pix;
pix = texture (sampler2DArray(sprites[spriteind], samp), vec3 (st, frame));
if (pix.a < 0.5) {
discard;
}
}

View file

@ -0,0 +1,31 @@
#version 450
layout (set = 0, binding = 0) uniform Matrices {
mat4 Projection3d;
mat4 View;
mat4 Sky;
mat4 Projection2d;
};
layout (set = 1, binding = 0) buffer Vertices {
vec4 xyuv[];
};
layout (push_constant) uniform PushConstants {
mat4 Model;
int frame;
};
layout (location = 0) out vec2 st;
void
main (void)
{
vec4 v = xyuv[frame * 4 + gl_VertexIndex];
vec4 pos = vec4 (0, 0, 0, 1);
pos += v.x * Model[1] + v.y * Model[2];
gl_Position = Projection3d * (View * pos);
st = v.zw;
}

View file

@ -0,0 +1,38 @@
#version 450
layout (constant_id = 0) const int MaxTextures = 256;
layout (set = 2, binding = 0) uniform sampler samp;
layout (set = 2, binding = 1) uniform texture2DArray sprites[MaxTextures];
layout (push_constant) uniform PushConstants {
layout (offset = 64)
int frame;
int spriteind;
// two slots
vec4 fog;
};
layout (location = 0) in vec2 st;
layout (location = 1) in vec4 position;
layout (location = 2) in vec3 normal;
layout (location = 0) out vec4 frag_color;
layout (location = 1) out vec4 frag_emission;
layout (location = 2) out vec4 frag_normal;
layout (location = 3) out vec4 frag_position;
void
main (void)
{
vec4 pix;
pix = texture (sampler2DArray(sprites[spriteind], samp), vec3 (st, frame));
if (pix.a < 0.5) {
discard;
}
frag_color = vec4(0,0,0,1);
frag_emission = pix;
frag_normal = vec4(normal, 1);
frag_position = position;
}

View file

@ -0,0 +1,35 @@
#version 450
layout (set = 0, binding = 0) uniform Matrices {
mat4 Projection3d;
mat4 View;
mat4 Sky;
mat4 Projection2d;
};
layout (set = 1, binding = 0) buffer Vertices {
vec4 xyuv[];
};
layout (push_constant) uniform PushConstants {
mat4 Model;
int frame;
};
layout (location = 0) out vec2 st;
layout (location = 1) out vec4 position;
layout (location = 2) out vec3 normal;
void
main (void)
{
vec4 v = xyuv[frame * 4 + gl_VertexIndex];
vec4 pos = vec4 (0, 0, 0, 1);
pos += v.x * Model[1] + v.y * Model[2];
gl_Position = Projection3d * (View * pos);
st = v.zw;
position = pos;
normal = -vec3(Model[0]);
}