1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +01:00

[hud] Implement HUD scaling

Can be set like DXVK_HUD=fps,scale=1.5.
This commit is contained in:
Philip Rebohle 2020-12-01 03:23:54 +01:00
parent 8fe3effb40
commit a23be756d7
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
6 changed files with 67 additions and 27 deletions

View File

@ -8,7 +8,8 @@ namespace dxvk::hud {
const Rc<DxvkDevice>& device)
: m_device (device),
m_renderer (device),
m_hudItems (device) {
m_hudItems (device),
m_scale (m_hudItems.getOption<float>("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);
}

View File

@ -83,6 +83,8 @@ namespace dxvk::hud {
HudRenderer m_renderer;
HudItemSet m_hudItems;
float m_scale;
void setupRendererState(
const Rc<DxvkContext>& ctx,
VkSurfaceFormatKHR surfaceFormat,

View File

@ -21,25 +21,34 @@ namespace dxvk::hud {
if (configStr.empty())
configStr = device->config().hud;
if (configStr == "full") {
// Just enable everything
m_enableFull = true;
} else if (configStr == "1") {
m_enabled.insert("devinfo");
m_enabled.insert("fps");
} else {
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;
if (m_enabled.find("1") != m_enabled.end()) {
m_enabled.insert("devinfo");
m_enabled.insert("fps");
}
}
@ -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) {

View File

@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
@ -97,12 +98,26 @@ namespace dxvk::hud {
}
}
template<typename T>
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<std::string> m_enabled;
std::unordered_map<std::string, std::string> m_options;
std::vector<Rc<HudItem>> m_items;
static void parseOption(const std::string& str, float& value);
};

View File

@ -10,6 +10,7 @@ namespace dxvk::hud {
HudRenderer::HudRenderer(const Rc<DxvkDevice>& 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<DxvkContext>& context, VkExtent2D surfaceSize) {
void HudRenderer::beginFrame(const Rc<DxvkContext>& 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();

View File

@ -93,7 +93,8 @@ namespace dxvk::hud {
void beginFrame(
const Rc<DxvkContext>& context,
VkExtent2D surfaceSize);
VkExtent2D surfaceSize,
float scale);
void drawText(
float size,
@ -125,6 +126,7 @@ namespace dxvk::hud {
std::array<uint8_t, 256> m_charMap;
Mode m_mode;
float m_scale;
VkExtent2D m_surfaceSize;
Rc<DxvkContext> m_context;