From d4703e9534854c3d2e27e6c6ab0f01696716a876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 10 May 2023 20:51:52 +0200 Subject: [PATCH] Decoded position format is always the same --- GPU/Common/VertexDecoderCommon.cpp | 14 +++++--------- GPU/Common/VertexDecoderCommon.h | 6 +++--- GPU/D3D11/DrawEngineD3D11.cpp | 2 +- GPU/Directx9/DrawEngineDX9.cpp | 2 +- GPU/GLES/DrawEngineGLES.cpp | 2 +- GPU/Vulkan/PipelineManagerVulkan.cpp | 2 +- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/GPU/Common/VertexDecoderCommon.cpp b/GPU/Common/VertexDecoderCommon.cpp index ec1af7c80e7d..cc8b6452e2b1 100644 --- a/GPU/Common/VertexDecoderCommon.cpp +++ b/GPU/Common/VertexDecoderCommon.cpp @@ -60,7 +60,7 @@ int TranslateNumBones(int bones) { return bones; } -int DecFmtSize(u8 fmt) { +static int DecFmtSize(u8 fmt) { switch (fmt) { case DEC_NONE: return 0; case DEC_FLOAT_1: return 4; @@ -83,7 +83,7 @@ int DecFmtSize(u8 fmt) { } void DecVtxFormat::ComputeID() { - id = w0fmt | (w1fmt << 4) | (uvfmt << 8) | (c0fmt << 12) | (c1fmt << 16) | (nrmfmt << 20) | (posfmt << 24); + id = w0fmt | (w1fmt << 4) | (uvfmt << 8) | (c0fmt << 12) | (c1fmt << 16) | (nrmfmt << 20); } void DecVtxFormat::InitializeFromID(uint32_t id) { @@ -94,7 +94,6 @@ void DecVtxFormat::InitializeFromID(uint32_t id) { c0fmt = ((id >> 12) & 0xF); c1fmt = ((id >> 16) & 0xF); nrmfmt = ((id >> 20) & 0xF); - posfmt = ((id >> 24) & 0xF); w0off = 0; w1off = w0off + DecFmtSize(w0fmt); uvoff = w1off + DecFmtSize(w1fmt); @@ -102,7 +101,7 @@ void DecVtxFormat::InitializeFromID(uint32_t id) { c1off = c0off + DecFmtSize(c0fmt); nrmoff = c1off + DecFmtSize(c1fmt); posoff = nrmoff + DecFmtSize(nrmfmt); - stride = posoff + DecFmtSize(posfmt); + stride = posoff + DecFmtSize(PosFmt()); } void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBound, u16 *indexUpperBound) { @@ -1248,20 +1247,18 @@ void VertexDecoder::SetVertexType(u32 fmt, const VertexDecoderOptions &options, if (posalign[pos] > biggest) biggest = posalign[pos]; + // We don't set posfmt because it's always DEC_FLOAT_3. if (throughmode) { steps_[numSteps_++] = posstep_through[pos]; - decFmt.posfmt = DEC_FLOAT_3; } else { if (skinInDecode) { steps_[numSteps_++] = morphcount == 1 ? posstep_skin[pos] : posstep_morph_skin[pos]; - decFmt.posfmt = DEC_FLOAT_3; } else { steps_[numSteps_++] = morphcount == 1 ? posstep[pos] : posstep_morph[pos]; - decFmt.posfmt = DEC_FLOAT_3; } } decFmt.posoff = decOff; - decOff += DecFmtSize(decFmt.posfmt); + decOff += DecFmtSize(DecVtxFormat::PosFmt()); } decFmt.stride = options.alignOutputToWord ? align(decOff, 4) : decOff; @@ -1279,7 +1276,6 @@ void VertexDecoder::SetVertexType(u32 fmt, const VertexDecoderOptions &options, ERROR_LOG_REPORT(G3D, "Vertices without position found: (%08x) %s", fmt_, temp); } - _assert_msg_(decFmt.posfmt == DEC_FLOAT_3, "Reader only supports float pos"); _assert_msg_(decFmt.uvfmt == DEC_FLOAT_2 || decFmt.uvfmt == DEC_NONE, "Reader only supports float UV"); // Attempt to JIT as well. But only do that if the main CPU JIT is enabled, in order to aid diff --git a/GPU/Common/VertexDecoderCommon.h b/GPU/Common/VertexDecoderCommon.h index 5e13332f707c..3a0de590bd83 100644 --- a/GPU/Common/VertexDecoderCommon.h +++ b/GPU/Common/VertexDecoderCommon.h @@ -67,8 +67,6 @@ enum { DEC_U16_4, }; -int DecFmtSize(u8 fmt); - struct DecVtxFormat { u8 w0fmt; u8 w0off; // first 4 weights u8 w1fmt; u8 w1off; // second 4 weights @@ -76,12 +74,14 @@ struct DecVtxFormat { u8 c0fmt; u8 c0off; // First color u8 c1fmt; u8 c1off; u8 nrmfmt; u8 nrmoff; - u8 posfmt; u8 posoff; + u8 posoff; // Output position format is always DEC_FLOAT_3. u8 stride; uint32_t id; void ComputeID(); void InitializeFromID(uint32_t id); + + static u8 PosFmt() { return DEC_FLOAT_3; } }; void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBound, u16 *indexUpperBound); diff --git a/GPU/D3D11/DrawEngineD3D11.cpp b/GPU/D3D11/DrawEngineD3D11.cpp index 0deb056ef45b..1172e0ce292f 100644 --- a/GPU/D3D11/DrawEngineD3D11.cpp +++ b/GPU/D3D11/DrawEngineD3D11.cpp @@ -243,7 +243,7 @@ ID3D11InputLayout *DrawEngineD3D11::SetupDecFmtForDraw(D3D11VertexShader *vshade // POSITION // Always - VertexAttribSetup(VertexElement, decFmt.posfmt, decFmt.posoff, "POSITION", 0); + VertexAttribSetup(VertexElement, DecVtxFormat::PosFmt(), decFmt.posoff, "POSITION", 0); VertexElement++; // Create declaration diff --git a/GPU/Directx9/DrawEngineDX9.cpp b/GPU/Directx9/DrawEngineDX9.cpp index 276fde10a3dc..72f19884721b 100644 --- a/GPU/Directx9/DrawEngineDX9.cpp +++ b/GPU/Directx9/DrawEngineDX9.cpp @@ -206,7 +206,7 @@ IDirect3DVertexDeclaration9 *DrawEngineDX9::SetupDecFmtForDraw(const DecVtxForma // POSITION // Always - VertexAttribSetup(VertexElement, decFmt.posfmt, decFmt.posoff, D3DDECLUSAGE_POSITION, 0); + VertexAttribSetup(VertexElement, DecVtxFormat::PosFmt(), decFmt.posoff, D3DDECLUSAGE_POSITION, 0); VertexElement++; // End diff --git a/GPU/GLES/DrawEngineGLES.cpp b/GPU/GLES/DrawEngineGLES.cpp index 9949d0c37bb7..f48a9d80b332 100644 --- a/GPU/GLES/DrawEngineGLES.cpp +++ b/GPU/GLES/DrawEngineGLES.cpp @@ -218,7 +218,7 @@ GLRInputLayout *DrawEngineGLES::SetupDecFmtForDraw(const DecVtxFormat &decFmt) { VertexAttribSetup(ATTR_COLOR0, decFmt.c0fmt, decFmt.stride, decFmt.c0off, entries); VertexAttribSetup(ATTR_COLOR1, decFmt.c1fmt, decFmt.stride, decFmt.c1off, entries); VertexAttribSetup(ATTR_NORMAL, decFmt.nrmfmt, decFmt.stride, decFmt.nrmoff, entries); - VertexAttribSetup(ATTR_POSITION, decFmt.posfmt, decFmt.stride, decFmt.posoff, entries); + VertexAttribSetup(ATTR_POSITION, DecVtxFormat::PosFmt(), decFmt.stride, decFmt.posoff, entries); inputLayout = render_->CreateInputLayout(entries); inputLayoutMap_.Insert(key, inputLayout); diff --git a/GPU/Vulkan/PipelineManagerVulkan.cpp b/GPU/Vulkan/PipelineManagerVulkan.cpp index 05803e30286e..75d280590398 100644 --- a/GPU/Vulkan/PipelineManagerVulkan.cpp +++ b/GPU/Vulkan/PipelineManagerVulkan.cpp @@ -134,7 +134,7 @@ static int SetupVertexAttribs(VkVertexInputAttributeDescription attrs[], const D VertexAttribSetup(&attrs[count++], decFmt.nrmfmt, decFmt.nrmoff, PspAttributeLocation::NORMAL); } // Position is always there. - VertexAttribSetup(&attrs[count++], decFmt.posfmt, decFmt.posoff, PspAttributeLocation::POSITION); + VertexAttribSetup(&attrs[count++], DecVtxFormat::PosFmt(), decFmt.posoff, PspAttributeLocation::POSITION); return count; }