Skip to content
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

Readback stencil buffer for debugger on GLES #16198

Merged
merged 4 commits into from
Oct 11, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
GLES: Refactor depth pipeline create.
So we can reuse for stencil as well.
  • Loading branch information
unknownbrackets committed Oct 10, 2022
commit c03d327ddd25c75b98c0f00e3ca4ea79852e8733
82 changes: 44 additions & 38 deletions GPU/GLES/DepthBufferGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,48 @@ static bool SupportsDepthTexturing() {
return gl_extensions.VersionGEThan(3, 0);
}

static Draw::Pipeline *CreateReadbackPipeline(Draw::DrawContext *draw, const char *tag, const UniformBufferDesc *ubDesc, const char *fs, const char *fsTag, const char *vs, const char *vsTag) {
using namespace Draw;

const ShaderLanguageDesc &shaderLanguageDesc = draw->GetShaderLanguageDesc();

ShaderModule *readbackFs = draw->CreateShaderModule(ShaderStage::Fragment, shaderLanguageDesc.shaderLanguage, (const uint8_t *)fs, strlen(fs), fsTag);
ShaderModule *readbackVs = draw->CreateShaderModule(ShaderStage::Vertex, shaderLanguageDesc.shaderLanguage, (const uint8_t *)vs, strlen(vs), vsTag);
_assert_(readbackFs && readbackVs);

InputLayoutDesc desc = {
{
{ 8, false },
},
{
{ 0, SEM_POSITION, DataFormat::R32G32_FLOAT, 0 },
},
};
InputLayout *inputLayout = draw->CreateInputLayout(desc);

BlendState *blendOff = draw->CreateBlendState({ false, 0xF });
DepthStencilState *stencilIgnore = draw->CreateDepthStencilState({});
RasterState *rasterNoCull = draw->CreateRasterState({});

PipelineDesc readbackDesc{
Primitive::TRIANGLE_LIST,
{ readbackVs, readbackFs },
inputLayout, stencilIgnore, blendOff, rasterNoCull, ubDesc,
};
Draw::Pipeline *pipeline = draw->CreateGraphicsPipeline(readbackDesc, tag);
_assert_(pipeline);

rasterNoCull->Release();
blendOff->Release();
stencilIgnore->Release();
inputLayout->Release();

readbackFs->Release();
readbackVs->Release();

return pipeline;
}

bool FramebufferManagerGLES::ReadbackDepthbufferSync(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint16_t *pixels, int pixelsStride) {
using namespace Draw;

Expand All @@ -117,44 +159,8 @@ bool FramebufferManagerGLES::ReadbackDepthbufferSync(Draw::Framebuffer *fbo, int

if (useColorPath) {
if (!depthReadbackPipeline_) {
const ShaderLanguageDesc &shaderLanguageDesc = draw_->GetShaderLanguageDesc();

ShaderModule *depthReadbackFs = draw_->CreateShaderModule(ShaderStage::Fragment, shaderLanguageDesc.shaderLanguage, (const uint8_t *)depth_dl_fs, strlen(depth_dl_fs), "depth_dl_fs");
ShaderModule *depthReadbackVs = draw_->CreateShaderModule(ShaderStage::Vertex, shaderLanguageDesc.shaderLanguage, (const uint8_t *)depth_vs, strlen(depth_vs), "depth_vs");
_assert_(depthReadbackFs && depthReadbackVs);

InputLayoutDesc desc = {
{
{ 8, false },
},
{
{ 0, SEM_POSITION, DataFormat::R32G32_FLOAT, 0 },
},
};
InputLayout *inputLayout = draw_->CreateInputLayout(desc);

BlendState *blendOff = draw_->CreateBlendState({ false, 0xF });
DepthStencilState *stencilIgnore = draw_->CreateDepthStencilState({});
RasterState *rasterNoCull = draw_->CreateRasterState({});

PipelineDesc depthReadbackDesc{
Primitive::TRIANGLE_LIST,
{ depthReadbackVs, depthReadbackFs },
inputLayout, stencilIgnore, blendOff, rasterNoCull, &depthUBDesc,
};
depthReadbackPipeline_ = draw_->CreateGraphicsPipeline(depthReadbackDesc, "depth_dl");
_assert_(depthReadbackPipeline_);

rasterNoCull->Release();
blendOff->Release();
stencilIgnore->Release();
inputLayout->Release();

depthReadbackFs->Release();
depthReadbackVs->Release();

SamplerStateDesc descNearest{};
depthReadbackSampler_ = draw_->CreateSamplerState(descNearest);
depthReadbackPipeline_ = CreateReadbackPipeline(draw_, "depth_dl", &depthUBDesc, depth_dl_fs, "depth_dl_fs", depth_vs, "depth_vs");
depthReadbackSampler_ = draw_->CreateSamplerState({});
}

shaderManager_->DirtyLastShader();
Expand Down