From ec8d7c7fc4abb5e11e75cb74a96ea782bf3f7342 Mon Sep 17 00:00:00 2001 From: FlayaN Date: Mon, 1 Apr 2024 19:33:37 +0200 Subject: [PATCH] feat: add perfevent and marker in development --- src/Features/SubsurfaceScattering.cpp | 3 +++ src/ShaderCache.cpp | 8 ++++++++ src/ShaderCache.h | 2 ++ src/State.cpp | 27 +++++++++++++++++++++++++++ src/State.h | 7 +++++++ 5 files changed, 47 insertions(+) diff --git a/src/Features/SubsurfaceScattering.cpp b/src/Features/SubsurfaceScattering.cpp index 8cc0d16e5..9ff550a02 100644 --- a/src/Features/SubsurfaceScattering.cpp +++ b/src/Features/SubsurfaceScattering.cpp @@ -160,6 +160,8 @@ void SubsurfaceScattering::DrawSSSWrapper(bool) if (!SIE::ShaderCache::Instance().IsEnabled()) return; + State::GetSingleton()->BeginPerfEvent(std::format("DrawSSS: {}", GetShortName())); + auto& context = State::GetSingleton()->context; ID3D11ShaderResourceView* srvs[8]; @@ -209,6 +211,7 @@ void SubsurfaceScattering::DrawSSSWrapper(bool) dsv->Release(); validMaterial = false; + State::GetSingleton()->EndPerfEvent(); } void SubsurfaceScattering::DrawSSS() diff --git a/src/ShaderCache.cpp b/src/ShaderCache.cpp index 2ee516304..8e417b641 100644 --- a/src/ShaderCache.cpp +++ b/src/ShaderCache.cpp @@ -1646,6 +1646,14 @@ namespace SIE return nullptr; } + std::string ShaderCache::GetDefinesString(RE::BSShader::Type enumType, uint32_t descriptor) + { + std::array defines{}; + SIE::SShaderCache::GetShaderDefines(enumType, descriptor, &defines[0]); + + return SIE::SShaderCache::MergeDefinesString(defines, true); + } + uint64_t ShaderCache::GetCachedHitTasks() { return compilationSet.cacheHitTasks; diff --git a/src/ShaderCache.h b/src/ShaderCache.h index 70d4c853f..28627dd06 100644 --- a/src/ShaderCache.h +++ b/src/ShaderCache.h @@ -173,6 +173,8 @@ namespace SIE RE::BSGraphics::PixelShader* MakeAndAddPixelShader(const RE::BSShader& shader, uint32_t descriptor); + static std::string GetDefinesString(RE::BSShader::Type enumType, uint32_t descriptor); + uint64_t GetCachedHitTasks(); uint64_t GetCompletedTasks(); uint64_t GetFailedTasks(); diff --git a/src/State.cpp b/src/State.cpp index 8ae319ff4..00f371f63 100644 --- a/src/State.cpp +++ b/src/State.cpp @@ -32,13 +32,24 @@ void State::Draw() context->PSSetShader(reinterpret_cast(pixelShader->shader), NULL, NULL); } + BeginPerfEvent(std::format("Draw: CommunityShaders {}::{}", magic_enum::enum_name(currentShader->shaderType.get()), currentPixelDescriptor)); + if (IsDeveloperMode()) { + SetPerfMarker(std::format("Defines: {}", SIE::ShaderCache::GetDefinesString(currentShader->shaderType.get(), currentPixelDescriptor))); + } + if (vertexShader && pixelShader) { for (auto* feature : Feature::GetFeatureList()) { if (feature->loaded) { + auto hasShaderDefine = feature->HasShaderDefine(currentShader->shaderType.get()); + if (hasShaderDefine) + BeginPerfEvent(feature->GetShortName()); feature->Draw(currentShader, currentPixelDescriptor); + if (hasShaderDefine) + EndPerfEvent(); } } } + EndPerfEvent(); } } } @@ -418,6 +429,7 @@ void State::SetupResources() context = reinterpret_cast(renderer->GetRuntimeData().context); device = reinterpret_cast(renderer->GetRuntimeData().forwarder); shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); + context->QueryInterface(__uuidof(pPerf), reinterpret_cast(&pPerf)); } void State::ModifyShaderLookup(const RE::BSShader& a_shader, uint& a_vertexDescriptor, uint& a_pixelDescriptor) @@ -516,6 +528,21 @@ void State::ModifyShaderLookup(const RE::BSShader& a_shader, uint& a_vertexDescr } } +void State::BeginPerfEvent(std::string_view title) +{ + pPerf->BeginEvent(std::wstring(title.begin(), title.end()).c_str()); +} + +void State::EndPerfEvent() +{ + pPerf->EndEvent(); +} + +void State::SetPerfMarker(std::string_view title) +{ + pPerf->SetMarker(std::wstring(title.begin(), title.end()).c_str()); +} + void State::UpdateSharedData(const RE::BSShader* a_shader, const uint32_t) { if (a_shader->shaderType.get() == RE::BSShader::Type::Lighting) { diff --git a/src/State.h b/src/State.h index f2219ec44..f22aa18b1 100644 --- a/src/State.h +++ b/src/State.h @@ -83,6 +83,10 @@ class State void SetupResources(); void ModifyShaderLookup(const RE::BSShader& a_shader, uint& a_vertexDescriptor, uint& a_pixelDescriptor); + void BeginPerfEvent(std::string_view title); + void EndPerfEvent(); + void SetPerfMarker(std::string_view title); + struct PerShader { uint VertexShaderDescriptor; @@ -118,4 +122,7 @@ class State ID3D11DeviceContext* context = nullptr; ID3D11Device* device = nullptr; RE::BSGraphics::RendererShadowState* shadowState = nullptr; + +private: + std::shared_ptr pPerf; };