1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-13 16:08:50 +01:00

[d3d9] Only enable FETCH4 for single channel formats

This commit is contained in:
Robin Kertels 2022-01-27 17:27:25 +01:00 committed by Joshie
parent 5b39f0307e
commit b220c8989b
3 changed files with 48 additions and 5 deletions

View File

@ -32,6 +32,7 @@ namespace dxvk {
m_mapMode = DetermineMapMode();
m_shadow = DetermineShadowState();
m_supportsFetch4 = DetermineFetch4Compatibility();
if (m_mapMode == D3D9_COMMON_TEXTURE_MAP_MODE_BACKED) {
bool plainSurface = m_type == D3DRTYPE_SURFACE &&
@ -316,7 +317,7 @@ namespace dxvk {
BOOL D3D9CommonTexture::DetermineShadowState() const {
static std::array<D3D9Format, 3> blacklist = {
constexpr std::array<D3D9Format, 3> blacklist = {
D3D9Format::INTZ, D3D9Format::DF16, D3D9Format::DF24
};
@ -325,6 +326,17 @@ namespace dxvk {
}
BOOL D3D9CommonTexture::DetermineFetch4Compatibility() const {
constexpr std::array<D3D9Format, 8> singleChannelFormats = {
D3D9Format::INTZ, D3D9Format::DF16, D3D9Format::DF24,
D3D9Format::R16F, D3D9Format::R32F, D3D9Format::A8,
D3D9Format::L8, D3D9Format::L16
};
return std::find(singleChannelFormats.begin(), singleChannelFormats.end(), m_desc.Format) != singleChannelFormats.end();
}
BOOL D3D9CommonTexture::CheckImageSupport(
const DxvkImageCreateInfo* pImageInfo,
VkImageTiling Tiling) const {

View File

@ -190,6 +190,14 @@ namespace dxvk {
return m_shadow;
}
/**
* \brief FETCH4 compatibility
* \returns Whether the format of the texture supports the FETCH4 hack
*/
bool SupportsFetch4() const {
return m_supportsFetch4;
}
/**
* \brief Null
* \returns Whether the texture is D3DFMT_NULL or not
@ -444,6 +452,7 @@ namespace dxvk {
D3D9_VK_FORMAT_MAPPING m_mapping;
bool m_shadow; //< Depth Compare-ness
bool m_supportsFetch4;
int64_t m_size = 0;
@ -483,6 +492,8 @@ namespace dxvk {
BOOL DetermineShadowState() const;
BOOL DetermineFetch4Compatibility() const;
BOOL CheckImageSupport(
const DxvkImageCreateInfo* pImageInfo,
VkImageTiling Tiling) const;

View File

@ -3682,11 +3682,15 @@ namespace dxvk {
constexpr DWORD Fetch4Disabled = MAKEFOURCC('G', 'E', 'T', '1');
if (unlikely(Type == D3DSAMP_MIPMAPLODBIAS)) {
auto texture = GetCommonTexture(m_state.textures[StateSampler]);
bool textureSupportsFetch4 = texture != nullptr && texture->SupportsFetch4();
if (unlikely(Value == Fetch4Enabled)) {
m_fetch4Enabled |= 1u << StateSampler;
if (state[StateSampler][D3DSAMP_MAGFILTER] == D3DTEXF_POINT)
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);
@ -3694,7 +3698,10 @@ namespace dxvk {
}
if (unlikely(Type == D3DSAMP_MAGFILTER && (m_fetch4Enabled & (1u << StateSampler)))) {
if (Value == D3DTEXF_POINT)
auto texture = GetCommonTexture(m_state.textures[StateSampler]);
bool textureSupportsFetch4 = texture != nullptr && texture->SupportsFetch4();
if (Value == D3DTEXF_POINT && textureSupportsFetch4)
m_fetch4 |= 1u << StateSampler;
else
m_fetch4 &= ~(1u << StateSampler);
@ -3748,6 +3755,19 @@ namespace dxvk {
m_dirtySamplerStates |= 1u << StateSampler;
}
if (unlikely(m_fetch4Enabled & (1u << StateSampler) && !(m_fetch4 & (1u << StateSampler)))) {
bool textureSupportsFetch4 = newTexture->SupportsFetch4();
if (textureSupportsFetch4
&& m_state.samplerStates[StateSampler][D3DSAMP_MAGFILTER] == D3DTEXF_POINT
&& m_state.samplerStates[StateSampler][D3DSAMP_MINFILTER] == D3DTEXF_POINT) {
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;