mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-20 19:54:19 +01:00
[d3d8] Implement Dref scaling and fixed-function depth textures (#3565)
This commit is contained in:
parent
a8710f70a5
commit
3e5eb1660f
@ -7441,6 +7441,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;
|
||||
|
@ -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) {
|
||||
@ -1791,6 +1792,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;
|
||||
@ -1834,10 +1840,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);
|
||||
@ -1865,11 +1884,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);
|
||||
@ -2266,6 +2280,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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -79,6 +79,9 @@ namespace dxvk {
|
||||
this->countLosableResources = config.getOption<bool> ("d3d9.countLosableResources", true);
|
||||
this->reproducibleCommandStream = config.getOption<bool> ("d3d9.reproducibleCommandStream", 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);
|
||||
|
||||
|
@ -160,6 +160,9 @@ namespace dxvk {
|
||||
/// don't change between runs. Useful for comparative benchmarking,
|
||||
/// can negatively affect performance.
|
||||
bool reproducibleCommandStream;
|
||||
|
||||
/// Enable depth texcoord Z (Dref) scaling (D3D8 quirk)
|
||||
int32_t drefScaling;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -2909,6 +2909,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));
|
||||
|
@ -31,6 +31,8 @@ namespace dxvk {
|
||||
|
||||
longMad = options.longMad;
|
||||
robustness2Supported = devFeatures.extRobustness2.robustBufferAccess2;
|
||||
|
||||
drefScaling = options.drefScaling;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user