From e309712fed585c58996d1ba2a3ef3a0055d13627 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 10 May 2020 20:34:42 -0700 Subject: [PATCH] Vulkan: Correct missing offsets in Draw. Was silently ignoring them. Caused stretch in postshaders. --- ext/native/thin3d/VulkanQueueRunner.cpp | 2 +- ext/native/thin3d/VulkanQueueRunner.h | 1 + ext/native/thin3d/VulkanRenderManager.h | 3 ++- ext/native/thin3d/thin3d.cpp | 4 ++-- ext/native/thin3d/thin3d_vulkan.cpp | 6 +++--- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ext/native/thin3d/VulkanQueueRunner.cpp b/ext/native/thin3d/VulkanQueueRunner.cpp index df2d386255..28aa244776 100644 --- a/ext/native/thin3d/VulkanQueueRunner.cpp +++ b/ext/native/thin3d/VulkanQueueRunner.cpp @@ -1091,7 +1091,7 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c if (c.draw.vbuffer) { vkCmdBindVertexBuffers(cmd, 0, 1, &c.draw.vbuffer, &c.draw.voffset); } - vkCmdDraw(cmd, c.draw.count, 1, 0, 0); + vkCmdDraw(cmd, c.draw.count, 1, c.draw.offset, 0); break; case VKRRenderCommand::CLEAR: diff --git a/ext/native/thin3d/VulkanQueueRunner.h b/ext/native/thin3d/VulkanQueueRunner.h index 19a29bf243..129c441b86 100644 --- a/ext/native/thin3d/VulkanQueueRunner.h +++ b/ext/native/thin3d/VulkanQueueRunner.h @@ -109,6 +109,7 @@ struct VkRenderData { VkBuffer vbuffer; VkDeviceSize voffset; uint32_t count; + uint32_t offset; } draw; struct { VkPipelineLayout pipelineLayout; diff --git a/ext/native/thin3d/VulkanRenderManager.h b/ext/native/thin3d/VulkanRenderManager.h index ff65ad94ab..530912d857 100644 --- a/ext/native/thin3d/VulkanRenderManager.h +++ b/ext/native/thin3d/VulkanRenderManager.h @@ -177,10 +177,11 @@ public: void Clear(uint32_t clearColor, float clearZ, int clearStencil, int clearMask); - void Draw(VkPipelineLayout layout, VkDescriptorSet descSet, int numUboOffsets, const uint32_t *uboOffsets, VkBuffer vbuffer, int voffset, int count) { + void Draw(VkPipelineLayout layout, VkDescriptorSet descSet, int numUboOffsets, const uint32_t *uboOffsets, VkBuffer vbuffer, int voffset, int count, int offset = 0) { _dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == VKRStepType::RENDER); VkRenderData data{ VKRRenderCommand::DRAW }; data.draw.count = count; + data.draw.offset = offset; data.draw.pipelineLayout = layout; data.draw.ds = descSet; data.draw.vbuffer = vbuffer; diff --git a/ext/native/thin3d/thin3d.cpp b/ext/native/thin3d/thin3d.cpp index 2d3fdcc2f8..5ee4a9e44a 100644 --- a/ext/native/thin3d/thin3d.cpp +++ b/ext/native/thin3d/thin3d.cpp @@ -140,7 +140,7 @@ static const std::vector fsTexCol = { "#extension GL_ARB_shading_language_420pack : enable\n" "layout(location = 0) in vec4 oColor0;\n" "layout(location = 1) in vec2 oTexCoord0;\n" - "layout(location = 0) out vec4 fragColor0\n;" + "layout(location = 0) out vec4 fragColor0;\n" "layout(set = 0, binding = 1) uniform sampler2D Sampler0;\n" "void main() { fragColor0 = texture(Sampler0, oTexCoord0) * oColor0; }\n" } @@ -220,7 +220,7 @@ static const std::vector fsCol = { "#extension GL_ARB_separate_shader_objects : enable\n" "#extension GL_ARB_shading_language_420pack : enable\n" "layout(location = 0) in vec4 oColor0;\n" - "layout(location = 0) out vec4 fragColor0\n;" + "layout(location = 0) out vec4 fragColor0;\n" "void main() { fragColor0 = oColor0; }\n" } }; diff --git a/ext/native/thin3d/thin3d_vulkan.cpp b/ext/native/thin3d/thin3d_vulkan.cpp index 8fa5571925..a6f185bdb4 100644 --- a/ext/native/thin3d/thin3d_vulkan.cpp +++ b/ext/native/thin3d/thin3d_vulkan.cpp @@ -1242,7 +1242,7 @@ void VKContext::Draw(int vertexCount, int offset) { renderManager_.BindPipeline(curPipeline_->vkpipeline); ApplyDynamicState(); - renderManager_.Draw(pipelineLayout_, descSet, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset, vertexCount); + renderManager_.Draw(pipelineLayout_, descSet, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset + curVBufferOffsets_[0], vertexCount, offset); } void VKContext::DrawIndexed(int vertexCount, int offset) { @@ -1258,7 +1258,7 @@ void VKContext::DrawIndexed(int vertexCount, int offset) { renderManager_.BindPipeline(curPipeline_->vkpipeline); ApplyDynamicState(); - renderManager_.DrawIndexed(pipelineLayout_, descSet, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset, vulkanIbuf, (int)ibBindOffset + offset * sizeof(uint32_t), vertexCount, 1, VK_INDEX_TYPE_UINT32); + renderManager_.DrawIndexed(pipelineLayout_, descSet, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset + curVBufferOffsets_[0], vulkanIbuf, (int)ibBindOffset + offset * sizeof(uint32_t), vertexCount, 1, VK_INDEX_TYPE_UINT32); } void VKContext::DrawUP(const void *vdata, int vertexCount) { @@ -1270,7 +1270,7 @@ void VKContext::DrawUP(const void *vdata, int vertexCount) { renderManager_.BindPipeline(curPipeline_->vkpipeline); ApplyDynamicState(); - renderManager_.Draw(pipelineLayout_, descSet, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset, vertexCount); + renderManager_.Draw(pipelineLayout_, descSet, 1, &ubo_offset, vulkanVbuf, (int)vbBindOffset + curVBufferOffsets_[0], vertexCount); } void VKContext::Clear(int clearMask, uint32_t colorval, float depthVal, int stencilVal) {