From af19bba048d75e454d68aa7b1667082a619e23c1 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 15 Apr 2018 20:12:41 +0200 Subject: [PATCH] [dxgi] Remove support gamma-related ScaleAndOffsetSupported Some games, including Heroes of the Storm (#287), do not set the values correctly so it's better to ignore them altogether. --- src/dxgi/dxgi_output.cpp | 2 +- src/dxgi/dxgi_presenter.cpp | 23 +--------------------- src/dxgi/dxgi_presenter.h | 24 ----------------------- src/dxgi/dxgi_swapchain.cpp | 15 ++------------ src/dxgi/shaders/dxgi_presenter_frag.frag | 16 +++------------ 5 files changed, 7 insertions(+), 73 deletions(-) diff --git a/src/dxgi/dxgi_output.cpp b/src/dxgi/dxgi_output.cpp index 96cf63d9..0abc465a 100644 --- a/src/dxgi/dxgi_output.cpp +++ b/src/dxgi/dxgi_output.cpp @@ -260,7 +260,7 @@ namespace dxvk { HRESULT STDMETHODCALLTYPE DxgiOutput::GetGammaControlCapabilities(DXGI_GAMMA_CONTROL_CAPABILITIES* pGammaCaps) { - pGammaCaps->ScaleAndOffsetSupported = TRUE; + pGammaCaps->ScaleAndOffsetSupported = FALSE; pGammaCaps->MaxConvertedValue = 1.0f; pGammaCaps->MinConvertedValue = 0.0f; pGammaCaps->NumGammaControlPoints = DXGI_VK_GAMMA_CP_COUNT; diff --git a/src/dxgi/dxgi_presenter.cpp b/src/dxgi/dxgi_presenter.cpp index 619a8b4a..21afa4a7 100644 --- a/src/dxgi/dxgi_presenter.cpp +++ b/src/dxgi/dxgi_presenter.cpp @@ -34,7 +34,6 @@ namespace dxvk { // Create objects required for the gamma ramp. This is implemented partially // with an UBO, which stores global parameters, and a lookup texture, which // stores the actual gamma ramp and can be sampled with a linear filter. - m_gammaUbo = CreateGammaUbo(); m_gammaSampler = CreateSampler(VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE); m_gammaTexture = CreateGammaTexture(); m_gammaTextureView = CreateGammaTextureView(); @@ -204,7 +203,6 @@ namespace dxvk { m_context->bindResourceSampler(BindingIds::GammaSmp, m_gammaSampler); m_context->bindResourceView (BindingIds::GammaTex, m_gammaTextureView, nullptr); - m_context->bindResourceBuffer (BindingIds::GammaUbo, DxvkBufferSlice(m_gammaUbo)); if (m_hud != nullptr) { m_blendMode.enableBlending = VK_TRUE; @@ -339,15 +337,10 @@ namespace dxvk { void DxgiVkPresenter::SetGammaControl( - const DXGI_VK_GAMMA_INPUT_CONTROL* pGammaControl, const DXGI_VK_GAMMA_CURVE* pGammaCurve) { m_context->beginRecording( m_device->createCommandList()); - m_context->updateBuffer(m_gammaUbo, - 0, sizeof(DXGI_VK_GAMMA_INPUT_CONTROL), - pGammaControl); - m_context->updateImage(m_gammaTexture, VkImageSubresourceLayers { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }, VkOffset3D { 0, 0, 0 }, @@ -383,19 +376,6 @@ namespace dxvk { } - Rc DxgiVkPresenter::CreateGammaUbo() { - DxvkBufferCreateInfo info; - info.size = sizeof(DXGI_VK_GAMMA_INPUT_CONTROL); - info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT - | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; - info.stages = VK_PIPELINE_STAGE_TRANSFER_BIT - | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; - info.access = VK_ACCESS_TRANSFER_WRITE_BIT - | VK_ACCESS_SHADER_READ_BIT; - return m_device->createBuffer(info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - } - - Rc DxgiVkPresenter::CreateGammaTexture() { DxvkImageCreateInfo info; info.type = VK_IMAGE_TYPE_1D; @@ -444,12 +424,11 @@ namespace dxvk { const SpirvCodeBuffer codeBuffer(dxgi_presenter_frag); // Shader resource slots - const std::array resourceSlots = {{ + const std::array resourceSlots = {{ { BindingIds::Sampler, VK_DESCRIPTOR_TYPE_SAMPLER, VK_IMAGE_VIEW_TYPE_MAX_ENUM }, { BindingIds::Texture, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_IMAGE_VIEW_TYPE_2D }, { BindingIds::GammaSmp, VK_DESCRIPTOR_TYPE_SAMPLER, VK_IMAGE_VIEW_TYPE_MAX_ENUM }, { BindingIds::GammaTex, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_IMAGE_VIEW_TYPE_1D }, - { BindingIds::GammaUbo, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_IMAGE_VIEW_TYPE_MAX_ENUM }, }}; // Create the actual shader module diff --git a/src/dxgi/dxgi_presenter.h b/src/dxgi/dxgi_presenter.h index 87b9aea4..1ce32606 100644 --- a/src/dxgi/dxgi_presenter.h +++ b/src/dxgi/dxgi_presenter.h @@ -35,26 +35,6 @@ namespace dxvk { DXGI_VK_GAMMA_CP ControlPoints[DXGI_VK_GAMMA_CP_COUNT]; }; - /** - * \brief Gamma input color - * A floating-point color vector. - */ - struct DXGI_VK_GAMMA_INPUT_COLOR { - float R, G, B, A; - }; - - /** - * \brief Gamma input control - * - * Stores a scaling factor and a bias that shall - * be applied to the input color before performing - * the gamma lookup in the fragment shader. - */ - struct DXGI_VK_GAMMA_INPUT_CONTROL { - DXGI_VK_GAMMA_INPUT_COLOR Factor; - DXGI_VK_GAMMA_INPUT_COLOR Offset; - }; - /** * \brief Maps color value to normalized integer * @@ -151,7 +131,6 @@ namespace dxvk { * \param [in] pGammaCurve Gamma curve */ void SetGammaControl( - const DXGI_VK_GAMMA_INPUT_CONTROL* pGammaControl, const DXGI_VK_GAMMA_CURVE* pGammaCurve); private: @@ -161,7 +140,6 @@ namespace dxvk { Texture = 1, GammaSmp = 2, GammaTex = 3, - GammaUbo = 4, }; Rc m_device; @@ -177,7 +155,6 @@ namespace dxvk { Rc m_backBufferResolve; Rc m_backBufferView; - Rc m_gammaUbo; Rc m_gammaSampler; Rc m_gammaTexture; Rc m_gammaTextureView; @@ -191,7 +168,6 @@ namespace dxvk { VkFilter Filter, VkSamplerAddressMode AddressMode); - Rc CreateGammaUbo(); Rc CreateGammaTexture(); Rc CreateGammaTextureView(); diff --git a/src/dxgi/dxgi_swapchain.cpp b/src/dxgi/dxgi_swapchain.cpp index 391df9d9..94614815 100644 --- a/src/dxgi/dxgi_swapchain.cpp +++ b/src/dxgi/dxgi_swapchain.cpp @@ -284,13 +284,6 @@ namespace dxvk { HRESULT DxgiSwapChain::SetGammaControl(const DXGI_GAMMA_CONTROL* pGammaControl) { std::lock_guard lock(m_mutex); - const DXGI_RGB Factor = pGammaControl->Scale; - const DXGI_RGB Offset = pGammaControl->Offset; - - DXGI_VK_GAMMA_INPUT_CONTROL control; - control.Factor = { Factor.Red, Factor.Green, Factor.Blue, 1.0f }; - control.Offset = { Offset.Red, Offset.Green, Offset.Blue, 0.0f }; - DXGI_VK_GAMMA_CURVE curve; for (uint32_t i = 0; i < DXGI_VK_GAMMA_CP_COUNT; i++) { @@ -301,7 +294,7 @@ namespace dxvk { curve.ControlPoints[i].A = 0; } - m_presenter->SetGammaControl(&control, &curve); + m_presenter->SetGammaControl(&curve); return S_OK; } @@ -309,10 +302,6 @@ namespace dxvk { HRESULT DxgiSwapChain::SetDefaultGammaControl() { std::lock_guard lock(m_mutex); - DXGI_VK_GAMMA_INPUT_CONTROL control; - control.Factor = { 1.0f, 1.0f, 1.0f, 1.0f }; - control.Offset = { 0.0f, 0.0f, 0.0f, 0.0f }; - DXGI_VK_GAMMA_CURVE curve; for (uint32_t i = 0; i < DXGI_VK_GAMMA_CP_COUNT; i++) { @@ -321,7 +310,7 @@ namespace dxvk { curve.ControlPoints[i] = { value, value, value, 0 }; } - m_presenter->SetGammaControl(&control, &curve); + m_presenter->SetGammaControl(&curve); return S_OK; } diff --git a/src/dxgi/shaders/dxgi_presenter_frag.frag b/src/dxgi/shaders/dxgi_presenter_frag.frag index 28cad139..73118a07 100644 --- a/src/dxgi/shaders/dxgi_presenter_frag.frag +++ b/src/dxgi/shaders/dxgi_presenter_frag.frag @@ -6,25 +6,15 @@ layout(binding = 1) uniform texture2D t_texture; layout(binding = 2) uniform sampler s_gamma; layout(binding = 3) uniform texture1D t_gamma; -layout(binding = 4) -uniform u_gamma_info_t { - layout(offset = 0) vec4 in_factor; - layout(offset = 16) vec4 in_offset; -} u_gamma_info; - layout(location = 0) in vec2 i_texcoord; layout(location = 0) out vec4 o_color; void main() { vec4 color = texture(sampler2D(t_texture, s_sampler), i_texcoord); - vec3 cp_lookup = color.rgb; - cp_lookup *= u_gamma_info.in_factor.rgb; - cp_lookup += u_gamma_info.in_offset.rgb; - o_color = vec4( - texture(sampler1D(t_gamma, s_gamma), cp_lookup.r).r, - texture(sampler1D(t_gamma, s_gamma), cp_lookup.g).g, - texture(sampler1D(t_gamma, s_gamma), cp_lookup.b).b, + texture(sampler1D(t_gamma, s_gamma), color.r).r, + texture(sampler1D(t_gamma, s_gamma), color.g).g, + texture(sampler1D(t_gamma, s_gamma), color.b).b, color.a); } \ No newline at end of file