From 7642ef57581430ff279d6a7a2758509a253808d6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 12 Jul 2023 23:30:43 +0900 Subject: [PATCH] [vulkan] Add debug displays for lights and bsp The lights debug is from the light splat experiment (this is why I kept the code), and the bsp debug is based on that. Both currently disabled for now until I get UI controls in. --- libs/video/renderer/Makemodule.am | 6 ++ libs/video/renderer/vulkan/rp_main_def.plist | 64 ++++++++++++++++---- libs/video/renderer/vulkan/shader.c | 3 + libs/video/renderer/vulkan/shader/debug.frag | 10 +++ libs/video/renderer/vulkan/vulkan_lighting.c | 8 +-- 5 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 libs/video/renderer/vulkan/shader/debug.frag diff --git a/libs/video/renderer/Makemodule.am b/libs/video/renderer/Makemodule.am index 312eae7e7..ac47caab1 100644 --- a/libs/video/renderer/Makemodule.am +++ b/libs/video/renderer/Makemodule.am @@ -326,6 +326,8 @@ bsp_skyf_src = $(vkshaderpath)/bsp_sky.frag bsp_skyf_c = $(vkshaderpath)/bsp_sky.frag.spvc bsp_turbf_src = $(vkshaderpath)/bsp_turb.frag bsp_turbf_c = $(vkshaderpath)/bsp_turb.frag.spvc +debug_src = $(vkshaderpath)/debug.frag +debug_c = $(vkshaderpath)/debug.frag.spvc light_flat_src = $(vkshaderpath)/light_flat.vert light_flat_c = $(vkshaderpath)/light_flat.vert.spvc light_splatv_src = $(vkshaderpath)/light_splat.vert @@ -420,6 +422,8 @@ $(bsp_skyf_c): $(bsp_skyf_src) $(oit_store) $(oit_h) $(bsp_turbf_c): $(bsp_turbf_src) $(oit_store) $(oit_h) +$(debug_c): $(debug_src) $(lighting_h) + $(light_flat_c): $(light_flat_src) $(lighting_h) $(light_splatv_c): $(light_splatv_src) $(lighting_h) @@ -488,6 +492,7 @@ vkshader_c = \ $(bsp_shadow_c) \ $(bsp_skyf_c) \ $(bsp_turbf_c) \ + $(debug_c) \ $(light_flat_c) \ $(light_splatv_c) \ $(light_splatf_c) \ @@ -576,6 +581,7 @@ EXTRA_DIST += \ $(bsp_shadow_src) \ $(bsp_skyf_src) \ $(bsp_turbf_src) \ + $(debug_src) \ $(light_flat_src) \ $(light_splatv_src) \ $(light_splatf_src) \ diff --git a/libs/video/renderer/vulkan/rp_main_def.plist b/libs/video/renderer/vulkan/rp_main_def.plist index fa0251a51..6bd3854c6 100644 --- a/libs/video/renderer/vulkan/rp_main_def.plist +++ b/libs/video/renderer/vulkan/rp_main_def.plist @@ -100,6 +100,15 @@ properties = { depthBiasEnable = false; lineWidth = 1; }; + debug_poly_lines = { + depthClampEnable = false; + rasterizerDiscardEnable = false; + polygonMode = line; + cullMode = none; + frontFace = clockwise; + depthBiasEnable = false; + lineWidth = 1; + }; cw_cull_back = { depthClampEnable = false; rasterizerDiscardEnable = false; @@ -228,6 +237,11 @@ properties = { name = main; module = $builtin/bsp_depth.vert; }; + debug_fragment = { + stage = fragment; + name = main; + module = $builtin/debug.frag; + }; gbuf_vertex = { stage = vertex; name = main; @@ -1499,8 +1513,44 @@ renderpasses = { ); layout = $compose.layout; }; - /*debug = { + debug_bsp = { @inherit = $compose_base; + disabled = true; + + color = $color.bsp; + tasks = ( + { func = bsp_draw_queue; + params = (main, solid, 0); }, + { func = bsp_draw_queue; + params = (main, sky, 0); }, + { func = bsp_draw_queue; + params = (main, translucent, 0); }, + { func = bsp_draw_queue; + params = (main, turbulent, 0); }, + ); + + stages = ( + $brush.shader.depth_vertex, + $brush.shader.debug_fragment, + ); + vertexInput = { + bindings = ( + "$brush.vertexInput.bindings[0]", + "$brush.vertexInput.bindings[1]", + ); + attributes = ( + "$brush.vertexInput.attributes[0]", + "$brush.vertexInput.attributes[2]", + ); + }; + inputAssembly = $brush.inputAssembly; + layout = $brush.layout; + rasterization = $debug_poly_lines; + depthStencil = $depth_disable; + }; + debug_lights = { + @inherit = $compose_base; + disabled = true; color = $color.lights; tasks = ( @@ -1515,17 +1565,9 @@ renderpasses = { vertexInput = $lighting.vertexInput_splat; inputAssembly = $lighting.inputAssembly; layout = $lighting.layout; - rasterization = { - depthClampEnable = false; - rasterizerDiscardEnable = false; - polygonMode = line; - cullMode = none; - frontFace = clockwise; - depthBiasEnable = false; - lineWidth = 1; - }; + rasterization = $debug_poly_lines; depthStencil = $depth_disable; - };*/ + }; }; }; }; diff --git a/libs/video/renderer/vulkan/shader.c b/libs/video/renderer/vulkan/shader.c index cb515a70f..ef6919058 100644 --- a/libs/video/renderer/vulkan/shader.c +++ b/libs/video/renderer/vulkan/shader.c @@ -89,6 +89,8 @@ static static #include "libs/video/renderer/vulkan/shader/bsp_turb.frag.spvc" static +#include "libs/video/renderer/vulkan/shader/debug.frag.spvc" +static #include "libs/video/renderer/vulkan/shader/light_flat.vert.spvc" static #include "libs/video/renderer/vulkan/shader/light_splat.vert.spvc" @@ -163,6 +165,7 @@ static shaderdata_t builtin_shaders[] = { { "bsp_shadow.vert", bsp_shadow_vert, sizeof (bsp_shadow_vert) }, { "bsp_sky.frag", bsp_sky_frag, sizeof (bsp_sky_frag) }, { "bsp_turb.frag", bsp_turb_frag, sizeof (bsp_turb_frag) }, + { "debug.frag", debug_frag, sizeof (debug_frag) }, { "light_flat.vert", light_flat_vert, sizeof (light_flat_vert) }, { "light_splat.vert", light_splat_vert, sizeof (light_splat_vert) }, { "light_splat.frag", light_splat_frag, sizeof (light_splat_frag) }, diff --git a/libs/video/renderer/vulkan/shader/debug.frag b/libs/video/renderer/vulkan/shader/debug.frag new file mode 100644 index 000000000..257f9456f --- /dev/null +++ b/libs/video/renderer/vulkan/shader/debug.frag @@ -0,0 +1,10 @@ +#version 450 +#extension GL_GOOGLE_include_directive : enable + +layout (location = 0) out vec4 frag_color; + +void +main (void) +{ + frag_color = gl_FrontFacing ? vec4 (0, 1, 0, 1) : vec4 (1, 0, 0, 1); +} diff --git a/libs/video/renderer/vulkan/vulkan_lighting.c b/libs/video/renderer/vulkan/vulkan_lighting.c index e3419dc6b..70cba51a6 100644 --- a/libs/video/renderer/vulkan/vulkan_lighting.c +++ b/libs/video/renderer/vulkan/vulkan_lighting.c @@ -248,10 +248,10 @@ lighting_update_lights (const exprval_t **params, exprval_t *result, QFV_PacketCopyBuffer (packet, lframe->data_buffer, 0, &bufferBarriers[qfv_BB_TransferWrite_to_UniformRead]); QFV_PacketSubmit (packet); - if (0) { + uint32_t id_count = lframe->ico_count + lframe->cone_count + + lframe->flat_count; + if (id_count) { packet = QFV_PacketAcquire (ctx->staging); - uint32_t id_count = lframe->ico_count + lframe->cone_count - + lframe->flat_count; uint32_t *ids = QFV_PacketExtend (packet, id_count * sizeof (uint32_t)); memcpy (ids, ico_ids, lframe->ico_count * sizeof (uint32_t)); ids += lframe->ico_count; @@ -335,7 +335,7 @@ lighting_bind_descriptors (const exprval_t **params, exprval_t *result, }; dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, 3, sets, 0, 0); - if (0) { + if (1) { VkBuffer buffers[] = { lframe->id_buffer, lctx->splat_verts,