Skip to content

Commit

Permalink
Merge pull request #642 from w23/E325
Browse files Browse the repository at this point in the history
Things done during stream E325

- [x] fix #638
- [x] fix #640 
- [x] fix #641
  • Loading branch information
w23 authored Nov 6, 2023
2 parents d5ee8ba + a25bf84 commit a18ed8d
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 26 deletions.
6 changes: 6 additions & 0 deletions ref/vk/TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2023-11-06 E325
- [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
- [x] r_lightmap
Expand Down
1 change: 1 addition & 0 deletions ref/vk/shaders/bounce.comp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions ref/vk/shaders/denoiser.comp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ref/vk/shaders/ray_interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 20 additions & 18 deletions ref/vk/vk_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
static qboolean doesTextureChainChange( const texture_t *const base ) {
const texture_t *cur = base;
if (!cur)
return false;

/* FIXME don't have ent here, need to check both explicitly
if( ent && ent->curstate.frame ) {
if( base->alternate_anims )
base = base->alternate_anims;
cur = cur->anim_next;
while (cur && cur != base) {
if (cur->gl_texturenum != base->gl_texturenum)
return true;
cur = cur->anim_next;
}
*/
return false;
}

if( !base->anim_total )
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 {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions ref/vk/vk_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions ref/vk/vk_materials.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,17 @@ 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)
R_TextureAcquire(mat->tex_normalmap);
}

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)
Expand Down Expand Up @@ -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 { \
Expand Down Expand Up @@ -561,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;
Expand Down
5 changes: 5 additions & 0 deletions ref/vk/vk_ray_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions ref/vk/vk_rtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) { \
Expand All @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion ref/vk/vk_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ static void preloadModels( void ) {
}

static void loadMap(const model_t* const map) {
VK_LogsReadCvar();
mapLoadBegin(map);

R_SpriteNewMapFIXME();
Expand Down

0 comments on commit a18ed8d

Please sign in to comment.