From 2740f6093b8c12aa340a6ef02e06a5eed7f88dab Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 8 Dec 2021 16:44:22 +0900 Subject: [PATCH] [vulkan] Update shaders and layouts for new scheme Still need to work on the code, though. --- libs/video/renderer/vulkan/qfpipeline.plist | 97 ++----------------- libs/video/renderer/vulkan/shader/alias.vert | 5 +- .../renderer/vulkan/shader/alias_depth.vert | 5 +- .../renderer/vulkan/shader/alias_gbuf.frag | 4 +- .../renderer/vulkan/shader/bsp_depth.vert | 5 +- .../renderer/vulkan/shader/bsp_gbuf.frag | 7 +- .../renderer/vulkan/shader/bsp_gbuf.geom | 5 +- .../renderer/vulkan/shader/bsp_gbuf.vert | 3 +- .../video/renderer/vulkan/shader/bsp_sky.frag | 6 +- .../renderer/vulkan/shader/bsp_turb.frag | 4 +- .../renderer/vulkan/shader/quakebsp.vert | 5 +- 11 files changed, 35 insertions(+), 111 deletions(-) diff --git a/libs/video/renderer/vulkan/qfpipeline.plist b/libs/video/renderer/vulkan/qfpipeline.plist index b2c83ceb5..2a917b573 100644 --- a/libs/video/renderer/vulkan/qfpipeline.plist +++ b/libs/video/renderer/vulkan/qfpipeline.plist @@ -155,7 +155,7 @@ binding = 0; descriptorType = uniform_buffer; descriptorCount = 1; - stageFlags = vertex; + stageFlags = vertex|geometry; }, ); }; @@ -173,38 +173,14 @@ bindings = ( { binding = 0; - descriptorType = uniform_buffer; + descriptorType = sampler; descriptorCount = 1; - stageFlags = vertex|geometry; + stageFlags = fragment; }, { binding = 1; - descriptorType = combined_image_sampler; - descriptorCount = 1; - stageFlags = fragment; - }, - { - binding = 2; - descriptorType = combined_image_sampler; - descriptorCount = 1; - stageFlags = fragment; - }, - { - binding = 3; - descriptorType = combined_image_sampler; - descriptorCount = 1; - stageFlags = fragment; - }, - { - binding = 4; - descriptorType = combined_image_sampler; - descriptorCount = 1; - stageFlags = fragment; - }, - { - binding = 5; - descriptorType = combined_image_sampler; - descriptorCount = 1; + descriptorType = sampled_image; + descriptorCount = $properties.limits.maxImages; stageFlags = fragment; }, ); @@ -213,9 +189,9 @@ bindings = ( { binding = 0; - descriptorType = uniform_buffer; + descriptorType = sampler; descriptorCount = 1; - stageFlags = vertex; + stageFlags = fragment; }, { binding = 1; @@ -223,60 +199,6 @@ descriptorCount = $properties.limits.maxImages; stageFlags = fragment; }, - { - binding = 2; - descriptorType = sampler; - descriptorCount = 1; - stageFlags = fragment; - }, - ); - }; - alias_matrices = { - bindings = ( - { - binding = 0; - descriptorType = uniform_buffer; - descriptorCount = 1; - stageFlags = vertex; - }, - ); - }; - alias_textures = { - bindings = ( - { - binding = 0; - descriptorType = combined_image_sampler; - descriptorCount = 1; - stageFlags = fragment; - }, - { - binding = 1; - descriptorType = combined_image_sampler; - descriptorCount = 1; - stageFlags = fragment; - }, - { - binding = 2; - descriptorType = combined_image_sampler; - descriptorCount = 1; - stageFlags = fragment; - }, - { - binding = 3; - descriptorType = combined_image_sampler; - descriptorCount = 1; - stageFlags = fragment; - }, - ); - }; - alias_lights = { - bindings = ( - { - binding = 0; - descriptorType = uniform_buffer; - descriptorCount = 1; - stageFlags = fragment; - }, ); }; lighting_attach = { @@ -355,7 +277,7 @@ setLayouts = (matrix_set, twod_set); }; quakebsp_layout = { - setLayouts = (quakebsp_set); + setLayouts = (matrix_set, quakebsp_set); pushConstantRanges = ( { stageFlags = vertex; @@ -370,8 +292,7 @@ ); }; alias_layout = { - //setLayouts = (alias_matrices, alias_lights, alias_textures); - setLayouts = (alias_set); + setLayouts = (matrix_set, alias_set); pushConstantRanges = ( { stageFlags = vertex; diff --git a/libs/video/renderer/vulkan/shader/alias.vert b/libs/video/renderer/vulkan/shader/alias.vert index a54b43674..52f390781 100644 --- a/libs/video/renderer/vulkan/shader/alias.vert +++ b/libs/video/renderer/vulkan/shader/alias.vert @@ -1,9 +1,10 @@ #version 450 layout (set = 0, binding = 0) uniform Matrices { - mat4 Projection; + mat4 Projection3d; mat4 View; mat4 Sky; + mat4 Projection2d; }; layout (push_constant) uniform PushConstants { @@ -31,7 +32,7 @@ main (void) vertex = mix (vertexa, vertexb, blend); norm = mix (normala, normalb, blend); pos = (Model * vertex); - gl_Position = Projection * (View * pos); + gl_Position = Projection3d * (View * pos); position = pos; normal = mat3 (Model) * norm; st = uv; diff --git a/libs/video/renderer/vulkan/shader/alias_depth.vert b/libs/video/renderer/vulkan/shader/alias_depth.vert index 44437788e..2d580cd11 100644 --- a/libs/video/renderer/vulkan/shader/alias_depth.vert +++ b/libs/video/renderer/vulkan/shader/alias_depth.vert @@ -1,9 +1,10 @@ #version 450 layout (set = 0, binding = 0) uniform Matrices { - mat4 Projection; + mat4 Projection3d; mat4 View; mat4 Sky; + mat4 Projection2d; }; layout (push_constant) uniform PushConstants { @@ -24,5 +25,5 @@ main (void) vertex = mix (vertexa, vertexb, blend); pos = (Model * vertex); - gl_Position = Projection * (View * pos); + gl_Position = Projection3d * (View * pos); } diff --git a/libs/video/renderer/vulkan/shader/alias_gbuf.frag b/libs/video/renderer/vulkan/shader/alias_gbuf.frag index b09997caf..74c33e58f 100644 --- a/libs/video/renderer/vulkan/shader/alias_gbuf.frag +++ b/libs/video/renderer/vulkan/shader/alias_gbuf.frag @@ -2,8 +2,8 @@ layout (constant_id = 0) const int MaxTextures = 256; -layout (set = 0, binding = 1) uniform texture2DArray skins[MaxTextures]; -layout (set = 0, binding = 2) uniform sampler samp; +layout (set = 1, binding = 0) uniform sampler samp; +layout (set = 1, binding = 1) uniform texture2DArray skins[MaxTextures]; layout (push_constant) uniform PushConstants { layout (offset = 68) diff --git a/libs/video/renderer/vulkan/shader/bsp_depth.vert b/libs/video/renderer/vulkan/shader/bsp_depth.vert index 02a4fed80..8ee96735f 100644 --- a/libs/video/renderer/vulkan/shader/bsp_depth.vert +++ b/libs/video/renderer/vulkan/shader/bsp_depth.vert @@ -1,9 +1,10 @@ #version 450 layout (set = 0, binding = 0) uniform Matrices { - mat4 Projection; + mat4 Projection3d; mat4 View; mat4 Sky; + mat4 Projection2d; }; layout (push_constant) uniform PushConstants { @@ -15,5 +16,5 @@ layout (location = 0) in vec4 vertex; void main (void) { - gl_Position = Projection * (View * (Model * vertex)); + gl_Position = Projection3d * (View * (Model * vertex)); } diff --git a/libs/video/renderer/vulkan/shader/bsp_gbuf.frag b/libs/video/renderer/vulkan/shader/bsp_gbuf.frag index 2be3743ca..1e70788b5 100644 --- a/libs/video/renderer/vulkan/shader/bsp_gbuf.frag +++ b/libs/video/renderer/vulkan/shader/bsp_gbuf.frag @@ -2,11 +2,8 @@ layout (constant_id = 0) const int MaxTextures = 256; -layout (set = 0, binding = 1) uniform texture2DArray textures[MaxTextures]; -layout (set = 0, binding = 2) uniform sampler samp; - -layout (set = 0, binding = 1) uniform sampler2D Texture; -layout (set = 0, binding = 2) uniform sampler2D GlowMap; +layout (set = 1, binding = 0) uniform sampler samp; +layout (set = 1, binding = 1) uniform texture2DArray textures[MaxTextures]; layout (push_constant) uniform PushConstants { layout (offset = 64) diff --git a/libs/video/renderer/vulkan/shader/bsp_gbuf.geom b/libs/video/renderer/vulkan/shader/bsp_gbuf.geom index bb46ae43a..44f17a3b1 100644 --- a/libs/video/renderer/vulkan/shader/bsp_gbuf.geom +++ b/libs/video/renderer/vulkan/shader/bsp_gbuf.geom @@ -1,9 +1,10 @@ #version 450 layout (set = 0, binding = 0) uniform Matrices { - mat4 Projection; + mat4 Projection3d; mat4 View; mat4 Sky; + mat4 Projection2d; }; layout (triangles) in; @@ -27,7 +28,7 @@ main() for (int vert = 0; vert < 3; vert++) { vec4 p = gl_in[vert].gl_Position; - gl_Position = Projection * (View * (p)); + gl_Position = Projection3d * (View * (p)); tl_st = v_tl_st[vert]; direction = v_direction[vert]; normal = n; diff --git a/libs/video/renderer/vulkan/shader/bsp_gbuf.vert b/libs/video/renderer/vulkan/shader/bsp_gbuf.vert index abfb6c4e6..7b80384c5 100644 --- a/libs/video/renderer/vulkan/shader/bsp_gbuf.vert +++ b/libs/video/renderer/vulkan/shader/bsp_gbuf.vert @@ -1,9 +1,10 @@ #version 450 layout (set = 0, binding = 0) uniform Matrices { - mat4 Projection; + mat4 Projection3d; mat4 View; mat4 Sky; + mat4 Projection2d; }; layout (push_constant) uniform PushConstants { diff --git a/libs/video/renderer/vulkan/shader/bsp_sky.frag b/libs/video/renderer/vulkan/shader/bsp_sky.frag index 0c8dc7893..dc6fe6d6a 100644 --- a/libs/video/renderer/vulkan/shader/bsp_sky.frag +++ b/libs/video/renderer/vulkan/shader/bsp_sky.frag @@ -4,9 +4,9 @@ layout (constant_id = 0) const int MaxTextures = 256; layout (constant_id = 1) const bool doSkyBox = false; layout (constant_id = 2) const bool doSkySheet = false; -layout (set = 0, binding = 1) uniform texture2DArray sheet_tex[MaxTextures]; -layout (set = 0, binding = 1) uniform textureCube cube_tex[MaxTextures]; -layout (set = 0, binding = 2) uniform sampler samp; +layout (set = 1, binding = 0) uniform sampler samp; +layout (set = 1, binding = 1) uniform texture2DArray sheet_tex[MaxTextures]; +layout (set = 1, binding = 1) uniform textureCube cube_tex[MaxTextures]; layout (push_constant) uniform PushConstants { layout (offset = 64) diff --git a/libs/video/renderer/vulkan/shader/bsp_turb.frag b/libs/video/renderer/vulkan/shader/bsp_turb.frag index 9929e60e1..969e9221f 100644 --- a/libs/video/renderer/vulkan/shader/bsp_turb.frag +++ b/libs/video/renderer/vulkan/shader/bsp_turb.frag @@ -2,8 +2,8 @@ layout (constant_id = 0) const int MaxTextures = 256; -layout (set = 0, binding = 1) uniform texture2D textures[MaxTextures]; -layout (set = 0, binding = 2) uniform sampler samp; +layout (set = 1, binding = 0) uniform sampler samp; +layout (set = 1, binding = 1) uniform texture2D textures[MaxTextures]; layout (push_constant) uniform PushConstants { layout (offset = 64) diff --git a/libs/video/renderer/vulkan/shader/quakebsp.vert b/libs/video/renderer/vulkan/shader/quakebsp.vert index bb9e87e4a..397bd2595 100644 --- a/libs/video/renderer/vulkan/shader/quakebsp.vert +++ b/libs/video/renderer/vulkan/shader/quakebsp.vert @@ -1,9 +1,10 @@ #version 450 layout (set = 0, binding = 0) uniform Matrices { - mat4 Projection; + mat4 Projection3d; mat4 View; mat4 Sky; + mat4 Projection2d; }; layout (push_constant) uniform PushConstants { @@ -19,7 +20,7 @@ layout (location = 1) out vec3 direction; void main (void) { - gl_Position = Projection * (View * (Model * vertex)); + gl_Position = Projection3d * (View * (Model * vertex)); direction = (Sky * vertex).xyz; tl_st = tl_uv; }