mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-12 22:08:59 +01:00
[d3d9] Clean up fetch4 handling
This commit is contained in:
parent
8c9601b4cd
commit
9108f8c76c
@ -3691,6 +3691,8 @@ namespace dxvk {
|
|||||||
|
|
||||||
state[StateSampler][Type] = Value;
|
state[StateSampler][Type] = Value;
|
||||||
|
|
||||||
|
const uint32_t samplerBit = 1u << StateSampler;
|
||||||
|
|
||||||
if (Type == D3DSAMP_ADDRESSU
|
if (Type == D3DSAMP_ADDRESSU
|
||||||
|| Type == D3DSAMP_ADDRESSV
|
|| Type == D3DSAMP_ADDRESSV
|
||||||
|| Type == D3DSAMP_ADDRESSW
|
|| Type == D3DSAMP_ADDRESSW
|
||||||
@ -3701,38 +3703,24 @@ namespace dxvk {
|
|||||||
|| Type == D3DSAMP_MIPMAPLODBIAS
|
|| Type == D3DSAMP_MIPMAPLODBIAS
|
||||||
|| Type == D3DSAMP_MAXMIPLEVEL
|
|| Type == D3DSAMP_MAXMIPLEVEL
|
||||||
|| Type == D3DSAMP_BORDERCOLOR)
|
|| Type == D3DSAMP_BORDERCOLOR)
|
||||||
m_dirtySamplerStates |= 1u << StateSampler;
|
m_dirtySamplerStates |= samplerBit;
|
||||||
else if (Type == D3DSAMP_SRGBTEXTURE && (m_activeTextures & (1u << StateSampler)))
|
else if (Type == D3DSAMP_SRGBTEXTURE && (m_activeTextures & samplerBit))
|
||||||
m_dirtyTextures |= 1u << StateSampler;
|
m_dirtyTextures |= samplerBit;
|
||||||
|
|
||||||
constexpr DWORD Fetch4Enabled = MAKEFOURCC('G', 'E', 'T', '4');
|
constexpr DWORD Fetch4Enabled = MAKEFOURCC('G', 'E', 'T', '4');
|
||||||
constexpr DWORD Fetch4Disabled = MAKEFOURCC('G', 'E', 'T', '1');
|
constexpr DWORD Fetch4Disabled = MAKEFOURCC('G', 'E', 'T', '1');
|
||||||
|
|
||||||
if (unlikely(Type == D3DSAMP_MIPMAPLODBIAS)) {
|
if (unlikely(Type == D3DSAMP_MIPMAPLODBIAS)) {
|
||||||
auto texture = GetCommonTexture(m_state.textures[StateSampler]);
|
if (unlikely(Value == Fetch4Enabled))
|
||||||
bool textureSupportsFetch4 = texture != nullptr && texture->SupportsFetch4();
|
m_fetch4Enabled |= samplerBit;
|
||||||
|
else if (unlikely(Value == Fetch4Disabled))
|
||||||
|
m_fetch4Enabled &= ~samplerBit;
|
||||||
|
|
||||||
if (unlikely(Value == Fetch4Enabled)) {
|
UpdateActiveFetch4(StateSampler);
|
||||||
m_fetch4Enabled |= 1u << StateSampler;
|
|
||||||
if (textureSupportsFetch4 && state[StateSampler][D3DSAMP_MAGFILTER] == D3DTEXF_POINT) {
|
|
||||||
m_fetch4 |= 1u << StateSampler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (unlikely(Value == Fetch4Disabled)) {
|
|
||||||
m_fetch4Enabled &= ~(1u << StateSampler);
|
|
||||||
m_fetch4 &= ~(1u << StateSampler);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(Type == D3DSAMP_MAGFILTER && (m_fetch4Enabled & (1u << StateSampler)))) {
|
if (unlikely(Type == D3DSAMP_MAGFILTER && (m_fetch4Enabled & samplerBit)))
|
||||||
auto texture = GetCommonTexture(m_state.textures[StateSampler]);
|
UpdateActiveFetch4(StateSampler);
|
||||||
bool textureSupportsFetch4 = texture != nullptr && texture->SupportsFetch4();
|
|
||||||
|
|
||||||
if (Value == D3DTEXF_POINT && textureSupportsFetch4)
|
|
||||||
m_fetch4 |= 1u << StateSampler;
|
|
||||||
else
|
|
||||||
m_fetch4 &= ~(1u << StateSampler);
|
|
||||||
}
|
|
||||||
|
|
||||||
return D3D_OK;
|
return D3D_OK;
|
||||||
}
|
}
|
||||||
@ -3783,25 +3771,11 @@ namespace dxvk {
|
|||||||
m_dirtySamplerStates |= 1u << StateSampler;
|
m_dirtySamplerStates |= 1u << StateSampler;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(m_fetch4Enabled & (1u << StateSampler))) {
|
if (unlikely(m_fetch4Enabled & (1u << StateSampler)))
|
||||||
const bool samplerFetch4 = (m_fetch4 & (1u << StateSampler)) != 0;
|
UpdateActiveFetch4(StateSampler);
|
||||||
const bool pointFilter = m_state.samplerStates[StateSampler][D3DSAMP_MAGFILTER] == D3DTEXF_POINT
|
} else {
|
||||||
&& m_state.samplerStates[StateSampler][D3DSAMP_MINFILTER] == D3DTEXF_POINT;
|
if (unlikely(m_fetch4 & (1u << StateSampler)))
|
||||||
const bool textureSupportsFetch4 = newTexture->SupportsFetch4();
|
UpdateActiveFetch4(StateSampler);
|
||||||
|
|
||||||
if (unlikely(textureSupportsFetch4 && pointFilter && !samplerFetch4)) {
|
|
||||||
// We're swapping a multi channel texture for a single channel texture => turn on fetch4
|
|
||||||
m_fetch4 |= 1u << StateSampler;
|
|
||||||
m_dirtySamplerStates |= 1u << StateSampler;
|
|
||||||
} else if (unlikely(!textureSupportsFetch4 && samplerFetch4)) {
|
|
||||||
// We're swapping a single channel texture for a multi channel one => turn off fetch4
|
|
||||||
m_fetch4 &= ~(1u << StateSampler);
|
|
||||||
m_dirtySamplerStates |= 1u << StateSampler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (unlikely(m_fetch4 & (1u << StateSampler))) {
|
|
||||||
m_fetch4 &= ~(1u << StateSampler);
|
|
||||||
m_dirtySamplerStates |= 1u << StateSampler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD combinedUsage = oldUsage | newUsage;
|
DWORD combinedUsage = oldUsage | newUsage;
|
||||||
@ -5256,6 +5230,27 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void D3D9DeviceEx::UpdateActiveFetch4(uint32_t stateSampler) {
|
||||||
|
auto& state = m_state.samplerStates;
|
||||||
|
|
||||||
|
const uint32_t samplerBit = 1u << stateSampler;
|
||||||
|
|
||||||
|
auto texture = GetCommonTexture(m_state.textures[stateSampler]);
|
||||||
|
const bool textureSupportsFetch4 = texture != nullptr && texture->SupportsFetch4();
|
||||||
|
|
||||||
|
const bool fetch4Enabled = m_fetch4Enabled & samplerBit;
|
||||||
|
const bool pointSampled = state[stateSampler][D3DSAMP_MAGFILTER] == D3DTEXF_POINT;
|
||||||
|
const bool shouldFetch4 = fetch4Enabled && textureSupportsFetch4 && pointSampled;
|
||||||
|
|
||||||
|
if (unlikely(shouldFetch4 != !!(m_fetch4 & samplerBit))) {
|
||||||
|
if (shouldFetch4)
|
||||||
|
m_fetch4 |= samplerBit;
|
||||||
|
else
|
||||||
|
m_fetch4 &= ~samplerBit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void D3D9DeviceEx::UploadManagedTexture(D3D9CommonTexture* pResource) {
|
void D3D9DeviceEx::UploadManagedTexture(D3D9CommonTexture* pResource) {
|
||||||
for (uint32_t subresource = 0; subresource < pResource->CountSubresources(); subresource++) {
|
for (uint32_t subresource = 0; subresource < pResource->CountSubresources(); subresource++) {
|
||||||
if (!pResource->NeedsUpload(subresource))
|
if (!pResource->NeedsUpload(subresource))
|
||||||
|
@ -767,6 +767,8 @@ namespace dxvk {
|
|||||||
|
|
||||||
void MarkRenderHazards();
|
void MarkRenderHazards();
|
||||||
|
|
||||||
|
void UpdateActiveFetch4(uint32_t stateSampler);
|
||||||
|
|
||||||
void UploadManagedTexture(D3D9CommonTexture* pResource);
|
void UploadManagedTexture(D3D9CommonTexture* pResource);
|
||||||
|
|
||||||
void UploadManagedTextures(uint32_t mask);
|
void UploadManagedTextures(uint32_t mask);
|
||||||
@ -1240,6 +1242,12 @@ namespace dxvk {
|
|||||||
uint32_t m_activeTexturesToUpload = 0;
|
uint32_t m_activeTexturesToUpload = 0;
|
||||||
uint32_t m_activeTexturesToGen = 0;
|
uint32_t m_activeTexturesToGen = 0;
|
||||||
|
|
||||||
|
// m_fetch4Enabled is whether fetch4 is currently enabled
|
||||||
|
// from the application.
|
||||||
|
//
|
||||||
|
// m_fetch4 is whether it should be enabled in the shader
|
||||||
|
// ie. are we in a correct state to use it
|
||||||
|
// (enabled + texture supports it + point sampled)
|
||||||
uint32_t m_fetch4Enabled = 0;
|
uint32_t m_fetch4Enabled = 0;
|
||||||
uint32_t m_fetch4 = 0;
|
uint32_t m_fetch4 = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user