mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-01 10:54:14 +01:00
[hud] Implement HUD scaling
Can be set like DXVK_HUD=fps,scale=1.5.
This commit is contained in:
parent
8fe3effb40
commit
a23be756d7
@ -8,7 +8,8 @@ namespace dxvk::hud {
|
|||||||
const Rc<DxvkDevice>& device)
|
const Rc<DxvkDevice>& device)
|
||||||
: m_device (device),
|
: m_device (device),
|
||||||
m_renderer (device),
|
m_renderer (device),
|
||||||
m_hudItems (device) {
|
m_hudItems (device),
|
||||||
|
m_scale (m_hudItems.getOption<float>("scale", 1.0f)) {
|
||||||
// Set up constant state
|
// Set up constant state
|
||||||
m_rsState.polygonMode = VK_POLYGON_MODE_FILL;
|
m_rsState.polygonMode = VK_POLYGON_MODE_FILL;
|
||||||
m_rsState.cullMode = VK_CULL_MODE_BACK_BIT;
|
m_rsState.cullMode = VK_CULL_MODE_BACK_BIT;
|
||||||
@ -77,7 +78,7 @@ namespace dxvk::hud {
|
|||||||
ctx->setBlendMode(0, m_blendMode);
|
ctx->setBlendMode(0, m_blendMode);
|
||||||
|
|
||||||
ctx->setSpecConstant(VK_PIPELINE_BIND_POINT_GRAPHICS, 0, isSrgb);
|
ctx->setSpecConstant(VK_PIPELINE_BIND_POINT_GRAPHICS, 0, isSrgb);
|
||||||
m_renderer.beginFrame(ctx, surfaceSize);
|
m_renderer.beginFrame(ctx, surfaceSize, m_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +83,8 @@ namespace dxvk::hud {
|
|||||||
HudRenderer m_renderer;
|
HudRenderer m_renderer;
|
||||||
HudItemSet m_hudItems;
|
HudItemSet m_hudItems;
|
||||||
|
|
||||||
|
float m_scale;
|
||||||
|
|
||||||
void setupRendererState(
|
void setupRendererState(
|
||||||
const Rc<DxvkContext>& ctx,
|
const Rc<DxvkContext>& ctx,
|
||||||
VkSurfaceFormatKHR surfaceFormat,
|
VkSurfaceFormatKHR surfaceFormat,
|
||||||
|
@ -21,25 +21,34 @@ namespace dxvk::hud {
|
|||||||
if (configStr.empty())
|
if (configStr.empty())
|
||||||
configStr = device->config().hud;
|
configStr = device->config().hud;
|
||||||
|
|
||||||
if (configStr == "full") {
|
std::string::size_type pos = 0;
|
||||||
// Just enable everything
|
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;
|
m_enableFull = true;
|
||||||
} else if (configStr == "1") {
|
|
||||||
|
if (m_enabled.find("1") != m_enabled.end()) {
|
||||||
m_enabled.insert("devinfo");
|
m_enabled.insert("devinfo");
|
||||||
m_enabled.insert("fps");
|
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(
|
HudPos HudVersionItem::render(
|
||||||
HudRenderer& renderer,
|
HudRenderer& renderer,
|
||||||
HudPos position) {
|
HudPos position) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -97,11 +98,25 @@ 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:
|
private:
|
||||||
|
|
||||||
bool m_enableFull = false;
|
bool m_enableFull = false;
|
||||||
std::unordered_set<std::string> m_enabled;
|
std::unordered_set<std::string> m_enabled;
|
||||||
std::vector<Rc<HudItem>> m_items;
|
std::unordered_map<std::string, std::string> m_options;
|
||||||
|
std::vector<Rc<HudItem>> m_items;
|
||||||
|
|
||||||
|
static void parseOption(const std::string& str, float& value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ namespace dxvk::hud {
|
|||||||
|
|
||||||
HudRenderer::HudRenderer(const Rc<DxvkDevice>& device)
|
HudRenderer::HudRenderer(const Rc<DxvkDevice>& device)
|
||||||
: m_mode (Mode::RenderNone),
|
: m_mode (Mode::RenderNone),
|
||||||
|
m_scale (0.0f),
|
||||||
m_surfaceSize { 0, 0 },
|
m_surfaceSize { 0, 0 },
|
||||||
m_textShaders (createTextShaders(device)),
|
m_textShaders (createTextShaders(device)),
|
||||||
m_lineShaders (createLineShaders(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->bindResourceSampler(0, m_fontSampler);
|
||||||
context->bindResourceView (0, m_fontView, nullptr);
|
context->bindResourceView (0, m_fontView, nullptr);
|
||||||
|
|
||||||
m_mode = Mode::RenderNone;
|
m_mode = Mode::RenderNone;
|
||||||
|
m_scale = scale;
|
||||||
m_surfaceSize = surfaceSize;
|
m_surfaceSize = surfaceSize;
|
||||||
m_context = context;
|
m_context = context;
|
||||||
|
|
||||||
@ -46,8 +48,8 @@ namespace dxvk::hud {
|
|||||||
const std::string& text) {
|
const std::string& text) {
|
||||||
beginTextRendering();
|
beginTextRendering();
|
||||||
|
|
||||||
const float xscale = 1.0f / std::max(float(m_surfaceSize.width), 1.0f);
|
const float xscale = m_scale / std::max(float(m_surfaceSize.width), 1.0f);
|
||||||
const float yscale = 1.0f / std::max(float(m_surfaceSize.height), 1.0f);
|
const float yscale = m_scale / std::max(float(m_surfaceSize.height), 1.0f);
|
||||||
|
|
||||||
uint32_t vertexCount = 6 * text.size();
|
uint32_t vertexCount = 6 * text.size();
|
||||||
|
|
||||||
@ -112,8 +114,8 @@ namespace dxvk::hud {
|
|||||||
const HudLineVertex* vertexData) {
|
const HudLineVertex* vertexData) {
|
||||||
beginLineRendering();
|
beginLineRendering();
|
||||||
|
|
||||||
const float xscale = 1.0f / std::max(float(m_surfaceSize.width), 1.0f);
|
const float xscale = m_scale / std::max(float(m_surfaceSize.width), 1.0f);
|
||||||
const float yscale = 1.0f / std::max(float(m_surfaceSize.height), 1.0f);
|
const float yscale = m_scale / std::max(float(m_surfaceSize.height), 1.0f);
|
||||||
|
|
||||||
if (m_currLineVertex + vertexCount > MaxLineVertexCount)
|
if (m_currLineVertex + vertexCount > MaxLineVertexCount)
|
||||||
allocVertexBufferSlice();
|
allocVertexBufferSlice();
|
||||||
|
@ -93,7 +93,8 @@ namespace dxvk::hud {
|
|||||||
|
|
||||||
void beginFrame(
|
void beginFrame(
|
||||||
const Rc<DxvkContext>& context,
|
const Rc<DxvkContext>& context,
|
||||||
VkExtent2D surfaceSize);
|
VkExtent2D surfaceSize,
|
||||||
|
float scale);
|
||||||
|
|
||||||
void drawText(
|
void drawText(
|
||||||
float size,
|
float size,
|
||||||
@ -125,6 +126,7 @@ namespace dxvk::hud {
|
|||||||
std::array<uint8_t, 256> m_charMap;
|
std::array<uint8_t, 256> m_charMap;
|
||||||
|
|
||||||
Mode m_mode;
|
Mode m_mode;
|
||||||
|
float m_scale;
|
||||||
VkExtent2D m_surfaceSize;
|
VkExtent2D m_surfaceSize;
|
||||||
Rc<DxvkContext> m_context;
|
Rc<DxvkContext> m_context;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user