Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add perfevent and marker flags #240

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 27 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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment that we'll want to do this for deferred too when merged.

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,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) {
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;
};
Loading