From dfcfd786a9fa07515877d6f4af06936bd1096b58 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Mon, 6 Nov 2023 10:31:55 -0500 Subject: [PATCH 1/4] vk: fix material basecolor_map handling - Do not replace inherited base color texture - Do not acquire default base color texture Fixes #638 --- ref/vk/vk_materials.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ref/vk/vk_materials.c b/ref/vk/vk_materials.c index 8fb9318b..074b858e 100644 --- a/ref/vk/vk_materials.c +++ b/ref/vk/vk_materials.c @@ -126,7 +126,8 @@ static void printMaterial(int index) { static void acquireTexturesForMaterial( int index ) { const r_vk_material_t *mat = &g_materials.table[index].material; DEBUG("%s(%d: %s)", __FUNCTION__, index, g_materials.table[index].name); - R_TextureAcquire(mat->tex_base_color); + if (mat->tex_base_color > 0) + R_TextureAcquire(mat->tex_base_color); R_TextureAcquire(mat->tex_metalness); R_TextureAcquire(mat->tex_roughness); if (mat->tex_normalmap > 0) @@ -134,7 +135,8 @@ static void acquireTexturesForMaterial( int index ) { } static void releaseTexturesForMaterialPtr( const r_vk_material_t *mat ) { - R_TextureRelease(mat->tex_base_color); + if (mat->tex_base_color > 0) + R_TextureRelease(mat->tex_base_color); R_TextureRelease(mat->tex_metalness); R_TextureRelease(mat->tex_roughness); if (mat->tex_normalmap > 0) @@ -245,8 +247,11 @@ static void loadMaterialsFromFile( const char *filename, int depth ) { continue; } + // If basecolor_map wasn't inherited + if (current_material.tex_base_color < 0) { // Start with *default texture for base color, it will be acquired if no replacement is specified or could be loaded. - current_material.tex_base_color = for_tex_id >= 0 ? for_tex_id : 0; + current_material.tex_base_color = for_tex_id >= 0 ? for_tex_id : 0; + } #define LOAD_TEXTURE_FOR(name, field, colorspace) \ do { \ From f8c0baf78d068e25fa0482dd6844212db6c722e1 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Mon, 6 Nov 2023 11:07:58 -0500 Subject: [PATCH 2/4] vk: fixup -vkverboselogs, make it actually work --- ref/vk/TODO.md | 4 ++++ ref/vk/vk_core.c | 6 +++--- ref/vk/vk_ray_model.c | 5 +++++ ref/vk/vk_scene.c | 1 - 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ref/vk/TODO.md b/ref/vk/TODO.md index a9793e5c..31110033 100644 --- a/ref/vk/TODO.md +++ b/ref/vk/TODO.md @@ -1,3 +1,7 @@ +# 2023-11-06 E325 +- [x] fix material asserts and inherit +- [ ] changing textures on buttons, etc + # 2023-11-03 E324 - [x] add cvar for displaying only specified channel - [x] r_lightmap diff --git a/ref/vk/vk_core.c b/ref/vk/vk_core.c index 4d2e9dab..135376a3 100644 --- a/ref/vk/vk_core.c +++ b/ref/vk/vk_core.c @@ -700,15 +700,15 @@ qboolean R_VkInit( void ) vk_core.debug = vk_core.validate || !!(gEngine.Sys_CheckParm("-vkdebug") || gEngine.Sys_CheckParm("-gldebug")); vk_core.rtx = false; + VK_LoadCvars(); + VK_LogsReadCvar(); + // Force extremely verbose logs at startup. // This is instrumental in some investigations, because the usual "vk_debug_log" cvar is not set // at this point and cannot be used to selectively swith things on. if (gEngine.Sys_CheckParm("-vkverboselogs")) g_log_debug_bits = 0xffffffffu; - VK_LoadCvars(); - VK_LogsReadCvar(); - R_SpeedsInit(); if( !gEngine.R_Init_Video( REF_VULKAN )) // request Vulkan surface diff --git a/ref/vk/vk_ray_model.c b/ref/vk/vk_ray_model.c index 478f3fa8..76c407dc 100644 --- a/ref/vk/vk_ray_model.c +++ b/ref/vk/vk_ray_model.c @@ -29,6 +29,11 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr const r_vk_material_t *const mat = override_material ? override_material : &geom->material; ASSERT(mat); + ASSERT(mat->tex_base_color >= 0); + ASSERT(mat->tex_roughness >= 0); + ASSERT(mat->tex_metalness >= 0); + ASSERT(mat->tex_normalmap >= 0); + // TODO split kusochki into static geometry data and potentially dynamic material data // This data is static, should never change kusok->vertex_offset = geom->vertex_offset; diff --git a/ref/vk/vk_scene.c b/ref/vk/vk_scene.c index c84c12f9..a40617a7 100644 --- a/ref/vk/vk_scene.c +++ b/ref/vk/vk_scene.c @@ -144,7 +144,6 @@ static void preloadModels( void ) { } static void loadMap(const model_t* const map) { - VK_LogsReadCvar(); mapLoadBegin(map); R_SpriteNewMapFIXME(); From 4509e2075d5b6b62769939a898e825c3a7630c5a Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Mon, 6 Nov 2023 11:42:07 -0500 Subject: [PATCH 3/4] vk: fix changing textures on buttons, etc Detect changes in alternate_anims sequences. Fixes #640 --- ref/vk/TODO.md | 3 ++- ref/vk/vk_brush.c | 44 +++++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/ref/vk/TODO.md b/ref/vk/TODO.md index 31110033..23e51bff 100644 --- a/ref/vk/TODO.md +++ b/ref/vk/TODO.md @@ -1,6 +1,7 @@ # 2023-11-06 E325 - [x] fix material asserts and inherit -- [ ] changing textures on buttons, etc +- [x] fixup -vkverboselogs +- [x] changing textures on buttons, etc # 2023-11-03 E324 - [x] add cvar for displaying only specified channel diff --git a/ref/vk/vk_brush.c b/ref/vk/vk_brush.c index 19eadc46..5ed7d6e0 100644 --- a/ref/vk/vk_brush.c +++ b/ref/vk/vk_brush.c @@ -404,32 +404,35 @@ static void fillWaterSurfaces( const cl_entity_t *ent, vk_brush_model_t *bmodel, static rt_light_add_polygon_t loadPolyLight(const model_t *mod, const int surface_index, const msurface_t *surf, const vec3_t emissive); -static qboolean isSurfaceAnimated( const msurface_t *s ) { - const texture_t *base = s->texinfo->texture; - - /* FIXME don't have ent here, need to check both explicitly - if( ent && ent->curstate.frame ) { - if( base->alternate_anims ) - base = base->alternate_anims; - } - */ - - if( !base->anim_total ) +static qboolean doesTextureChainChange( const texture_t *const base ) { + const texture_t *cur = base; + if (!cur) return false; + cur = cur->anim_next; + while (cur && cur != base) { + if (cur->gl_texturenum != base->gl_texturenum) + return true; + cur = cur->anim_next; + } + return false; +} + +static qboolean isSurfaceAnimated( const msurface_t *s ) { + const texture_t *const base = s->texinfo->texture; + + if( !base->anim_total && !base->alternate_anims ) + return false; + + /* TODO why did we do this? It doesn't seem to rule out animation really. if( base->name[0] == '-' ) return false; + */ - // It is not an animation if all textures are the same - const texture_t *prev = base; - base = base->anim_next; - while (base && base != prev) { - if (prev->gl_texturenum != base->gl_texturenum) - return true; - base = base->anim_next; - } + if (base->alternate_anims && base->gl_texturenum != base->alternate_anims->gl_texturenum) + return true; - return false; + return doesTextureChainChange(base) || doesTextureChainChange(base->alternate_anims); } typedef enum { @@ -742,7 +745,6 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co const int geom_index = bmodel->animated_indexes[i]; vk_render_geometry_t *geom = bmodel->render_model.geometries + geom_index; const int surface_index = geom->surf_deprecate - mod->surfaces; - const xvk_patch_surface_t *const patch_surface = R_VkPatchGetSurface(surface_index); // Optionally patch by texture_s pointer and run animations const texture_t *t = R_TextureAnimation(ent, geom->surf_deprecate); From a25bf841ac174adb354ada0eefc827f87f74fe10 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Mon, 6 Nov 2023 12:47:21 -0500 Subject: [PATCH 4/4] vk: fix bright artifacts coming from unpatched chrome materials Fixes a typo that rewrote roughness value with garbage. Also adds a few more debug channel displays for lighting phases. And prints out available debug displays. Fixes #641 --- ref/vk/TODO.md | 1 + ref/vk/shaders/bounce.comp | 1 + ref/vk/shaders/denoiser.comp | 15 +++++++++++++++ ref/vk/shaders/ray_interop.h | 4 ++++ ref/vk/vk_materials.c | 2 +- ref/vk/vk_rtx.c | 11 +++++++++++ 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ref/vk/TODO.md b/ref/vk/TODO.md index 23e51bff..814518f5 100644 --- a/ref/vk/TODO.md +++ b/ref/vk/TODO.md @@ -2,6 +2,7 @@ - [x] fix material asserts and inherit - [x] fixup -vkverboselogs - [x] changing textures on buttons, etc +- [x] fix unpatched chrome surfaces brightness glitches # 2023-11-03 E324 - [x] add cvar for displaying only specified channel diff --git a/ref/vk/shaders/bounce.comp b/ref/vk/shaders/bounce.comp index 291ceada..65f7b76b 100644 --- a/ref/vk/shaders/bounce.comp +++ b/ref/vk/shaders/bounce.comp @@ -149,6 +149,7 @@ void computeBounce(ivec2 pix, vec3 direction, out vec3 diffuse, out vec3 specula RayPayloadPrimary payload; payload.base_color_a = vec4(0.); payload.emissive = vec4(0.); + payload.material_rmxx = vec4(0.); const vec3 pos = imageLoad(position_t, pix).xyz + geometry_normal * ray_normal_fudge; if (!getHit(pos, bounce_direction, payload)) return; diff --git a/ref/vk/shaders/denoiser.comp b/ref/vk/shaders/denoiser.comp index d0bb55c9..d2fe3fd2 100644 --- a/ref/vk/shaders/denoiser.comp +++ b/ref/vk/shaders/denoiser.comp @@ -213,6 +213,21 @@ void main() { const Components c = blurSamples(res, pix); + if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_DISABLED) { + } else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_DIRECT) { + imageStore(out_dest, pix, vec4(LINEARtoSRGB(c.direct_diffuse + c.direct_specular), 0.)); return; + return; + } else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_INDIRECT) { + imageStore(out_dest, pix, vec4(LINEARtoSRGB(c.indirect_diffuse + c.indirect_specular), 0.)); return; + return; + } else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_INDIRECT_SPEC) { + imageStore(out_dest, pix, vec4(LINEARtoSRGB(c.indirect_specular), 0.)); return; + return; + } else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_INDIRECT_DIFF) { + imageStore(out_dest, pix, vec4(LINEARtoSRGB(c.indirect_diffuse), 0.)); return; + return; + } + vec3 colour = vec3(0.); { // TODO: need to extract reprojecting from this shader because reprojected stuff need svgf denoising pass after it diff --git a/ref/vk/shaders/ray_interop.h b/ref/vk/shaders/ray_interop.h index 431a4fee..bc4c28f9 100644 --- a/ref/vk/shaders/ray_interop.h +++ b/ref/vk/shaders/ray_interop.h @@ -176,6 +176,10 @@ struct PushConstants { #define DEBUG_DISPLAY_NGEOM 5 #define DEBUG_DISPLAY_LIGHTING 6 #define DEBUG_DISPLAY_SURFHASH 7 +#define DEBUG_DISPLAY_DIRECT 8 +#define DEBUG_DISPLAY_INDIRECT 9 +#define DEBUG_DISPLAY_INDIRECT_SPEC 10 +#define DEBUG_DISPLAY_INDIRECT_DIFF 11 // add more when needed struct UniformBuffer { diff --git a/ref/vk/vk_materials.c b/ref/vk/vk_materials.c index 074b858e..1f8fbe84 100644 --- a/ref/vk/vk_materials.c +++ b/ref/vk/vk_materials.c @@ -566,7 +566,7 @@ r_vk_material_t R_VkMaterialGetForTextureWithFlags( int tex_index, uint32_t flag ret.tex_base_color = tex_index; if ( flags & kVkMaterialFlagChrome ) - ret.roughness = tglob.grayTexture; + ret.tex_roughness = tglob.grayTexture; //DEBUG("Returning default material with tex_base_color=%d", tex_index); return ret; diff --git a/ref/vk/vk_rtx.c b/ref/vk/vk_rtx.c index 6c470677..72890295 100644 --- a/ref/vk/vk_rtx.c +++ b/ref/vk/vk_rtx.c @@ -164,6 +164,10 @@ static void parseDebugDisplayValue( void ) { X(NSHADE) \ X(NGEOM) \ X(SURFHASH) \ + X(DIRECT) \ + X(INDIRECT) \ + X(INDIRECT_SPEC) \ + X(INDIRECT_DIFF) \ #define X(suffix) \ if (0 == Q_stricmp(cvalue, #suffix)) { \ @@ -174,6 +178,13 @@ static void parseDebugDisplayValue( void ) { LIST_DISPLAYS(X) #undef X + if (Q_strlen(cvalue) > 0) { + gEngine.Con_Printf("Invalid rt_debug_display_only mode %s. Valid modes are:\n", cvalue); +#define X(suffix) gEngine.Con_Printf("\t%s\n", #suffix); +LIST_DISPLAYS(X) +#undef X + } + g_rtx.debug.rt_debug_display_only_value = DEBUG_DISPLAY_DISABLED; }