[vulkan] Move viewport and scissor into vulkan_ctx

Not only does it makes sense to centralize the setting of viewport and
scissor, but it's actually necessary in order to fix the upside-down
rendering on windows.
This commit is contained in:
Bill Currie 2021-03-31 23:38:49 +09:00
parent 92859b7c2e
commit f13af65b32
9 changed files with 24 additions and 21 deletions

View file

@ -99,6 +99,8 @@ typedef struct vulkan_ctx_s {
struct qfv_tex_s *default_white;
struct qfv_tex_s *default_magenta;
VkViewport viewport;
VkRect2D scissor;
// projection and view matrices (model is push constant)
vulkan_matrices_t matrices;

View file

@ -208,7 +208,7 @@ QFV_CreateInstance (vulkan_ctx_t *ctx,
VK_STRUCTURE_TYPE_APPLICATION_INFO, 0,
appName, appVersion,
PACKAGE_STRING, 0x000702ff, //FIXME version
VK_API_VERSION_1_0,
VK_API_VERSION_1_1,
};
VkInstanceCreateInfo createInfo = {
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, 0, 0,

View file

@ -201,10 +201,8 @@ alias_begin_subpass (QFV_AliasSubpass subpass, VkPipeline pipeline,
dfunc->vkCmdPushDescriptorSetKHR (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
actx->layout,
0, 1, aframe->descriptors + 0);
VkViewport viewport = {0, 0, vid.width, vid.height, 0, 1};
VkRect2D scissor = { {0, 0}, {vid.width, vid.height} };
dfunc->vkCmdSetViewport (cmd, 0, 1, &viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &scissor);
dfunc->vkCmdSetViewport (cmd, 0, 1, &ctx->viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &ctx->scissor);
//dfunc->vkUpdateDescriptorSets (device->dev, 2, aframe->descriptors, 0, 0);

View file

@ -896,10 +896,8 @@ bsp_begin_subpass (QFV_BspSubpass subpass, VkPipeline pipeline,
dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
pipeline);
VkViewport viewport = {0, 0, vid.width, vid.height, 0, 1};
VkRect2D scissor = { {0, 0}, {vid.width, vid.height} };
dfunc->vkCmdSetViewport (cmd, 0, 1, &viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &scissor);
dfunc->vkCmdSetViewport (cmd, 0, 1, &ctx->viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &ctx->scissor);
VkDeviceSize offsets[] = { 0 };
dfunc->vkCmdBindVertexBuffers (cmd, 0, 1, &bctx->vertex_buffer, offsets);

View file

@ -94,10 +94,8 @@ Vulkan_Compose_Draw (vulkan_ctx_t *ctx)
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
cctx->layout, 0, 1, sets, 0, 0);
VkViewport viewport = {0, 0, vid.width, vid.height, 0, 1};
VkRect2D scissor = { {0, 0}, {vid.width, vid.height} };
dfunc->vkCmdSetViewport (cmd, 0, 1, &viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &scissor);
dfunc->vkCmdSetViewport (cmd, 0, 1, &ctx->viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &ctx->scissor);
VkDeviceSize offset = 0;
dfunc->vkCmdBindVertexBuffers (cmd, 0, 1, &ctx->quad_buffer, &offset);

View file

@ -732,10 +732,8 @@ Vulkan_FlushText (vulkan_ctx_t *ctx)
dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
dctx->pipeline);
VkViewport viewport = {0, 0, vid.width, vid.height, 0, 1};
VkRect2D scissor = { {0, 0}, {vid.width, vid.height} };
dfunc->vkCmdSetViewport (cmd, 0, 1, &viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &scissor);
dfunc->vkCmdSetViewport (cmd, 0, 1, &ctx->viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &ctx->scissor);
VkDeviceSize offsets[] = {dframe->vert_offset};
dfunc->vkCmdBindVertexBuffers (cmd, 0, 1, &dctx->vert_buffer, offsets);
dfunc->vkCmdBindIndexBuffer (cmd, dctx->ind_buffer, 0,

View file

@ -230,10 +230,8 @@ Vulkan_Lighting_Draw (vulkan_ctx_t *ctx)
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
lctx->layout, 0, 2, sets, 0, 0);
VkViewport viewport = {0, 0, vid.width, vid.height, 0, 1};
VkRect2D scissor = { {0, 0}, {vid.width, vid.height} };
dfunc->vkCmdSetViewport (cmd, 0, 1, &viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &scissor);
dfunc->vkCmdSetViewport (cmd, 0, 1, &ctx->viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &ctx->scissor);
VkDeviceSize offset = 0;
dfunc->vkCmdBindVertexBuffers (cmd, 0, 1, &ctx->quad_buffer, &offset);

View file

@ -154,6 +154,12 @@ win_vulkan_create_surface (vulkan_ctx_t *ctx)
.hinstance = pres->instance,
.hwnd = pres->window,
};
int width = viddef.width;
int height = viddef.height;
ctx->viewport = (VkViewport) { 0, 0, width, height, 0, 1 };
ctx->scissor = (VkRect2D) { {0, 0}, {width, height} };
if (pres->vkCreateWin32SurfaceKHR (inst, &createInfo, 0, &surface)
!= VK_SUCCESS) {
return 0;

View file

@ -194,6 +194,11 @@ x11_vulkan_create_surface (vulkan_ctx_t *ctx)
.window = pres->window
};
int width = viddef.width;
int height = viddef.height;
ctx->viewport = (VkViewport) { 0, 0, width, height, 0, 1 };
ctx->scissor = (VkRect2D) { {0, 0}, {width, height} };
if (pres->vkCreateXlibSurfaceKHR (inst, &createInfo, 0, &surface)
!= VK_SUCCESS) {
return 0;