mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Make depth readback through the "color path" work on all backends except D3D9
This commit is contained in:
parent
4402530ca7
commit
23c8a79473
6 changed files with 14 additions and 35 deletions
|
@ -80,6 +80,7 @@ FramebufferManagerCommon::~FramebufferManagerCommon() {
|
|||
bvfbs_.clear();
|
||||
|
||||
delete presentation_;
|
||||
delete[] convBuf_;
|
||||
}
|
||||
|
||||
void FramebufferManagerCommon::Init(int msaaLevel) {
|
||||
|
@ -2769,18 +2770,6 @@ void FramebufferManagerCommon::ReadbackFramebufferSync(VirtualFramebuffer *vfb,
|
|||
gpuStats.numReadbacks++;
|
||||
}
|
||||
|
||||
bool FramebufferManagerCommon::ReadbackDepthbufferSync(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint16_t *pixels, int pixelsStride, int destW, int destH) {
|
||||
Draw::DataFormat destFormat = GEFormatToThin3D(GE_FORMAT_DEPTH16);
|
||||
|
||||
if (w != destW || h != destH) {
|
||||
// This path can't handle stretch blits. That's fine, this path is going away later.
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Apply depth scale factors if we don't have depth clamp.
|
||||
return draw_->CopyFramebufferToMemorySync(fbo, Draw::FB_DEPTH_BIT, x, y, w, h, destFormat, pixels, pixelsStride, "ReadbackDepthbufferSync");
|
||||
}
|
||||
|
||||
bool FramebufferManagerCommon::ReadbackStencilbufferSync(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint8_t *pixels, int pixelsStride) {
|
||||
return draw_->CopyFramebufferToMemorySync(fbo, Draw::FB_DEPTH_BIT, x, y, w, h, Draw::DataFormat::S8, pixels, pixelsStride, "ReadbackStencilbufferSync");
|
||||
}
|
||||
|
|
|
@ -601,4 +601,8 @@ protected:
|
|||
|
||||
Draw2D draw2D_;
|
||||
// The fragment shaders are "owned" by the pipelines since they're 1:1.
|
||||
|
||||
// Depth readback helper state
|
||||
u8 *convBuf_ = nullptr;
|
||||
u32 convBufSize_ = 0;
|
||||
};
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
|
||||
#include <d3d9.h>
|
||||
|
||||
// Keeps track of allocated FBOs.
|
||||
// Also provides facilities for drawing and later converting raw
|
||||
// pixel data.
|
||||
|
||||
#include "GPU/GPUCommon.h"
|
||||
#include "GPU/Common/FramebufferManagerCommon.h"
|
||||
|
||||
|
@ -38,5 +34,6 @@ public:
|
|||
~FramebufferManagerDX9();
|
||||
|
||||
protected:
|
||||
// TODO: The non-color path of FramebufferManagerCommon::ReadbackDepthbufferSync seems to work just as well.
|
||||
bool ReadbackDepthbufferSync(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint16_t *pixels, int pixelsStride, int destW, int destH) override;
|
||||
};
|
||||
|
|
|
@ -28,9 +28,8 @@
|
|||
#include "Common/GPU/ShaderWriter.h"
|
||||
|
||||
|
||||
static const InputDef inputs[2] = {
|
||||
static const InputDef vs_inputs[] = {
|
||||
{ "vec2", "a_position", Draw::SEM_POSITION },
|
||||
{ "vec2", "a_texcoord0", Draw::SEM_TEXCOORD0 },
|
||||
};
|
||||
|
||||
struct DepthUB {
|
||||
|
@ -39,7 +38,7 @@ struct DepthUB {
|
|||
float u_depthTo8[4];
|
||||
};
|
||||
|
||||
const UniformDef depthUniforms[3] = {
|
||||
const UniformDef depthUniforms[] = {
|
||||
{ "vec4", "u_depthFactor", 0 },
|
||||
{ "vec4", "u_depthShift", 1},
|
||||
{ "vec4", "u_depthTo8", 2},
|
||||
|
@ -51,18 +50,18 @@ const UniformBufferDesc depthUBDesc{ sizeof(DepthUB), {
|
|||
{ "u_depthTo8", -1, -1, UniformType::FLOAT4, 32 },
|
||||
} };
|
||||
|
||||
static const SamplerDef samplers[1] = {
|
||||
{ 0, "tex", SamplerFlags::ARRAY_ON_VULKAN },
|
||||
static const SamplerDef samplers[] = {
|
||||
{ 0, "tex" },
|
||||
};
|
||||
|
||||
static const VaryingDef varyings[1] = {
|
||||
static const VaryingDef varyings[] = {
|
||||
{ "vec2", "v_texcoord", Draw::SEM_TEXCOORD0, 0, "highp" },
|
||||
};
|
||||
|
||||
void GenerateDepthDownloadFs(ShaderWriter &writer) {
|
||||
writer.DeclareSamplers(samplers);
|
||||
writer.BeginFSMain(depthUniforms, varyings);
|
||||
writer.C(" float depth = texture2D(tex, v_texcoord).r;\n");
|
||||
writer.C(" float depth = ").SampleTexture2D("tex", "v_texcoord").C(".r; \n");
|
||||
// At this point, clamped maps [0, 1] to [0, 65535].
|
||||
writer.C(" float clamped = clamp((depth + u_depthFactor.x) * u_depthFactor.y, 0.0, 1.0);\n");
|
||||
writer.C(" vec4 enc = u_depthShift * clamped;\n");
|
||||
|
@ -72,7 +71,7 @@ void GenerateDepthDownloadFs(ShaderWriter &writer) {
|
|||
}
|
||||
|
||||
void GenerateDepthDownloadVs(ShaderWriter &writer) {
|
||||
writer.BeginVSMain(inputs, Slice<UniformDef>::empty(), varyings);
|
||||
writer.BeginVSMain(vs_inputs, Slice<UniformDef>::empty(), varyings);
|
||||
writer.C("v_texcoord = a_position * 2.0;\n");
|
||||
writer.C("gl_Position = vec4(v_texcoord * 2.0 - vec2(1.0, 1.0), 0.0, 1.0);");
|
||||
writer.EndVSMain(varyings);
|
||||
|
@ -166,7 +165,7 @@ static Draw::Pipeline *CreateReadbackPipeline(Draw::DrawContext *draw, const cha
|
|||
return pipeline;
|
||||
}
|
||||
|
||||
bool FramebufferManagerGLES::ReadbackDepthbufferSync(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint16_t *pixels, int pixelsStride, int destW, int destH) {
|
||||
bool FramebufferManagerCommon::ReadbackDepthbufferSync(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint16_t *pixels, int pixelsStride, int destW, int destH) {
|
||||
using namespace Draw;
|
||||
|
||||
if (!fbo) {
|
||||
|
|
|
@ -45,10 +45,6 @@ FramebufferManagerGLES::FramebufferManagerGLES(Draw::DrawContext *draw) :
|
|||
presentation_->SetLanguage(draw_->GetShaderLanguageDesc().shaderLanguage);
|
||||
}
|
||||
|
||||
FramebufferManagerGLES::~FramebufferManagerGLES() {
|
||||
delete[] convBuf_;
|
||||
}
|
||||
|
||||
void FramebufferManagerGLES::UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) {
|
||||
_assert_msg_(nvfb->fbo, "Expecting a valid nvfb in UpdateDownloadTempBuffer");
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ class GLRProgram;
|
|||
class FramebufferManagerGLES : public FramebufferManagerCommon {
|
||||
public:
|
||||
FramebufferManagerGLES(Draw::DrawContext *draw);
|
||||
~FramebufferManagerGLES();
|
||||
|
||||
void NotifyDisplayResized() override;
|
||||
|
||||
|
@ -37,10 +36,5 @@ public:
|
|||
|
||||
protected:
|
||||
void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) override;
|
||||
bool ReadbackDepthbufferSync(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint16_t *pixels, int pixelsStride, int destW, int destH) override;
|
||||
bool ReadbackStencilbufferSync(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint8_t *pixels, int pixelsStride) override;
|
||||
|
||||
private:
|
||||
u8 *convBuf_ = nullptr;
|
||||
u32 convBufSize_ = 0;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue