mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-19 05:52:11 +01:00
[hud] Don't pass DXVK context around in HUD modules
This commit is contained in:
parent
8e587af0da
commit
4346f82209
@ -87,7 +87,7 @@ namespace dxvk::hud {
|
||||
HudPos position = { 8.0f, 24.0f };
|
||||
|
||||
if (m_config.elements.test(HudElement::DxvkVersion)) {
|
||||
m_renderer.drawText(ctx, 16.0f,
|
||||
m_renderer.drawText(16.0f,
|
||||
{ position.x, position.y },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
"DXVK " DXVK_VERSION);
|
||||
@ -95,20 +95,18 @@ namespace dxvk::hud {
|
||||
}
|
||||
|
||||
if (m_config.elements.test(HudElement::DxvkClientApi)) {
|
||||
m_renderer.drawText(ctx, 16.0f,
|
||||
m_renderer.drawText(16.0f,
|
||||
{ position.x, position.y },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
m_device->clientApi());
|
||||
position.y += 24.0f;
|
||||
}
|
||||
|
||||
if (m_config.elements.test(HudElement::DeviceInfo)) {
|
||||
position = m_hudDeviceInfo.render(
|
||||
ctx, m_renderer, position);
|
||||
}
|
||||
if (m_config.elements.test(HudElement::DeviceInfo))
|
||||
position = m_hudDeviceInfo.render(m_renderer, position);
|
||||
|
||||
position = m_hudFramerate.render(ctx, m_renderer, position);
|
||||
position = m_hudStats .render(ctx, m_renderer, position);
|
||||
position = m_hudFramerate.render(m_renderer, position);
|
||||
position = m_hudStats .render(m_renderer, position);
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,20 +22,19 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
HudPos HudDeviceInfo::render(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
m_deviceName);
|
||||
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y + 24 },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
m_driverVer);
|
||||
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y + 44 },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
m_vulkanVer);
|
||||
|
@ -18,7 +18,6 @@ namespace dxvk::hud {
|
||||
~HudDeviceInfo();
|
||||
|
||||
HudPos render(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
|
@ -43,28 +43,22 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
HudPos HudFps::render(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
if (m_elements.test(HudElement::Framerate)) {
|
||||
position = this->renderFpsText(
|
||||
context, renderer, position);
|
||||
}
|
||||
if (m_elements.test(HudElement::Framerate))
|
||||
position = this->renderFpsText(renderer, position);
|
||||
|
||||
if (m_elements.test(HudElement::Frametimes)) {
|
||||
position = this->renderFrametimeGraph(
|
||||
context, renderer, position);
|
||||
}
|
||||
if (m_elements.test(HudElement::Frametimes))
|
||||
position = this->renderFrametimeGraph(renderer, position);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
HudPos HudFps::renderFpsText(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
m_fpsString);
|
||||
@ -74,7 +68,6 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
HudPos HudFps::renderFrametimeGraph(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
std::array<HudLineVertex, NumDataPoints * 2> vData;
|
||||
@ -116,15 +109,15 @@ namespace dxvk::hud {
|
||||
vData[2 * i + 1] = HudLineVertex { { x, y - h }, color };
|
||||
}
|
||||
|
||||
renderer.drawLines(context, vData.size(), vData.data());
|
||||
renderer.drawLines(vData.size(), vData.data());
|
||||
|
||||
// Paint min/max frame times in the entire window
|
||||
renderer.drawText(context, 14.0f,
|
||||
renderer.drawText(14.0f,
|
||||
{ position.x, position.y + 44.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
str::format("min: ", minMs / 10, ".", minMs % 10));
|
||||
|
||||
renderer.drawText(context, 14.0f,
|
||||
renderer.drawText(14.0f,
|
||||
{ position.x + 150.0f, position.y + 44.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
str::format("max: ", maxMs / 10, ".", maxMs % 10));
|
||||
|
@ -27,7 +27,6 @@ namespace dxvk::hud {
|
||||
void update();
|
||||
|
||||
HudPos render(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
@ -45,12 +44,10 @@ namespace dxvk::hud {
|
||||
uint32_t m_dataPointId = 0;
|
||||
|
||||
HudPos renderFpsText(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
HudPos renderFrametimeGraph(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
|
@ -36,25 +36,23 @@ namespace dxvk::hud {
|
||||
|
||||
m_mode = Mode::RenderNone;
|
||||
m_surfaceSize = surfaceSize;
|
||||
m_context = context;
|
||||
}
|
||||
|
||||
|
||||
void HudRenderer::drawText(
|
||||
const Rc<DxvkContext>& context,
|
||||
float size,
|
||||
HudPos pos,
|
||||
HudColor color,
|
||||
const std::string& text) {
|
||||
beginTextRendering(context);
|
||||
beginTextRendering();
|
||||
|
||||
uint32_t vertexCount = 6 * text.size();
|
||||
|
||||
auto vertexSlice = allocVertexBuffer(context,
|
||||
vertexCount * sizeof(HudTextVertex));
|
||||
|
||||
context->bindVertexBuffer(0, vertexSlice, sizeof(HudTextVertex));
|
||||
context->pushConstants(0, sizeof(color), &color);
|
||||
context->draw(vertexCount, 1, 0, 0);
|
||||
auto vertexSlice = allocVertexBuffer(vertexCount * sizeof(HudTextVertex));
|
||||
m_context->bindVertexBuffer(0, vertexSlice, sizeof(HudTextVertex));
|
||||
m_context->pushConstants(0, sizeof(color), &color);
|
||||
m_context->draw(vertexCount, 1, 0, 0);
|
||||
|
||||
auto vertexData = reinterpret_cast<HudTextVertex*>(
|
||||
vertexSlice.getSliceHandle().mapPtr);
|
||||
@ -108,16 +106,13 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
void HudRenderer::drawLines(
|
||||
const Rc<DxvkContext>& context,
|
||||
size_t vertexCount,
|
||||
const HudLineVertex* vertexData) {
|
||||
beginLineRendering(context);
|
||||
beginLineRendering();
|
||||
|
||||
auto vertexSlice = allocVertexBuffer(context,
|
||||
vertexCount * sizeof(HudLineVertex));
|
||||
|
||||
context->bindVertexBuffer(0, vertexSlice, sizeof(HudLineVertex));
|
||||
context->draw(vertexCount, 1, 0, 0);
|
||||
auto vertexSlice = allocVertexBuffer(vertexCount * sizeof(HudLineVertex));
|
||||
m_context->bindVertexBuffer(0, vertexSlice, sizeof(HudLineVertex));
|
||||
m_context->draw(vertexCount, 1, 0, 0);
|
||||
|
||||
auto dstVertexData = reinterpret_cast<HudLineVertex*>(
|
||||
vertexSlice.getSliceHandle().mapPtr);
|
||||
@ -128,12 +123,11 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
DxvkBufferSlice HudRenderer::allocVertexBuffer(
|
||||
const Rc<DxvkContext>& context,
|
||||
VkDeviceSize dataSize) {
|
||||
dataSize = align(dataSize, 64);
|
||||
|
||||
if (m_vertexOffset + dataSize > m_vertexBuffer->info().size) {
|
||||
context->invalidateBuffer(m_vertexBuffer, m_vertexBuffer->allocSlice());
|
||||
m_context->invalidateBuffer(m_vertexBuffer, m_vertexBuffer->allocSlice());
|
||||
m_vertexOffset = 0;
|
||||
}
|
||||
|
||||
@ -143,13 +137,12 @@ namespace dxvk::hud {
|
||||
}
|
||||
|
||||
|
||||
void HudRenderer::beginTextRendering(
|
||||
const Rc<DxvkContext>& context) {
|
||||
void HudRenderer::beginTextRendering() {
|
||||
if (m_mode != Mode::RenderText) {
|
||||
m_mode = Mode::RenderText;
|
||||
|
||||
context->bindShader(VK_SHADER_STAGE_VERTEX_BIT, m_textShaders.vert);
|
||||
context->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, m_textShaders.frag);
|
||||
m_context->bindShader(VK_SHADER_STAGE_VERTEX_BIT, m_textShaders.vert);
|
||||
m_context->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, m_textShaders.frag);
|
||||
|
||||
static const DxvkInputAssemblyState iaState = {
|
||||
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
|
||||
@ -164,8 +157,8 @@ namespace dxvk::hud {
|
||||
{ 0, VK_VERTEX_INPUT_RATE_VERTEX },
|
||||
}};
|
||||
|
||||
context->setInputAssemblyState(iaState);
|
||||
context->setInputLayout(
|
||||
m_context->setInputAssemblyState(iaState);
|
||||
m_context->setInputLayout(
|
||||
ilAttributes.size(),
|
||||
ilAttributes.data(),
|
||||
ilBindings.size(),
|
||||
@ -174,13 +167,12 @@ namespace dxvk::hud {
|
||||
}
|
||||
|
||||
|
||||
void HudRenderer::beginLineRendering(
|
||||
const Rc<DxvkContext>& context) {
|
||||
void HudRenderer::beginLineRendering() {
|
||||
if (m_mode != Mode::RenderLines) {
|
||||
m_mode = Mode::RenderLines;
|
||||
|
||||
context->bindShader(VK_SHADER_STAGE_VERTEX_BIT, m_lineShaders.vert);
|
||||
context->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, m_lineShaders.frag);
|
||||
m_context->bindShader(VK_SHADER_STAGE_VERTEX_BIT, m_lineShaders.vert);
|
||||
m_context->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, m_lineShaders.frag);
|
||||
|
||||
static const DxvkInputAssemblyState iaState = {
|
||||
VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
|
||||
@ -195,8 +187,8 @@ namespace dxvk::hud {
|
||||
{ 0, VK_VERTEX_INPUT_RATE_VERTEX },
|
||||
}};
|
||||
|
||||
context->setInputAssemblyState(iaState);
|
||||
context->setInputLayout(
|
||||
m_context->setInputAssemblyState(iaState);
|
||||
m_context->setInputLayout(
|
||||
ilAttributes.size(),
|
||||
ilAttributes.data(),
|
||||
ilBindings.size(),
|
||||
|
@ -88,14 +88,12 @@ namespace dxvk::hud {
|
||||
VkExtent2D surfaceSize);
|
||||
|
||||
void drawText(
|
||||
const Rc<DxvkContext>& context,
|
||||
float size,
|
||||
HudPos pos,
|
||||
HudColor color,
|
||||
const std::string& text);
|
||||
|
||||
void drawLines(
|
||||
const Rc<DxvkContext>& context,
|
||||
size_t vertexCount,
|
||||
const HudLineVertex* vertexData);
|
||||
|
||||
@ -120,6 +118,7 @@ namespace dxvk::hud {
|
||||
|
||||
Mode m_mode;
|
||||
VkExtent2D m_surfaceSize;
|
||||
Rc<DxvkContext> m_context;
|
||||
|
||||
ShaderPair m_textShaders;
|
||||
ShaderPair m_lineShaders;
|
||||
@ -132,14 +131,11 @@ namespace dxvk::hud {
|
||||
VkDeviceSize m_vertexOffset = 0;
|
||||
|
||||
DxvkBufferSlice allocVertexBuffer(
|
||||
const Rc<DxvkContext>& context,
|
||||
VkDeviceSize dataSize);
|
||||
|
||||
void beginTextRendering(
|
||||
const Rc<DxvkContext>& context);
|
||||
void beginTextRendering();
|
||||
|
||||
void beginLineRendering(
|
||||
const Rc<DxvkContext>& context);
|
||||
void beginLineRendering();
|
||||
|
||||
ShaderPair createTextShaders(
|
||||
const Rc<DxvkDevice>& device);
|
||||
|
@ -30,26 +30,25 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
HudPos HudStats::render(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
if (m_elements.test(HudElement::StatSubmissions))
|
||||
position = this->printSubmissionStats(context, renderer, position);
|
||||
position = this->printSubmissionStats(renderer, position);
|
||||
|
||||
if (m_elements.test(HudElement::StatDrawCalls))
|
||||
position = this->printDrawCallStats(context, renderer, position);
|
||||
position = this->printDrawCallStats(renderer, position);
|
||||
|
||||
if (m_elements.test(HudElement::StatPipelines))
|
||||
position = this->printPipelineStats(context, renderer, position);
|
||||
position = this->printPipelineStats(renderer, position);
|
||||
|
||||
if (m_elements.test(HudElement::StatMemory))
|
||||
position = this->printMemoryStats(context, renderer, position);
|
||||
position = this->printMemoryStats(renderer, position);
|
||||
|
||||
if (m_elements.test(HudElement::StatGpuLoad))
|
||||
position = this->printGpuLoad(context, renderer, position);
|
||||
position = this->printGpuLoad(renderer, position);
|
||||
|
||||
if (m_elements.test(HudElement::CompilerActivity)) {
|
||||
this->printCompilerActivity(context, renderer,
|
||||
this->printCompilerActivity(renderer,
|
||||
{ position.x, float(renderer.surfaceSize().height) - 20.0f });
|
||||
}
|
||||
|
||||
@ -77,7 +76,6 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
HudPos HudStats::printDrawCallStats(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
const uint64_t frameCount = std::max<uint64_t>(m_diffCounters.getCtr(DxvkStatCounter::QueuePresentCount), 1);
|
||||
@ -90,17 +88,17 @@ namespace dxvk::hud {
|
||||
const std::string strDispatchCalls = str::format("Dispatch calls: ", cpCalls);
|
||||
const std::string strRenderPasses = str::format("Render passes: ", rpCalls);
|
||||
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
strDrawCalls);
|
||||
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y + 20.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
strDispatchCalls);
|
||||
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y + 40.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
strRenderPasses);
|
||||
@ -110,7 +108,6 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
HudPos HudStats::printSubmissionStats(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
const uint64_t frameCount = std::max<uint64_t>(m_diffCounters.getCtr(DxvkStatCounter::QueuePresentCount), 1);
|
||||
@ -118,7 +115,7 @@ namespace dxvk::hud {
|
||||
|
||||
const std::string strSubmissions = str::format("Queue submissions: ", numSubmits);
|
||||
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
strSubmissions);
|
||||
@ -128,7 +125,6 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
HudPos HudStats::printPipelineStats(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
const uint64_t gpCount = m_prevCounters.getCtr(DxvkStatCounter::PipeCountGraphics);
|
||||
@ -137,12 +133,12 @@ namespace dxvk::hud {
|
||||
const std::string strGpCount = str::format("Graphics pipelines: ", gpCount);
|
||||
const std::string strCpCount = str::format("Compute pipelines: ", cpCount);
|
||||
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
strGpCount);
|
||||
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y + 20.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
strCpCount);
|
||||
@ -152,7 +148,6 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
HudPos HudStats::printMemoryStats(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
constexpr uint64_t mib = 1024 * 1024;
|
||||
@ -163,12 +158,12 @@ namespace dxvk::hud {
|
||||
const std::string strMemAllocated = str::format("Memory allocated: ", memAllocated / mib, " MB");
|
||||
const std::string strMemUsed = str::format("Memory used: ", memUsed / mib, " MB");
|
||||
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
strMemAllocated);
|
||||
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y + 20.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
strMemUsed);
|
||||
@ -178,10 +173,9 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
HudPos HudStats::printGpuLoad(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
m_gpuLoadString);
|
||||
@ -191,7 +185,6 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
HudPos HudStats::printCompilerActivity(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position) {
|
||||
auto now = dxvk::high_resolution_clock::now();
|
||||
@ -207,7 +200,7 @@ namespace dxvk::hud {
|
||||
}
|
||||
|
||||
if (doShow) {
|
||||
renderer.drawText(context, 16.0f,
|
||||
renderer.drawText(16.0f,
|
||||
{ position.x, position.y },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
"Compiling shaders...");
|
||||
|
@ -27,7 +27,6 @@ namespace dxvk::hud {
|
||||
const Rc<DxvkDevice>& device);
|
||||
|
||||
HudPos render(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
@ -49,32 +48,26 @@ namespace dxvk::hud {
|
||||
void updateGpuLoad();
|
||||
|
||||
HudPos printDrawCallStats(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
HudPos printSubmissionStats(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
HudPos printPipelineStats(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
HudPos printMemoryStats(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
HudPos printGpuLoad(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
HudPos printCompilerActivity(
|
||||
const Rc<DxvkContext>& context,
|
||||
HudRenderer& renderer,
|
||||
HudPos position);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user