From 79b7abd54e0200bb7142d4037b784a3c5a842ec1 Mon Sep 17 00:00:00 2001 From: Alan Tse Date: Sat, 30 Mar 2024 20:16:20 -0700 Subject: [PATCH] build: bump commonlibng to 3.7.0 (#236) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * build: bump commonlibng to 3.7.0 Due to an upstream breaking change, any access to winapi namespace is now under the REX::D3D namespace. This means that accessing various D3D objects will need a cast. * style: 🎨 apply clang-format changes * refactor: move renderer objects to State closes Refactor to consolidate variables from `RE::BSGraphics::Renderer` #237 --- extern/CommonLibSSE-NG | 2 +- include/PCH.h | 1 - src/Bindings.cpp | 19 +++++++------ src/Buffer.h | 40 +++++++++++++-------------- src/Features/CloudShadows.cpp | 18 ++++++------ src/Features/DistantTreeLighting.cpp | 2 +- src/Features/DynamicCubemaps.cpp | 18 ++++++------ src/Features/DynamicCubemaps.h | 1 + src/Features/ExtendedMaterials.cpp | 5 ++-- src/Features/ExtendedMaterials.h | 1 + src/Features/GrassCollision.cpp | 8 +++--- src/Features/GrassLighting.cpp | 2 +- src/Features/LightLimitFix.cpp | 10 +++---- src/Features/ScreenSpaceShadows.cpp | 6 ++-- src/Features/SubsurfaceScattering.cpp | 18 ++++++------ src/Features/TerrainBlending.cpp | 2 +- src/Features/WaterBlending.cpp | 2 +- src/Features/WaterBlending.h | 1 + src/Features/WaterCaustics.cpp | 6 ++-- src/Features/WaterCaustics.h | 2 +- src/Features/WetnessEffects.cpp | 4 +-- src/Features/WetnessEffects.h | 5 ++-- src/Hooks.cpp | 6 ++-- src/ShaderCache.cpp | 16 +++++------ src/State.cpp | 22 ++++----------- src/State.h | 5 ++++ src/Util.cpp | 4 +-- 27 files changed, 110 insertions(+), 116 deletions(-) diff --git a/extern/CommonLibSSE-NG b/extern/CommonLibSSE-NG index 0b92b1aad..c5d4f170b 160000 --- a/extern/CommonLibSSE-NG +++ b/extern/CommonLibSSE-NG @@ -1 +1 @@ -Subproject commit 0b92b1aad79c22b9a0620c4bdd244e9f4ad94fea +Subproject commit c5d4f170b7d37658d6988f201aaabaa973695e4a diff --git a/include/PCH.h b/include/PCH.h index d2ef4dc1f..36cf660ac 100644 --- a/include/PCH.h +++ b/include/PCH.h @@ -83,7 +83,6 @@ namespace stl } namespace logger = SKSE::log; -namespace WinAPI = SKSE::WinAPI; namespace util { diff --git a/src/Bindings.cpp b/src/Bindings.cpp index 98d4011e6..e0d2b30c4 100644 --- a/src/Bindings.cpp +++ b/src/Bindings.cpp @@ -1,9 +1,10 @@ #include "Bindings.h" +#include "State.h" #include "Util.h" void Bindings::DepthStencilStateSetDepthMode(RE::BSGraphics::DepthStencilDepthMode a_mode) { - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; GET_INSTANCE_MEMBER(depthStencilDepthMode, state) GET_INSTANCE_MEMBER(depthStencilDepthModePrevious, state) GET_INSTANCE_MEMBER(stateUpdateFlags, state) @@ -19,7 +20,7 @@ void Bindings::DepthStencilStateSetDepthMode(RE::BSGraphics::DepthStencilDepthMo void Bindings::AlphaBlendStateSetMode(uint32_t a_mode) { - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; GET_INSTANCE_MEMBER(alphaBlendMode, state) GET_INSTANCE_MEMBER(stateUpdateFlags, state) @@ -31,7 +32,7 @@ void Bindings::AlphaBlendStateSetMode(uint32_t a_mode) void Bindings::AlphaBlendStateSetAlphaToCoverage(uint32_t a_value) { - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; GET_INSTANCE_MEMBER(alphaBlendAlphaToCoverage, state) GET_INSTANCE_MEMBER(stateUpdateFlags, state) @@ -43,7 +44,7 @@ void Bindings::AlphaBlendStateSetAlphaToCoverage(uint32_t a_value) void Bindings::AlphaBlendStateSetWriteMode(uint32_t a_value) { - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; GET_INSTANCE_MEMBER(alphaBlendWriteMode, state) GET_INSTANCE_MEMBER(stateUpdateFlags, state) @@ -57,7 +58,7 @@ void Bindings::SetOverwriteTerrainMode(bool a_enable) { if (overrideTerrain != a_enable) { overrideTerrain = a_enable; - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; GET_INSTANCE_MEMBER(stateUpdateFlags, state) stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_DEPTH_MODE); stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_ALPHA_BLEND); @@ -68,7 +69,7 @@ void Bindings::SetOverwriteTerrainMaskingMode(TerrainMaskMode a_mode) { if (terrainMask != a_mode) { terrainMask = a_mode; - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; GET_INSTANCE_MEMBER(stateUpdateFlags, state) stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET); } @@ -88,8 +89,8 @@ struct BlendStates void Bindings::SetDirtyStates(bool) { - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& state = State::GetSingleton()->shadowState; + auto& context = State::GetSingleton()->context; GET_INSTANCE_MEMBER(depthStencilStencilMode, state) GET_INSTANCE_MEMBER(depthStencilDepthMode, state) GET_INSTANCE_MEMBER(alphaBlendAlphaToCoverage, state) @@ -261,7 +262,7 @@ void Bindings::Reset() //SetOverwriteTerrainMode(false); //SetOverwriteTerrainMaskingMode(TerrainMaskMode::kNone); - //auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + //auto& context = State::GetSingleton()->context; //FLOAT clear[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; //context->ClearRenderTargetView(terrainBlendingMask->rtv.get(), clear); } diff --git a/src/Buffer.h b/src/Buffer.h index 0cfb2332f..dda56f415 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -47,7 +47,7 @@ class ConstantBuffer ConstantBuffer(D3D11_BUFFER_DESC const& a_desc) { desc = a_desc; - auto device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + auto device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateBuffer(&desc, nullptr, resource.ReleaseAndGetAddressOf())); } @@ -55,7 +55,7 @@ class ConstantBuffer void Update(void const* src_data, size_t data_size) { - ID3D11DeviceContext* ctx = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + ID3D11DeviceContext* ctx = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context); if (desc.Usage & D3D11_USAGE_DYNAMIC) { D3D11_MAPPED_SUBRESOURCE mapped_buffer{}; ZeroMemory(&mapped_buffer, sizeof(D3D11_MAPPED_SUBRESOURCE)); @@ -98,7 +98,7 @@ class StructuredBuffer { desc = a_desc; count = a_count; - auto device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + auto device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateBuffer(&desc, nullptr, resource.ReleaseAndGetAddressOf())); } @@ -107,7 +107,7 @@ class StructuredBuffer virtual void CreateSRV() { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc{}; srv_desc.Format = DXGI_FORMAT_UNKNOWN; srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX; @@ -120,7 +120,7 @@ class StructuredBuffer virtual void CreateUAV() { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc{}; uav_desc.Format = DXGI_FORMAT_UNKNOWN; uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; @@ -134,7 +134,7 @@ class StructuredBuffer void Update(void const* src_data, [[maybe_unused]] size_t data_size) { - ID3D11DeviceContext* ctx = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + ID3D11DeviceContext* ctx = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context); D3D11_MAPPED_SUBRESOURCE mapped_buffer{}; ZeroMemory(&mapped_buffer, sizeof(D3D11_MAPPED_SUBRESOURCE)); DX::ThrowIfFailed(ctx->Map(resource.Get(), 0u, D3D11_MAP_WRITE_DISCARD, 0u, &mapped_buffer)); @@ -161,18 +161,18 @@ class Buffer Buffer(D3D11_BUFFER_DESC const& a_desc, D3D11_SUBRESOURCE_DATA* a_init = nullptr) { desc = a_desc; - auto device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + auto device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateBuffer(&desc, a_init, resource.put())); } void CreateSRV(D3D11_SHADER_RESOURCE_VIEW_DESC const& a_desc) { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateShaderResourceView(resource.get(), &a_desc, srv.put())); } void CreateUAV(D3D11_UNORDERED_ACCESS_VIEW_DESC const& a_desc) { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateUnorderedAccessView(resource.get(), &a_desc, uav.put())); } @@ -188,24 +188,24 @@ class Texture1D Texture1D(D3D11_TEXTURE1D_DESC const& a_desc) { desc = a_desc; - auto device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + auto device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateTexture1D(&desc, nullptr, resource.put())); } void CreateSRV(D3D11_SHADER_RESOURCE_VIEW_DESC const& a_desc) { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateShaderResourceView(resource.get(), &a_desc, srv.put())); } void CreateUAV(D3D11_UNORDERED_ACCESS_VIEW_DESC const& a_desc) { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateUnorderedAccessView(resource.get(), &a_desc, uav.put())); } void CreateRTV(D3D11_RENDER_TARGET_VIEW_DESC const& a_desc) { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateRenderTargetView(resource.get(), &a_desc, rtv.put())); } @@ -222,7 +222,7 @@ class Texture2D Texture2D(D3D11_TEXTURE2D_DESC const& a_desc) { desc = a_desc; - auto device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + auto device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateTexture2D(&desc, nullptr, resource.put())); } @@ -234,18 +234,18 @@ class Texture2D void CreateSRV(D3D11_SHADER_RESOURCE_VIEW_DESC const& a_desc) { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateShaderResourceView(resource.get(), &a_desc, srv.put())); } void CreateUAV(D3D11_UNORDERED_ACCESS_VIEW_DESC const& a_desc) { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateUnorderedAccessView(resource.get(), &a_desc, uav.put())); } void CreateRTV(D3D11_RENDER_TARGET_VIEW_DESC const& a_desc) { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateRenderTargetView(resource.get(), &a_desc, rtv.put())); } @@ -262,18 +262,18 @@ class Texture3D Texture3D(D3D11_TEXTURE3D_DESC const& a_desc) { desc = a_desc; - auto device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + auto device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateTexture3D(&desc, nullptr, resource.put())); } void CreateSRV(D3D11_SHADER_RESOURCE_VIEW_DESC const& a_desc) { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateShaderResourceView(resource.get(), &a_desc, srv.put())); } void CreateUAV(D3D11_UNORDERED_ACCESS_VIEW_DESC const& a_desc) { - ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + ID3D11Device* device = reinterpret_cast(RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder); DX::ThrowIfFailed(device->CreateUnorderedAccessView(resource.get(), &a_desc, uav.put())); } diff --git a/src/Features/CloudShadows.cpp b/src/Features/CloudShadows.cpp index 35c5a47c7..56c1d1e60 100644 --- a/src/Features/CloudShadows.cpp +++ b/src/Features/CloudShadows.cpp @@ -74,7 +74,7 @@ void CloudShadows::CheckResourcesSide(int side) if (!frame_checker[side].isNewFrame()) return; - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; float black[4] = { 0, 0, 0, 0 }; context->ClearRenderTargetView(cubemapCloudOccRTVs[side], black); @@ -85,7 +85,7 @@ void CloudShadows::ModifySky(const RE::BSShader*, const uint32_t descriptor) if (!settings.EnableCloudShadows) return; - auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& shadowState = State::GetSingleton()->shadowState; auto cubeMapRenderTarget = !REL::Module::IsVR() ? shadowState->GetRuntimeData().cubeMapRenderTarget : shadowState->GetVRRuntimeData().cubeMapRenderTarget; if (cubeMapRenderTarget != RE::RENDER_TARGETS_CUBEMAP::kREFLECTIONS) return; @@ -106,8 +106,8 @@ void CloudShadows::ModifySky(const RE::BSShader*, const uint32_t descriptor) auto tech_enum = static_cast(descriptor); if (tech_enum == SkyShaderTechniques::Clouds || tech_enum == SkyShaderTechniques::CloudsLerp || tech_enum == SkyShaderTechniques::CloudsFade) { auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; - auto device = renderer->GetRuntimeData().forwarder; + auto& context = State::GetSingleton()->context; + auto& device = State::GetSingleton()->device; { ID3D11ShaderResourceView* srv = nullptr; @@ -165,9 +165,9 @@ void CloudShadows::ModifySky(const RE::BSShader*, const uint32_t descriptor) void CloudShadows::ModifyLighting() { - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; - auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& shadowState = State::GetSingleton()->shadowState; auto cubeMapRenderTarget = !REL::Module::IsVR() ? shadowState->GetRuntimeData().cubeMapRenderTarget : shadowState->GetVRRuntimeData().cubeMapRenderTarget; if (cubeMapRenderTarget != RE::RENDER_TARGETS_CUBEMAP::kREFLECTIONS) { static Util::FrameChecker frame_checker; @@ -191,7 +191,7 @@ void CloudShadows::Draw(const RE::BSShader* shader, const uint32_t descriptor) static Util::FrameChecker frame_checker; if (frame_checker.isNewFrame()) { // update settings buffer - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; PerPass perPassData{}; @@ -237,7 +237,7 @@ void CloudShadows::Save(json& o_json) void CloudShadows::SetupResources() { auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto device = renderer->GetRuntimeData().forwarder; + auto& device = State::GetSingleton()->device; { auto reflections = renderer->GetRendererData().cubemapRenderTargets[RE::RENDER_TARGET_CUBEMAP::kREFLECTIONS]; @@ -290,7 +290,7 @@ void CloudShadows::RestoreDefaultSettings() void CloudShadows::Hooks::BSBatchRenderer__RenderPassImmediately::thunk(RE::BSRenderPass* Pass, uint32_t Technique, bool AlphaTest, uint32_t RenderFlags) { auto feat = GetSingleton(); - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; func(Pass, Technique, AlphaTest, RenderFlags); diff --git a/src/Features/DistantTreeLighting.cpp b/src/Features/DistantTreeLighting.cpp index 0ccca8f08..05e3eed93 100644 --- a/src/Features/DistantTreeLighting.cpp +++ b/src/Features/DistantTreeLighting.cpp @@ -113,7 +113,7 @@ void DistantTreeLighting::ModifyDistantTree(const RE::BSShader*, const uint32_t perPass->Update(perPassData); - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; ID3D11Buffer* buffers[2]; context->VSGetConstantBuffers(2, 1, buffers); // buffers[0] diff --git a/src/Features/DynamicCubemaps.cpp b/src/Features/DynamicCubemaps.cpp index 02542744c..c86336454 100644 --- a/src/Features/DynamicCubemaps.cpp +++ b/src/Features/DynamicCubemaps.cpp @@ -44,9 +44,8 @@ void DynamicCubemaps::DrawSettings() ImGui::ColorEdit3("Color", (float*)&cubemapColor); ImGui::SliderFloat("Roughness", &cubemapColor.w, 0.0f, 1.0f, "%.2f"); if (ImGui::Button("Export")) { - auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto device = renderer->GetRuntimeData().forwarder; - auto context = renderer->GetRuntimeData().context; + auto& device = State::GetSingleton()->device; + auto& context = State::GetSingleton()->context; D3D11_TEXTURE2D_DESC texDesc{}; texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; @@ -222,7 +221,7 @@ void DynamicCubemaps::UpdateCubemapCapture() { auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; auto& depth = renderer->GetDepthStencilData().depthStencils[RE::RENDER_TARGETS_DEPTHSTENCIL::kPOST_ZPREPASS_COPY]; auto& snowSwap = renderer->GetRuntimeData().renderTargets[RE::RENDER_TARGETS::kSNOW_SWAP]; @@ -243,7 +242,7 @@ void DynamicCubemaps::UpdateCubemapCapture() static float3 cameraPreviousPosAdjust = { 0, 0, 0 }; updateData.CameraPreviousPosAdjust = cameraPreviousPosAdjust; - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; auto eyePosition = !REL::Module::IsVR() ? state->GetRuntimeData().posAdjust.getEye(0) : state->GetVRRuntimeData().posAdjust.getEye(0); @@ -297,7 +296,7 @@ void DynamicCubemaps::DrawDeferred() void DynamicCubemaps::UpdateCubemap() { auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; //if (!REL::Module::IsVR()) { // auto imageSpaceManager = RE::ImageSpaceManager::GetSingleton(); @@ -397,14 +396,13 @@ void DynamicCubemaps::Draw(const RE::BSShader* shader, const uint32_t) { if (shader->shaderType.get() == RE::BSShader::Type::Lighting || shader->shaderType.get() == RE::BSShader::Type::Water) { // During world cubemap generation we cannot use the cubemap - auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& shadowState = State::GetSingleton()->shadowState; auto cubeMapRenderTarget = !REL::Module::IsVR() ? shadowState->GetRuntimeData().cubeMapRenderTarget : shadowState->GetVRRuntimeData().cubeMapRenderTarget; if (cubeMapRenderTarget != RE::RENDER_TARGETS_CUBEMAP::kREFLECTIONS && !renderedScreenCamera) { UpdateCubemap(); renderedScreenCamera = true; - auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; if (enableCreator) { CreatorSettingsCB data{}; @@ -434,7 +432,7 @@ void DynamicCubemaps::SetupResources() GetComputeShaderSpecularIrradiance(); auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto device = renderer->GetRuntimeData().forwarder; + auto& device = State::GetSingleton()->device; { D3D11_SAMPLER_DESC samplerDesc = {}; diff --git a/src/Features/DynamicCubemaps.h b/src/Features/DynamicCubemaps.h index 3bed15638..302dc96ac 100644 --- a/src/Features/DynamicCubemaps.h +++ b/src/Features/DynamicCubemaps.h @@ -2,6 +2,7 @@ #include "Buffer.h" #include "Feature.h" +#include "State.h" class MenuOpenCloseEventHandler : public RE::BSTEventSink { diff --git a/src/Features/ExtendedMaterials.cpp b/src/Features/ExtendedMaterials.cpp index 23f42d447..b7d9e77ab 100644 --- a/src/Features/ExtendedMaterials.cpp +++ b/src/Features/ExtendedMaterials.cpp @@ -125,7 +125,7 @@ void ExtendedMaterials::DrawSettings() void ExtendedMaterials::ModifyLighting(const RE::BSShader*, const uint32_t) { - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; { PerPass data{}; @@ -174,8 +174,7 @@ void ExtendedMaterials::SetupResources() logger::info("Creating terrain parallax sampler state"); - auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto device = renderer->GetRuntimeData().forwarder; + auto& device = State::GetSingleton()->device; D3D11_SAMPLER_DESC samplerDesc = {}; samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC; diff --git a/src/Features/ExtendedMaterials.h b/src/Features/ExtendedMaterials.h index eea9b55bc..876bd5468 100644 --- a/src/Features/ExtendedMaterials.h +++ b/src/Features/ExtendedMaterials.h @@ -2,6 +2,7 @@ #include "Buffer.h" #include "Feature.h" +#include "State.h" struct ExtendedMaterials : Feature { diff --git a/src/Features/GrassCollision.cpp b/src/Features/GrassCollision.cpp index 85d4059bf..50b084f99 100644 --- a/src/Features/GrassCollision.cpp +++ b/src/Features/GrassCollision.cpp @@ -135,7 +135,7 @@ static bool GetShapeBound(RE::bhkNiCollisionObject* Colliedobj, RE::NiPoint3& ce void GrassCollision::UpdateCollisions() { - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; auto frameCount = RE::BSGraphics::State::GetSingleton()->uiFrameCount; @@ -227,7 +227,7 @@ void GrassCollision::UpdateCollisions() collisions->CreateSRV(srvDesc); } - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; D3D11_MAPPED_SUBRESOURCE mapped; DX::ThrowIfFailed(context->Map(collisions->resource.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)); size_t bytes = sizeof(CollisionSData) * colllisionCount; @@ -248,7 +248,7 @@ void GrassCollision::ModifyGrass(const RE::BSShader*, const uint32_t) PerFrame perFrameData{}; ZeroMemory(&perFrameData, sizeof(perFrameData)); - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; auto& shaderState = RE::BSShaderManager::State::GetSingleton(); auto bound = shaderState.cachedPlayerBound; @@ -273,7 +273,7 @@ void GrassCollision::ModifyGrass(const RE::BSShader*, const uint32_t) } if (settings.EnableGrassCollision) { - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; ID3D11ShaderResourceView* views[1]{}; views[0] = collisions->srv.get(); diff --git a/src/Features/GrassLighting.cpp b/src/Features/GrassLighting.cpp index 143ea1b2b..2063233e0 100644 --- a/src/Features/GrassLighting.cpp +++ b/src/Features/GrassLighting.cpp @@ -100,7 +100,7 @@ void GrassLighting::ModifyGrass(const RE::BSShader*, const uint32_t descriptor) updatePerFrame = false; } - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; ID3D11Buffer* buffers[2]; context->VSGetConstantBuffers(2, 1, buffers); // buffers[0] diff --git a/src/Features/LightLimitFix.cpp b/src/Features/LightLimitFix.cpp index ca974e760..78d308604 100644 --- a/src/Features/LightLimitFix.cpp +++ b/src/Features/LightLimitFix.cpp @@ -310,7 +310,7 @@ void LightLimitFix::BSLightingShader_SetupGeometry_After(RE::BSRenderPass*) static bool wasEmpty = false; bool isEmpty = strictLightDataTemp.NumLights == 0; if (!isEmpty || (isEmpty && !wasEmpty)) { - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; D3D11_MAPPED_SUBRESOURCE mapped; DX::ThrowIfFailed(context->Map(strictLightData->resource.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)); size_t bytes = sizeof(StrictLightData); @@ -322,7 +322,7 @@ void LightLimitFix::BSLightingShader_SetupGeometry_After(RE::BSRenderPass*) void LightLimitFix::SetLightPosition(LightLimitFix::LightData& a_light, RE::NiPoint3 a_initialPosition, bool a_cached) { - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; for (int eyeIndex = 0; eyeIndex < eyeCount; eyeIndex++) { RE::NiPoint3 eyePosition; Matrix viewMatrix; @@ -377,7 +377,7 @@ void LightLimitFix::AddParticleLightLuminance(RE::NiPoint3& targetPosition, int& void LightLimitFix::Bind() { - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; auto accumulator = RE::BSGraphics::BSShaderAccumulator::GetCurrentAccumulator(); auto reflections = (!REL::Module::IsVR() ? @@ -732,7 +732,7 @@ void LightLimitFix::UpdateLights() lightsFar = std::min(16384.0f, accumulator->kCamera->GetRuntimeData2().viewFrustum.fFar); auto shadowSceneNode = RE::BSShaderManager::State::GetSingleton().shadowSceneNode[0]; - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; // Cache data since cameraData can become invalid in first-person @@ -922,7 +922,7 @@ void LightLimitFix::UpdateLights() } } - static auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + static auto& context = State::GetSingleton()->context; { auto projMatrixUnjittered = eyeCount == 1 ? state->GetRuntimeData().cameraData.getEye().projMatrixUnjittered : state->GetVRRuntimeData().cameraData.getEye().projMatrixUnjittered; diff --git a/src/Features/ScreenSpaceShadows.cpp b/src/Features/ScreenSpaceShadows.cpp index 809e19b33..9581e4bc3 100644 --- a/src/Features/ScreenSpaceShadows.cpp +++ b/src/Features/ScreenSpaceShadows.cpp @@ -195,7 +195,7 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) if (!loaded) return; - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; auto accumulator = RE::BSGraphics::BSShaderAccumulator::GetCurrentAccumulator(); auto dirLight = skyrim_cast(accumulator->GetRuntimeData().activeShadowSceneNode->GetRuntimeData().sunLight->light.get()); @@ -211,7 +211,7 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) { logger::debug("Creating screenSpaceShadowsTexture"); - auto device = renderer->GetRuntimeData().forwarder; + auto& device = State::GetSingleton()->device; D3D11_SAMPLER_DESC samplerDesc = {}; samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; @@ -252,7 +252,7 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) } } - auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& shadowState = State::GetSingleton()->shadowState; bool enableSSS = true; diff --git a/src/Features/SubsurfaceScattering.cpp b/src/Features/SubsurfaceScattering.cpp index d6e041549..8cc0d16e5 100644 --- a/src/Features/SubsurfaceScattering.cpp +++ b/src/Features/SubsurfaceScattering.cpp @@ -160,7 +160,7 @@ void SubsurfaceScattering::DrawSSSWrapper(bool) if (!SIE::ShaderCache::Instance().IsEnabled()) return; - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; ID3D11ShaderResourceView* srvs[8]; context->PSGetShaderResources(0, 8, srvs); @@ -229,7 +229,7 @@ void SubsurfaceScattering::DrawSSS() imageSpaceManager->GetVRRuntimeData().BSImagespaceShaderISTemporalAA->taaEnabled; blurCBData.FrameCount = viewport->uiFrameCount * (bTAA || State::GetSingleton()->upscalerLoaded); - auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& shadowState = State::GetSingleton()->shadowState; auto cameraData = !REL::Module::IsVR() ? shadowState->GetRuntimeData().cameraData.getEye() : shadowState->GetVRRuntimeData().cameraData.getEye(); @@ -244,7 +244,7 @@ void SubsurfaceScattering::DrawSSS() } auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; { ID3D11Buffer* buffer[1] = { blurCB->CB() }; @@ -311,7 +311,7 @@ void SubsurfaceScattering::Draw(const RE::BSShader* a_shader, const uint32_t) { if (a_shader->shaderType.get() == RE::BSShader::Type::Lighting) { if (normalsMode == RE::RENDER_TARGET::kNONE) { - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; GET_INSTANCE_MEMBER(renderTargets, state) normalsMode = renderTargets[2]; } @@ -441,7 +441,7 @@ void SubsurfaceScattering::PostPostLoad() void SubsurfaceScattering::OverrideFirstPersonRenderTargets() { - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); + auto& state = State::GetSingleton()->shadowState; GET_INSTANCE_MEMBER(renderTargets, state) GET_INSTANCE_MEMBER(setRenderTargetMode, state) GET_INSTANCE_MEMBER(stateUpdateFlags, state) @@ -452,7 +452,7 @@ void SubsurfaceScattering::OverrideFirstPersonRenderTargets() renderTargets[2] = normalsMode; auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; { auto& target = renderer->GetRuntimeData().renderTargets[renderTargets[2]]; @@ -506,8 +506,7 @@ void SubsurfaceScattering::BSLightingShader_SetupSkin(RE::BSRenderPass* a_pass) perPassData.ValidMaterial = validMaterial; perPassData.IsBeastRace = isBeastRace; - auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; D3D11_MAPPED_SUBRESOURCE mapped; DX::ThrowIfFailed(context->Map(perPass->resource.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)); @@ -520,8 +519,7 @@ void SubsurfaceScattering::BSLightingShader_SetupSkin(RE::BSRenderPass* a_pass) void SubsurfaceScattering::Bind() { - auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; ID3D11ShaderResourceView* view = perPass->srv.get(); context->PSSetShaderResources(36, 1, &view); validMaterial = true; diff --git a/src/Features/TerrainBlending.cpp b/src/Features/TerrainBlending.cpp index b1e2d528e..64dc5d5d2 100644 --- a/src/Features/TerrainBlending.cpp +++ b/src/Features/TerrainBlending.cpp @@ -72,7 +72,7 @@ void TerrainBlending::SetupGeometry(RE::BSRenderPass* a_pass) Bindings::GetSingleton()->SetOverwriteTerrainMode(true); Bindings::GetSingleton()->SetOverwriteTerrainMaskingMode(Bindings::TerrainMaskMode::kRead); - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; auto view = Bindings::GetSingleton()->terrainBlendingMask ? Bindings::GetSingleton()->terrainBlendingMask->srv.get() : nullptr; if (view) context->PSSetShaderResources(35, 1, &view); diff --git a/src/Features/WaterBlending.cpp b/src/Features/WaterBlending.cpp index 1f65ac5e2..885689059 100644 --- a/src/Features/WaterBlending.cpp +++ b/src/Features/WaterBlending.cpp @@ -40,7 +40,7 @@ void WaterBlending::DrawSettings() void WaterBlending::Draw(const RE::BSShader* shader, const uint32_t) { if (shader->shaderType.any(RE::BSShader::Type::Water, RE::BSShader::Type::Lighting)) { - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; PerPass data{}; data.settings = settings; diff --git a/src/Features/WaterBlending.h b/src/Features/WaterBlending.h index 3dc4eb65c..f2879739f 100644 --- a/src/Features/WaterBlending.h +++ b/src/Features/WaterBlending.h @@ -2,6 +2,7 @@ #include "Buffer.h" #include "Feature.h" +#include "State.h" struct WaterBlending : Feature { diff --git a/src/Features/WaterCaustics.cpp b/src/Features/WaterCaustics.cpp index 438f43642..76a74555b 100644 --- a/src/Features/WaterCaustics.cpp +++ b/src/Features/WaterCaustics.cpp @@ -8,14 +8,14 @@ void WaterCaustics::DrawSettings() void WaterCaustics::Draw(const RE::BSShader*, const uint32_t) { - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; context->PSSetShaderResources(70, 1, &causticsView); } void WaterCaustics::SetupResources() { - auto device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& device = State::GetSingleton()->device; + auto& context = State::GetSingleton()->context; DirectX::CreateDDSTextureFromFile(device, context, L"Data\\Shaders\\WaterCaustics\\watercaustics.dds", nullptr, &causticsView); } diff --git a/src/Features/WaterCaustics.h b/src/Features/WaterCaustics.h index 698e5d26e..8b6bd3107 100644 --- a/src/Features/WaterCaustics.h +++ b/src/Features/WaterCaustics.h @@ -1,7 +1,7 @@ #pragma once #include "Feature.h" - +#include "State.h" struct WaterCaustics : Feature { public: diff --git a/src/Features/WetnessEffects.cpp b/src/Features/WetnessEffects.cpp index 086f98e1c..e57163342 100644 --- a/src/Features/WetnessEffects.cpp +++ b/src/Features/WetnessEffects.cpp @@ -269,7 +269,7 @@ void WetnessEffects::CalculateWetness(RE::TESWeather* weather, RE::Sky* sky, flo void WetnessEffects::Draw(const RE::BSShader* shader, const uint32_t) { if (shader->shaderType.any(RE::BSShader::Type::Lighting, RE::BSShader::Type::Grass)) { - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; if (requiresUpdate) { requiresUpdate = false; @@ -458,7 +458,7 @@ void WetnessEffects::Hooks::BSParticleShader_SetupGeometry::thunk(RE::BSShader* static Util::FrameChecker frameChecker; if (frameChecker.isNewFrame()) { auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; + auto& context = State::GetSingleton()->context; auto precipation = renderer->GetDepthStencilData().depthStencils[RE::RENDER_TARGETS_DEPTHSTENCIL::kPRECIPITATION_OCCLUSION_MAP]; context->CopyResource(GetSingleton()->precipOcclusionTex->resource.get(), precipation.texture); } diff --git a/src/Features/WetnessEffects.h b/src/Features/WetnessEffects.h index a47b38021..2633ebf35 100644 --- a/src/Features/WetnessEffects.h +++ b/src/Features/WetnessEffects.h @@ -2,6 +2,7 @@ #include "Buffer.h" #include "Feature.h" +#include "State.h" struct WetnessEffects : Feature { @@ -64,7 +65,7 @@ struct WetnessEffects : Feature float Wetness; float PuddleWetness; DirectX::XMFLOAT3X4 DirectionalAmbientWS; - RE::DirectX::XMFLOAT4X4 PrecipProj; + REX::W32::XMFLOAT4X4 PrecipProj; Settings settings; float pad[4 - (sizeof(Settings) / 4 + 16) % 4]; @@ -83,7 +84,7 @@ struct WetnessEffects : Feature uint32_t currentWeatherID = 0; uint32_t lastWeatherID = 0; float previousWeatherTransitionPercentage = 0.0f; - RE::DirectX::XMFLOAT4X4 precipProj; + REX::W32::XMFLOAT4X4 precipProj; virtual void SetupResources(); virtual void Reset(); diff --git a/src/Hooks.cpp b/src/Hooks.cpp index e6daec893..834203fe6 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -275,9 +275,9 @@ namespace Hooks auto manager = RE::BSGraphics::Renderer::GetSingleton(); - auto context = manager->GetRuntimeData().context; - auto swapchain = manager->GetRuntimeData().renderWindows->swapChain; - auto device = manager->GetRuntimeData().forwarder; + auto context = reinterpret_cast(manager->GetRuntimeData().context); + auto swapchain = reinterpret_cast(manager->GetRuntimeData().renderWindows->swapChain); + auto device = reinterpret_cast(manager->GetRuntimeData().forwarder); logger::info("Detouring virtual function tables"); diff --git a/src/ShaderCache.cpp b/src/ShaderCache.cpp index 14b5a2539..2ee516304 100644 --- a/src/ShaderCache.cpp +++ b/src/ShaderCache.cpp @@ -1144,21 +1144,21 @@ namespace SIE ShaderClass::Vertex, type, descriptor); if (bufferSizes[0] != 0) { newShader->constantBuffers[0].buffer = - (RE::ID3D11Buffer*)perTechniqueBuffersArray.get()[bufferSizes[0]]; + (REX::W32::ID3D11Buffer*)perTechniqueBuffersArray.get()[bufferSizes[0]]; } else { newShader->constantBuffers[0].buffer = nullptr; newShader->constantBuffers[0].data = bufferData.get(); } if (bufferSizes[1] != 0) { newShader->constantBuffers[1].buffer = - (RE::ID3D11Buffer*)perMaterialBuffersArray.get()[bufferSizes[1]]; + (REX::W32::ID3D11Buffer*)perMaterialBuffersArray.get()[bufferSizes[1]]; } else { newShader->constantBuffers[1].buffer = nullptr; newShader->constantBuffers[1].data = bufferData.get(); } if (bufferSizes[2] != 0) { newShader->constantBuffers[2].buffer = - (RE::ID3D11Buffer*)perGeometryBuffersArray.get()[bufferSizes[2]]; + (REX::W32::ID3D11Buffer*)perGeometryBuffersArray.get()[bufferSizes[2]]; } else { newShader->constantBuffers[2].buffer = nullptr; newShader->constantBuffers[2].data = bufferData.get(); @@ -1201,21 +1201,21 @@ namespace SIE ShaderClass::Pixel, type, descriptor); if (bufferSizes[0] != 0) { newShader->constantBuffers[0].buffer = - (RE::ID3D11Buffer*)perTechniqueBuffersArray.get()[bufferSizes[0]]; + (REX::W32::ID3D11Buffer*)perTechniqueBuffersArray.get()[bufferSizes[0]]; } else { newShader->constantBuffers[0].buffer = nullptr; newShader->constantBuffers[0].data = bufferData.get(); } if (bufferSizes[1] != 0) { newShader->constantBuffers[1].buffer = - (RE::ID3D11Buffer*)perMaterialBuffersArray.get()[bufferSizes[1]]; + (REX::W32::ID3D11Buffer*)perMaterialBuffersArray.get()[bufferSizes[1]]; } else { newShader->constantBuffers[1].buffer = nullptr; newShader->constantBuffers[1].data = bufferData.get(); } if (bufferSizes[2] != 0) { newShader->constantBuffers[2].buffer = - (RE::ID3D11Buffer*)perGeometryBuffersArray.get()[bufferSizes[2]]; + (REX::W32::ID3D11Buffer*)perGeometryBuffersArray.get()[bufferSizes[2]]; } else { newShader->constantBuffers[2].buffer = nullptr; newShader->constantBuffers[2].data = bufferData.get(); @@ -1601,7 +1601,7 @@ namespace SIE std::lock_guard lockGuard(vertexShadersMutex); const auto result = (*device)->CreateVertexShader(shaderBlob->GetBufferPointer(), - newShader->byteCodeSize, nullptr, &newShader->shader); + newShader->byteCodeSize, nullptr, reinterpret_cast(&newShader->shader)); if (FAILED(result)) { logger::error("Failed to create vertex shader {}::{}", magic_enum::enum_name(shader.shaderType.get()), descriptor); @@ -1629,7 +1629,7 @@ namespace SIE std::lock_guard lockGuard(pixelShadersMutex); const auto result = (*device)->CreatePixelShader(shaderBlob->GetBufferPointer(), - shaderBlob->GetBufferSize(), nullptr, &newShader->shader); + shaderBlob->GetBufferSize(), nullptr, reinterpret_cast(&newShader->shader)); if (FAILED(result)) { logger::error("Failed to create pixel shader {}::{}", magic_enum::enum_name(shader.shaderType.get()), diff --git a/src/State.cpp b/src/State.cpp index c8dec244d..8ae319ff4 100644 --- a/src/State.cpp +++ b/src/State.cpp @@ -21,8 +21,6 @@ void State::Draw() ModifyShaderLookup(*currentShader, currentVertexDescriptor, currentPixelDescriptor); UpdateSharedData(currentShader, currentPixelDescriptor); - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; - static RE::BSGraphics::VertexShader* vertexShader = nullptr; static RE::BSGraphics::PixelShader* pixelShader = nullptr; @@ -30,8 +28,8 @@ void State::Draw() pixelShader = shaderCache.GetPixelShader(*currentShader, currentPixelDescriptor); if (vertexShader && pixelShader) { - context->VSSetShader(vertexShader->shader, NULL, NULL); - context->PSSetShader(pixelShader->shader, NULL, NULL); + context->VSSetShader(reinterpret_cast(vertexShader->shader), NULL, NULL); + context->PSSetShader(reinterpret_cast(pixelShader->shader), NULL, NULL); } if (vertexShader && pixelShader) { @@ -49,9 +47,6 @@ void State::Draw() void State::DrawDeferred() { - auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; - ID3D11ShaderResourceView* srvs[8]; context->PSGetShaderResources(0, 8, srvs); @@ -105,9 +100,6 @@ void State::DrawDeferred() void State::DrawPreProcess() { - auto renderer = RE::BSGraphics::Renderer::GetSingleton(); - auto context = renderer->GetRuntimeData().context; - ID3D11ShaderResourceView* srvs[8]; context->PSGetShaderResources(0, 8, srvs); @@ -420,15 +412,17 @@ void State::SetupResources() D3D11_TEXTURE2D_DESC texDesc{}; renderer->GetRuntimeData().renderTargets[RE::RENDER_TARGETS::kMAIN].texture->GetDesc(&texDesc); + isVR = REL::Module::IsVR(); screenWidth = (float)texDesc.Width; screenHeight = (float)texDesc.Height; + context = reinterpret_cast(renderer->GetRuntimeData().context); + device = reinterpret_cast(renderer->GetRuntimeData().forwarder); + shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); } void State::ModifyShaderLookup(const RE::BSShader& a_shader, uint& a_vertexDescriptor, uint& a_pixelDescriptor) { if (a_shader.shaderType.get() == RE::BSShader::Type::Lighting || a_shader.shaderType.get() == RE::BSShader::Type::Water || a_shader.shaderType.get() == RE::BSShader::Type::Effect) { - auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; - if (a_vertexDescriptor != lastVertexDescriptor || a_pixelDescriptor != lastPixelDescriptor) { PerShader data{}; data.VertexShaderDescriptor = a_vertexDescriptor; @@ -527,8 +521,6 @@ void State::UpdateSharedData(const RE::BSShader* a_shader, const uint32_t) if (a_shader->shaderType.get() == RE::BSShader::Type::Lighting) { bool updateBuffer = false; - auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); - bool currentReflections = (!REL::Module::IsVR() ? shadowState->GetRuntimeData().cubeMapRenderTarget : shadowState->GetVRRuntimeData().cubeMapRenderTarget) == RE::RENDER_TARGETS_CUBEMAP::kREFLECTIONS; @@ -568,8 +560,6 @@ void State::UpdateSharedData(const RE::BSShader* a_shader, const uint32_t) lightingData.Timer = timer; - auto context = renderer->GetRuntimeData().context; - if (updateBuffer) { D3D11_MAPPED_SUBRESOURCE mapped; DX::ThrowIfFailed(context->Map(lightingDataBuffer->resource.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)); diff --git a/src/State.h b/src/State.h index e645108d6..f2219ec44 100644 --- a/src/State.h +++ b/src/State.h @@ -111,6 +111,11 @@ class State std::unique_ptr lightingDataBuffer = nullptr; + // Skyrim constants + bool isVR = false; float screenWidth = 0; float screenHeight = 0; + ID3D11DeviceContext* context = nullptr; + ID3D11Device* device = nullptr; + RE::BSGraphics::RendererShadowState* shadowState = nullptr; }; diff --git a/src/Util.cpp b/src/Util.cpp index 548805850..df18a3843 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -111,7 +111,7 @@ namespace Util ID3D11DeviceChild* CompileShader(const wchar_t* FilePath, const std::vector>& Defines, const char* ProgramType, const char* Program) { - auto device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + auto& device = State::GetSingleton()->device; // Build defines (aka convert vector->D3DCONSTANT array) std::vector macros; @@ -235,7 +235,7 @@ namespace Util float TryGetWaterHeight(float offsetX, float offsetY) { - if (auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton()) { + if (auto& shadowState = State::GetSingleton()->shadowState) { if (auto tes = RE::TES::GetSingleton()) { auto position = !REL::Module::IsVR() ? shadowState->GetRuntimeData().posAdjust.getEye() : shadowState->GetVRRuntimeData().posAdjust.getEye(); position.x += offsetX;