From c75568c1cf11c9c1ea457bf95c72cdbb5fb0ba47 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 22 Jan 2021 02:20:32 +0900 Subject: [PATCH] [vulkan] Get wall rendering partially working Many surfaces are missing (I suspect it's due to transform stage management in the index emitter), and currently only the light maps are rendered (still not binding the correct textures), but the basics are working. --- libs/video/renderer/vulkan/qfpipeline.plist | 2 +- libs/video/renderer/vulkan/quakebsp.frag | 5 +++-- libs/video/renderer/vulkan/quakebsp.vert | 2 +- libs/video/renderer/vulkan/scrap.c | 2 +- libs/video/renderer/vulkan/vulkan_bsp.c | 20 ++++++++++++++++++++ libs/video/renderer/vulkan/vulkan_main.c | 7 ++++--- libs/video/renderer/vulkan/vulkan_matrices.c | 6 +++--- 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/libs/video/renderer/vulkan/qfpipeline.plist b/libs/video/renderer/vulkan/qfpipeline.plist index 094f49948..9b0a6a1d7 100644 --- a/libs/video/renderer/vulkan/qfpipeline.plist +++ b/libs/video/renderer/vulkan/qfpipeline.plist @@ -195,7 +195,7 @@ location = 1; binding = 0; format = r32g32b32a32_sfloat; - offset = 8; + offset = 16; }, ); }; diff --git a/libs/video/renderer/vulkan/quakebsp.frag b/libs/video/renderer/vulkan/quakebsp.frag index 21c26dfaa..d79408bf9 100644 --- a/libs/video/renderer/vulkan/quakebsp.frag +++ b/libs/video/renderer/vulkan/quakebsp.frag @@ -115,10 +115,11 @@ main (void) } else { c = texture (Texture, t_st); }*/ + c = texture (Texture, t_st); if (doLight) { c *= texture (Lightmap, l_st); } c += texture (Glowmap, t_st); - - frag_color = vec4(t_st, 1, 1);//fogBlend (c); + c = texture (Lightmap, l_st); + frag_color = c;//fogBlend (c); } diff --git a/libs/video/renderer/vulkan/quakebsp.vert b/libs/video/renderer/vulkan/quakebsp.vert index bb9e87e4a..efc03bac8 100644 --- a/libs/video/renderer/vulkan/quakebsp.vert +++ b/libs/video/renderer/vulkan/quakebsp.vert @@ -20,6 +20,6 @@ void main (void) { gl_Position = Projection * (View * (Model * vertex)); - direction = (Sky * vertex).xyz; + direction = vertex.xyz;//(Sky * vertex).xyz; tl_st = tl_uv; } diff --git a/libs/video/renderer/vulkan/scrap.c b/libs/video/renderer/vulkan/scrap.c index bc5efeda5..27c2ea3bd 100644 --- a/libs/video/renderer/vulkan/scrap.c +++ b/libs/video/renderer/vulkan/scrap.c @@ -270,7 +270,7 @@ QFV_SubpicBatch (subpic_t *subpic, qfv_stagebuf_t *stage) dest = QFV_PacketExtend (scrap->packet, size); } if (!dest) { - printf ("could not get space for update\n"); + printf ("scrap: could not get space for update\n"); return 0; } } diff --git a/libs/video/renderer/vulkan/vulkan_bsp.c b/libs/video/renderer/vulkan/vulkan_bsp.c index b0b4c2162..18e7d2c49 100644 --- a/libs/video/renderer/vulkan/vulkan_bsp.c +++ b/libs/video/renderer/vulkan/vulkan_bsp.c @@ -59,6 +59,7 @@ #include "QF/Vulkan/command.h" #include "QF/Vulkan/descriptor.h" #include "QF/Vulkan/device.h" +#include "QF/Vulkan/instance.h" #include "QF/Vulkan/scrap.h" #include "QF/Vulkan/staging.h" @@ -450,9 +451,13 @@ Vulkan_BuildDisplayLists (model_t **models, int num_models, vulkan_ctx_t *ctx) } } + size_t atom = device->physDev->properties.limits.nonCoherentAtomSize; + size_t atom_mask = atom - 1; size_t frames = bctx->frames.size; size_t index_buffer_size = index_count * frames * sizeof (uint32_t); size_t vertex_buffer_size = vertex_count * sizeof (bspvert_t); + + index_buffer_size = (index_buffer_size + atom_mask) & ~atom_mask; stage = QFV_CreateStagingBuffer (device, vertex_buffer_size, 1, ctx->cmdpool); qfv_packet_t *packet = QFV_PacketAcquire (stage); @@ -1144,6 +1149,21 @@ Vulkan_DrawWorld (vulkan_ctx_t *ctx) tex->elechain_tail = &tex->elechain; } bsp_end (ctx); + + size_t atom = device->physDev->properties.limits.nonCoherentAtomSize; + size_t atom_mask = atom - 1; + size_t offset = bframe->index_offset; + size_t size = bframe->index_count * sizeof (uint32_t); + + offset &= ~atom_mask; + size = (size + atom_mask) & ~atom_mask; + + //FIXME this needs to come at the end of the frame after all passes + VkMappedMemoryRange range = { + VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0, + bctx->index_memory, offset, size + }; + dfunc->vkFlushMappedMemoryRanges (device->dev, 1, &range); } void diff --git a/libs/video/renderer/vulkan/vulkan_main.c b/libs/video/renderer/vulkan/vulkan_main.c index 1e1913de9..f31558e7b 100644 --- a/libs/video/renderer/vulkan/vulkan_main.c +++ b/libs/video/renderer/vulkan/vulkan_main.c @@ -78,7 +78,8 @@ setup_frame (vulkan_ctx_t *ctx) static void setup_view (vulkan_ctx_t *ctx) { - float *mat = ctx->matrices.view_3d; + mat4_t mat; + float *view = ctx->matrices.view_3d; static mat4_t z_up = { 0, 0, -1, 0, -1, 0, 0, 0, @@ -98,11 +99,11 @@ setup_view (vulkan_ctx_t *ctx) VectorCopy (vup, mat + 8); mat[15] = 1; Mat4Transpose (mat, mat);//AngleVectors gives the transpose of what we want - Mat4Mult (z_up, mat, glsl_view); + Mat4Mult (z_up, mat, view); Mat4Identity (mat); VectorNegate (r_refdef.vieworg, mat + 12); - Mat4Mult (glsl_view, mat, glsl_view); + Mat4Mult (view, mat, view); } static void diff --git a/libs/video/renderer/vulkan/vulkan_matrices.c b/libs/video/renderer/vulkan/vulkan_matrices.c index 62eb16c1d..e1a1dd13e 100644 --- a/libs/video/renderer/vulkan/vulkan_matrices.c +++ b/libs/video/renderer/vulkan/vulkan_matrices.c @@ -96,14 +96,14 @@ persp_mat (float *proj, float xmin, float xmax, float ymin, float ymax, proj[12] = 0; proj[1] = 0; - proj[5] = (2 * neard) / (ymax - ymin); + proj[5] = -(2 * neard) / (ymax - ymin); proj[9] = (ymax + ymin) / (ymax - ymin); proj[13] = 0; proj[2] = 0; proj[6] = 0; - proj[10] = (fard + neard) / (neard - fard); - proj[14] = (2 * fard * neard) / (neard - fard); + proj[10] = (fard) / (neard - fard); + proj[14] = (fard * neard) / (neard - fard); proj[3] = 0; proj[7] = 0;