Skip to content

Commit

Permalink
feat: add perfevent and marker in development
Browse files Browse the repository at this point in the history
  • Loading branch information
FlayaN committed Apr 1, 2024
1 parent 79b7abd commit 84a1990
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Features/SubsurfaceScattering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -209,6 +211,7 @@ void SubsurfaceScattering::DrawSSSWrapper(bool)
dsv->Release();

validMaterial = false;
State::GetSingleton()->EndPerfEvent();
}

void SubsurfaceScattering::DrawSSS()
Expand Down
8 changes: 8 additions & 0 deletions src/ShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,14 @@ namespace SIE
return nullptr;
}

std::string ShaderCache::GetDefinesString(RE::BSShader::Type enumType, uint32_t descriptor)
{
std::array<D3D_SHADER_MACRO, 64> defines{};
SIE::SShaderCache::GetShaderDefines(enumType, descriptor, &defines[0]);

return SIE::SShaderCache::MergeDefinesString(defines, true);
}

uint64_t ShaderCache::GetCachedHitTasks()
{
return compilationSet.cacheHitTasks;
Expand Down
2 changes: 2 additions & 0 deletions src/ShaderCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
36 changes: 36 additions & 0 deletions src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,24 @@ void State::Draw()
context->PSSetShader(reinterpret_cast<ID3D11PixelShader*>(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();
}
}
}
Expand Down Expand Up @@ -418,6 +429,7 @@ void State::SetupResources()
context = reinterpret_cast<ID3D11DeviceContext*>(renderer->GetRuntimeData().context);
device = reinterpret_cast<ID3D11Device*>(renderer->GetRuntimeData().forwarder);
shadowState = RE::BSGraphics::RendererShadowState::GetSingleton();
context->QueryInterface(__uuidof(pPerf), reinterpret_cast<void**>(&pPerf));
}

void State::ModifyShaderLookup(const RE::BSShader& a_shader, uint& a_vertexDescriptor, uint& a_pixelDescriptor)
Expand Down Expand Up @@ -516,6 +528,30 @@ void State::ModifyShaderLookup(const RE::BSShader& a_shader, uint& a_vertexDescr
}
}

void State::BeginPerfEvent(std::string_view title)
{
if (!IsDeveloperMode())
return;

pPerf->BeginEvent(std::wstring(title.begin(), title.end()).c_str());
}

void State::EndPerfEvent()
{
if (!IsDeveloperMode())
return;

pPerf->EndEvent();
}

void State::SetPerfMarker(std::string_view title)
{
if (!IsDeveloperMode())
return;

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) {
Expand Down
7 changes: 7 additions & 0 deletions src/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,4 +122,7 @@ class State
ID3D11DeviceContext* context = nullptr;
ID3D11Device* device = nullptr;
RE::BSGraphics::RendererShadowState* shadowState = nullptr;

private:
std::shared_ptr<REX::W32::ID3DUserDefinedAnnotation> pPerf;
};

0 comments on commit 84a1990

Please sign in to comment.