Skip to content

Commit

Permalink
Merge branch 'sultimt/unbound-light-index' into 'main'
Browse files Browse the repository at this point in the history
Uncap light index

See merge request lightspeedrtx/dxvk-remix-nv!353
  • Loading branch information
sultim-t-nv committed Jul 24, 2023
2 parents 8e682d3 + 02f2683 commit 4ab7b01
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ namespace dxvk {
, m_isSWVP ( (BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING) ? true : false )
, m_csThread ( dxvkDevice->createRtxContext() )
, m_csChunk ( AllocCsChunk() )
// NV-DXVK start: unbound light indices
, m_state ( Direct3DState9 { D3D9CapturableState{ static_cast<uint32_t>(std::max(m_d3d9Options.maxEnabledLights, 0)) } } )
// NV-DXVK end
, m_rtx ( this ) {
// If we can SWVP, then we use an extended constant set
// as SWVP has many more slots available than HWVP.
Expand Down Expand Up @@ -6805,7 +6808,9 @@ namespace dxvk {
uint32_t lightCount = 0;

if (key.Data.Contents.UseLighting) {
for (uint32_t i = 0; i < caps::MaxEnabledLights; i++) {
// NV-DXVK start: unbound light indices
for (uint32_t i = 0; i < caps::MaxEnabledLights && m_state.enabledLightIndices.size(); i++) {
// NV-DXVK end
if (m_state.enabledLightIndices[i] != UINT32_MAX)
lightCount++;
}
Expand Down Expand Up @@ -6908,7 +6913,9 @@ namespace dxvk {
DecodeD3DCOLOR(m_state.renderStates[D3DRS_AMBIENT], data->GlobalAmbient.data);

uint32_t lightIdx = 0;
for (uint32_t i = 0; i < caps::MaxEnabledLights; i++) {
// NV-DXVK start: unbound light indices
for (uint32_t i = 0; i < data->Lights.size() && i < m_state.enabledLightIndices.size(); i++) {
// NV-DXVK end
auto idx = m_state.enabledLightIndices[i];
if (idx == UINT32_MAX)
continue;
Expand Down
3 changes: 1 addition & 2 deletions src/d3d9/d3d9_rtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ namespace dxvk {

std::vector<D3DLIGHT9> activeLightsRT;
uint32_t lightIdx = 0;
for (uint32_t i = 0; i < caps::MaxEnabledLights; i++) {
auto idx = d3d9State().enabledLightIndices[i];
for (auto idx : d3d9State().enabledLightIndices) {
if (idx == UINT32_MAX)
continue;
activeLightsRT.push_back(d3d9State().lights[idx].value());
Expand Down
8 changes: 7 additions & 1 deletion src/d3d9/d3d9_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace dxvk {

D3D9CapturableState::D3D9CapturableState() {
// NV-DXVK start: unbound light indices
D3D9CapturableState::D3D9CapturableState(uint32_t maxEnabledLights) {
// NV-DXVK end
for (uint32_t i = 0; i < textures.size(); i++)
textures[i] = nullptr;

Expand All @@ -14,6 +16,10 @@ namespace dxvk {
for (uint32_t i = 0; i < streamFreq.size(); i++)
streamFreq[i] = 1;

// NV-DXVK start: unbound light indices
enabledLightIndices.resize(maxEnabledLights);
// NV-DXVK end

for (uint32_t i = 0; i < enabledLightIndices.size(); i++)
enabledLightIndices[i] = UINT32_MAX;
}
Expand Down
8 changes: 6 additions & 2 deletions src/d3d9/d3d9_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ namespace dxvk {
};

struct D3D9CapturableState {
D3D9CapturableState();
// NV-DXVK start: unbound light indices
explicit D3D9CapturableState(uint32_t maxEnabledLights);
// NV-DXVK end

~D3D9CapturableState();

Expand Down Expand Up @@ -246,7 +248,9 @@ namespace dxvk {
D3DMATERIAL9 material = D3DMATERIAL9();

std::vector<std::optional<D3DLIGHT9>> lights;
std::array<DWORD, caps::MaxEnabledLights> enabledLightIndices;
// NV-DXVK start: unbound light indices
std::vector<DWORD> enabledLightIndices;
// NV-DXVK end

bool IsLightEnabled(DWORD Index) {
const auto& indices = enabledLightIndices;
Expand Down
3 changes: 3 additions & 0 deletions src/d3d9/d3d9_stateblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace dxvk {

D3D9StateBlock::D3D9StateBlock(D3D9DeviceEx* pDevice, D3D9StateBlockType Type)
: D3D9StateBlockBase(pDevice)
// NV-DXVK start: unbound light indices
, m_state (pDevice->GetOptions()->maxEnabledLights)
// NV-DXVK end
, m_deviceState (pDevice->GetRawState()) {
CaptureType(Type);
}
Expand Down
1 change: 0 additions & 1 deletion src/util/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,6 @@ namespace dxvk {
{ "rtx.animatedWaterTextures",
"522E5513DB9638B6,"
},
{ "d3d9.maxEnabledLights", "32" }, // This game seems to read this caps bit and push more lights accordingly.
{ "rtx.zUp", "True" },
{ "rtx.uniqueObjectDistance", "300.0" }, // Game is 1unit=1cm - picking up objects can move them very quickly, 3m should be sufficient.
{ "rtx.rayPortalModelTextureHashes", "5EC61BC800744B26, DFDACB6DE1C7741E" }, // Orange and Blue Portal textures
Expand Down

0 comments on commit 4ab7b01

Please sign in to comment.