This commit is contained in:
Jeff 2024-01-24 18:33:20 +01:00 committed by GitHub
commit 2cc8acc60a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 58 additions and 9 deletions

View File

@ -7156,6 +7156,8 @@ namespace dxvk {
stage.Projected = (ttff & D3DTTFF_PROJECTED) ? 1 : 0;
stage.ProjectedCount = (ttff & D3DTTFF_PROJECTED) ? count : 0;
stage.SampleDref = (m_depthTextures & (1 << idx)) != 0;
}
auto& stage0 = key.Stages[0].Contents;

View File

@ -15,6 +15,7 @@ namespace dxvk {
D3D9FixedFunctionOptions::D3D9FixedFunctionOptions(const D3D9Options* options) {
invariantPosition = options->invariantPosition;
forceSampleRateShading = options->forceSampleRateShading;
drefScaling = options->drefScaling;
}
uint32_t DoFixedFunctionFog(D3D9ShaderSpecConstantManager& spec, SpirvModule& spvModule, const D3D9FogContext& fogCtx) {
@ -1789,6 +1790,11 @@ namespace dxvk {
return coords;
};
auto ScalarReplicate = [&](uint32_t reg) {
std::array<uint32_t, 4> replicant = { reg, reg, reg, reg };
return m_module.opCompositeConstruct(m_vec4Type, replicant.size(), replicant.data());
};
auto GetTexture = [&]() {
if (!processedTexture) {
SpirvImageOperands imageOperands;
@ -1837,10 +1843,23 @@ namespace dxvk {
shouldProject = false;
}
if (shouldProject)
if (unlikely(stage.SampleDref)) {
uint32_t component = 2;
uint32_t reference = m_module.opCompositeExtract(m_floatType, texcoord, 1, &component);
// [D3D8] Scale Dref to [0..(2^N - 1)] for D24S8 and D16 if Dref scaling is enabled
if (m_options.drefScaling) {
uint32_t maxDref = m_module.constf32(1.0f / (float(1 << m_options.drefScaling) - 1.0f));
reference = m_module.opFMul(m_floatType, reference, maxDref);
}
texture = m_module.opImageSampleDrefImplicitLod(m_floatType, imageVarId, texcoord, reference, imageOperands);
texture = ScalarReplicate(texture);
} else if (shouldProject) {
texture = m_module.opImageSampleProjImplicitLod(m_vec4Type, imageVarId, texcoord, imageOperands);
else
} else {
texture = m_module.opImageSampleImplicitLod(m_vec4Type, imageVarId, texcoord, imageOperands);
}
if (i != 0 && m_fsKey.Stages[i - 1].Contents.ColorOp == D3DTOP_BUMPENVMAPLUMINANCE) {
uint32_t index = m_module.constu32(D3D9SharedPSStages_Count * (i - 1) + D3D9SharedPSStages_BumpEnvLScale);
@ -1868,11 +1887,6 @@ namespace dxvk {
return texture;
};
auto ScalarReplicate = [&](uint32_t reg) {
std::array<uint32_t, 4> replicant = { reg, reg, reg, reg };
return m_module.opCompositeConstruct(m_vec4Type, replicant.size(), replicant.data());
};
auto AlphaReplicate = [&](uint32_t reg) {
uint32_t alphaComponentId = 3;
uint32_t alpha = m_module.opCompositeExtract(m_floatType, reg, 1, &alphaComponentId);
@ -2269,6 +2283,11 @@ namespace dxvk {
dimensionality = spv::Dim2D;
sampler.texcoordCnt = 2;
viewType = VK_IMAGE_VIEW_TYPE_2D;
// Z coordinate for Dref sampling
if (m_fsKey.Stages[i].Contents.SampleDref)
sampler.texcoordCnt++;
break;
case D3DRTYPE_CUBETEXTURE:
dimensionality = spv::DimCube;

View File

@ -48,10 +48,15 @@ namespace dxvk {
struct D3D9FixedFunctionOptions {
D3D9FixedFunctionOptions(const D3D9Options* options);
bool invariantPosition;
bool forceSampleRateShading;
bool invariantPosition;
bool forceSampleRateShading;
int32_t drefScaling;
};
constexpr float GetDrefScaleFactor(int32_t bitDepth) {
return 1.0f / (float(1 << bitDepth) - 1.0f);
}
// Returns new oFog if VS
// Returns new oColor if PS
uint32_t DoFixedFunctionFog(D3D9ShaderSpecConstantManager& spec, SpirvModule& spvModule, const D3D9FogContext& fogCtx);
@ -163,6 +168,7 @@ namespace dxvk {
uint32_t Projected : 1;
uint32_t ProjectedCount : 3;
uint32_t SampleDref : 1;
uint32_t TextureBound : 1;

View File

@ -77,6 +77,9 @@ namespace dxvk {
this->samplerLodBias = config.getOption<float> ("d3d9.samplerLodBias", 0.0f);
this->clampNegativeLodBias = config.getOption<bool> ("d3d9.clampNegativeLodBias", false);
// D3D8 options
this->drefScaling = config.getOption<int32_t> ("d3d8.scaleDref", 0);
// Clamp LOD bias so that people don't abuse this in unintended ways
this->samplerLodBias = dxvk::fclamp(this->samplerLodBias, -2.0f, 1.0f);

View File

@ -152,6 +152,9 @@ namespace dxvk {
/// Enable emulation of device loss when a fullscreen app loses focus
bool deviceLossOnFocusLoss;
/// [D3D8] Enable depth texcoord Z (Dref) scaling for games that expect it
int32_t drefScaling;
};
}

View File

@ -2899,6 +2899,14 @@ void DxsoCompiler::emitControlFlowGenericLoop(
uint32_t component = sampler.dimensions;
reference = m_module.opCompositeExtract(
fType, texcoordVar.id, 1, &component);
// [D3D8] Scale Dref from [0..(2^N - 1)] for D24S8 and D16 if Dref scaling is enabled
if (m_moduleInfo.options.drefScaling) {
uint32_t drefScale = m_module.constf32(GetDrefScaleFactor(m_moduleInfo.options.drefScaling));
reference = m_module.opFMul(fType, reference, drefScale);
}
// Clamp Dref to [0..1] for D32F emulating UNORM textures
uint32_t clampDref = m_spec.get(m_module, m_specUbo, SpecDrefClamp, samplerIdx, 1);
clampDref = m_module.opINotEqual(bool_t, clampDref, m_module.constu32(0));
uint32_t clampedDref = m_module.opFClamp(fType, reference, m_module.constf32(0.0f), m_module.constf32(1.0f));

View File

@ -31,6 +31,8 @@ namespace dxvk {
longMad = options.longMad;
robustness2Supported = devFeatures.extRobustness2.robustBufferAccess2;
drefScaling = options.drefScaling;
}
}

View File

@ -49,6 +49,12 @@ namespace dxvk {
/// Whether or not we can rely on robustness2 to handle oob constant access
bool robustness2Supported;
/// Whether runtime to apply Dref scaling for depth textures of specified bit depth
/// (24: D24S8, 16: D16, 0: Disabled). This allows compatability with games
/// that expect a different depth test range, which was typically a D3D8 quirk on
/// early NVIDIA hardware.
int32_t drefScaling = 0;
};
}