From d4f4e87e66551f0d53decfbe76de6beb97f26d5e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 10 May 2020 20:29:28 -0700 Subject: [PATCH] Vulkan: Correct postshader sampler binding. This was causing a lost device. --- GPU/Common/PresentationCommon.cpp | 5 +++-- GPU/Common/ShaderTranslation.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/GPU/Common/PresentationCommon.cpp b/GPU/Common/PresentationCommon.cpp index d211ce6402..2898c2eecb 100644 --- a/GPU/Common/PresentationCommon.cpp +++ b/GPU/Common/PresentationCommon.cpp @@ -538,8 +538,9 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u Draw::SamplerState *sampler = useNearest ? samplerNearest_ : samplerLinear_; draw_->BindSamplerStates(0, 1, &sampler); - float post_v0 = flags & OutputFlags::BACKBUFFER_FLIPPED ? 1.0f : 0.0f; - float post_v1 = flags & OutputFlags::BACKBUFFER_FLIPPED ? 0.0f : 1.0f; + bool flipped = GetGPUBackend() == GPUBackend::DIRECT3D9 || GetGPUBackend() == GPUBackend::DIRECT3D11; + float post_v0 = !flipped ? 1.0f : 0.0f; + float post_v1 = !flipped ? 0.0f : 1.0f; verts[4] = { -1, -1, 0, 0, post_v1, 0xFFFFFFFF }; // TL verts[5] = { -1, 1, 0, 0, post_v0, 0xFFFFFFFF }; // BL verts[6] = { 1, 1, 0, 1, post_v0, 0xFFFFFFFF }; // BR diff --git a/GPU/Common/ShaderTranslation.cpp b/GPU/Common/ShaderTranslation.cpp index 79b45b0d0f..7f42a7b2b7 100644 --- a/GPU/Common/ShaderTranslation.cpp +++ b/GPU/Common/ShaderTranslation.cpp @@ -96,8 +96,8 @@ R"(#version 430 #extension GL_ARB_shading_language_420pack : enable )"; -static const char *pushconstantBufferDecl = R"( -layout(push_constant) uniform data { +static const char *vulkanUboDecl = R"( +layout (std140, set = 0, binding = 0) uniform Data { vec2 u_texelDelta; vec2 u_pixelDelta; vec4 u_time; @@ -155,7 +155,7 @@ bool ConvertToVulkanGLSL(std::string *dest, TranslatedShaderMetadata *destMetada const char *replacement; } replacements[] = { { Draw::ShaderStage::VERTEX, "attribute vec4 a_position;", "layout(location = 0) in vec4 a_position;" }, - { Draw::ShaderStage::VERTEX, "attribute vec2 a_texcoord0;", "layout(location = 1) in vec2 a_texcoord0;"}, + { Draw::ShaderStage::VERTEX, "attribute vec2 a_texcoord0;", "layout(location = 2) in vec2 a_texcoord0;"}, { Draw::ShaderStage::VERTEX, "varying vec2 v_position;", "layout(location = 0) out vec2 v_position;" }, { Draw::ShaderStage::FRAGMENT, "varying vec2 v_position;", "layout(location = 0) in vec2 v_position;" }, { Draw::ShaderStage::FRAGMENT, "texture2D(", "texture(" }, @@ -167,7 +167,7 @@ bool ConvertToVulkanGLSL(std::string *dest, TranslatedShaderMetadata *destMetada out << "layout (location = 0) out vec4 fragColor0;\n"; } // Output the uniform buffer. - out << pushconstantBufferDecl; + out << vulkanUboDecl; // Alright, now let's go through it line by line and zap the single uniforms // and perform replacements. @@ -178,7 +178,7 @@ bool ConvertToVulkanGLSL(std::string *dest, TranslatedShaderMetadata *destMetada if (line.find("uniform bool") != std::string::npos) { continue; } else if (line.find("uniform sampler2D") == 0) { - line = "layout(set = 0, binding = 0) " + line; + line = "layout(set = 0, binding = 1) " + line; } else if (line.find("uniform ") != std::string::npos) { continue; } else if (2 == sscanf(line.c_str(), "varying vec%d v_texcoord%d;", &vecSize, &num)) {