diff --git a/src/dxvk/hud/dxvk_hud.cpp b/src/dxvk/hud/dxvk_hud.cpp index cdf8ddeea..919bee37d 100644 --- a/src/dxvk/hud/dxvk_hud.cpp +++ b/src/dxvk/hud/dxvk_hud.cpp @@ -8,7 +8,8 @@ namespace dxvk::hud { const Rc& device) : m_device (device), m_renderer (device), - m_hudItems (device) { + m_hudItems (device), + m_scale (m_hudItems.getOption("scale", 1.0f)) { // Set up constant state m_rsState.polygonMode = VK_POLYGON_MODE_FILL; m_rsState.cullMode = VK_CULL_MODE_BACK_BIT; @@ -77,7 +78,7 @@ namespace dxvk::hud { ctx->setBlendMode(0, m_blendMode); ctx->setSpecConstant(VK_PIPELINE_BIND_POINT_GRAPHICS, 0, isSrgb); - m_renderer.beginFrame(ctx, surfaceSize); + m_renderer.beginFrame(ctx, surfaceSize, m_scale); } diff --git a/src/dxvk/hud/dxvk_hud.h b/src/dxvk/hud/dxvk_hud.h index 3dc1b6f72..d6217b8c0 100644 --- a/src/dxvk/hud/dxvk_hud.h +++ b/src/dxvk/hud/dxvk_hud.h @@ -83,6 +83,8 @@ namespace dxvk::hud { HudRenderer m_renderer; HudItemSet m_hudItems; + float m_scale; + void setupRendererState( const Rc& ctx, VkSurfaceFormatKHR surfaceFormat, diff --git a/src/dxvk/hud/dxvk_hud_item.cpp b/src/dxvk/hud/dxvk_hud_item.cpp index fdd6892ad..878a761a3 100644 --- a/src/dxvk/hud/dxvk_hud_item.cpp +++ b/src/dxvk/hud/dxvk_hud_item.cpp @@ -21,25 +21,34 @@ namespace dxvk::hud { if (configStr.empty()) configStr = device->config().hud; - if (configStr == "full") { - // Just enable everything + std::string::size_type pos = 0; + std::string::size_type end = 0; + std::string::size_type mid = 0; + + while (pos < configStr.size()) { + end = configStr.find(',', pos); + mid = configStr.find('=', pos); + + if (end == std::string::npos) + end = configStr.size(); + + if (mid != std::string::npos && mid < end) { + m_options.insert({ + configStr.substr(pos, mid - pos), + configStr.substr(mid + 1, end - mid - 1) }); + } else { + m_enabled.insert(configStr.substr(pos, end - pos)); + } + + pos = end + 1; + } + + if (m_enabled.find("full") != m_enabled.end()) m_enableFull = true; - } else if (configStr == "1") { + + if (m_enabled.find("1") != m_enabled.end()) { m_enabled.insert("devinfo"); m_enabled.insert("fps"); - } else { - std::string::size_type pos = 0; - std::string::size_type end = 0; - - while (pos < configStr.size()) { - end = configStr.find(',', pos); - - if (end == std::string::npos) - end = configStr.size(); - - m_enabled.insert(configStr.substr(pos, end - pos)); - pos = end + 1; - } } } @@ -65,6 +74,15 @@ namespace dxvk::hud { } + void HudItemSet::parseOption(const std::string& str, float& value) { + try { + value = std::stof(str); + } catch (const std::invalid_argument&) { + return; + } + } + + HudPos HudVersionItem::render( HudRenderer& renderer, HudPos position) { diff --git a/src/dxvk/hud/dxvk_hud_item.h b/src/dxvk/hud/dxvk_hud_item.h index d71af8809..84fe5ccdc 100644 --- a/src/dxvk/hud/dxvk_hud_item.h +++ b/src/dxvk/hud/dxvk_hud_item.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -97,11 +98,25 @@ namespace dxvk::hud { } } + template + T getOption(const char *option, T fallback) { + auto entry = m_options.find(option); + if (entry == m_options.end()) + return fallback; + + T value = fallback; + parseOption(entry->second, value); + return value; + } + private: - bool m_enableFull = false; - std::unordered_set m_enabled; - std::vector> m_items; + bool m_enableFull = false; + std::unordered_set m_enabled; + std::unordered_map m_options; + std::vector> m_items; + + static void parseOption(const std::string& str, float& value); }; diff --git a/src/dxvk/hud/dxvk_hud_renderer.cpp b/src/dxvk/hud/dxvk_hud_renderer.cpp index 392b2db64..2bb5ff87d 100644 --- a/src/dxvk/hud/dxvk_hud_renderer.cpp +++ b/src/dxvk/hud/dxvk_hud_renderer.cpp @@ -10,6 +10,7 @@ namespace dxvk::hud { HudRenderer::HudRenderer(const Rc& device) : m_mode (Mode::RenderNone), + m_scale (0.0f), m_surfaceSize { 0, 0 }, m_textShaders (createTextShaders(device)), m_lineShaders (createLineShaders(device)), @@ -27,11 +28,12 @@ namespace dxvk::hud { } - void HudRenderer::beginFrame(const Rc& context, VkExtent2D surfaceSize) { + void HudRenderer::beginFrame(const Rc& context, VkExtent2D surfaceSize, float scale) { context->bindResourceSampler(0, m_fontSampler); context->bindResourceView (0, m_fontView, nullptr); m_mode = Mode::RenderNone; + m_scale = scale; m_surfaceSize = surfaceSize; m_context = context; @@ -46,8 +48,8 @@ namespace dxvk::hud { const std::string& text) { beginTextRendering(); - const float xscale = 1.0f / std::max(float(m_surfaceSize.width), 1.0f); - const float yscale = 1.0f / std::max(float(m_surfaceSize.height), 1.0f); + const float xscale = m_scale / std::max(float(m_surfaceSize.width), 1.0f); + const float yscale = m_scale / std::max(float(m_surfaceSize.height), 1.0f); uint32_t vertexCount = 6 * text.size(); @@ -112,8 +114,8 @@ namespace dxvk::hud { const HudLineVertex* vertexData) { beginLineRendering(); - const float xscale = 1.0f / std::max(float(m_surfaceSize.width), 1.0f); - const float yscale = 1.0f / std::max(float(m_surfaceSize.height), 1.0f); + const float xscale = m_scale / std::max(float(m_surfaceSize.width), 1.0f); + const float yscale = m_scale / std::max(float(m_surfaceSize.height), 1.0f); if (m_currLineVertex + vertexCount > MaxLineVertexCount) allocVertexBufferSlice(); diff --git a/src/dxvk/hud/dxvk_hud_renderer.h b/src/dxvk/hud/dxvk_hud_renderer.h index a0dd0abc1..12080424b 100644 --- a/src/dxvk/hud/dxvk_hud_renderer.h +++ b/src/dxvk/hud/dxvk_hud_renderer.h @@ -93,7 +93,8 @@ namespace dxvk::hud { void beginFrame( const Rc& context, - VkExtent2D surfaceSize); + VkExtent2D surfaceSize, + float scale); void drawText( float size, @@ -125,6 +126,7 @@ namespace dxvk::hud { std::array m_charMap; Mode m_mode; + float m_scale; VkExtent2D m_surfaceSize; Rc m_context;