Merge pull request #16181 from unknownbrackets/d3d9-clut

Add rendered CLUT handling to D3D9
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2022-10-09 10:17:17 +02:00
commit 76be009b41
3 files changed
+25 -6

No files matched your search

+13 -5
View File
@@ -201,11 +201,19 @@ public:
D3DTEXTUREFILTERTYPE magFilt, minFilt, mipFilt;
void Apply(LPDIRECT3DDEVICE9 device, int index) {
dxstate.texAddressU.set(wrapS);
dxstate.texAddressV.set(wrapT);
dxstate.texMagFilter.set(magFilt);
dxstate.texMinFilter.set(minFilt);
dxstate.texMipFilter.set(mipFilt);
if (index == 0) {
dxstate.texAddressU.set(wrapS);
dxstate.texAddressV.set(wrapT);
dxstate.texMagFilter.set(magFilt);
dxstate.texMinFilter.set(minFilt);
dxstate.texMipFilter.set(mipFilt);
} else {
pD3Ddevice9->SetSamplerState(index, D3DSAMP_ADDRESSU, wrapS);
pD3Ddevice9->SetSamplerState(index, D3DSAMP_ADDRESSV, wrapT);
pD3Ddevice9->SetSamplerState(index, D3DSAMP_MAGFILTER, magFilt);
pD3Ddevice9->SetSamplerState(index, D3DSAMP_MINFILTER, minFilt);
pD3Ddevice9->SetSamplerState(index, D3DSAMP_MIPFILTER, mipFilt);
}
}
};
+8 -1
View File
@@ -174,7 +174,10 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config) {
case GE_FORMAT_CLUT8:
if (shift == 0 && mask == 0xFF) {
// Easy peasy.
sprintf(lookupMethod, "index.r");
if (writer.Lang().shaderLanguage == HLSL_D3D9)
sprintf(lookupMethod, "index.a");
else
sprintf(lookupMethod, "index.r");
formatOK = true;
} else {
// Deal with this if we find it.
@@ -302,6 +305,10 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config) {
// Offset by half a texel (plus clutBase) to turn NEAREST filtering into FLOOR.
// Technically, the clutBase should be |'d, not added, but that's hard with floats.
float texel_offset = ((float)config.startPos + 0.5f) / texturePixels;
if (writer.Lang().shaderLanguage == HLSL_D3D9) {
// Seems to need a half-pixel offset fix? Might mean it was rendered wrong...
texel_offset += 0.5f / texturePixels;
}
char offset[128] = "";
sprintf(offset, " + %f", texel_offset);
+4
View File
@@ -47,6 +47,8 @@ Draw::DataFormat FromD3D9Format(u32 fmt) {
return Draw::DataFormat::A1R5G5B5_UNORM_PACK16;
case D3DFMT_R5G6B5:
return Draw::DataFormat::R5G6B5_UNORM_PACK16;
case D3DFMT_A8:
return Draw::DataFormat::R8_UNORM;
case D3DFMT_A8R8G8B8:
default:
return Draw::DataFormat::R8G8B8A8_UNORM;
@@ -251,6 +253,8 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry) {
dstFmt = ToD3D9Format(plan.replaced->Format(plan.baseLevelSrc));
} else if (plan.scaleFactor > 1 || plan.saveTexture) {
dstFmt = D3DFMT_A8R8G8B8;
} else if (plan.decodeToClut8) {
dstFmt = D3DFMT_A8;
}
int levels;