-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement basic depth texturing for OpenGL #14042
Changes from all commits
df6abe8
4e8ffae
cde3889
4c9b5ad
90460df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
#include "Common/Log.h" | ||
#include "Core/Reporting.h" | ||
#include "GPU/GPUState.h" | ||
#include "GPU/Common/GPUStateUtils.h" | ||
#include "GPU/Common/DepalettizeShaderCommon.h" | ||
|
||
#define WRITE p+=sprintf | ||
|
@@ -71,6 +72,12 @@ void GenerateDepalShader300(char *buffer, GEBufferFormat pixelFormat, ShaderLang | |
WRITE(p, "out vec4 fragColor0;\n"); | ||
WRITE(p, "uniform sampler2D tex;\n"); | ||
WRITE(p, "uniform sampler2D pal;\n"); | ||
|
||
if (pixelFormat == GE_FORMAT_DEPTH16) { | ||
DepthScaleFactors factors = GetDepthScaleFactors(); | ||
WRITE(p, "const float z_scale = %f;\n", factors.scale); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, I'd recommend These values wouldn't vary, so we could avoid the formula when offset is 0 and scale is 65535, which will be true if clamp is enabled. -[Unknown] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I don't see how dividing by 65535 helps here. Then we'd just have to scale it up again to turn it into an integer index later... Indeed, the values are constant, but I'm thinking that we might be able to also support this when we use the depth rescaling/offset stuff to simulate clamping, in some cases, so want to keep the flexibility. The distortion you mentioned earlier kind of prevents that though I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I missed the other code below that wants it as an int. This doesn't already work with the 1/4 scale thing? Also in that case, how does -[Unknown] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure honestly if it works correctly with the 1/4 scale. But hopefully it does. You can take .x of a float in HLSL, it's effectively a vec1. However it does look confusing... |
||
WRITE(p, "const float z_offset = %f;\n", factors.offset); | ||
} | ||
} | ||
|
||
if (language == HLSL_D3D11) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -341,13 +341,15 @@ class TextureShaderApplier { | |
}; | ||
|
||
void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) { | ||
DepalShader *depal = nullptr; | ||
DepalShader *depalShader = nullptr; | ||
uint32_t clutMode = gstate.clutformat & 0xFFFFFF; | ||
bool need_depalettize = IsClutFormat(texFormat); | ||
|
||
bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300) || gstate_c.Supports(GPU_SUPPORTS_GLSL_330)); | ||
bool depth = channel == NOTIFY_FB_DEPTH; | ||
bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300) || gstate_c.Supports(GPU_SUPPORTS_GLSL_330)) && !depth; | ||
if (!gstate_c.Supports(GPU_SUPPORTS_32BIT_INT_FSHADER)) { | ||
useShaderDepal = false; | ||
depth = false; // Can't support this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, is it better to use the color part of the framebuf or just ignore the attachment I wonder? -[Unknown] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The color part probably isn't usually very meaningful when you're trying to read the depth, so ignoring is probably better... unfortunately currently no good way to bind an empty texture here? Hm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the better thing would be a Supports flag and handle this when choosing candidates... (maybe we already even do that?) -[Unknown] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think we already do... |
||
} | ||
|
||
if (need_depalettize && !g_Config.bDisableSlowFramebufEffects) { | ||
|
@@ -375,10 +377,10 @@ void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, | |
return; | ||
} | ||
|
||
depalShader = depalShaderCache_->GetDepalettizeShader(clutMode, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat); | ||
gstate_c.SetUseShaderDepal(false); | ||
depal = depalShaderCache_->GetDepalettizeShader(clutMode, framebuffer->drawnFormat); | ||
} | ||
if (depal) { | ||
if (depalShader) { | ||
shaderManager_->DirtyLastShader(); | ||
|
||
const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); | ||
|
@@ -388,11 +390,12 @@ void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, | |
|
||
render_->SetScissor(GLRect2D{ 0, 0, (int)framebuffer->renderWidth, (int)framebuffer->renderHeight }); | ||
render_->SetViewport(GLRViewport{ 0.0f, 0.0f, (float)framebuffer->renderWidth, (float)framebuffer->renderHeight, 0.0f, 1.0f }); | ||
TextureShaderApplier shaderApply(depal, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight); | ||
TextureShaderApplier shaderApply(depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight); | ||
shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); | ||
shaderApply.Use(render_, drawEngine_, shadeInputLayout_); | ||
|
||
framebufferManagerGL_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_SKIP_COPY | BINDFBCOLOR_FORCE_SELF); | ||
draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0); | ||
|
||
render_->BindTexture(TEX_SLOT_CLUT, clutTexture); | ||
render_->SetTextureSampler(TEX_SLOT_CLUT, GL_REPEAT, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST, 0.0f); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should do this, but I'd think we might need a setting - it might make things a lot slower in some games where people might be willing to withstand weird clipping issues near the edges for speed...
In some games depending on how they draw, it might not be that big a difference I suppose.
-[Unknown]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, will depend a lot on the GPU architectures too, changing gl_FragDepth can have between nearly none to a very large performance penalty, I believe. So a blanket enable is probably not realistic, adding that to the comment.