1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-13 19:29:14 +01:00

[hud] Enable manual sRGB conversion for non-sRGB swap chains

We still blend in the wrong color space, but text should be a bit
more readable in some games now.
This commit is contained in:
Philip Rebohle 2019-12-13 14:03:00 +01:00
parent 08d5b4e0e7
commit 2689204d74
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
5 changed files with 52 additions and 6 deletions

View File

@ -335,7 +335,7 @@ namespace dxvk {
m_context->draw(3, 1, 0, 0);
if (m_hud != nullptr)
m_hud->render(m_context, info.imageExtent);
m_hud->render(m_context, info.format, info.imageExtent);
if (i + 1 >= SyncInterval)
m_context->signal(m_frameLatencySignal, frameId);

View File

@ -53,13 +53,17 @@ namespace dxvk::hud {
}
void Hud::render(const Rc<DxvkContext>& ctx, VkExtent2D surfaceSize) {
void Hud::render(
const Rc<DxvkContext>& ctx,
VkSurfaceFormatKHR surfaceFormat,
VkExtent2D surfaceSize) {
m_uniformData.surfaceSize = surfaceSize;
this->updateUniformBuffer(ctx, m_uniformData);
this->setupRendererState(ctx);
this->setupRendererState(ctx, surfaceFormat);
this->renderHudElements(ctx);
this->resetRendererState(ctx);
}
@ -68,17 +72,27 @@ namespace dxvk::hud {
}
void Hud::setupRendererState(const Rc<DxvkContext>& ctx) {
void Hud::setupRendererState(
const Rc<DxvkContext>& ctx,
VkSurfaceFormatKHR surfaceFormat) {
bool isSrgb = imageFormatInfo(surfaceFormat.format)->flags.test(DxvkFormatFlag::ColorSpaceSrgb);
ctx->setRasterizerState(m_rsState);
ctx->setBlendMode(0, m_blendMode);
ctx->bindResourceBuffer(0,
DxvkBufferSlice(m_uniformBuffer));
ctx->setSpecConstant(VK_PIPELINE_BIND_POINT_GRAPHICS, 0, isSrgb);
m_renderer.beginFrame(ctx, m_uniformData.surfaceSize);
}
void Hud::resetRendererState(const Rc<DxvkContext>& ctx) {
ctx->setSpecConstant(VK_PIPELINE_BIND_POINT_GRAPHICS, 0, 0);
}
void Hud::renderHudElements(const Rc<DxvkContext>& ctx) {
m_hudItems.render(m_renderer);
}

View File

@ -45,8 +45,9 @@ namespace dxvk::hud {
* \param [in] surfaceSize Image size, in pixels
*/
void render(
const Rc<DxvkContext>& ctx,
VkExtent2D surfaceSize);
const Rc<DxvkContext>& ctx,
VkSurfaceFormatKHR surfaceFormat,
VkExtent2D surfaceSize);
/**
* \brief Adds a HUD item if enabled
@ -85,6 +86,10 @@ namespace dxvk::hud {
HudItemSet m_hudItems;
void setupRendererState(
const Rc<DxvkContext>& ctx,
VkSurfaceFormatKHR surfaceFormat);
void resetRendererState(
const Rc<DxvkContext>& ctx);
void renderHudElements(

View File

@ -1,10 +1,23 @@
#version 450
layout(constant_id = 1249) const bool srgbSwapchain = false;
layout(location = 0) in vec4 v_color;
layout(location = 0) out vec4 o_color;
vec3 linearToSrgb(vec3 color) {
bvec3 isLo = lessThanEqual(color, vec3(0.0031308f));
vec3 loPart = color * 12.92f;
vec3 hiPart = pow(color, vec3(5.0f / 12.0f)) * 1.055f - 0.055f;
return mix(hiPart, loPart, isLo);
}
void main() {
o_color = vec4(
v_color.rgb * v_color.a,
v_color.a);
if (!srgbSwapchain)
o_color.rgb = linearToSrgb(o_color.rgb);
}

View File

@ -1,5 +1,8 @@
#version 450
layout(constant_id = 1249) const bool srgbSwapchain = false;
layout(set = 0, binding = 0) uniform texture2D s_base;
layout(set = 0, binding = 1) uniform sampler2D s_font;
layout(location = 0) in vec2 v_texcoord;
@ -10,6 +13,14 @@ uniform push_data {
vec4 color;
};
vec3 linearToSrgb(vec3 color) {
bvec3 isLo = lessThanEqual(color, vec3(0.0031308f));
vec3 loPart = color * 12.92f;
vec3 hiPart = pow(color, vec3(5.0f / 12.0f)) * 1.055f - 0.055f;
return mix(hiPart, loPart, isLo);
}
float sampleAlpha(float alpha_bias, float dist_range) {
float value = texture(s_font, v_texcoord).r + alpha_bias - 0.5f;
float dist = value * dot(vec2(dist_range, dist_range), 1.0f / fwidth(v_texcoord.xy));
@ -25,4 +36,7 @@ void main() {
o_color = mix(r_shadow, r_center, r_alpha_center);
o_color.rgb *= o_color.a;
if (!srgbSwapchain)
o_color.rgb = linearToSrgb(o_color.rgb);
}