diff --git a/src/Cafe/HW/Latte/Core/LatteShader.cpp b/src/Cafe/HW/Latte/Core/LatteShader.cpp index c0ad06a1..503fb664 100644 --- a/src/Cafe/HW/Latte/Core/LatteShader.cpp +++ b/src/Cafe/HW/Latte/Core/LatteShader.cpp @@ -838,7 +838,6 @@ LatteDecompilerShader* LatteShader_CompileSeparablePixelShader(uint64 baseHash, void LatteSHRC_UpdateVertexShader(uint8* vertexShaderPtr, uint32 vertexShaderSize, bool usesGeometryShader) { // todo - should include VTX_SEMANTIC table in state - LatteSHRC_UpdateVSBaseHash(vertexShaderPtr, vertexShaderSize, usesGeometryShader); uint64 vsAuxHash = 0; auto itBaseShader = sVertexShaders.find(_shaderBaseHash_vs); @@ -855,15 +854,13 @@ void LatteSHRC_UpdateVertexShader(uint8* vertexShaderPtr, uint32 vertexShaderSiz LatteGPUState.activeShaderHasError = true; return; } - g_renderer->shader_bind(vertexShader->shader); _activeVertexShader = vertexShader; } void LatteSHRC_UpdateGeometryShader(bool usesGeometryShader, uint8* geometryShaderPtr, uint32 geometryShaderSize, uint8* geometryCopyShader, uint32 geometryCopyShaderSize) { - if (usesGeometryShader == false || _activeVertexShader == nullptr) + if (!usesGeometryShader || !_activeVertexShader) { - g_renderer->shader_unbind(RendererShader::ShaderType::kGeometry); _shaderBaseHash_gs = 0; _activeGeometryShader = nullptr; return; @@ -887,21 +884,11 @@ void LatteSHRC_UpdateGeometryShader(bool usesGeometryShader, uint8* geometryShad LatteGPUState.activeShaderHasError = true; return; } - g_renderer->shader_bind(geometryShader->shader); _activeGeometryShader = geometryShader; } void LatteSHRC_UpdatePixelShader(uint8* pixelShaderPtr, uint32 pixelShaderSize, bool usesGeometryShader) { - if (LatteGPUState.contextRegister[mmVGT_STRMOUT_EN] != 0 && g_renderer->GetType() == RendererAPI::OpenGL) - { - if (_activePixelShader) - { - g_renderer->shader_unbind(RendererShader::ShaderType::kFragment); - _activePixelShader = nullptr; - } - return; - } LatteSHRC_UpdatePSBaseHash(pixelShaderPtr, pixelShaderSize, usesGeometryShader); uint64 psAuxHash = 0; auto itBaseShader = sPixelShaders.find(_shaderBaseHash_ps); @@ -918,7 +905,6 @@ void LatteSHRC_UpdatePixelShader(uint8* pixelShaderPtr, uint32 pixelShaderSize, LatteGPUState.activeShaderHasError = true; return; } - g_renderer->shader_bind(pixelShader->shader); _activePixelShader = pixelShader; } diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp index 5269be64..01068a3d 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp @@ -275,10 +275,6 @@ void OpenGLRenderer::Initialize() cemuLog_log(LogType::Force, "ARB_copy_image: {}", (glCopyImageSubData != NULL) ? "available" : "not supported"); cemuLog_log(LogType::Force, "NV_depth_buffer_float: {}", (glDepthRangedNV != NULL) ? "available" : "not supported"); - // generate default frame buffer - glGenFramebuffers(1, &m_defaultFramebufferId); - catchOpenGLError(); - // enable framebuffer SRGB support glEnable(GL_FRAMEBUFFER_SRGB); @@ -566,10 +562,9 @@ void OpenGLRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu sint32 effectiveHeight; LatteTexture_getEffectiveSize(texView->baseTexture, &effectiveWidth, &effectiveHeight, nullptr, 0); - g_renderer->shader_unbind(RendererShader::ShaderType::kVertex); - g_renderer->shader_unbind(RendererShader::ShaderType::kGeometry); - g_renderer->shader_unbind(RendererShader::ShaderType::kFragment); - shader->Bind(); + shader_unbind(RendererShader::ShaderType::kGeometry); + shader_bind(shader->GetVertexShader()); + shader_bind(shader->GetFragmentShader()); shader->SetUniformParameters(*texView, { effectiveWidth, effectiveHeight }, { imageWidth, imageHeight }); // set viewport @@ -1433,31 +1428,25 @@ RendererShader* OpenGLRenderer::shader_create(RendererShader::ShaderType type, u void OpenGLRenderer::shader_bind(RendererShader* shader) { auto shaderGL = (RendererShaderGL*)shader; - GLbitfield shaderBit; - const auto program = shaderGL->GetProgram(); - switch(shader->GetType()) { case RendererShader::ShaderType::kVertex: if (program == prevVertexShaderProgram) return; - shaderBit = GL_VERTEX_SHADER_BIT; prevVertexShaderProgram = program; break; case RendererShader::ShaderType::kFragment: if (program == prevPixelShaderProgram) return; - shaderBit = GL_FRAGMENT_SHADER_BIT; prevPixelShaderProgram = program; break; case RendererShader::ShaderType::kGeometry: if (program == prevGeometryShaderProgram) return; - shaderBit = GL_GEOMETRY_SHADER_BIT; prevGeometryShaderProgram = program; break; @@ -1470,13 +1459,6 @@ void OpenGLRenderer::shader_bind(RendererShader* shader) catchOpenGLError(); } -void OpenGLRenderer::shader_bind(GLuint program, GLbitfield shaderType) -{ - catchOpenGLError(); - glUseProgramStages(m_pipeline, shaderType, program); - catchOpenGLError(); -} - void OpenGLRenderer::shader_unbind(RendererShader::ShaderType shaderType) { switch (shaderType) { diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h index 600985ff..b789e2a7 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h @@ -127,9 +127,8 @@ public: // shader RendererShader* shader_create(RendererShader::ShaderType type, uint64 baseHash, uint64 auxHash, const std::string& source, bool isGameShader, bool isGfxPackShader) override; - void shader_bind(RendererShader* shader) override; - void shader_bind(GLuint program, GLbitfield shaderType); - void shader_unbind(RendererShader::ShaderType shaderType) override; + void shader_bind(RendererShader* shader); + void shader_unbind(RendererShader::ShaderType shaderType); // streamout void streamout_setupXfbBuffer(uint32 bufferIndex, sint32 ringBufferOffset, uint32 rangeAddr, uint32 rangeSize) override; @@ -165,7 +164,6 @@ private: void texture_syncSliceSpecialBC4(LatteTexture* srcTexture, sint32 srcSliceIndex, sint32 srcMipIndex, LatteTexture* dstTexture, sint32 dstSliceIndex, sint32 dstMipIndex); void texture_syncSliceSpecialIntegerToBC3(LatteTexture* srcTexture, sint32 srcSliceIndex, sint32 srcMipIndex, LatteTexture* dstTexture, sint32 dstSliceIndex, sint32 dstMipIndex); - GLuint m_defaultFramebufferId; GLuint m_pipeline = 0; bool m_isPadViewContext{}; @@ -216,8 +214,6 @@ private: uint32 prevLogicOp = 0; uint32 prevBlendColorConstant[4] = { 0 }; uint8 prevAlphaTestEnable = 0; - uint8 prevAlphaTestFunc = 0; - uint32 prevAlphaTestRefU32 = 0; bool prevDepthEnable = 0; bool prevDepthWriteEnable = 0; Latte::LATTE_DB_DEPTH_CONTROL::E_ZFUNC prevDepthFunc = (Latte::LATTE_DB_DEPTH_CONTROL::E_ZFUNC)-1; @@ -263,9 +259,9 @@ private: std::vector list_queryCacheOcclusion; // cache for unused queries // resource garbage collection - struct bufferCacheReleaseQueueEntry_t + struct BufferCacheReleaseQueueEntry { - bufferCacheReleaseQueueEntry_t(VirtualBufferHeap_t* heap, VirtualBufferHeapEntry_t* entry) : m_heap(heap), m_entry(entry) {}; + BufferCacheReleaseQueueEntry(VirtualBufferHeap_t* heap, VirtualBufferHeapEntry_t* entry) : m_heap(heap), m_entry(entry) {}; void free() { @@ -279,7 +275,7 @@ private: struct { sint32 index; - std::vector bufferCacheEntries; + std::vector bufferCacheEntries; }m_destructionQueues; }; diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRendererCore.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRendererCore.cpp index d5cec237..f78b8bd6 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRendererCore.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRendererCore.cpp @@ -912,6 +912,21 @@ void OpenGLRenderer::draw_genericDrawHandler(uint32 baseVertex, uint32 baseInsta { beginPerfMonProfiling(performanceMonitor.gpuTime_dcStageShaderAndUniformMgr); LatteSHRC_UpdateActiveShaders(); + LatteDecompilerShader* vs = (LatteDecompilerShader*)LatteSHRC_GetActiveVertexShader(); + LatteDecompilerShader* gs = (LatteDecompilerShader*)LatteSHRC_GetActiveGeometryShader(); + LatteDecompilerShader* ps = (LatteDecompilerShader*)LatteSHRC_GetActivePixelShader(); + if (vs) + shader_bind(vs->shader); + else + shader_unbind(RendererShader::ShaderType::kVertex); + if (ps && LatteGPUState.contextRegister[mmVGT_STRMOUT_EN] == 0) + shader_bind(ps->shader); + else + shader_unbind(RendererShader::ShaderType::kFragment); + if (gs) + shader_bind(gs->shader); + else + shader_unbind(RendererShader::ShaderType::kGeometry); endPerfMonProfiling(performanceMonitor.gpuTime_dcStageShaderAndUniformMgr); } if (LatteGPUState.activeShaderHasError) diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp index 5530b4ec..3d46f206 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp @@ -230,11 +230,6 @@ sint32 RendererShaderGL::GetUniformLocation(const char* name) return glGetUniformLocation(m_program, name); } -void RendererShaderGL::SetUniform1iv(sint32 location, void* data, sint32 count) -{ - glProgramUniform1iv(m_program, location, count, (const GLint*)data); -} - void RendererShaderGL::SetUniform2fv(sint32 location, void* data, sint32 count) { glProgramUniform2fv(m_program, location, count, (const GLfloat*)data); diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h index abc62358..60c51cc1 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h @@ -18,7 +18,6 @@ public: GLuint GetShaderObject() const { cemu_assert_debug(m_isCompiled); return m_shader_object; } sint32 GetUniformLocation(const char* name) override; - void SetUniform1iv(sint32 location, void* data, sint32 count) override; void SetUniform2fv(sint32 location, void* data, sint32 count) override; void SetUniform4iv(sint32 location, void* data, sint32 count) override; diff --git a/src/Cafe/HW/Latte/Renderer/Renderer.h b/src/Cafe/HW/Latte/Renderer/Renderer.h index 61ff10c8..11d102d0 100644 --- a/src/Cafe/HW/Latte/Renderer/Renderer.h +++ b/src/Cafe/HW/Latte/Renderer/Renderer.h @@ -135,8 +135,6 @@ public: // shader virtual RendererShader* shader_create(RendererShader::ShaderType type, uint64 baseHash, uint64 auxHash, const std::string& source, bool compileAsync, bool isGfxPackSource) = 0; - virtual void shader_bind(RendererShader* shader) = 0; - virtual void shader_unbind(RendererShader::ShaderType shaderType) = 0; // streamout virtual void streamout_setupXfbBuffer(uint32 bufferIndex, sint32 ringBufferOffset, uint32 rangeAddr, uint32 rangeSize) = 0; diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index ae528944..cdbeb3f3 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -233,12 +233,6 @@ void RendererOutputShader::SetUniformParameters(const LatteTextureView& texture_ } } -void RendererOutputShader::Bind() const -{ - g_renderer->shader_bind(m_vertex_shader); - g_renderer->shader_bind(m_fragment_shader); -} - RendererOutputShader* RendererOutputShader::s_copy_shader; RendererOutputShader* RendererOutputShader::s_copy_shader_ud; diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h index 253990e2..398ac663 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h @@ -18,7 +18,6 @@ public: virtual ~RendererOutputShader() = default; void SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& input_res, const Vector2i& output_res) const; - void Bind() const; RendererShader* GetVertexShader() const { diff --git a/src/Cafe/HW/Latte/Renderer/RendererShader.h b/src/Cafe/HW/Latte/Renderer/RendererShader.h index 1c15211f..e3f254c6 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererShader.h +++ b/src/Cafe/HW/Latte/Renderer/RendererShader.h @@ -19,8 +19,7 @@ public: virtual bool WaitForCompiled() = 0; virtual sint32 GetUniformLocation(const char* name) = 0; - - virtual void SetUniform1iv(sint32 location, void* data, sint32 count) = 0; + virtual void SetUniform2fv(sint32 location, void* data, sint32 count) = 0; virtual void SetUniform4iv(sint32 location, void* data, sint32 count) = 0; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp index 8460c8b5..970f5517 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp @@ -227,11 +227,6 @@ sint32 RendererShaderVk::GetUniformLocation(const char* name) return 0; } -void RendererShaderVk::SetUniform1iv(sint32 location, void* data, sint32 count) -{ - cemu_assert_suspicious(); -} - void RendererShaderVk::SetUniform2fv(sint32 location, void* data, sint32 count) { cemu_assert_suspicious(); diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.h b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.h index 207ea3ea..f9c3ede1 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.h +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.h @@ -32,7 +32,6 @@ public: static void Shutdown(); sint32 GetUniformLocation(const char* name) override; - void SetUniform1iv(sint32 location, void* data, sint32 count) override; void SetUniform2fv(sint32 location, void* data, sint32 count) override; void SetUniform4iv(sint32 location, void* data, sint32 count) override; VkShaderModule& GetShaderModule() { return m_shader_module; } diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index 5b4dd739..2ce5dacd 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -1090,17 +1090,6 @@ RendererShader* VulkanRenderer::shader_create(RendererShader::ShaderType type, u return new RendererShaderVk(type, baseHash, auxHash, isGameShader, isGfxPackShader, source); } -void VulkanRenderer::shader_bind(RendererShader* shader) -{ - // does nothing on Vulkan - // remove from main render backend and internalize into GL backend -} - -void VulkanRenderer::shader_unbind(RendererShader::ShaderType shaderType) -{ - // does nothing on Vulkan -} - bool VulkanRenderer::CheckDeviceExtensionSupport(const VkPhysicalDevice device, FeatureControl& info) { std::vector availableDeviceExtensions; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h index 3d68f844..84cae587 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h @@ -350,8 +350,6 @@ public: void buffer_bindUniformBuffer(LatteConst::ShaderType shaderType, uint32 bufferIndex, uint32 offset, uint32 size) override; RendererShader* shader_create(RendererShader::ShaderType type, uint64 baseHash, uint64 auxHash, const std::string& source, bool isGameShader, bool isGfxPackShader) override; - void shader_bind(RendererShader* shader) override; - void shader_unbind(RendererShader::ShaderType shaderType) override; void* indexData_reserveIndexMemory(uint32 size, uint32& offset, uint32& bufferIndex) override; void indexData_uploadIndexMemory(uint32 offset, uint32 size) override;