From 2c0e7033edcceb61be16cec1df663befb4c84479 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Tue, 7 Nov 2023 13:30:46 -0500 Subject: [PATCH] vk: fix crashing on maps with skybox We were using a negative value for `SURF_SKY` surfaces, which hit an assert on uploading kusochki. --- ref/vk/TODO.md | 11 ++++++++++- ref/vk/shaders/ray_interop.h | 2 +- ref/vk/vk_brush.c | 2 +- ref/vk/vk_materials.c | 5 +++++ ref/vk/vk_ray_model.c | 7 +++++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ref/vk/TODO.md b/ref/vk/TODO.md index 65a6f61c..f5ce32c0 100644 --- a/ref/vk/TODO.md +++ b/ref/vk/TODO.md @@ -4,6 +4,13 @@ - [x] remove stvecs from patches -- not used, inconvenient - [x] patch texture coordinates by matrices - [x] add `_xvk_tex_rotate` +- [x] ASSERT in c2a5 -- skybox sentinel +- [ ] woditschka + - [ ] height not switching to negative underwater + - not even sure we need it? + - [ ] do not draw water sides when not requested. + - [ ] potentially collinear planes vs ray tracing #264 +- [ ] update animated textures is now super slow # 2023-11-06 E325 - [x] fix material asserts and inherit @@ -182,7 +189,6 @@ - [ ] rtx: do not rebuild static studio models (most of them). BLAS building takes most of the frame time (~12ms where ray tracing itself is just 3ms) - [ ] rtx: importance-sample sky light; there are sky surfaces that we can consider light sources - [ ] cull water surfaces (see c3a2a) -- [ ] create water surfaces once in vk_brush - [ ] consider doing per-geometry rendermode: brushes can be built only once; late transparency depth sorting for vk render; - [ ] rtx: too many emissive lights in c3a1b - [ ] studio models: pre-compute buffer sizes and allocate them at once @@ -606,3 +612,6 @@ - [x] render skybox - [x] better flashlight: spotlight instead of dlight point - [x] rtx: add fps: rasterize into G-buffer, and only then compute lighting with rtx + +# Done somewhen +- [x] create water surfaces once in vk_brush diff --git a/ref/vk/shaders/ray_interop.h b/ref/vk/shaders/ray_interop.h index bc4c28f9..0fd0e740 100644 --- a/ref/vk/shaders/ray_interop.h +++ b/ref/vk/shaders/ray_interop.h @@ -71,7 +71,7 @@ LIST_SPECIALIZATION_CONSTANTS(DECLARE_SPECIALIZATION_CONSTANT) #define MATERIAL_MODE_BLEND_GLOW 5 #define MATERIAL_MODE_COUNT 6 -#define TEX_BASE_SKYBOX 0xffffffffu +#define TEX_BASE_SKYBOX 0x0f000000u struct Material { uint tex_base_color; diff --git a/ref/vk/vk_brush.c b/ref/vk/vk_brush.c index efdd9d65..1950a00e 100644 --- a/ref/vk/vk_brush.c +++ b/ref/vk/vk_brush.c @@ -1174,7 +1174,7 @@ static qboolean fillBrushSurfaces(fill_geometries_args_t args) { model_geometry->index_offset = index_offset; if ( type == BrushSurface_Sky ) { -#define TEX_BASE_SKYBOX 0xffffffffu // FIXME ray_interop.h +#define TEX_BASE_SKYBOX 0x0f000000u // FIXME ray_interop.h model_geometry->material.tex_base_color = TEX_BASE_SKYBOX; } else { ASSERT(!FBitSet( surf->flags, SURF_DRAWTILED )); diff --git a/ref/vk/vk_materials.c b/ref/vk/vk_materials.c index 1f8fbe84..d2135aaf 100644 --- a/ref/vk/vk_materials.c +++ b/ref/vk/vk_materials.c @@ -161,6 +161,11 @@ static int addMaterial(const char *name, const r_vk_material_t* mat) { printMaterial(g_materials.count); + ASSERT(mat->tex_base_color >= 0); + ASSERT(mat->tex_metalness >= 0); + ASSERT(mat->tex_roughness >= 0); + ASSERT(mat->tex_normalmap >= 0); + return g_materials.count++; } diff --git a/ref/vk/vk_ray_model.c b/ref/vk/vk_ray_model.c index 76c407dc..6a481116 100644 --- a/ref/vk/vk_ray_model.c +++ b/ref/vk/vk_ray_model.c @@ -30,9 +30,16 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr ASSERT(mat); ASSERT(mat->tex_base_color >= 0); + ASSERT(mat->tex_base_color < MAX_TEXTURES || mat->tex_base_color == TEX_BASE_SKYBOX); + ASSERT(mat->tex_roughness >= 0); + ASSERT(mat->tex_roughness < MAX_TEXTURES); + ASSERT(mat->tex_metalness >= 0); + ASSERT(mat->tex_metalness < MAX_TEXTURES); + ASSERT(mat->tex_normalmap >= 0); + ASSERT(mat->tex_normalmap < MAX_TEXTURES); // TODO split kusochki into static geometry data and potentially dynamic material data // This data is static, should never change