mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-02 09:03:37 +00:00
Fix N64 Depth compare with Adreno
This commit is contained in:
parent
442d4ed894
commit
35554dabf0
|
@ -320,18 +320,7 @@ void DepthBuffer::activateDepthBufferTexture(FrameBuffer * _pBuffer)
|
|||
|
||||
void DepthBuffer::bindDepthImageTexture(ObjectHandle _fbo)
|
||||
{
|
||||
if (Context::ImageTextures) {
|
||||
Context::BindImageTextureParameters bindParams;
|
||||
bindParams.imageUnit = textureImageUnits::DepthZ;
|
||||
bindParams.texture = m_pDepthImageZTexture->name;
|
||||
bindParams.accessMode = textureImageAccessMode::READ_WRITE;
|
||||
bindParams.textureFormat = gfxContext.getFramebufferTextureFormats().depthImageInternalFormat;
|
||||
gfxContext.bindImageTexture(bindParams);
|
||||
|
||||
bindParams.imageUnit = textureImageUnits::DepthDeltaZ;
|
||||
bindParams.texture = m_pDepthImageDeltaZTexture->name;
|
||||
gfxContext.bindImageTexture(bindParams);
|
||||
} else if (Context::FramebufferFetchDepth) {
|
||||
if (Context::FramebufferFetchDepth) {
|
||||
Context::FrameBufferRenderTarget targetParams;
|
||||
targetParams.bufferHandle = _fbo;
|
||||
targetParams.bufferTarget = bufferTarget::DRAW_FRAMEBUFFER;
|
||||
|
@ -345,6 +334,17 @@ void DepthBuffer::bindDepthImageTexture(ObjectHandle _fbo)
|
|||
gfxContext.addFrameBufferRenderTarget(targetParams);
|
||||
|
||||
gfxContext.setDrawBuffers(3);
|
||||
} else if (Context::ImageTextures) {
|
||||
Context::BindImageTextureParameters bindParams;
|
||||
bindParams.imageUnit = textureImageUnits::DepthZ;
|
||||
bindParams.texture = m_pDepthImageZTexture->name;
|
||||
bindParams.accessMode = textureImageAccessMode::READ_WRITE;
|
||||
bindParams.textureFormat = gfxContext.getFramebufferTextureFormats().depthImageInternalFormat;
|
||||
gfxContext.bindImageTexture(bindParams);
|
||||
|
||||
bindParams.imageUnit = textureImageUnits::DepthDeltaZ;
|
||||
bindParams.texture = m_pDepthImageDeltaZTexture->name;
|
||||
gfxContext.bindImageTexture(bindParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ void Context::init()
|
|||
ImageTextures = m_impl->isSupported(SpecialFeatures::ImageTextures);
|
||||
IntegerTextures = m_impl->isSupported(SpecialFeatures::IntegerTextures);
|
||||
ClipControl = m_impl->isSupported(SpecialFeatures::ClipControl);
|
||||
FramebufferFetchDepth = m_impl->isSupported(SpecialFeatures::FramebufferFetchDepth);
|
||||
FramebufferFetchDepth = m_impl->isSupported(SpecialFeatures::N64DepthWithFbFetchDepth);
|
||||
FramebufferFetchColor = m_impl->isSupported(SpecialFeatures::FramebufferFetchColor);
|
||||
TextureBarrier = m_impl->isSupported(SpecialFeatures::TextureBarrier);
|
||||
EglImage = m_impl->isSupported(SpecialFeatures::EglImage);
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace graphics {
|
|||
ImageTextures,
|
||||
IntegerTextures,
|
||||
ClipControl,
|
||||
FramebufferFetchDepth,
|
||||
N64DepthWithFbFetchDepth,
|
||||
FramebufferFetchColor,
|
||||
TextureBarrier,
|
||||
EglImage,
|
||||
|
|
|
@ -559,7 +559,9 @@ public:
|
|||
std::stringstream ss;
|
||||
ss << "#version " << Utils::to_string(_glinfo.majorVersion) << Utils::to_string(_glinfo.minorVersion) << "0 core " << std::endl;
|
||||
if (config.frameBufferEmulation.N64DepthCompare != Config::dcDisable) {
|
||||
if (_glinfo.imageTextures) {
|
||||
if (_glinfo.ext_fetch)
|
||||
ss << "#extension GL_EXT_shader_framebuffer_fetch : enable" << std::endl;
|
||||
else if (_glinfo.imageTextures) {
|
||||
if (_glinfo.majorVersion * 10 + _glinfo.minorVersion < 42) {
|
||||
ss << "#extension GL_ARB_shader_image_load_store : enable" << std::endl
|
||||
<< "#extension GL_ARB_shading_language_420pack : enable" << std::endl;
|
||||
|
@ -572,8 +574,7 @@ public:
|
|||
<< "layout(pixel_interlock_ordered) in;" << std::endl;
|
||||
else if (_glinfo.fragment_ordering)
|
||||
ss << "#extension GL_INTEL_fragment_shader_ordering : enable" << std::endl;
|
||||
} else if (_glinfo.ext_fetch)
|
||||
ss << "#extension GL_EXT_shader_framebuffer_fetch : enable" << std::endl;
|
||||
}
|
||||
}
|
||||
ss << "# define IN in" << std::endl
|
||||
<< "# define OUT out" << std::endl
|
||||
|
@ -1037,7 +1038,7 @@ public:
|
|||
;
|
||||
}
|
||||
|
||||
if (config.frameBufferEmulation.N64DepthCompare == Config::dcFast && _glinfo.ext_fetch) {
|
||||
if (config.frameBufferEmulation.N64DepthCompare == Config::dcFast && _glinfo.n64DepthWithFbFetch) {
|
||||
m_part +=
|
||||
"layout(location = 1) inout highp vec4 depthZ; \n"
|
||||
"layout(location = 2) inout highp vec4 depthDeltaZ; \n"
|
||||
|
@ -1148,7 +1149,7 @@ public:
|
|||
;
|
||||
}
|
||||
|
||||
if (config.frameBufferEmulation.N64DepthCompare == Config::dcFast && _glinfo.ext_fetch) {
|
||||
if (config.frameBufferEmulation.N64DepthCompare == Config::dcFast && _glinfo.n64DepthWithFbFetch) {
|
||||
m_part +=
|
||||
"layout(location = 1) inout highp vec4 depthZ; \n"
|
||||
"layout(location = 2) inout highp vec4 depthDeltaZ; \n"
|
||||
|
@ -1276,7 +1277,7 @@ public:
|
|||
"bool depth_compare(highp float curZ); \n"
|
||||
"bool depth_render(highp float Z, highp float curZ); \n"
|
||||
;
|
||||
if (_glinfo.imageTextures) {
|
||||
if (_glinfo.imageTextures & !_glinfo.n64DepthWithFbFetch) {
|
||||
m_part +=
|
||||
"layout(binding = 2, r32f) highp uniform restrict image2D uDepthImageZ; \n"
|
||||
"layout(binding = 3, r32f) highp uniform restrict image2D uDepthImageDeltaZ; \n"
|
||||
|
@ -1735,7 +1736,7 @@ public:
|
|||
if (config.frameBufferEmulation.N64DepthCompare != Config::dcDisable) {
|
||||
m_part = " bool should_discard = false; \n";
|
||||
|
||||
if (_glinfo.imageTextures) {
|
||||
if (_glinfo.imageTextures && !_glinfo.n64DepthWithFbFetch) {
|
||||
if (_glinfo.fragment_interlock)
|
||||
m_part += " beginInvocationInterlockARB(); \n";
|
||||
else if (_glinfo.fragment_interlockNV)
|
||||
|
@ -1749,7 +1750,7 @@ public:
|
|||
" else if (!depth_compare(fragDepth)) should_discard = true; \n"
|
||||
;
|
||||
|
||||
if (_glinfo.imageTextures) {
|
||||
if (_glinfo.imageTextures & !_glinfo.n64DepthWithFbFetch) {
|
||||
if (_glinfo.fragment_interlock)
|
||||
m_part += " endInvocationInterlockARB(); \n";
|
||||
else if (_glinfo.fragment_interlockNV)
|
||||
|
@ -2470,7 +2471,7 @@ public:
|
|||
"{ \n"
|
||||
" if (uEnableDepth == 0) return true; \n"
|
||||
;
|
||||
if (_glinfo.imageTextures) {
|
||||
if (_glinfo.imageTextures && !_glinfo.n64DepthWithFbFetch) {
|
||||
m_part +=
|
||||
" ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
" highp vec4 depthZ = imageLoad(uDepthImageZ,coord); \n"
|
||||
|
@ -2506,19 +2507,20 @@ public:
|
|||
" bRes = bRes || (uEnableDepthCompare == 0); \n"
|
||||
" if (uEnableDepthUpdate != 0 && bRes) { \n"
|
||||
;
|
||||
if (_glinfo.imageTextures) {
|
||||
if (_glinfo.n64DepthWithFbFetch) {
|
||||
m_part +=
|
||||
" depthZ.r = curZ; \n"
|
||||
" depthDeltaZ.r = dz; \n"
|
||||
;
|
||||
} else if (_glinfo.imageTextures) {
|
||||
m_part +=
|
||||
" highp vec4 depthOutZ = vec4(curZ, 1.0, 1.0, 1.0); \n"
|
||||
" highp vec4 depthOutDeltaZ = vec4(dz, 1.0, 1.0, 1.0); \n"
|
||||
" imageStore(uDepthImageZ, coord, depthOutZ); \n"
|
||||
" imageStore(uDepthImageDeltaZ, coord, depthOutDeltaZ); \n"
|
||||
;
|
||||
} else if (_glinfo.ext_fetch) {
|
||||
m_part +=
|
||||
" depthZ.r = curZ; \n"
|
||||
" depthDeltaZ.r = dz; \n"
|
||||
;
|
||||
}
|
||||
|
||||
m_part +=
|
||||
" } \n"
|
||||
" return bRes; \n"
|
||||
|
@ -2540,7 +2542,7 @@ public:
|
|||
" ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
" if (uEnableDepthCompare != 0) { \n"
|
||||
;
|
||||
if (_glinfo.imageTextures) {
|
||||
if (_glinfo.imageTextures && !_glinfo.n64DepthWithFbFetch) {
|
||||
m_part +=
|
||||
" highp vec4 depthZ = imageLoad(uDepthImageZ,coord); \n"
|
||||
;
|
||||
|
@ -2550,19 +2552,20 @@ public:
|
|||
" if (curZ >= bufZ) return false; \n"
|
||||
" } \n"
|
||||
;
|
||||
if (_glinfo.imageTextures) {
|
||||
if (_glinfo.n64DepthWithFbFetch) {
|
||||
m_part +=
|
||||
" depthZ.r = Z; \n"
|
||||
" depthDeltaZ.r = 0.0; \n"
|
||||
;
|
||||
} else if (_glinfo.imageTextures) {
|
||||
m_part +=
|
||||
" highp vec4 depthOutZ = vec4(Z, 1.0, 1.0, 1.0); \n"
|
||||
" highp vec4 depthOutDeltaZ = vec4(0.0, 1.0, 1.0, 1.0);\n"
|
||||
" imageStore(uDepthImageZ,coord, depthOutZ); \n"
|
||||
" imageStore(uDepthImageDeltaZ,coord, depthOutDeltaZ); \n"
|
||||
;
|
||||
} else if (_glinfo.ext_fetch) {
|
||||
m_part +=
|
||||
" depthZ.r = Z; \n"
|
||||
" depthDeltaZ.r = 0.0; \n"
|
||||
;
|
||||
}
|
||||
|
||||
m_part +=
|
||||
" return true; \n"
|
||||
"} \n"
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace glsl {
|
|||
bool _saveCombinerKeys(const graphics::Combiners & _combiners) const;
|
||||
bool _loadFromCombinerKeys(graphics::Combiners & _combiners);
|
||||
|
||||
const u32 m_formatVersion = 0x32U;
|
||||
const u32 m_formatVersion = 0x33U;
|
||||
const u32 m_keysFormatVersion = 0x05;
|
||||
const opengl::GLInfo & m_glinfo;
|
||||
opengl::CachedUseProgram * m_useProgram;
|
||||
|
|
|
@ -68,10 +68,10 @@ namespace glsl {
|
|||
;
|
||||
|
||||
if (config.frameBufferEmulation.N64DepthCompare != Config::dcDisable) {
|
||||
if (_glinfo.imageTextures)
|
||||
if (_glinfo.imageTextures && !_glinfo.n64DepthWithFbFetch)
|
||||
m_part += "layout(binding = 2, r32f) highp uniform restrict readonly image2D uDepthImageZ; \n";
|
||||
|
||||
if (_glinfo.ext_fetch) {
|
||||
if (_glinfo.n64DepthWithFbFetch) {
|
||||
m_part +=
|
||||
"layout(location = 0) OUT lowp vec4 fragColor; \n"
|
||||
"layout(location = 1) inout highp vec4 depthZ; \n"
|
||||
|
@ -100,15 +100,15 @@ namespace glsl {
|
|||
} else {
|
||||
// Either _glinfo.imageTextures or _glinfo.ext_fetch must be enabled when N64DepthCompare != 0
|
||||
// see GLInfo::init()
|
||||
if (_glinfo.imageTextures) {
|
||||
if (_glinfo.n64DepthWithFbFetch) {
|
||||
m_part +=
|
||||
" highp float bufZ = depthZ.r; \n"
|
||||
;
|
||||
} else if (_glinfo.imageTextures) {
|
||||
m_part +=
|
||||
" mediump ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
" highp float bufZ = imageLoad(uDepthImageZ,coord).r; \n"
|
||||
;
|
||||
} else if (_glinfo.ext_fetch) {
|
||||
m_part +=
|
||||
" highp float bufZ = depthZ.r; \n"
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -513,8 +513,8 @@ bool ContextImpl::isSupported(graphics::SpecialFeatures _feature) const
|
|||
return !m_glInfo.isGLES2;
|
||||
case graphics::SpecialFeatures::ClipControl:
|
||||
return !m_glInfo.isGLESX;
|
||||
case graphics::SpecialFeatures::FramebufferFetchDepth:
|
||||
return m_glInfo.ext_fetch;
|
||||
case graphics::SpecialFeatures::N64DepthWithFbFetchDepth:
|
||||
return m_glInfo.n64DepthWithFbFetch;
|
||||
case graphics::SpecialFeatures::FramebufferFetchColor:
|
||||
return m_glInfo.ext_fetch || m_glInfo.ext_fetch_arm;
|
||||
case graphics::SpecialFeatures::TextureBarrier:
|
||||
|
|
|
@ -169,7 +169,8 @@ void GLInfo::init() {
|
|||
texture_barrier = !isGLESX && (numericVersion >= 45 || Utils::isExtensionSupported(*this, "GL_ARB_texture_barrier"));
|
||||
texture_barrierNV = Utils::isExtensionSupported(*this, "GL_NV_texture_barrier");
|
||||
|
||||
ext_fetch = Utils::isExtensionSupported(*this, "GL_EXT_shader_framebuffer_fetch") && !isGLES2 && (!isGLESX || ext_draw_buffers_indexed) && !imageTexturesInterlock;
|
||||
ext_fetch = Utils::isExtensionSupported(*this, "GL_EXT_shader_framebuffer_fetch") && (!isGLESX || ext_draw_buffers_indexed);
|
||||
n64DepthWithFbFetch = ext_fetch && !imageTexturesInterlock;
|
||||
eglImage = (Utils::isEGLExtensionSupported("EGL_KHR_image_base") || Utils::isEGLExtensionSupported("EGL_KHR_image"));
|
||||
ext_fetch_arm = Utils::isExtensionSupported(*this, "GL_ARM_shader_framebuffer_fetch") && !ext_fetch;
|
||||
|
||||
|
@ -189,7 +190,7 @@ void GLInfo::init() {
|
|||
|
||||
if (config.frameBufferEmulation.N64DepthCompare != Config::dcDisable) {
|
||||
if (config.frameBufferEmulation.N64DepthCompare == Config::dcFast) {
|
||||
if (!imageTexturesInterlock && !ext_fetch) {
|
||||
if (!imageTexturesInterlock && !n64DepthWithFbFetch) {
|
||||
config.frameBufferEmulation.N64DepthCompare = Config::dcDisable;
|
||||
LOG(LOG_WARNING, "Your GPU does not support the extensions needed for fast N64 Depth Compare.");
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ struct GLInfo {
|
|||
bool fragment_ordering = false;
|
||||
bool ext_fetch = false;
|
||||
bool ext_fetch_arm = false;
|
||||
bool n64DepthWithFbFetch = false;
|
||||
bool eglImage = false;
|
||||
bool eglImageFramebuffer = false;
|
||||
bool dual_source_blending = false;
|
||||
|
|
Loading…
Reference in New Issue
Block a user