From bd674c47b66b62bfb00b8a2b1f57ee59092be2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 24 Aug 2022 11:01:57 +0200 Subject: [PATCH] OpenGL: Fix regular depal (shader depal still worked) that broke recently --- Common/GPU/OpenGL/GLQueueRunner.cpp | 12 +++++++----- Common/GPU/OpenGL/thin3d_gl.cpp | 2 +- GPU/Common/Draw2D.cpp | 5 ++++- GPU/Common/Draw2D.h | 3 ++- GPU/Common/TextureCacheCommon.cpp | 12 ++++++------ GPU/Common/TextureShaderCommon.cpp | 1 + 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index dd28d3cfb4..3d3c30e433 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -1035,15 +1035,17 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last activeSlot = slot; } if (c.bind_fb_texture.aspect == GL_COLOR_BUFFER_BIT) { - if (curTex[slot] != &c.bind_fb_texture.framebuffer->color_texture) + if (curTex[slot] != &c.bind_fb_texture.framebuffer->color_texture) { glBindTexture(GL_TEXTURE_2D, c.bind_fb_texture.framebuffer->color_texture.texture); - curTex[slot] = &c.bind_fb_texture.framebuffer->color_texture; + curTex[slot] = &c.bind_fb_texture.framebuffer->color_texture; + } } else if (c.bind_fb_texture.aspect == GL_DEPTH_BUFFER_BIT) { - if (curTex[slot] != &c.bind_fb_texture.framebuffer->z_stencil_texture) + if (curTex[slot] != &c.bind_fb_texture.framebuffer->z_stencil_texture) { glBindTexture(GL_TEXTURE_2D, c.bind_fb_texture.framebuffer->z_stencil_texture.texture); - curTex[slot] = &c.bind_fb_texture.framebuffer->z_stencil_texture; + curTex[slot] = &c.bind_fb_texture.framebuffer->z_stencil_texture; + } } else { - // TODO: Stencil texturing? + // Can't texture from stencil buffers. curTex[slot] = nullptr; } CHECK_GL_ERROR_IF_DEBUG(); diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index e26a666748..5391fe2198 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -1214,7 +1214,7 @@ bool OpenGLPipeline::LinkShaders() { } std::vector initialize; for (int i = 0; i < MAX_TEXTURE_SLOTS; ++i) { - if (i < queries.size()) { + if (i < samplers_.size()) { initialize.push_back({ &samplerLocs_[i], 0, i }); } else { samplerLocs_[i] = -1; diff --git a/GPU/Common/Draw2D.cpp b/GPU/Common/Draw2D.cpp index b9ac114f92..c1aefbce20 100644 --- a/GPU/Common/Draw2D.cpp +++ b/GPU/Common/Draw2D.cpp @@ -230,7 +230,10 @@ Draw2DPipeline *Draw2D::Create2DPipeline(std::functionCreateGraphicsPipeline(pipelineDesc); diff --git a/GPU/Common/Draw2D.h b/GPU/Common/Draw2D.h index b9516e8d39..ad489dfce6 100644 --- a/GPU/Common/Draw2D.h +++ b/GPU/Common/Draw2D.h @@ -1,6 +1,7 @@ #pragma once #include "GPU/GPU.h" +#include "Common/GPU/Shader.h" // For framebuffer copies and similar things that just require passthrough. struct Draw2DVertex { @@ -32,7 +33,7 @@ inline RasterChannel Draw2DSourceChannel(Draw2DShader shader) { struct Draw2DPipelineInfo { RasterChannel readChannel; RasterChannel writeChannel; - bool secondTexture; + Slice samplers; }; struct Draw2DPipeline { diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index aaa38bb7c7..3c26ba9544 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1890,13 +1890,14 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer bool depth = channel == RASTER_DEPTH; bool need_depalettize = CanDepalettize(texFormat, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat); - bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && !depth && !gstate_c.curTextureIs3D; + + // Shader depal is not supported during 3D texturing or depth texturing, and requires 32-bit integer instructions in the shader. + bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && + !depth && + !gstate_c.curTextureIs3D && + draw_->GetDeviceCaps().fragmentShaderInt32Supported; // TODO: Implement shader depal in the fragment shader generator for D3D11 at least. - if (!draw_->GetDeviceCaps().fragmentShaderInt32Supported) { - useShaderDepal = false; - } - switch (draw_->GetShaderLanguageDesc().shaderLanguage) { case ShaderLanguage::HLSL_D3D11: case ShaderLanguage::HLSL_D3D9: @@ -1915,7 +1916,6 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer smoothedDepal = CanUseSmoothDepal(gstate, framebuffer->drawnFormat, clutTexture.rampLength); if (useShaderDepal) { - // Very icky conflation here of native and thin3d rendering. This will need careful work per backend in BindAsClutTexture. BindAsClutTexture(clutTexture.texture); diff --git a/GPU/Common/TextureShaderCommon.cpp b/GPU/Common/TextureShaderCommon.cpp index 694a646131..8fb8cd6fe9 100644 --- a/GPU/Common/TextureShaderCommon.cpp +++ b/GPU/Common/TextureShaderCommon.cpp @@ -213,6 +213,7 @@ Draw2DPipeline *TextureShaderCache::GetDepalettizeShader(uint32_t clutMode, GETe return Draw2DPipelineInfo{ config.bufferFormat == GE_FORMAT_DEPTH16 ? RASTER_DEPTH : RASTER_COLOR, RASTER_COLOR, + samplers }; }); delete[] buffer;