From ae4c28aa4da2012d2eb8ae9a2dadbf215194777d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 22 Apr 2017 18:36:25 -0700 Subject: [PATCH] D3D9: Support AUTO mip bias and approximate CONST. --- GPU/Directx9/FramebufferDX9.cpp | 2 ++ GPU/Directx9/TextureCacheDX9.cpp | 21 +++++++++++++++++---- GPU/GPUState.h | 1 + ext/native/gfx/d3d9_state.cpp | 3 ++- ext/native/gfx/d3d9_state.h | 1 + 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/GPU/Directx9/FramebufferDX9.cpp b/GPU/Directx9/FramebufferDX9.cpp index 46c719555b..3471108f30 100644 --- a/GPU/Directx9/FramebufferDX9.cpp +++ b/GPU/Directx9/FramebufferDX9.cpp @@ -313,6 +313,8 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = { dxstate.texMagFilter.set(D3DTEXF_POINT); dxstate.texMinFilter.set(D3DTEXF_POINT); } + dxstate.texMipLodBias.set(0.0f); + dxstate.texMaxMipLevel.set(0); device_->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); HRESULT hr = device_->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coord, 5 * sizeof(float)); if (FAILED(hr)) { diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 980e08c1eb..148bbff86c 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -160,17 +160,26 @@ void TextureCacheDX9::UpdateSamplingParams(TexCacheEntry &entry, bool force) { GETexLevelMode mode = gstate.getTexLevelMode(); switch (mode) { case GE_TEXLEVEL_MODE_AUTO: - // TODO + dxstate.texMaxMipLevel.set(0); + dxstate.texMipLodBias.set(lodBias); break; case GE_TEXLEVEL_MODE_CONST: - dxstate.texMipLodBias.set(lodBias); - // TODO + // TODO: This is just an approximation - texMaxMipLevel sets the lowest numbered mip to use. + // Unfortunately, this doesn't support a const 1.5 or etc. + dxstate.texMaxMipLevel.set((int)lodBias); + dxstate.texMipLodBias.set(-1000.0f); break; case GE_TEXLEVEL_MODE_SLOPE: - // TODO + WARN_LOG_REPORT_ONCE(texSlope, G3D, "Unsupported texture lod slope: %f + %f", gstate.getTextureLodSlope(), lodBias); + // TODO: This behavior isn't correct. + dxstate.texMaxMipLevel.set(0); + dxstate.texMipLodBias.set(lodBias); break; } entry.lodBias = lodBias; + } else { + dxstate.texMaxMipLevel.set(0); + dxstate.texMipLodBias.set(0.0f); } D3DTEXTUREFILTERTYPE minf = (D3DTEXTUREFILTERTYPE)MinFilt[minFilt]; @@ -199,6 +208,8 @@ void TextureCacheDX9::SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHe dxstate.texMinFilter.set(MinFilt[minFilt]); dxstate.texMipFilter.set(MipFilt[minFilt]); dxstate.texMagFilter.set(MagFilt[magFilt]); + dxstate.texMipLodBias.set(0.0f); + dxstate.texMaxMipLevel.set(0.0f); // Often the framebuffer will not match the texture size. We'll wrap/clamp in the shader in that case. // This happens whether we have OES_texture_npot or not. @@ -437,6 +448,8 @@ void TextureCacheDX9::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFrame device_->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); device_->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); device_->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); + device_->SetSamplerState(0, D3DSAMP_MIPMAPLODBIAS, 0); + device_->SetSamplerState(0, D3DSAMP_MAXMIPLEVEL, 0); shaderApply.Shade(); diff --git a/GPU/GPUState.h b/GPU/GPUState.h index a64265674b..b49010460e 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -304,6 +304,7 @@ struct GPUgstate { bool isTextureSwizzled() const { return texmode & 1; } bool isClutSharedForMipmaps() const { return (texmode & 0x100) == 0; } int getTextureMaxLevel() const { return (texmode >> 16) & 0x7; } + float getTextureLodSlope() const { return getFloat24(texlodslope); } // Lighting bool isLightingEnabled() const { return lightingEnable & 1; } diff --git a/ext/native/gfx/d3d9_state.cpp b/ext/native/gfx/d3d9_state.cpp index 9bbb60097d..4fadf21b44 100644 --- a/ext/native/gfx/d3d9_state.cpp +++ b/ext/native/gfx/d3d9_state.cpp @@ -59,6 +59,7 @@ void DirectXState::Restore() { texMagFilter.restore(); count++; texMipFilter.restore(); count++; texMipLodBias.restore(); count++; + texMaxMipLevel.restore(); count++; texAddressU.restore(); count++; texAddressV.restore(); count++; } @@ -76,4 +77,4 @@ void DirectXState::SetVSyncInterval(int interval) { } // namespace DX9 -#endif // _MSC_VER \ No newline at end of file +#endif // _MSC_VER diff --git a/ext/native/gfx/d3d9_state.h b/ext/native/gfx/d3d9_state.h index e0735832d8..a9a8eed86d 100644 --- a/ext/native/gfx/d3d9_state.h +++ b/ext/native/gfx/d3d9_state.h @@ -480,6 +480,7 @@ public: DxSampler0State1 texMagFilter; DxSampler0State1 texMipFilter; DxSampler0State1Float texMipLodBias; + DxSampler0State1 texMaxMipLevel; DxSampler0State1 texAddressU; DxSampler0State1 texAddressV;