mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-14 22:29:15 +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:
parent
08d5b4e0e7
commit
2689204d74
@ -335,7 +335,7 @@ namespace dxvk {
|
|||||||
m_context->draw(3, 1, 0, 0);
|
m_context->draw(3, 1, 0, 0);
|
||||||
|
|
||||||
if (m_hud != nullptr)
|
if (m_hud != nullptr)
|
||||||
m_hud->render(m_context, info.imageExtent);
|
m_hud->render(m_context, info.format, info.imageExtent);
|
||||||
|
|
||||||
if (i + 1 >= SyncInterval)
|
if (i + 1 >= SyncInterval)
|
||||||
m_context->signal(m_frameLatencySignal, frameId);
|
m_context->signal(m_frameLatencySignal, frameId);
|
||||||
|
@ -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;
|
m_uniformData.surfaceSize = surfaceSize;
|
||||||
|
|
||||||
this->updateUniformBuffer(ctx, m_uniformData);
|
this->updateUniformBuffer(ctx, m_uniformData);
|
||||||
|
|
||||||
this->setupRendererState(ctx);
|
this->setupRendererState(ctx, surfaceFormat);
|
||||||
this->renderHudElements(ctx);
|
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->setRasterizerState(m_rsState);
|
||||||
ctx->setBlendMode(0, m_blendMode);
|
ctx->setBlendMode(0, m_blendMode);
|
||||||
|
|
||||||
ctx->bindResourceBuffer(0,
|
ctx->bindResourceBuffer(0,
|
||||||
DxvkBufferSlice(m_uniformBuffer));
|
DxvkBufferSlice(m_uniformBuffer));
|
||||||
|
|
||||||
|
ctx->setSpecConstant(VK_PIPELINE_BIND_POINT_GRAPHICS, 0, isSrgb);
|
||||||
m_renderer.beginFrame(ctx, m_uniformData.surfaceSize);
|
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) {
|
void Hud::renderHudElements(const Rc<DxvkContext>& ctx) {
|
||||||
m_hudItems.render(m_renderer);
|
m_hudItems.render(m_renderer);
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,9 @@ namespace dxvk::hud {
|
|||||||
* \param [in] surfaceSize Image size, in pixels
|
* \param [in] surfaceSize Image size, in pixels
|
||||||
*/
|
*/
|
||||||
void render(
|
void render(
|
||||||
const Rc<DxvkContext>& ctx,
|
const Rc<DxvkContext>& ctx,
|
||||||
VkExtent2D surfaceSize);
|
VkSurfaceFormatKHR surfaceFormat,
|
||||||
|
VkExtent2D surfaceSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Adds a HUD item if enabled
|
* \brief Adds a HUD item if enabled
|
||||||
@ -85,6 +86,10 @@ namespace dxvk::hud {
|
|||||||
HudItemSet m_hudItems;
|
HudItemSet m_hudItems;
|
||||||
|
|
||||||
void setupRendererState(
|
void setupRendererState(
|
||||||
|
const Rc<DxvkContext>& ctx,
|
||||||
|
VkSurfaceFormatKHR surfaceFormat);
|
||||||
|
|
||||||
|
void resetRendererState(
|
||||||
const Rc<DxvkContext>& ctx);
|
const Rc<DxvkContext>& ctx);
|
||||||
|
|
||||||
void renderHudElements(
|
void renderHudElements(
|
||||||
|
@ -1,10 +1,23 @@
|
|||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
|
layout(constant_id = 1249) const bool srgbSwapchain = false;
|
||||||
|
|
||||||
layout(location = 0) in vec4 v_color;
|
layout(location = 0) in vec4 v_color;
|
||||||
layout(location = 0) out vec4 o_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() {
|
void main() {
|
||||||
o_color = vec4(
|
o_color = vec4(
|
||||||
v_color.rgb * v_color.a,
|
v_color.rgb * v_color.a,
|
||||||
v_color.a);
|
v_color.a);
|
||||||
|
|
||||||
|
if (!srgbSwapchain)
|
||||||
|
o_color.rgb = linearToSrgb(o_color.rgb);
|
||||||
}
|
}
|
@ -1,5 +1,8 @@
|
|||||||
#version 450
|
#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(set = 0, binding = 1) uniform sampler2D s_font;
|
||||||
|
|
||||||
layout(location = 0) in vec2 v_texcoord;
|
layout(location = 0) in vec2 v_texcoord;
|
||||||
@ -10,6 +13,14 @@ uniform push_data {
|
|||||||
vec4 color;
|
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 sampleAlpha(float alpha_bias, float dist_range) {
|
||||||
float value = texture(s_font, v_texcoord).r + alpha_bias - 0.5f;
|
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));
|
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 = mix(r_shadow, r_center, r_alpha_center);
|
||||||
o_color.rgb *= o_color.a;
|
o_color.rgb *= o_color.a;
|
||||||
|
|
||||||
|
if (!srgbSwapchain)
|
||||||
|
o_color.rgb = linearToSrgb(o_color.rgb);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user