mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-12-25 01:01:52 +01:00
Latte: Refactor legacy OpenGL code for shader binding
This commit is contained in:
parent
dee764473d
commit
646835346c
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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<class LatteQueryObjectGL*> 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<bufferCacheReleaseQueueEntry_t> bufferCacheEntries;
|
||||
std::vector<BufferCacheReleaseQueueEntry> bufferCacheEntries;
|
||||
}m_destructionQueues;
|
||||
|
||||
};
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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; }
|
||||
|
@ -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<VkExtensionProperties> availableDeviceExtensions;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user