Skip to content

Commit

Permalink
[d3d9] Clamp Dref to [0.0, 1.0] if the texture is emulated UNORM
Browse files Browse the repository at this point in the history
  • Loading branch information
DadSchoorse committed Sep 26, 2022
1 parent 2af8bd8 commit e3778d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3791,6 +3791,9 @@ namespace dxvk {
m_dirtySamplerStates |= 1u << StateSampler;
}

m_drefClamp &= ~(1u << StateSampler);
m_drefClamp |= uint32_t(newTexture->IsUpgradedToD32f()) << StateSampler;

const bool oldCube = m_cubeTextures & (1u << StateSampler);
const bool newCube = newTexture->GetType() == D3DRTYPE_CUBETEXTURE;
if (oldCube != newCube) {
Expand Down Expand Up @@ -6249,7 +6252,8 @@ namespace dxvk {

const uint32_t nullTextureMask = usedSamplerMask & ~usedTextureMask;
const uint32_t depthTextureMask = m_depthTextures & usedTextureMask;
UpdateCommonSamplerSpec(nullTextureMask, depthTextureMask);
const uint32_t drefClampMask = m_drefClamp & depthTextureMask;
UpdateCommonSamplerSpec(nullTextureMask, depthTextureMask, drefClampMask);

if (m_flags.test(D3D9DeviceFlag::DirtySharedPixelShaderData)) {
m_flags.clr(D3D9DeviceFlag::DirtySharedPixelShaderData);
Expand Down Expand Up @@ -7249,7 +7253,7 @@ namespace dxvk {
UpdatePixelShaderSamplerSpec(0u, 0u, 0u);
UpdateVertexBoolSpec(0u);
UpdatePixelBoolSpec(0u);
UpdateCommonSamplerSpec(0u, 0u);
UpdateCommonSamplerSpec(0u, 0u, 0u);

return D3D_OK;
}
Expand Down Expand Up @@ -7443,9 +7447,10 @@ namespace dxvk {
}


void D3D9DeviceEx::UpdateCommonSamplerSpec(uint32_t nullMask, uint32_t depthMask) {
void D3D9DeviceEx::UpdateCommonSamplerSpec(uint32_t nullMask, uint32_t depthMask, uint32_t drefMask) {
bool dirty = m_specInfo.set<SpecSamplerDepthMode>(depthMask);
dirty |= m_specInfo.set<SpecSamplerNull>(nullMask);
dirty |= m_specInfo.set<SpecDrefClamp>(drefMask);

if (dirty)
m_flags.set(D3D9DeviceFlag::DirtySpecializationEntries);
Expand Down
3 changes: 2 additions & 1 deletion src/d3d9/d3d9_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ namespace dxvk {
void UpdateVertexBoolSpec(uint32_t value);
void UpdatePixelBoolSpec(uint32_t value);
void UpdatePixelShaderSamplerSpec(uint32_t types, uint32_t projections, uint32_t fetch4);
void UpdateCommonSamplerSpec(uint32_t boundMask, uint32_t depthMask);
void UpdateCommonSamplerSpec(uint32_t boundMask, uint32_t depthMask, uint32_t drefMask);
void UpdatePointModeSpec(uint32_t mode);
void UpdateFogModeSpec(bool fogEnabled, D3DFOGMODE vertexFogMode, D3DFOGMODE pixelFogMode);

Expand Down Expand Up @@ -1237,6 +1237,7 @@ namespace dxvk {
uint32_t m_instancedData = 0;

uint32_t m_depthTextures = 0;
uint32_t m_drefClamp = 0;
uint32_t m_cubeTextures = 0;
uint32_t m_textureTypes = 0;
uint32_t m_projectionBitfield = 0;
Expand Down

0 comments on commit e3778d6

Please sign in to comment.