check if pixel formats match for framebuffer fetch

This commit is contained in:
Samuliak 2025-01-11 10:26:35 +01:00
parent ca3fe96104
commit 217e2edda3
No known key found for this signature in database
2 changed files with 26 additions and 19 deletions

View file

@ -9,6 +9,9 @@
#include "Cafe/HW/Latte/Core/LatteShader.h" #include "Cafe/HW/Latte/Core/LatteShader.h"
#include "Cafe/HW/Latte/Renderer/Renderer.h" #include "Cafe/HW/Latte/Renderer/Renderer.h"
// Defined in LatteTextureLegacy.cpp
Latte::E_GX2SURFFMT LatteTexture_ReconstructGX2Format(const Latte::LATTE_SQ_TEX_RESOURCE_WORD1_N& texUnitWord1, const Latte::LATTE_SQ_TEX_RESOURCE_WORD4_N& texUnitWord4);
/* /*
* Return index of used color attachment based on shader pixel export index (0-7) * Return index of used color attachment based on shader pixel export index (0-7)
*/ */
@ -876,10 +879,13 @@ void LatteDecompiler_analyze(LatteDecompilerShaderContext* shaderContext, LatteD
// TODO: uncomment? // TODO: uncomment?
/* /*
auto lastMip = texRegister.word5.get_LAST_LEVEL(); auto lastMip = texRegister.word5.get_LAST_LEVEL();
// TODO: multiple mip levels could technically be supported as well
if (lastMip != 0) if (lastMip != 0)
continue; continue;
*/ */
Latte::E_GX2SURFFMT format = LatteTexture_ReconstructGX2Format(texRegister.word1, texRegister.word4);
// Check if the texture is used as render target // Check if the texture is used as render target
for (sint32 j = 0; j < LATTE_NUM_COLOR_TARGET; j++) for (sint32 j = 0; j < LATTE_NUM_COLOR_TARGET; j++)
{ {
@ -890,9 +896,10 @@ void LatteDecompiler_analyze(LatteDecompilerShaderContext* shaderContext, LatteD
uint32 regColorBufferBase = colorBufferRegBase[mmCB_COLOR0_BASE - mmCB_COLOR0_BASE] & 0xFFFFFF00; // the low 8 bits are ignored? How to Survive seems to rely on this uint32 regColorBufferBase = colorBufferRegBase[mmCB_COLOR0_BASE - mmCB_COLOR0_BASE] & 0xFFFFFF00; // the low 8 bits are ignored? How to Survive seems to rely on this
MPTR colorBufferPhysMem = regColorBufferBase; MPTR colorBufferPhysMem = regColorBufferBase;
Latte::E_GX2SURFFMT colorBufferFormat = LatteMRT::GetColorBufferFormat(j, *shaderContext->contextRegistersNew);
// TODO: check if mip matches as well? // TODO: check if mip matches as well?
if (physAddr == colorBufferPhysMem) if (physAddr == colorBufferPhysMem && format == colorBufferFormat)
{ {
shader->textureRenderTargetIndex[textureIndex] = j; shader->textureRenderTargetIndex[textureIndex] = j;
break; break;

View file

@ -2293,7 +2293,7 @@ static void _emitTEXSampleTextureCode(LatteDecompilerShaderContext* shaderContex
if (isGather) if (isGather)
src->add("gather"); src->add("gather");
else else
src->add("sample"); src->add("sample");
if (isCompare) if (isCompare)
src->add("_compare"); src->add("_compare");
src->addFmt("(samplr{}, ", texInstruction->textureFetch.textureIndex); src->addFmt("(samplr{}, ", texInstruction->textureFetch.textureIndex);
@ -2456,25 +2456,25 @@ static void _emitTEXSampleTextureCode(LatteDecompilerShaderContext* shaderContex
// 1D textures don't support lod // 1D textures don't support lod
if (texDim != Latte::E_DIM::DIM_1D && texDim != Latte::E_DIM::DIM_1D_ARRAY) if (texDim != Latte::E_DIM::DIM_1D && texDim != Latte::E_DIM::DIM_1D_ARRAY)
{ {
if (texOpcode == GPU7_TEX_INST_SAMPLE_L || texOpcode == GPU7_TEX_INST_SAMPLE_LB || texOpcode == GPU7_TEX_INST_SAMPLE_C_L) if (texOpcode == GPU7_TEX_INST_SAMPLE_L || texOpcode == GPU7_TEX_INST_SAMPLE_LB || texOpcode == GPU7_TEX_INST_SAMPLE_C_L)
{ {
src->add(", "); src->add(", ");
if (texOpcode == GPU7_TEX_INST_SAMPLE_LB) if (texOpcode == GPU7_TEX_INST_SAMPLE_LB)
{ {
src->addFmt("bias({})", _FormatFloatAsConstant((float)texInstruction->textureFetch.lodBias / 16.0f)); src->addFmt("bias({})", _FormatFloatAsConstant((float)texInstruction->textureFetch.lodBias / 16.0f));
} }
else else
{ {
// TODO: is this correct? // TODO: is this correct?
src->add("level("); src->add("level(");
_emitTEXSampleCoordInputComponent(shaderContext, texInstruction, 3, LATTE_DECOMPILER_DTYPE_FLOAT); _emitTEXSampleCoordInputComponent(shaderContext, texInstruction, 3, LATTE_DECOMPILER_DTYPE_FLOAT);
src->add(")"); src->add(")");
} }
} }
else if (texOpcode == GPU7_TEX_INST_SAMPLE_LZ || texOpcode == GPU7_TEX_INST_SAMPLE_C_LZ) else if (texOpcode == GPU7_TEX_INST_SAMPLE_LZ || texOpcode == GPU7_TEX_INST_SAMPLE_C_LZ)
{ {
src->add(", level(0.0)"); src->add(", level(0.0)");
} }
} }
} }
// gradient parameters // gradient parameters