mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-17 06:30:44 +01:00
rtx: fix brush models being invisible
An incorrect range of used vertices was pased into `VkAccelerationStructureGeometryTrianglesDataKHR`. `maxVertex` was being set to a count of vertices per geometry, not a maximum used vertex number. The fix is to track `vertex_offset` of the first used vertex, which makes `maxVertex` correct.
This commit is contained in:
parent
2034acbe76
commit
750d3b7608
@ -482,12 +482,14 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
|
||||
}
|
||||
|
||||
model_geometry->surf = surf;
|
||||
model_geometry->index_offset = index_offset;
|
||||
model_geometry->vertex_offset = 0;
|
||||
model_geometry->texture = t;
|
||||
model_geometry->vertex_count = surf->numedges;
|
||||
|
||||
model_geometry->vertex_buffer = vertex_buffer;
|
||||
model_geometry->vertex_offset = vertex_offset;
|
||||
model_geometry->vertex_count = surf->numedges;
|
||||
|
||||
model_geometry->index_buffer = index_buffer;
|
||||
model_geometry->index_offset = index_offset;
|
||||
|
||||
if( FBitSet( surf->flags, SURF_DRAWSKY )) {
|
||||
model_geometry->material = kXVkMaterialSky;
|
||||
@ -538,9 +540,9 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
|
||||
|
||||
// Ray tracing apparently expects triangle list only (although spec is not very clear about this kekw)
|
||||
if (k > 1) {
|
||||
*(bind++) = (uint16_t)(vertex_offset + 0);
|
||||
*(bind++) = (uint16_t)(vertex_offset + k - 1);
|
||||
*(bind++) = (uint16_t)(vertex_offset + k);
|
||||
*(bind++) = (uint16_t)(0);
|
||||
*(bind++) = (uint16_t)(k - 1);
|
||||
*(bind++) = (uint16_t)(k);
|
||||
index_count += 3;
|
||||
index_offset += 3;
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ qboolean VK_RenderInit( void )
|
||||
// TODO device memory and friends (e.g. handle mobile memory ...)
|
||||
|
||||
if (!createBuffer("render buffer", &g_render.buffer, vertex_buffer_size + index_buffer_size,
|
||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | (vk_core.rtx ? VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : 0),
|
||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | (vk_core.rtx ? VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR : 0),
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | (vk_core.rtx ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0))) // TODO staging buffer?
|
||||
return false;
|
||||
|
||||
@ -842,6 +842,7 @@ void VK_RenderModelDraw( vk_render_model_t* model ) {
|
||||
int current_texture = -1;
|
||||
int index_count = 0;
|
||||
int index_offset = -1;
|
||||
int vertex_offset = 0;
|
||||
vk_buffer_handle_t vertex_buffer = InvalidHandle;
|
||||
vk_buffer_handle_t index_buffer = InvalidHandle;
|
||||
|
||||
@ -855,7 +856,7 @@ void VK_RenderModelDraw( vk_render_model_t* model ) {
|
||||
if (geom->texture < 0)
|
||||
continue;
|
||||
|
||||
if (current_texture != geom->texture || vertex_buffer != geom->vertex_buffer || index_buffer != geom->index_buffer)
|
||||
if (current_texture != geom->texture || vertex_buffer != geom->vertex_buffer || index_buffer != geom->index_buffer || vertex_offset != geom->vertex_offset)
|
||||
{
|
||||
if (index_count) {
|
||||
const render_draw_t draw = {
|
||||
@ -865,7 +866,7 @@ void VK_RenderModelDraw( vk_render_model_t* model ) {
|
||||
.element_count = index_count,
|
||||
.vertex_buffer = vertex_buffer,
|
||||
.index_buffer = index_buffer,
|
||||
.vertex_offset = 0,
|
||||
.vertex_offset = vertex_offset,
|
||||
.index_offset = index_offset,
|
||||
};
|
||||
|
||||
@ -877,6 +878,7 @@ void VK_RenderModelDraw( vk_render_model_t* model ) {
|
||||
index_buffer = geom->index_buffer;
|
||||
index_count = 0;
|
||||
index_offset = -1;
|
||||
vertex_offset = geom->vertex_offset;
|
||||
}
|
||||
|
||||
if (index_offset < 0)
|
||||
@ -894,7 +896,7 @@ void VK_RenderModelDraw( vk_render_model_t* model ) {
|
||||
.element_count = index_count,
|
||||
.vertex_buffer = vertex_buffer,
|
||||
.index_buffer = index_buffer,
|
||||
.vertex_offset = 0,
|
||||
.vertex_offset = vertex_offset,
|
||||
.index_offset = index_offset,
|
||||
};
|
||||
|
||||
|
@ -1152,9 +1152,6 @@ vk_ray_model_t* VK_RayModelCreate( vk_ray_model_init_t args ) {
|
||||
const uint32_t prim_count = mg->element_count / 3;
|
||||
const uint32_t vertex_offset = mg->vertex_offset + VK_RenderBufferGetOffsetInUnits(mg->vertex_buffer);
|
||||
const uint32_t index_offset = mg->index_buffer == InvalidHandle ? UINT32_MAX : (mg->index_offset + VK_RenderBufferGetOffsetInUnits(mg->index_buffer));
|
||||
// const qboolean is_emissive = ((mg->texture >= 0 && mg->texture < MAX_TEXTURES)
|
||||
// ? g_emissive_texture_table[mg->texture].set
|
||||
// : false);
|
||||
|
||||
max_prims += prim_count;
|
||||
geom_max_prim_counts[i] = prim_count;
|
||||
@ -1175,9 +1172,11 @@ vk_ray_model_t* VK_RayModelCreate( vk_ray_model_init_t args ) {
|
||||
},
|
||||
};
|
||||
|
||||
// gEngine.Con_Printf(" g%d: v(%#x %d %#x) V%d i(%#x %d %#x) I%d\n", i,
|
||||
// vertex_offset*sizeof(vk_vertex_t), mg->vertex_count * sizeof(vk_vertex_t), (vertex_offset + mg->vertex_count) * sizeof(vk_vertex_t), mg->vertex_count,
|
||||
// index_offset*sizeof(uint16_t), mg->element_count * sizeof(uint16_t), (index_offset + mg->element_count) * sizeof(uint16_t), mg->element_count);
|
||||
#if 0
|
||||
gEngine.Con_Reportf(" g%d: v(%#x %d %#x) V%d i(%#x %d %#x) I%d\n", i,
|
||||
vertex_offset*sizeof(vk_vertex_t), mg->vertex_count * sizeof(vk_vertex_t), (vertex_offset + mg->vertex_count) * sizeof(vk_vertex_t), mg->vertex_count,
|
||||
index_offset*sizeof(uint16_t), mg->element_count * sizeof(uint16_t), (index_offset + mg->element_count) * sizeof(uint16_t), mg->element_count);
|
||||
#endif
|
||||
|
||||
geom_build_ranges[i] = (VkAccelerationStructureBuildRangeInfoKHR) {
|
||||
.primitiveCount = prim_count,
|
||||
|
@ -2014,13 +2014,13 @@ static void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float
|
||||
.texture = texture,
|
||||
.material = kXVkMaterialDiffuse,
|
||||
|
||||
.vertex_count = num_vertices,
|
||||
.vertex_buffer = vertex_buffer,
|
||||
.vertex_offset = 0,
|
||||
.vertex_count = num_vertices,
|
||||
|
||||
.element_count = num_indices,
|
||||
.index_offset = 0,
|
||||
.index_buffer = index_buffer,
|
||||
.index_offset = 0,
|
||||
.element_count = num_indices,
|
||||
};
|
||||
|
||||
VK_RenderModelDynamicAddGeometry( &geometry );
|
||||
|
Loading…
Reference in New Issue
Block a user