@@ -2171,9 +2171,11 @@ namespace dxvk {
21712171 if (Index >= m_state.lights .size ())
21722172 m_state.lights .resize (Index + 1 );
21732173
2174- m_state.lights [Index] = *pLight;
2174+ auto & light = m_state.lights [Index];
2175+ light.isValid = true ;
2176+ light.light = *pLight;
21752177
2176- if (m_state. IsLightEnabled (Index) )
2178+ if (light. isEnabled )
21772179 m_dirty.set (D3D9DeviceDirtyFlag::FFVertexData);
21782180
21792181 return D3D_OK ;
@@ -2186,11 +2188,15 @@ namespace dxvk {
21862188 if (unlikely (pLight == nullptr ))
21872189 return D3DERR_INVALIDCALL ;
21882190
2189- if (unlikely (Index >= m_state.lights .size () || !m_state. lights [Index] ))
2191+ if (unlikely (Index >= m_state.lights .size ()))
21902192 return D3DERR_INVALIDCALL ;
21912193
2192- *pLight = m_state.lights [Index].value ();
2194+ auto & light = m_state.lights [Index];
2195+
2196+ if (unlikely (!light.isValid ))
2197+ return D3DERR_INVALIDCALL ;
21932198
2199+ *pLight = m_state.lights [Index].light ;
21942200 return D3D_OK ;
21952201 }
21962202
@@ -2206,27 +2212,16 @@ namespace dxvk {
22062212 if (unlikely (Index >= m_state.lights .size ()))
22072213 m_state.lights .resize (Index + 1 );
22082214
2209- if (unlikely (!m_state.lights [Index]))
2210- m_state.lights [Index] = DefaultLight;
2215+ auto & light = m_state.lights [Index];
22112216
2212- if (m_state. IsLightEnabled (Index) == !! Enable)
2217+ if (light. isEnabled == bool ( Enable) )
22132218 return D3D_OK ;
22142219
2215- uint32_t searchIndex = std::numeric_limits<uint32_t >::max ();
2216- uint32_t setIndex = Index;
2217-
2218- if (!Enable)
2219- std::swap (searchIndex, setIndex);
2220-
2221- for (auto & idx : m_state.enabledLightIndices ) {
2222- if (idx == searchIndex) {
2223- idx = setIndex;
2224- m_dirty.set (D3D9DeviceDirtyFlag::FFVertexData);
2225- m_dirty.set (D3D9DeviceDirtyFlag::FFVertexShader);
2226- break ;
2227- }
2228- }
2220+ light.isValid = true ;
2221+ light.isEnabled = bool (Enable);
22292222
2223+ m_dirty.set (D3D9DeviceDirtyFlag::FFVertexData,
2224+ D3D9DeviceDirtyFlag::FFVertexShader);
22302225 return D3D_OK ;
22312226 }
22322227
@@ -2237,11 +2232,15 @@ namespace dxvk {
22372232 if (unlikely (pEnable == nullptr ))
22382233 return D3DERR_INVALIDCALL ;
22392234
2240- if (unlikely (Index >= m_state.lights .size () || !m_state. lights [Index] ))
2235+ if (unlikely (Index >= m_state.lights .size ()))
22412236 return D3DERR_INVALIDCALL ;
22422237
2243- *pEnable = m_state.IsLightEnabled (Index) ? 128 : 0 ; // Weird quirk but OK.
2238+ auto & light = m_state.lights [Index];
2239+
2240+ if (unlikely (!light.isValid ))
2241+ return D3DERR_INVALIDCALL ;
22442242
2243+ *pEnable = light.isEnabled ? 128 : 0 ; // Weird quirk but OK.
22452244 return D3D_OK ;
22462245 }
22472246
@@ -8169,18 +8168,20 @@ namespace dxvk {
81698168 DecodeD3DCOLOR (m_state.renderStates [D3DRS_AMBIENT ], data->GlobalAmbient .data );
81708169
81718170 uint32_t lightIdx = 0 ;
8172- for ( uint32_t i = 0 ; i < caps::MaxEnabledLights; i++) {
8173- auto idx = m_state.enabledLightIndices [i];
8174- if (idx == std::numeric_limits< uint32_t >:: max () )
8171+
8172+ for ( auto & light : m_state.lights ) {
8173+ if (!light. isEnabled )
81758174 continue ;
81768175
81778176 // D3D8/9 will allow lights with invalid types to be set and retrieved,
81788177 // and even enabled, however they won't affect overall lighting
8179- const D3DLIGHT9 & light = m_state.lights [idx].value ();
8180- if (unlikely (light.Type == 0 || light.Type > D3DLIGHT_DIRECTIONAL ))
8178+ if (unlikely (!light.light .Type || light.light .Type > D3DLIGHT_DIRECTIONAL ))
81818179 continue ;
81828180
8183- data->Lights [lightIdx++] = D3D9Light (light, m_state.transforms [GetTransformIndex (D3DTS_VIEW )]);
8181+ data->Lights [lightIdx++] = D3D9Light (light.light , m_state.transforms [GetTransformIndex (D3DTS_VIEW )]);
8182+
8183+ if (lightIdx == caps::MaxEnabledLights)
8184+ break ;
81848185 }
81858186
81868187 data->Material = m_state.material ;
0 commit comments