Skip to content

Commit

Permalink
Merge pull request #15855 from hrydgard/fix-depth-blit-regression
Browse files Browse the repository at this point in the history
Fix depth blit regression
  • Loading branch information
hrydgard committed Aug 17, 2022
2 parents 3c3708e + bd6f79e commit 6cc8ca5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Common/GPU/D3D9/thin3d_d3d9.cpp
Expand Up @@ -665,7 +665,7 @@ D3D9Context::D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, ID
caps_.tesselationShaderSupported = false;
caps_.framebufferBlitSupported = true;
caps_.framebufferCopySupported = false;
caps_.framebufferDepthBlitSupported = true;
caps_.framebufferDepthBlitSupported = false;
caps_.framebufferStencilBlitSupported = false;
caps_.framebufferDepthCopySupported = false;
caps_.framebufferSeparateDepthCopySupported = false;
Expand Down
42 changes: 23 additions & 19 deletions GPU/Common/Draw2D.cpp
Expand Up @@ -39,19 +39,23 @@ static const SamplerDef samplers[1] = {
{ "tex" },
};

void GenerateDraw2DFs(ShaderWriter &writer) {
RasterChannel GenerateDraw2DFs(ShaderWriter &writer) {
writer.DeclareSamplers(samplers);
writer.BeginFSMain(Slice<UniformDef>::empty(), varyings, FSFLAG_NONE);
writer.C(" vec4 outColor = ").SampleTexture2D("tex", "v_texcoord.xy").C(";\n");
writer.EndFSMain("outColor", FSFLAG_NONE);

return RASTER_COLOR;
}

void GenerateDraw2DDepthFs(ShaderWriter &writer) {
RasterChannel GenerateDraw2DDepthFs(ShaderWriter &writer) {
writer.DeclareSamplers(samplers);
writer.BeginFSMain(Slice<UniformDef>::empty(), varyings, FSFLAG_WRITEDEPTH);
writer.C(" vec4 outColor = vec4(0.0, 0.0, 0.0, 0.0);\n");
writer.C(" gl_FragDepth = ").SampleTexture2D("tex", "v_texcoord.xy").C(".x;\n");
writer.EndFSMain("outColor", FSFLAG_WRITEDEPTH);

return RASTER_DEPTH;
}

void GenerateDraw2DVS(ShaderWriter &writer) {
Expand Down Expand Up @@ -98,13 +102,13 @@ void FramebufferManagerCommon::Ensure2DResources() {
}
}

Draw::Pipeline *FramebufferManagerCommon::Create2DPipeline(void (*generate)(ShaderWriter &)) {
Draw::Pipeline *FramebufferManagerCommon::Create2DPipeline(RasterChannel (*generate)(ShaderWriter &)) {
using namespace Draw;
const ShaderLanguageDesc &shaderLanguageDesc = draw_->GetShaderLanguageDesc();

char *fsCode = new char[4000];
ShaderWriter writer(fsCode, shaderLanguageDesc, ShaderStage::Fragment);
generate(writer);
RasterChannel channel = generate(writer);

ShaderModule *fs = draw_->CreateShaderModule(ShaderStage::Fragment, shaderLanguageDesc.shaderLanguage, (const uint8_t *)fsCode, strlen(fsCode), "draw2d_fs");
delete[] fsCode;
Expand All @@ -123,33 +127,33 @@ Draw::Pipeline *FramebufferManagerCommon::Create2DPipeline(void (*generate)(Shad
};
InputLayout *inputLayout = draw_->CreateInputLayout(desc);

BlendState *blendOff = draw_->CreateBlendState({ false, 0xF });
BlendState *blendDiscard = draw_->CreateBlendState({ false, 0x0 });
BlendState *blend = draw_->CreateBlendState({ false, channel == RASTER_COLOR ? 0xF : 0 });

DepthStencilState *noDepthStencil = draw_->CreateDepthStencilState(DepthStencilStateDesc{});
RasterState *rasterNoCull = draw_->CreateRasterState({});
DepthStencilStateDesc dsDesc{};
if (channel == RASTER_DEPTH) {
dsDesc.depthTestEnabled = true;
dsDesc.depthWriteEnabled = true;
dsDesc.depthCompare = Draw::Comparison::ALWAYS;
}

DepthStencilStateDesc dsWriteDesc{};
dsWriteDesc.depthTestEnabled = true;
dsWriteDesc.depthWriteEnabled = true;
dsWriteDesc.depthCompare = Draw::Comparison::ALWAYS;
DepthStencilState *depthWriteAlways = draw_->CreateDepthStencilState(dsWriteDesc);
DepthStencilState *depthStencil = draw_->CreateDepthStencilState(dsDesc);
RasterState *rasterNoCull = draw_->CreateRasterState({});

PipelineDesc pipelineDesc{
Primitive::TRIANGLE_STRIP,
{ draw2DVs_, fs },
inputLayout, noDepthStencil, blendOff, rasterNoCull, nullptr,
inputLayout,
depthStencil,
blend, rasterNoCull, nullptr,
};

Draw::Pipeline *pipeline = draw_->CreateGraphicsPipeline(pipelineDesc);

fs->Release();

rasterNoCull->Release();
blendOff->Release();
blendDiscard->Release();
noDepthStencil->Release();
depthWriteAlways->Release();
blend->Release();
depthStencil->Release();
inputLayout->Release();

return pipeline;
Expand All @@ -176,7 +180,7 @@ void FramebufferManagerCommon::DrawStrip2D(Draw::Texture *tex, Draw2DVertex *ver
return;
}
if (!draw2DPipelineDepth_) {
draw2DPipelineDepth_ = Create2DPipeline(&GenerateDraw2DFs);
draw2DPipelineDepth_ = Create2DPipeline(&GenerateDraw2DDepthFs);
}
draw_->BindPipeline(draw2DPipelineDepth_);
break;
Expand Down
5 changes: 5 additions & 0 deletions GPU/Common/FramebufferManagerCommon.cpp
Expand Up @@ -348,6 +348,9 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame
break;
}
} else if (params.fb_address > v->fb_address && params.fb_address < v_fb_end_ptr && PSP_CoreParameter().compat.flags().AllowLargeFBTextureOffsets) {
// Fixes Juiced 2, though causes a lot of copying due to self-texturing. A better solution
// would be to copy from the overlapping framebuffer on bind.

if (params.fb_address % params.fb_stride == v->fb_address % params.fb_stride) {
// Framebuffers are overlapping on the Y axis.
const int y_offset = (params.fb_address - v->fb_address) / (bpp * params.fb_stride);
Expand Down Expand Up @@ -2432,6 +2435,7 @@ void FramebufferManagerCommon::BlitFramebuffer(VirtualFramebuffer *dst, int dstX
float srcYFactor = src->renderScaleFactor;
const int srcBpp = src->format == GE_FORMAT_8888 ? 4 : 2;
if (srcBpp != bpp && bpp != 0) {
// If we do this, we're kinda in nonsense territory since the actual formats won't match (unless intentionally blitting black or white).
srcXFactor = (srcXFactor * bpp) / srcBpp;
}
int srcX1 = srcX * srcXFactor;
Expand All @@ -2443,6 +2447,7 @@ void FramebufferManagerCommon::BlitFramebuffer(VirtualFramebuffer *dst, int dstX
float dstYFactor = dst->renderScaleFactor;
const int dstBpp = dst->format == GE_FORMAT_8888 ? 4 : 2;
if (dstBpp != bpp && bpp != 0) {
// If we do this, we're kinda in nonsense territory since the actual formats won't match (unless intentionally blitting black or white).
dstXFactor = (dstXFactor * bpp) / dstBpp;
}
int dstX1 = dstX * dstXFactor;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/FramebufferManagerCommon.h
Expand Up @@ -382,7 +382,7 @@ class FramebufferManagerCommon {

void DrawStrip2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, bool linearFilter, RasterChannel channel);
void Ensure2DResources();
Draw::Pipeline *Create2DPipeline(void (*generate)(ShaderWriter &));
Draw::Pipeline *Create2DPipeline(RasterChannel (*generate)(ShaderWriter &));

bool UpdateSize();

Expand Down

0 comments on commit 6cc8ca5

Please sign in to comment.