Skip to content

Commit 296cb35

Browse files
committed
[d3d9] Clip plane compaction
Compact clip planes to the smallest amount that are enabled. Signed-off-by: Autumn Ashton <[email protected]>
1 parent c552fa9 commit 296cb35

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/d3d9/d3d9_device.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5933,17 +5933,21 @@ namespace dxvk {
59335933
auto mapPtr = m_vsClipPlanes.AllocSlice();
59345934
auto dst = reinterpret_cast<D3D9ClipPlane*>(mapPtr);
59355935

5936-
uint32_t clipPlaneMask = 0u;
5936+
uint32_t clipPlaneCount = 0u;
59375937
for (uint32_t i = 0; i < caps::MaxClipPlanes; i++) {
5938-
dst[i] = (m_state.renderStates[D3DRS_CLIPPLANEENABLE] & (1 << i))
5938+
D3D9ClipPlane clipPlane = (m_state.renderStates[D3DRS_CLIPPLANEENABLE] & (1 << i))
59395939
? m_state.clipPlanes[i]
59405940
: D3D9ClipPlane();
59415941

5942-
if (dst[i] != D3D9ClipPlane())
5943-
clipPlaneMask |= 1u << i;
5942+
if (clipPlane != D3D9ClipPlane())
5943+
dst[clipPlaneCount++] = clipPlane;
59445944
}
59455945

5946-
if (m_specInfo.set<SpecClipPlaneMask>(clipPlaneMask))
5946+
// Write the rest to 0 for GPL.
5947+
for (uint32_t i = clipPlaneCount; i < caps::MaxClipPlanes; i++)
5948+
dst[i] = D3D9ClipPlane();
5949+
5950+
if (m_specInfo.set<SpecClipPlaneCount>(clipPlaneCount))
59475951
m_flags.set(D3D9DeviceFlag::DirtySpecializationEntries);
59485952
}
59495953

src/d3d9/d3d9_fixed_function.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,9 @@ namespace dxvk {
24072407

24082408
m_module.decorateBuiltIn(clipDistArray, spv::BuiltInClipDistance);
24092409

2410+
// Always consider clip planes enabled when doing GPL by forcing 6 the quick value.
2411+
uint32_t clipPlaneCount = m_spec.get(m_module, m_specUbo, SpecClipPlaneCount, 0, 32, m_module.constu32(6));
2412+
24102413
// Compute clip distances
24112414
for (uint32_t i = 0; i < caps::MaxClipPlanes; i++) {
24122415
std::array<uint32_t, 2> blockMembers = {{
@@ -2421,9 +2424,7 @@ namespace dxvk {
24212424

24222425
uint32_t distId = m_module.opDot(floatType, worldPos, planeId);
24232426

2424-
// Always consider clip planes enabled when doing GPL by forcing a mask of 0xffffffff for the quick value.
2425-
uint32_t clipPlaneEnabledBit = m_spec.get(m_module, m_specUbo, SpecClipPlaneMask, i, 1, m_module.constu32(0xffffffff));
2426-
uint32_t clipPlaneEnabled = m_module.opINotEqual(boolType, clipPlaneEnabledBit, m_module.constu32(0));
2427+
uint32_t clipPlaneEnabled = m_module.opULessThan(boolType, m_module.constu32(i), clipPlaneCount);
24272428

24282429
uint32_t value = m_module.opSelect(floatType, clipPlaneEnabled, distId, m_module.constf32(0.0f));
24292430

src/d3d9/d3d9_spec_constants.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace dxvk {
3030
SpecDrefClamp, // 1 bit for 16 PS samplers | Bits: 16
3131
SpecFetch4, // 1 bit for 16 PS samplers | Bits: 16
3232

33-
SpecClipPlaneMask, // 6 bits for 6 clip planes | Bits : 6
33+
SpecClipPlaneCount, // 3 bits for 6 clip planes | Bits : 3
3434

3535
SpecConstantCount,
3636
};
@@ -71,7 +71,7 @@ namespace dxvk {
7171
{ 4, 0, 16 }, // DrefClamp
7272
{ 4, 16, 16 }, // Fetch4
7373

74-
{ 5, 0, 6 }, // ClipPlaneEnabled
74+
{ 5, 0, 3 }, // ClipPlaneCount
7575
}};
7676

7777
template <D3D9SpecConstantId Id, typename T>

src/dxso/dxso_compiler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3537,6 +3537,9 @@ void DxsoCompiler::emitControlFlowGenericLoop(
35373537
DxsoRegisterValue position;
35383538
position.type = { DxsoScalarType::Float32, 4 };
35393539
position.id = m_module.opLoad(vec4Type, positionPtr);
3540+
3541+
// Always consider clip planes enabled when doing GPL by forcing 6 the quick value.
3542+
uint32_t clipPlaneCount = m_spec.get(m_module, m_specUbo, SpecClipPlaneCount, 0, 32, m_module.constu32(6));
35403543

35413544
for (uint32_t i = 0; i < caps::MaxClipPlanes; i++) {
35423545
std::array<uint32_t, 2> blockMembers = {{
@@ -3552,9 +3555,7 @@ void DxsoCompiler::emitControlFlowGenericLoop(
35523555

35533556
DxsoRegisterValue dist = emitDot(position, plane);
35543557

3555-
// Always consider clip planes enabled when doing GPL by forcing a mask of 0xffffffff for the quick value.
3556-
uint32_t clipPlaneEnabledBit = m_spec.get(m_module, m_specUbo, SpecClipPlaneMask, i, 1, m_module.constu32(0xffffffff));
3557-
uint32_t clipPlaneEnabled = m_module.opINotEqual(boolType, clipPlaneEnabledBit, m_module.constu32(0));
3558+
uint32_t clipPlaneEnabled = m_module.opULessThan(boolType, m_module.constu32(i), clipPlaneCount);
35583559

35593560
uint32_t value = m_module.opSelect(floatType, clipPlaneEnabled, dist.id, m_module.constf32(0.0f));
35603561

0 commit comments

Comments
 (0)