mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Finish the depal refactoring.
Needed for an upcoming change (since this lets us use the Draw2D uniform mechanism in depal shaders).
This commit is contained in:
parent
4390a05fe0
commit
7cba231e58
6 changed files with 37 additions and 65 deletions
|
@ -253,6 +253,20 @@ Draw2DPipeline *Draw2D::Create2DPipeline(std::function<Draw2DPipelineInfo (Shade
|
|||
};
|
||||
}
|
||||
|
||||
void Draw2D::Blit(Draw2DPipeline *pipeline, float srcX1, float srcY1, float srcX2, float srcY2, float dstX1, float dstY1, float dstX2, float dstY2, float srcWidth, float srcHeight, float dstWidth, float dstHeight, bool linear, int scaleFactor) {
|
||||
float dX = 1.0f / (float)dstWidth;
|
||||
float dY = 1.0f / (float)dstHeight;
|
||||
float sX = 1.0f / (float)srcWidth;
|
||||
float sY = 1.0f / (float)srcHeight;
|
||||
Draw2DVertex vtx[4] = {
|
||||
{ -1.0f + 2.0f * dX * dstX1, -(1.0f - 2.0f * dY * dstY1), sX * srcX1, sY * srcY1 },
|
||||
{ -1.0f + 2.0f * dX * dstX2, -(1.0f - 2.0f * dY * dstY1), sX * srcX2, sY * srcY1 },
|
||||
{ -1.0f + 2.0f * dX * dstX1, -(1.0f - 2.0f * dY * dstY2), sX * srcX1, sY * srcY2 },
|
||||
{ -1.0f + 2.0f * dX * dstX2, -(1.0f - 2.0f * dY * dstY2), sX * srcX2, sY * srcY2 },
|
||||
};
|
||||
|
||||
DrawStrip2D(nullptr, vtx, 4, linear, pipeline, srcWidth, srcHeight, scaleFactor);
|
||||
}
|
||||
|
||||
void Draw2D::DrawStrip2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, bool linearFilter, Draw2DPipeline *pipeline, float texW, float texH, int scaleFactor) {
|
||||
using namespace Draw;
|
||||
|
|
|
@ -58,6 +58,8 @@ public:
|
|||
Draw2DPipeline *Create2DPipeline(std::function<Draw2DPipelineInfo(ShaderWriter &)> generate);
|
||||
|
||||
void DrawStrip2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, bool linearFilter, Draw2DPipeline *pipeline, float texW = 0.0f, float texH = 0.0f, int scaleFactor = 0);
|
||||
|
||||
void Blit(Draw2DPipeline *pipeline, float srcX1, float srcY1, float srcX2, float srcY2, float dstX1, float dstY1, float dstX2, float dstY2, float srcWidth, float srcHeight, float dstWidth, float dstHeight, bool linear, int scaleFactor);
|
||||
void Ensure2DResources();
|
||||
|
||||
private:
|
||||
|
|
|
@ -2666,17 +2666,6 @@ void FramebufferManagerCommon::BlitUsingRaster(
|
|||
draw_->GetFramebufferDimensions(src, &srcW, &srcH);
|
||||
draw_->GetFramebufferDimensions(dest, &destW, &destH);
|
||||
|
||||
float dX = 1.0f / (float)destW;
|
||||
float dY = 1.0f / (float)destH;
|
||||
float sX = 1.0f / (float)srcW;
|
||||
float sY = 1.0f / (float)srcH;
|
||||
Draw2DVertex vtx[4] = {
|
||||
{ -1.0f + 2.0f * dX * destX1, -(1.0f - 2.0f * dY * destY1), sX * srcX1, sY * srcY1 },
|
||||
{ -1.0f + 2.0f * dX * destX2, -(1.0f - 2.0f * dY * destY1), sX * srcX2, sY * srcY1 },
|
||||
{ -1.0f + 2.0f * dX * destX1, -(1.0f - 2.0f * dY * destY2), sX * srcX1, sY * srcY2 },
|
||||
{ -1.0f + 2.0f * dX * destX2, -(1.0f - 2.0f * dY * destY2), sX * srcX2, sY * srcY2 },
|
||||
};
|
||||
|
||||
// Unbind the texture first to avoid the D3D11 hazard check (can't set render target to things bound as textures and vice versa, not even temporarily).
|
||||
draw_->BindTexture(0, nullptr);
|
||||
// This will get optimized away in case it's already bound (in VK and GL at least..)
|
||||
|
@ -2687,7 +2676,7 @@ void FramebufferManagerCommon::BlitUsingRaster(
|
|||
draw_->SetViewports(1, &vp);
|
||||
draw_->SetScissorRect(0, 0, (int)dest->Width(), (int)dest->Height());
|
||||
|
||||
draw2D_.DrawStrip2D(nullptr, vtx, 4, linearFilter, pipeline, src->Width(), src->Height(), renderScaleFactor_);
|
||||
draw2D_.Blit(pipeline, srcX1, srcY1, srcX2, srcY2, destX1, destY1, destX2, destY2, (float)srcW, (float)srcH, (float)destW, (float)destH, linearFilter , renderScaleFactor_);
|
||||
|
||||
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE);
|
||||
}
|
||||
|
|
|
@ -1967,9 +1967,26 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
|
|||
draw_->BindSamplerStates(0, 1, &nearest);
|
||||
draw_->BindSamplerStates(1, 1, &clutSampler);
|
||||
|
||||
textureShaderCache_->ApplyShader(textureShader,
|
||||
framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight,
|
||||
gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset);
|
||||
// If min is not < max, then we don't have values (wasn't set during decode.)
|
||||
const KnownVertexBounds &bounds = gstate_c.vertBounds;
|
||||
float u1 = 0.0f;
|
||||
float v1 = 0.0f;
|
||||
float u2 = framebuffer->renderWidth;
|
||||
float v2 = framebuffer->renderHeight;
|
||||
if (bounds.minV < bounds.maxV) {
|
||||
u1 = bounds.minU + gstate_c.curTextureXOffset;
|
||||
v1 = bounds.minV + gstate_c.curTextureYOffset;
|
||||
u2 = bounds.maxU + gstate_c.curTextureXOffset;
|
||||
v2 = bounds.maxV + gstate_c.curTextureYOffset;
|
||||
// We need to reapply the texture next time since we cropped UV.
|
||||
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
||||
}
|
||||
u1 *= framebuffer->renderScaleFactor;
|
||||
v1 *= framebuffer->renderScaleFactor;
|
||||
u2 *= framebuffer->renderScaleFactor;
|
||||
v2 *= framebuffer->renderScaleFactor;
|
||||
|
||||
draw2D_->Blit(textureShader, u1, v1, u2, v2, u1, v1, u2, v2, framebuffer->renderWidth, framebuffer->renderHeight, framebuffer->renderWidth, framebuffer->renderHeight, false, framebuffer->renderScaleFactor);
|
||||
|
||||
draw_->BindTexture(0, nullptr);
|
||||
framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer");
|
||||
|
|
|
@ -247,51 +247,3 @@ std::string TextureShaderCache::DebugGetShaderString(std::string idstr, DebugSha
|
|||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void TextureShaderCache::ApplyShader(Draw2DPipeline *pipeline, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff) {
|
||||
Draw2DVertex verts[4] = {
|
||||
{-1, -1, 0, 0 },
|
||||
{ 1, -1, 1, 0 },
|
||||
{-1, 1, 0, 1 },
|
||||
{ 1, 1, 1, 1 },
|
||||
};
|
||||
|
||||
// If min is not < max, then we don't have values (wasn't set during decode.)
|
||||
if (bounds.minV < bounds.maxV) {
|
||||
const float invWidth = 1.0f / bufferW;
|
||||
const float invHeight = 1.0f / bufferH;
|
||||
// Inverse of half = double.
|
||||
const float invHalfWidth = invWidth * 2.0f;
|
||||
const float invHalfHeight = invHeight * 2.0f;
|
||||
|
||||
const int u1 = bounds.minU + uoff;
|
||||
const int v1 = bounds.minV + voff;
|
||||
const int u2 = bounds.maxU + uoff;
|
||||
const int v2 = bounds.maxV + voff;
|
||||
|
||||
const float left = u1 * invHalfWidth - 1.0f;
|
||||
const float right = u2 * invHalfWidth - 1.0f;
|
||||
const float top = v1 * invHalfHeight - 1.0f;
|
||||
const float bottom = v2 * invHalfHeight - 1.0f;
|
||||
|
||||
const float uvleft = u1 * invWidth;
|
||||
const float uvright = u2 * invWidth;
|
||||
const float uvtop = v1 * invHeight;
|
||||
const float uvbottom = v2 * invHeight;
|
||||
|
||||
// Points are: BL, BR, TR, TL.
|
||||
verts[0] = Draw2DVertex{ left, bottom, uvleft, uvbottom };
|
||||
verts[1] = Draw2DVertex{ right, bottom, uvright, uvbottom };
|
||||
verts[2] = Draw2DVertex{ left, top, uvleft, uvtop };
|
||||
verts[3] = Draw2DVertex{ right, top, uvright, uvtop };
|
||||
|
||||
// We need to reapply the texture next time since we cropped UV.
|
||||
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
||||
}
|
||||
|
||||
Draw::Viewport vp{ 0.0f, 0.0f, (float)renderW, (float)renderH, 0.0f, 1.0f };
|
||||
draw_->BindPipeline(pipeline->pipeline);
|
||||
draw_->SetViewports(1, &vp);
|
||||
draw_->SetScissorRect(0, 0, renderW, renderH);
|
||||
draw_->DrawUP((const uint8_t *)verts, 4);
|
||||
}
|
||||
|
|
|
@ -48,8 +48,6 @@ public:
|
|||
|
||||
Draw::SamplerState *GetSampler(bool linearFilter);
|
||||
|
||||
void ApplyShader(Draw2DPipeline *pipeline, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff);
|
||||
|
||||
void Clear();
|
||||
void Decimate();
|
||||
std::vector<std::string> DebugGetShaderIDs(DebugShaderType type);
|
||||
|
|
Loading…
Add table
Reference in a new issue