OGL: Add support for glDepthRangedNV to handle oversized depth ranges.
This commit is contained in:
parent
28e6e259ed
commit
94522d4cf3
|
@ -105,6 +105,7 @@
|
|||
<ClInclude Include="GL\GLExtensions\gl_common.h" />
|
||||
<ClInclude Include="GL\GLExtensions\HP_occlusion_test.h" />
|
||||
<ClInclude Include="GL\GLExtensions\KHR_debug.h" />
|
||||
<ClInclude Include="GL\GLExtensions\NV_depth_buffer_float.h" />
|
||||
<ClInclude Include="GL\GLExtensions\NV_occlusion_query_samples.h" />
|
||||
<ClInclude Include="GL\GLExtensions\NV_primitive_restart.h" />
|
||||
<ClInclude Include="GL\GLInterfaceBase.h" />
|
||||
|
|
|
@ -218,6 +218,9 @@
|
|||
<ClInclude Include="GL\GLExtensions\NV_primitive_restart.h">
|
||||
<Filter>GL\GLExtensions</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GL\GLExtensions\NV_depth_buffer_float.h">
|
||||
<Filter>GL\GLExtensions</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GL\GLInterface\WGL.h">
|
||||
<Filter>GL\GLInterface</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -984,6 +984,11 @@ PFNDOLCOPYIMAGESUBDATAPROC dolCopyImageSubData;
|
|||
// ARB_shader_storage_buffer_object
|
||||
PFNDOLSHADERSTORAGEBLOCKBINDINGPROC dolShaderStorageBlockBinding;
|
||||
|
||||
// NV_depth_buffer_float
|
||||
PFNDOLDEPTHRANGEDNVPROC dolDepthRangedNV;
|
||||
PFNDOLCLEARDEPTHDNVPROC dolClearDepthdNV;
|
||||
PFNDOLDEPTHBOUNDSDNVPROC dolDepthBoundsdNV;
|
||||
|
||||
// Creates a GLFunc object that requires a feature
|
||||
#define GLFUNC_REQUIRES(x, y) \
|
||||
{ \
|
||||
|
@ -1838,6 +1843,11 @@ const GLFunc gl_function_array[] = {
|
|||
|
||||
// ARB_shader_storage_buffer_object
|
||||
GLFUNC_REQUIRES(glShaderStorageBlockBinding, "ARB_shader_storage_buffer_object !VERSION_4_3"),
|
||||
|
||||
// NV_depth_buffer_float
|
||||
GLFUNC_REQUIRES(glDepthRangedNV, "GL_NV_depth_buffer_float"),
|
||||
GLFUNC_REQUIRES(glClearDepthdNV, "GL_NV_depth_buffer_float"),
|
||||
GLFUNC_REQUIRES(glDepthBoundsdNV, "GL_NV_depth_buffer_float"),
|
||||
};
|
||||
|
||||
namespace GLExtensions
|
||||
|
@ -2060,26 +2070,21 @@ static void InitExtensionList()
|
|||
// Quite a lot of these had their names changed when merged in to core
|
||||
// Disable the ones that have
|
||||
std::string gl300exts[] = {
|
||||
"GL_ARB_map_buffer_range",
|
||||
"GL_ARB_map_buffer_range", "GL_ARB_color_buffer_float", "GL_ARB_texture_float",
|
||||
"GL_ARB_half_float_pixel", "GL_ARB_framebuffer_object", "GL_ARB_texture_float",
|
||||
"GL_ARB_vertex_array_object", "GL_NV_depth_buffer_float",
|
||||
//"GL_EXT_texture_integer",
|
||||
//"GL_EXT_gpu_shader4",
|
||||
//"GL_APPLE_flush_buffer_range",
|
||||
"GL_ARB_color_buffer_float",
|
||||
//"GL_NV_depth_buffer_float",
|
||||
"GL_ARB_texture_float",
|
||||
//"GL_EXT_packed_float",
|
||||
//"GL_EXT_texture_shared_exponent",
|
||||
"GL_ARB_half_float_pixel",
|
||||
//"GL_NV_half_float",
|
||||
"GL_ARB_framebuffer_object",
|
||||
//"GL_EXT_framebuffer_sRGB",
|
||||
"GL_ARB_texture_float",
|
||||
//"GL_EXT_texture_integer",
|
||||
//"GL_EXT_draw_buffers2",
|
||||
//"GL_EXT_texture_integer",
|
||||
//"GL_EXT_texture_array",
|
||||
//"GL_EXT_texture_compression_rgtc",
|
||||
//"GL_EXT_transform_feedback",
|
||||
"GL_ARB_vertex_array_object",
|
||||
//"GL_NV_conditional_render",
|
||||
"VERSION_3_0",
|
||||
};
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "Common/GL/GLExtensions/EXT_texture_filter_anisotropic.h"
|
||||
#include "Common/GL/GLExtensions/HP_occlusion_test.h"
|
||||
#include "Common/GL/GLExtensions/KHR_debug.h"
|
||||
#include "Common/GL/GLExtensions/NV_depth_buffer_float.h"
|
||||
#include "Common/GL/GLExtensions/NV_occlusion_query_samples.h"
|
||||
#include "Common/GL/GLExtensions/NV_primitive_restart.h"
|
||||
#include "Common/GL/GLExtensions/gl_1_1.h"
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
** Copyright (c) 2013-2015 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included
|
||||
** in all copies or substantial portions of the Materials.
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#include "Common/GL/GLExtensions/gl_common.h"
|
||||
|
||||
#define GL_DEPTH_COMPONENT32F_NV 0x8DAB
|
||||
#define GL_DEPTH32F_STENCIL8_NV 0x8DAC
|
||||
#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV_NV 0x8DAD
|
||||
#define GL_DEPTH_BUFFER_FLOAT_MODE_NV 0x8DAF
|
||||
|
||||
typedef void(APIENTRYP PFNDOLDEPTHRANGEDNVPROC)(GLdouble zNear, GLdouble zFar);
|
||||
typedef void(APIENTRYP PFNDOLCLEARDEPTHDNVPROC)(GLdouble depth);
|
||||
typedef void(APIENTRYP PFNDOLDEPTHBOUNDSDNVPROC)(GLdouble zmin, GLdouble zmax);
|
||||
|
||||
extern PFNDOLDEPTHRANGEDNVPROC dolDepthRangedNV;
|
||||
extern PFNDOLCLEARDEPTHDNVPROC dolClearDepthdNV;
|
||||
extern PFNDOLDEPTHBOUNDSDNVPROC dolDepthBoundsdNV;
|
||||
|
||||
#define glDepthRangedNV dolDepthRangedNV
|
||||
#define glClearDepthdNV dolClearDepthdNV
|
||||
#define glDepthBoundsdNV dolDepthBoundsdNV
|
|
@ -234,6 +234,8 @@ void DolphinAnalytics::MakePerGameBuilder()
|
|||
builder.AddData("gpu-has-dual-source-blend", g_Config.backend_info.bSupportsDualSourceBlend);
|
||||
builder.AddData("gpu-has-primitive-restart", g_Config.backend_info.bSupportsPrimitiveRestart);
|
||||
builder.AddData("gpu-has-oversized-viewports", g_Config.backend_info.bSupportsOversizedViewports);
|
||||
builder.AddData("gpu-has-oversized-depth-ranges",
|
||||
g_Config.backend_info.bSupportsOversizedDepthRanges);
|
||||
builder.AddData("gpu-has-geometry-shaders", g_Config.backend_info.bSupportsGeometryShaders);
|
||||
builder.AddData("gpu-has-3d-vision", g_Config.backend_info.bSupports3DVision);
|
||||
builder.AddData("gpu-has-early-z", g_Config.backend_info.bSupportsEarlyZ);
|
||||
|
|
|
@ -64,6 +64,7 @@ void VideoBackend::InitBackendInfo()
|
|||
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
||||
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
||||
g_Config.backend_info.bSupportsOversizedViewports = false;
|
||||
g_Config.backend_info.bSupportsOversizedDepthRanges = false;
|
||||
g_Config.backend_info.bSupportsGeometryShaders = true;
|
||||
g_Config.backend_info.bSupports3DVision = true;
|
||||
g_Config.backend_info.bSupportsPostProcessing = false;
|
||||
|
|
|
@ -68,6 +68,7 @@ void VideoBackend::InitBackendInfo()
|
|||
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
||||
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
||||
g_Config.backend_info.bSupportsOversizedViewports = false;
|
||||
g_Config.backend_info.bSupportsOversizedDepthRanges = false;
|
||||
g_Config.backend_info.bSupportsGeometryShaders = true;
|
||||
g_Config.backend_info.bSupports3DVision = true;
|
||||
g_Config.backend_info.bSupportsPostProcessing = false;
|
||||
|
|
|
@ -28,6 +28,7 @@ void VideoBackend::InitBackendInfo()
|
|||
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
||||
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
||||
g_Config.backend_info.bSupportsOversizedViewports = true;
|
||||
g_Config.backend_info.bSupportsOversizedDepthRanges = false;
|
||||
g_Config.backend_info.bSupportsGeometryShaders = true;
|
||||
g_Config.backend_info.bSupports3DVision = false;
|
||||
g_Config.backend_info.bSupportsEarlyZ = true;
|
||||
|
|
|
@ -474,6 +474,8 @@ Renderer::Renderer()
|
|||
|
||||
// Clip distance support is useless without a method to clamp the depth range
|
||||
g_Config.backend_info.bSupportsDepthClamp = GLExtensions::Supports("GL_ARB_depth_clamp");
|
||||
g_Config.backend_info.bSupportsOversizedDepthRanges =
|
||||
GLExtensions::Supports("GL_NV_depth_buffer_float");
|
||||
|
||||
g_ogl_config.bSupportsGLSLCache = GLExtensions::Supports("GL_ARB_get_program_binary");
|
||||
g_ogl_config.bSupportsGLPinnedMemory = GLExtensions::Supports("GL_AMD_pinned_memory");
|
||||
|
@ -666,7 +668,7 @@ Renderer::Renderer()
|
|||
g_ogl_config.gl_renderer, g_ogl_config.gl_version),
|
||||
5000);
|
||||
|
||||
WARN_LOG(VIDEO, "Missing OGL Extensions: %s%s%s%s%s%s%s%s%s%s%s%s%s%s",
|
||||
WARN_LOG(VIDEO, "Missing OGL Extensions: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
|
||||
g_ActiveConfig.backend_info.bSupportsDualSourceBlend ? "" : "DualSourceBlend ",
|
||||
g_ActiveConfig.backend_info.bSupportsPrimitiveRestart ? "" : "PrimitiveRestart ",
|
||||
g_ActiveConfig.backend_info.bSupportsEarlyZ ? "" : "EarlyZ ",
|
||||
|
@ -679,7 +681,8 @@ Renderer::Renderer()
|
|||
g_ActiveConfig.backend_info.bSupportsGSInstancing ? "" : "GSInstancing ",
|
||||
g_ActiveConfig.backend_info.bSupportsClipControl ? "" : "ClipControl ",
|
||||
g_ogl_config.bSupportsCopySubImage ? "" : "CopyImageSubData ",
|
||||
g_ActiveConfig.backend_info.bSupportsDepthClamp ? "" : "DepthClamp ");
|
||||
g_ActiveConfig.backend_info.bSupportsDepthClamp ? "" : "DepthClamp ",
|
||||
g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges ? "" : "DepthRangedNV ");
|
||||
|
||||
s_last_multisamples = g_ActiveConfig.iMultisamples;
|
||||
s_MSAASamples = s_last_multisamples;
|
||||
|
@ -1108,10 +1111,6 @@ void Renderer::SetViewport()
|
|||
(float)scissorYOff);
|
||||
float Width = EFBToScaledXf(2.0f * xfmem.viewport.wd);
|
||||
float Height = EFBToScaledYf(-2.0f * xfmem.viewport.ht);
|
||||
float range = MathUtil::Clamp<float>(xfmem.viewport.zRange, -16777215.0f, 16777215.0f);
|
||||
float min_depth =
|
||||
MathUtil::Clamp<float>(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f;
|
||||
float max_depth = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
|
||||
if (Width < 0)
|
||||
{
|
||||
X += Width;
|
||||
|
@ -1123,24 +1122,6 @@ void Renderer::SetViewport()
|
|||
Height *= -1;
|
||||
}
|
||||
|
||||
// If an oversized depth range is used, we need to calculate the depth range in the vertex shader.
|
||||
if (g_ActiveConfig.backend_info.bSupportsDepthClamp &&
|
||||
(fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f))
|
||||
{
|
||||
// We need to ensure depth values are clamped the maximum value supported by the console GPU.
|
||||
// Taking into account whether the depth range is inverted or not.
|
||||
if (xfmem.viewport.zRange < 0.0f)
|
||||
{
|
||||
min_depth = GX_MAX_DEPTH;
|
||||
max_depth = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
min_depth = 0.0f;
|
||||
max_depth = GX_MAX_DEPTH;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the view port
|
||||
if (g_ogl_config.bSupportViewportFloat)
|
||||
{
|
||||
|
@ -1153,7 +1134,40 @@ void Renderer::SetViewport()
|
|||
}
|
||||
|
||||
// Set the reversed depth range.
|
||||
glDepthRangef(max_depth, min_depth);
|
||||
if (g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges)
|
||||
{
|
||||
float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f;
|
||||
float max_depth = xfmem.viewport.farZ / 16777216.0f;
|
||||
glDepthRangedNV(max_depth, min_depth);
|
||||
}
|
||||
else
|
||||
{
|
||||
float range = MathUtil::Clamp<float>(xfmem.viewport.zRange, -16777216.0f, 16777216.0f);
|
||||
float min_depth =
|
||||
MathUtil::Clamp<float>(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f;
|
||||
float max_depth = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
|
||||
|
||||
// If an oversized depth range is used, we need to calculate the depth range in the
|
||||
// vertex shader.
|
||||
if (g_ActiveConfig.backend_info.bSupportsDepthClamp &&
|
||||
(fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f))
|
||||
{
|
||||
// We need to ensure depth values are clamped the maximum value supported by the console GPU.
|
||||
// Taking into account whether the depth range is inverted or not.
|
||||
if (xfmem.viewport.zRange < 0.0f)
|
||||
{
|
||||
min_depth = GX_MAX_DEPTH;
|
||||
max_depth = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
min_depth = 0.0f;
|
||||
max_depth = GX_MAX_DEPTH;
|
||||
}
|
||||
}
|
||||
|
||||
glDepthRangef(max_depth, min_depth);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
|
||||
|
|
|
@ -107,6 +107,7 @@ void VideoBackend::InitBackendInfo()
|
|||
g_Config.backend_info.bSupportsInternalResolutionFrameDumps = true;
|
||||
|
||||
// Overwritten in Render.cpp later
|
||||
g_Config.backend_info.bSupportsOversizedDepthRanges = false;
|
||||
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
||||
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
||||
g_Config.backend_info.bSupportsPaletteConversion = true;
|
||||
|
|
|
@ -128,6 +128,7 @@ void VideoSoftware::InitBackendInfo()
|
|||
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
||||
g_Config.backend_info.bSupportsEarlyZ = true;
|
||||
g_Config.backend_info.bSupportsOversizedViewports = true;
|
||||
g_Config.backend_info.bSupportsOversizedDepthRanges = true;
|
||||
g_Config.backend_info.bSupportsPrimitiveRestart = false;
|
||||
g_Config.backend_info.bSupportsMultithreading = false;
|
||||
g_Config.backend_info.bSupportsInternalResolutionFrameDumps = false;
|
||||
|
|
|
@ -225,15 +225,16 @@ VulkanContext::GPUList VulkanContext::EnumerateGPUs(VkInstance instance)
|
|||
void VulkanContext::PopulateBackendInfo(VideoConfig* config)
|
||||
{
|
||||
config->backend_info.api_type = APIType::Vulkan;
|
||||
config->backend_info.bSupportsExclusiveFullscreen = false; // Currently WSI does not allow this.
|
||||
config->backend_info.bSupports3DVision = false; // D3D-exclusive.
|
||||
config->backend_info.bSupportsOversizedViewports = true; // Assumed support.
|
||||
config->backend_info.bSupportsEarlyZ = true; // Assumed support.
|
||||
config->backend_info.bSupportsPrimitiveRestart = true; // Assumed support.
|
||||
config->backend_info.bSupportsBindingLayout = false; // Assumed support.
|
||||
config->backend_info.bSupportsPaletteConversion = true; // Assumed support.
|
||||
config->backend_info.bSupportsClipControl = true; // Assumed support.
|
||||
config->backend_info.bSupportsMultithreading = true; // Assumed support.
|
||||
config->backend_info.bSupportsExclusiveFullscreen = false; // Currently WSI does not allow this.
|
||||
config->backend_info.bSupports3DVision = false; // D3D-exclusive.
|
||||
config->backend_info.bSupportsOversizedViewports = true; // Assumed support.
|
||||
config->backend_info.bSupportsOversizedDepthRanges = false; // No support yet.
|
||||
config->backend_info.bSupportsEarlyZ = true; // Assumed support.
|
||||
config->backend_info.bSupportsPrimitiveRestart = true; // Assumed support.
|
||||
config->backend_info.bSupportsBindingLayout = false; // Assumed support.
|
||||
config->backend_info.bSupportsPaletteConversion = true; // Assumed support.
|
||||
config->backend_info.bSupportsClipControl = true; // Assumed support.
|
||||
config->backend_info.bSupportsMultithreading = true; // Assumed support.
|
||||
config->backend_info.bSupportsInternalResolutionFrameDumps = true; // Assumed support.
|
||||
config->backend_info.bSupportsPostProcessing = false; // No support yet.
|
||||
config->backend_info.bSupportsDualSourceBlend = false; // Dependent on features.
|
||||
|
|
|
@ -391,7 +391,8 @@ void VertexShaderManager::SetConstants()
|
|||
constants.pixelcentercorrection[2] = 1.0f;
|
||||
constants.pixelcentercorrection[3] = 0.0f;
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
|
||||
if (g_ActiveConfig.backend_info.bSupportsDepthClamp &&
|
||||
!g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges)
|
||||
{
|
||||
// Oversized depth ranges are handled in the vertex shader. We need to reverse
|
||||
// the far value to get a reversed depth range mapping. This is necessary
|
||||
|
|
|
@ -172,6 +172,7 @@ struct VideoConfig final
|
|||
bool bSupportsDualSourceBlend;
|
||||
bool bSupportsPrimitiveRestart;
|
||||
bool bSupportsOversizedViewports;
|
||||
bool bSupportsOversizedDepthRanges;
|
||||
bool bSupportsGeometryShaders;
|
||||
bool bSupports3DVision;
|
||||
bool bSupportsEarlyZ; // needed by PixelShaderGen, so must stay in VideoCommon
|
||||
|
|
Loading…
Reference in New Issue