From 73859890b17227770875485ac066379efe165f30 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Fri, 17 Mar 2023 17:04:58 -0500 Subject: [PATCH] feat(gx): use caps-defined shader profiles --- src/gx/CGxCaps.hpp | 3 +-- src/gx/CGxDevice.cpp | 2 +- src/gx/CGxDevice.hpp | 1 - src/gx/d3d/CGxDeviceD3d.cpp | 20 ++++++++------------ src/gx/gll/CGxDeviceGLL.cpp | 4 ++-- src/model/CM2Cache.cpp | 2 +- src/world/CWorld.cpp | 4 ++-- 7 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/gx/CGxCaps.hpp b/src/gx/CGxCaps.hpp index 546fd62..6a9b0f4 100644 --- a/src/gx/CGxCaps.hpp +++ b/src/gx/CGxCaps.hpp @@ -17,8 +17,7 @@ class CGxCaps { int32_t m_texFmt[GxTexFormats_Last] = { 0 }; int32_t m_texTarget[GxTexTargets_Last]; uint32_t m_texMaxSize[GxTexTargets_Last]; - EGxShVS m_vertexShaderTarget = GxShVS_none; - EGxShPS m_pixelShaderTarget = GxShPS_none; + int32_t m_shaderTargets[GxShTargets_Last] = { 0 }; int32_t m_texFilterTrilinear = 0; int32_t m_texFilterAnisotropic = 0; uint32_t m_maxTexAnisotropy = 0; diff --git a/src/gx/CGxDevice.cpp b/src/gx/CGxDevice.cpp index 0850208..75f4a65 100644 --- a/src/gx/CGxDevice.cpp +++ b/src/gx/CGxDevice.cpp @@ -444,7 +444,7 @@ void CGxDevice::IRsSync(int32_t force) { } void CGxDevice::IShaderLoad(CGxShader* shaders[], EGxShTarget target, const char* a4, const char* a5, int32_t permutations) { - int32_t profile = this->m_shaderProfiles[target]; + int32_t profile = this->m_caps.m_shaderTargets[target]; if (!profile) { return; diff --git a/src/gx/CGxDevice.hpp b/src/gx/CGxDevice.hpp index dbcc353..38621a8 100644 --- a/src/gx/CGxDevice.hpp +++ b/src/gx/CGxDevice.hpp @@ -69,7 +69,6 @@ class CGxDevice { EGxApi m_api = GxApis_Last; CGxFormat m_format; CGxCaps m_caps; - int32_t m_shaderProfiles[GxShTargets_Last] = { 6, 0, 0, 0, 12, 0 }; // TODO placeholder TSHashTable m_shaderList[GxShTargets_Last]; int32_t (*m_windowProc)(void* window, uint32_t message, uintptr_t wparam, intptr_t lparam) = nullptr; int32_t m_context = 0; diff --git a/src/gx/d3d/CGxDeviceD3d.cpp b/src/gx/d3d/CGxDeviceD3d.cpp index cf9c788..4db6117 100644 --- a/src/gx/d3d/CGxDeviceD3d.cpp +++ b/src/gx/d3d/CGxDeviceD3d.cpp @@ -372,10 +372,6 @@ CGxDeviceD3d::CGxDeviceD3d() : CGxDevice() { this->m_api = GxApi_D3d9; - // TODO remove m_shaderProfiles in favor of caps-defined profiles - this->m_shaderProfiles[GxSh_Vertex] = GxShVS_vs_3_0; - this->m_shaderProfiles[GxSh_Pixel] = GxShPS_ps_3_0; - // TODO memset(this->m_deviceStates, 0xFF, sizeof(this->m_deviceStates)); @@ -1181,24 +1177,24 @@ void CGxDeviceD3d::ISetCaps(const CGxFormat& format) { auto pixelShaderVersion = this->m_d3dCaps.PixelShaderVersion; if (pixelShaderVersion >= D3DPS_VERSION(3, 0)) { - this->m_caps.m_pixelShaderTarget = GxShPS_ps_3_0; + this->m_caps.m_shaderTargets[GxSh_Pixel] = GxShPS_ps_3_0; } else if (pixelShaderVersion >= D3DPS_VERSION(2, 0)) { - this->m_caps.m_pixelShaderTarget = GxShPS_ps_2_0; + this->m_caps.m_shaderTargets[GxSh_Pixel] = GxShPS_ps_2_0; } else if (pixelShaderVersion >= D3DPS_VERSION(1, 4)) { - this->m_caps.m_pixelShaderTarget = GxShPS_ps_1_4; + this->m_caps.m_shaderTargets[GxSh_Pixel] = GxShPS_ps_1_4; } else if (pixelShaderVersion >= D3DPS_VERSION(1, 1)) { - this->m_caps.m_pixelShaderTarget = GxShPS_ps_1_1; + this->m_caps.m_shaderTargets[GxSh_Pixel] = GxShPS_ps_1_1; } - if (this->m_caps.m_pixelShaderTarget != GxShPS_none) { + if (this->m_caps.m_shaderTargets[GxSh_Pixel] != GxShPS_none) { auto vertexShaderVersion = this->m_d3dCaps.VertexShaderVersion; if (vertexShaderVersion >= D3DVS_VERSION(3, 0)) { - this->m_caps.m_vertexShaderTarget = GxShVS_vs_3_0; + this->m_caps.m_shaderTargets[GxSh_Vertex] = GxShVS_vs_3_0; } else if (vertexShaderVersion >= D3DVS_VERSION(2, 0)) { - this->m_caps.m_vertexShaderTarget = GxShVS_vs_2_0; + this->m_caps.m_shaderTargets[GxSh_Vertex] = GxShVS_vs_2_0; } else if (vertexShaderVersion == D3DVS_VERSION(1, 1)) { - this->m_caps.m_vertexShaderTarget = GxShVS_vs_1_1; + this->m_caps.m_shaderTargets[GxSh_Vertex] = GxShVS_vs_1_1; } // TODO maxVertexShaderConst diff --git a/src/gx/gll/CGxDeviceGLL.cpp b/src/gx/gll/CGxDeviceGLL.cpp index 7ee6c09..6acc8e8 100644 --- a/src/gx/gll/CGxDeviceGLL.cpp +++ b/src/gx/gll/CGxDeviceGLL.cpp @@ -676,8 +676,8 @@ void CGxDeviceGLL::ISetCaps(const CGxFormat& format) { this->m_caps.m_texFmt[GxTex_Dxt3] = 1; this->m_caps.m_texFmt[GxTex_Dxt5] = 1; - this->m_caps.m_vertexShaderTarget = GxShVS_arbvp1; - this->m_caps.m_pixelShaderTarget = GxShPS_arbfp1; + this->m_caps.m_shaderTargets[GxSh_Vertex] = GxShVS_arbvp1; + this->m_caps.m_shaderTargets[GxSh_Pixel] = GxShPS_arbfp1; this->m_caps.m_texFilterAnisotropic = 1; this->m_caps.m_maxTexAnisotropy = 16; diff --git a/src/model/CM2Cache.cpp b/src/model/CM2Cache.cpp index a56f5cd..b4b223b 100644 --- a/src/model/CM2Cache.cpp +++ b/src/model/CM2Cache.cpp @@ -73,7 +73,7 @@ int32_t CM2Cache::Initialize(uint32_t flags) { // TODO if (flags & 0x8) { - if (GxCaps().m_vertexShaderTarget > GxShVS_none && GxCaps().m_pixelShaderTarget > GxShPS_none) { + if (GxCaps().m_shaderTargets[GxSh_Vertex] > GxShVS_none && GxCaps().m_shaderTargets[GxSh_Pixel] > GxShPS_none) { this->m_flags |= 0x8; } } diff --git a/src/world/CWorld.cpp b/src/world/CWorld.cpp index 457dd69..7da5185 100644 --- a/src/world/CWorld.cpp +++ b/src/world/CWorld.cpp @@ -24,11 +24,11 @@ void CWorld::Initialize() { // TODO - if (GxCaps().m_pixelShaderTarget > GxShPS_none) { + if (GxCaps().m_shaderTargets[GxSh_Pixel] > GxShPS_none) { CWorld::s_enables |= Enables::Enable_PixelShader; } - if (GxCaps().m_vertexShaderTarget > GxShVS_none) { + if (GxCaps().m_shaderTargets[GxSh_Vertex] > GxShVS_none) { CWorld::s_enables2 |= Enables2::Enable_VertexShader; }