1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +01:00

[d3d11] Don't sample gamma texture if the gamma curve is identity

Saves some GPU time in games that don't use DXGI gamma control at all.
This commit is contained in:
Philip Rebohle 2019-03-24 18:02:19 +01:00
parent 73bb0d8ae2
commit be1832a348
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
3 changed files with 32 additions and 19 deletions

View File

@ -35,8 +35,6 @@ namespace dxvk {
InitSamplers(); InitSamplers();
InitShaders(); InitShaders();
SetGammaControl(0, nullptr);
// The present fence seems to introduce stutter on ANV // The present fence seems to introduce stutter on ANV
if (m_device->adapter()->matchesDriver(DxvkGpuVendor::Intel, VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA_KHR, 0, 0)) if (m_device->adapter()->matchesDriver(DxvkGpuVendor::Intel, VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA_KHR, 0, 0))
m_usePresentFence = false; m_usePresentFence = false;
@ -135,31 +133,34 @@ namespace dxvk {
HRESULT STDMETHODCALLTYPE D3D11SwapChain::SetGammaControl( HRESULT STDMETHODCALLTYPE D3D11SwapChain::SetGammaControl(
UINT NumControlPoints, UINT NumControlPoints,
const DXGI_RGB* pControlPoints) { const DXGI_RGB* pControlPoints) {
if (NumControlPoints > 0) { bool isIdentity = true;
if (NumControlPoints > 1) {
std::array<D3D11_VK_GAMMA_CP, 1025> cp; std::array<D3D11_VK_GAMMA_CP, 1025> cp;
if (NumControlPoints > cp.size()) if (NumControlPoints > cp.size())
return E_INVALIDARG; return E_INVALIDARG;
for (uint32_t i = 0; i < NumControlPoints; i++) { for (uint32_t i = 0; i < NumControlPoints; i++) {
uint16_t identity = MapGammaControlPoint(float(i) / float(NumControlPoints - 1));
cp[i].R = MapGammaControlPoint(pControlPoints[i].Red); cp[i].R = MapGammaControlPoint(pControlPoints[i].Red);
cp[i].G = MapGammaControlPoint(pControlPoints[i].Green); cp[i].G = MapGammaControlPoint(pControlPoints[i].Green);
cp[i].B = MapGammaControlPoint(pControlPoints[i].Blue); cp[i].B = MapGammaControlPoint(pControlPoints[i].Blue);
cp[i].A = 0; cp[i].A = 0;
isIdentity &= cp[i].R == identity
&& cp[i].G == identity
&& cp[i].B == identity;
} }
CreateGammaTexture(NumControlPoints, cp.data()); if (!isIdentity)
} else { CreateGammaTexture(NumControlPoints, cp.data());
std::array<D3D11_VK_GAMMA_CP, 256> cp;
for (uint32_t i = 0; i < cp.size(); i++) {
const uint16_t value = 257 * i;
cp[i] = { value, value, value, 0 };
}
CreateGammaTexture(cp.size(), cp.data());
} }
if (isIdentity)
DestroyGammaTexture();
return S_OK; return S_OK;
} }
@ -570,6 +571,12 @@ namespace dxvk {
} }
void D3D11SwapChain::DestroyGammaTexture() {
m_gammaTexture = nullptr;
m_gammaTextureView = nullptr;
}
void D3D11SwapChain::CreateHud() { void D3D11SwapChain::CreateHud() {
m_hud = hud::Hud::createHud(m_device); m_hud = hud::Hud::createHud(m_device);
} }

View File

@ -139,6 +139,8 @@ namespace dxvk {
UINT NumControlPoints, UINT NumControlPoints,
const D3D11_VK_GAMMA_CP* pControlPoints); const D3D11_VK_GAMMA_CP* pControlPoints);
void DestroyGammaTexture();
void CreateHud(); void CreateHud();
void InitRenderState(); void InitRenderState();

View File

@ -1,5 +1,7 @@
#version 450 #version 450
layout(constant_id = 3) const bool s_gamma_bound = false;
layout(binding = 0) uniform sampler s_sampler; layout(binding = 0) uniform sampler s_sampler;
layout(binding = 1) uniform texture2D t_texture; layout(binding = 1) uniform texture2D t_texture;
@ -10,11 +12,13 @@ layout(location = 0) in vec2 i_texcoord;
layout(location = 0) out vec4 o_color; layout(location = 0) out vec4 o_color;
void main() { void main() {
vec4 color = texture(sampler2D(t_texture, s_sampler), i_texcoord); o_color = texture(sampler2D(t_texture, s_sampler), i_texcoord);
o_color = vec4( if (s_gamma_bound) {
texture(sampler1D(t_gamma, s_gamma), color.r).r, o_color = vec4(
texture(sampler1D(t_gamma, s_gamma), color.g).g, texture(sampler1D(t_gamma, s_gamma), o_color.r).r,
texture(sampler1D(t_gamma, s_gamma), color.b).b, texture(sampler1D(t_gamma, s_gamma), o_color.g).g,
color.a); texture(sampler1D(t_gamma, s_gamma), o_color.b).b,
o_color.a);
}
} }