From 756cb7e05a11afb3b370e3bef5b80600d402f44d Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 11 Mar 2023 09:13:23 -0600 Subject: [PATCH] feat(gx): handle shader constants in d3d backend --- src/gx/d3d/CGxDeviceD3d.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/gx/d3d/CGxDeviceD3d.cpp b/src/gx/d3d/CGxDeviceD3d.cpp index a7f3945..56d622f 100644 --- a/src/gx/d3d/CGxDeviceD3d.cpp +++ b/src/gx/d3d/CGxDeviceD3d.cpp @@ -766,7 +766,7 @@ void CGxDeviceD3d::IRsSendToHw(EGxRenderState which) { void CGxDeviceD3d::ISceneBegin() { if (this->m_context) { - // TODO + this->ShaderConstantsClear(); if (SUCCEEDED(this->m_d3dDevice->BeginScene())) { this->m_inScene = 1; @@ -1046,7 +1046,29 @@ void CGxDeviceD3d::IShaderBindVertex(CGxShader* shader) { } void CGxDeviceD3d::IShaderConstantsFlush() { - // TODO + // Vertex shader constants + auto vsConst = &CGxDevice::s_shadowConstants[1]; + if (vsConst->unk2 <= vsConst->unk1) { + this->m_d3dDevice->SetVertexShaderConstantF( + vsConst->unk2, + reinterpret_cast(&vsConst->constants[vsConst->unk2]), + vsConst->unk1 - vsConst->unk2 + 1 + ); + } + vsConst->unk2 = 255; + vsConst->unk1 = 0; + + // Pixel shader constants + auto psConst = &CGxDevice::s_shadowConstants[0]; + if (psConst->unk2 <= psConst->unk1) { + this->m_d3dDevice->SetPixelShaderConstantF( + psConst->unk2, + reinterpret_cast(&psConst->constants[psConst->unk2]), + psConst->unk1 - psConst->unk2 + 1 + ); + } + psConst->unk2 = 255; + psConst->unk1 = 0; } void CGxDeviceD3d::IShaderCreate(CGxShader* shader) {