mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
More work towards unifying CopyDisplayToOutput
This commit is contained in:
parent
cba37e54d0
commit
84e6054b23
10 changed files with 67 additions and 38 deletions
|
@ -109,6 +109,7 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW
|
|||
|
||||
FramebufferManagerCommon::FramebufferManagerCommon(Draw::DrawContext *draw) :
|
||||
draw_(draw),
|
||||
needBackBufferYSwap_(false),
|
||||
displayFramebufPtr_(0),
|
||||
displayStride_(0),
|
||||
displayFormat_(GE_FORMAT_565),
|
||||
|
|
|
@ -260,7 +260,9 @@ public:
|
|||
protected:
|
||||
virtual void SetViewport2D(int x, int y, int w, int h) = 0;
|
||||
void CalculatePostShaderUniforms(int bufferWidth, int bufferHeight, int renderWidth, int renderHeight, PostShaderUniforms *uniforms);
|
||||
virtual void MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) = 0;
|
||||
virtual void DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, bool linearFilter) = 0;
|
||||
virtual void Bind2DShader() = 0;
|
||||
virtual void BindPostShader(const PostShaderUniforms &uniforms) {}
|
||||
|
||||
// Cardboard Settings Calculator
|
||||
|
@ -314,6 +316,7 @@ protected:
|
|||
|
||||
Draw::DrawContext *draw_;
|
||||
TextureCacheCommon *textureCache_;
|
||||
bool needBackBufferYSwap_;
|
||||
|
||||
u32 displayFramebufPtr_;
|
||||
u32 displayStride_;
|
||||
|
|
|
@ -238,6 +238,7 @@ void FramebufferManagerD3D11::MakePixelTexture(const u8 *srcPixels, GEBufferForm
|
|||
}
|
||||
|
||||
context_->Unmap(drawPixelsTex_, 0);
|
||||
context_->PSSetShaderResources(0, 1, &drawPixelsTexView_);
|
||||
// D3DXSaveTextureToFile("game:\\cc.png", D3DXIFF_PNG, drawPixelsTex_, NULL);
|
||||
}
|
||||
|
||||
|
@ -259,16 +260,15 @@ void FramebufferManagerD3D11::DrawPixels(VirtualFramebuffer *vfb, int dstX, int
|
|||
}
|
||||
MakePixelTexture(srcPixels, srcPixelFormat, srcStride, width, height);
|
||||
DisableState();
|
||||
context_->PSSetShaderResources(0, 1, &drawPixelsTexView_);
|
||||
Bind2DShader();
|
||||
DrawActiveTexture(dstX, dstY, width, height, vfb->bufferWidth, vfb->bufferHeight, 0.0f, 0.0f, 1.0f, 1.0f, ROTATION_LOCKED_HORIZONTAL, true);
|
||||
textureCacheD3D11_->ForgetLastTexture();
|
||||
// context_->RSSetViewports(1, &vp);
|
||||
shaderManager_->DirtyLastShader();
|
||||
}
|
||||
|
||||
void FramebufferManagerD3D11::DrawFramebufferToOutput(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, bool applyPostShader) {
|
||||
MakePixelTexture(srcPixels, srcPixelFormat, srcStride, 512, 272);
|
||||
DisableState();
|
||||
|
||||
// This might draw directly at the backbuffer (if so, applyPostShader is set) so if there's a post shader, we need to apply it here.
|
||||
// Should try to unify this path with the regular path somehow, but this simple solution works for most of the post shaders
|
||||
// (it always runs at output resolution so FXAA may look odd).
|
||||
|
@ -276,7 +276,10 @@ void FramebufferManagerD3D11::DrawFramebufferToOutput(const u8 *srcPixels, GEBuf
|
|||
int uvRotation = (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE) ? g_Config.iInternalScreenRotation : ROTATION_LOCKED_HORIZONTAL;
|
||||
CenterDisplayOutputRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)pixelWidth_, (float)pixelHeight_, uvRotation);
|
||||
context_->PSSetShaderResources(0, 1, &drawPixelsTexView_);
|
||||
Bind2DShader();
|
||||
DrawActiveTexture(x, y, w, h, (float)pixelWidth_, (float)pixelHeight_, 0.0f, 0.0f, 480.0f / 512.0f, 1.0f, uvRotation, g_Config.iBufFilter == SCALE_LINEAR);
|
||||
textureCacheD3D11_->ForgetLastTexture();
|
||||
shaderManager_->DirtyLastShader();
|
||||
}
|
||||
|
||||
void FramebufferManagerD3D11::DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, bool linearFilter) {
|
||||
|
@ -331,17 +334,22 @@ void FramebufferManagerD3D11::DrawActiveTexture(float x, float y, float w, float
|
|||
context_->RSSetState(stockD3D11.rasterStateNoCull);
|
||||
context_->OMSetBlendState(stockD3D11.blendStateDisabledWithColorMask[0xF], nullptr, 0xFFFFFFFF);
|
||||
context_->OMSetDepthStencilState(stockD3D11.depthStencilDisabled, 0);
|
||||
context_->IASetInputLayout(quadInputLayout_);
|
||||
context_->PSSetShader(quadPixelShader_, 0, 0);
|
||||
context_->VSSetShader(quadVertexShader_, 0, 0);
|
||||
context_->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
context_->PSSetSamplers(0, 1, linearFilter ? &stockD3D11.samplerLinear2DClamp : &stockD3D11.samplerPoint2DClamp);
|
||||
UINT stride = 20;
|
||||
UINT offset = 0;
|
||||
context_->IASetVertexBuffers(0, 1, &quadBuffer_, &stride, &offset);
|
||||
context_->Draw(4, 0);
|
||||
}
|
||||
|
||||
void FramebufferManagerD3D11::Bind2DShader() {
|
||||
context_->IASetInputLayout(quadInputLayout_);
|
||||
context_->PSSetShader(quadPixelShader_, 0, 0);
|
||||
context_->VSSetShader(quadVertexShader_, 0, 0);
|
||||
}
|
||||
|
||||
void FramebufferManagerD3D11::BindPostShader(const PostShaderUniforms &uniforms) {
|
||||
|
||||
shaderManager_->DirtyLastShader();
|
||||
}
|
||||
|
||||
void FramebufferManagerD3D11::RebindFramebuffer() {
|
||||
|
@ -603,6 +611,7 @@ void FramebufferManagerD3D11::CopyDisplayToOutput() {
|
|||
if (1) {
|
||||
const u32 rw = PSP_CoreParameter().pixelWidth;
|
||||
const u32 rh = PSP_CoreParameter().pixelHeight;
|
||||
Bind2DShader();
|
||||
DrawActiveTexture(x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, u0, v0, u1, v1, uvRotation, g_Config.iBufFilter == SCALE_LINEAR);
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,9 @@ protected:
|
|||
void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) override;
|
||||
|
||||
private:
|
||||
void MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height);
|
||||
void BindPostShader(const PostShaderUniforms &uniforms) override;
|
||||
void Bind2DShader() override;
|
||||
void MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) override;
|
||||
void PackFramebufferD3D11_(VirtualFramebuffer *vfb, int x, int y, int w, int h);
|
||||
void PackDepthbuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h);
|
||||
|
||||
|
|
|
@ -279,6 +279,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
|
|||
device_->SetTexture(0, drawPixelsTex_);
|
||||
DrawActiveTexture(dstX, dstY, width, height, vfb->bufferWidth, vfb->bufferHeight, 0.0f, 0.0f, 1.0f, 1.0f, ROTATION_LOCKED_HORIZONTAL, true);
|
||||
textureCache_->ForgetLastTexture();
|
||||
shaderManager_->DirtyLastShader();
|
||||
dxstate.viewport.restore();
|
||||
}
|
||||
|
||||
|
@ -294,6 +295,8 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
|
|||
CenterDisplayOutputRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)pixelWidth_, (float)pixelHeight_, uvRotation);
|
||||
device_->SetTexture(0, drawPixelsTex_);
|
||||
DrawActiveTexture(x, y, w, h, (float)pixelWidth_, (float)pixelHeight_, 0.0f, 0.0f, 480.0f / 512.0f, 1.0f, uvRotation, true);
|
||||
textureCache_->ForgetLastTexture();
|
||||
shaderManager_->DirtyLastShader();
|
||||
}
|
||||
|
||||
void FramebufferManagerDX9::SetViewport2D(int x, int y, int w, int h) {
|
||||
|
@ -349,10 +352,6 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
|
|||
dxstate.texMinFilter.set(D3DTEXF_POINT);
|
||||
}
|
||||
pD3Ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
||||
pD3Ddevice->SetVertexDeclaration(pFramebufferVertexDecl);
|
||||
pD3Ddevice->SetPixelShader(pFramebufferPixelShader);
|
||||
pD3Ddevice->SetVertexShader(pFramebufferVertexShader);
|
||||
shaderManager_->DirtyLastShader();
|
||||
HRESULT hr = pD3Ddevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coord, 5 * sizeof(float));
|
||||
if (FAILED(hr)) {
|
||||
ERROR_LOG_REPORT(G3D, "DrawActiveTexture() failed: %08x", hr);
|
||||
|
@ -367,6 +366,12 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
|
|||
}
|
||||
}
|
||||
|
||||
void FramebufferManagerDX9::Bind2DShader() {
|
||||
pD3Ddevice->SetVertexDeclaration(pFramebufferVertexDecl);
|
||||
pD3Ddevice->SetPixelShader(pFramebufferPixelShader);
|
||||
pD3Ddevice->SetVertexShader(pFramebufferVertexShader);
|
||||
}
|
||||
|
||||
void FramebufferManagerDX9::ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old) {
|
||||
if (!useBufferedRendering_ || !vfb->fbo) {
|
||||
return;
|
||||
|
@ -743,6 +748,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
|
|||
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height, postShaderProgram_);
|
||||
}
|
||||
*/
|
||||
shaderManager_->DirtyLastShader();
|
||||
pD3Ddevice->SetTexture(0, NULL);
|
||||
}
|
||||
dxstate.viewport.restore();
|
||||
|
|
|
@ -88,6 +88,7 @@ public:
|
|||
LPDIRECT3DSURFACE9 GetOffscreenSurface(D3DFORMAT fmt, u32 w, u32 h);
|
||||
|
||||
protected:
|
||||
void Bind2DShader() override;
|
||||
void SetViewport2D(int x, int y, int w, int h) override;
|
||||
void DisableState() override;
|
||||
void ClearBuffer(bool keepState = false) override;
|
||||
|
@ -101,7 +102,7 @@ protected:
|
|||
void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) override;
|
||||
|
||||
private:
|
||||
void MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height);
|
||||
void MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) override;
|
||||
void PackFramebufferDirectx9_(VirtualFramebuffer *vfb, int x, int y, int w, int h);
|
||||
void PackDepthbuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h);
|
||||
static bool GetRenderTargetFramebuffer(LPDIRECT3DSURFACE9 renderTarget, LPDIRECT3DSURFACE9 offscreen, int w, int h, GPUDebugBuffer &buffer);
|
||||
|
|
|
@ -181,6 +181,10 @@ void FramebufferManagerGLES::CompileDraw2DProgram() {
|
|||
}
|
||||
}
|
||||
|
||||
void FramebufferManagerGLES::Bind2DShader() {
|
||||
glsl_bind(draw2dprogram_);
|
||||
}
|
||||
|
||||
void FramebufferManagerGLES::BindPostShader(const PostShaderUniforms &uniforms) {
|
||||
glsl_bind(postShaderProgram_);
|
||||
if (deltaLoc_ != -1)
|
||||
|
@ -220,6 +224,7 @@ FramebufferManagerGLES::FramebufferManagerGLES(Draw::DrawContext *draw) :
|
|||
pixelBufObj_(nullptr),
|
||||
currentPBO_(0)
|
||||
{
|
||||
needBackBufferYSwap_ = true;
|
||||
}
|
||||
|
||||
void FramebufferManagerGLES::Init() {
|
||||
|
@ -356,7 +361,7 @@ void FramebufferManagerGLES::DrawPixels(VirtualFramebuffer *vfb, int dstX, int d
|
|||
DisableState();
|
||||
|
||||
bool linearFilter = vfb || g_Config.iBufFilter == SCALE_LINEAR;
|
||||
glsl_bind(draw2dprogram_);
|
||||
Bind2DShader();
|
||||
DrawActiveTexture(dstX, dstY, width, height, vfb->bufferWidth, vfb->bufferHeight, 0.0f, v0, 1.0f, v1, ROTATION_LOCKED_HORIZONTAL, linearFilter);
|
||||
}
|
||||
|
||||
|
@ -385,16 +390,17 @@ void FramebufferManagerGLES::DrawFramebufferToOutput(const u8 *srcPixels, GEBuff
|
|||
CalculatePostShaderUniforms(480, 272, renderWidth_, renderHeight_, &uniforms);
|
||||
BindPostShader(uniforms);
|
||||
} else {
|
||||
glsl_bind(draw2dprogram_);
|
||||
Bind2DShader();
|
||||
}
|
||||
} else {
|
||||
glsl_bind(draw2dprogram_);
|
||||
Bind2DShader();
|
||||
}
|
||||
float u0 = 0.0f, u1 = 480.0f / 512.0f;
|
||||
float v0 = 0.0f, v1 = 1.0f;
|
||||
|
||||
// We are drawing directly to the back buffer.
|
||||
std::swap(v0, v1);
|
||||
if (needBackBufferYSwap_)
|
||||
std::swap(v0, v1);
|
||||
|
||||
bool linearFilter = g_Config.iBufFilter == SCALE_LINEAR;
|
||||
if (cardboardSettings.enabled) {
|
||||
|
@ -633,15 +639,7 @@ void FramebufferManagerGLES::CopyDisplayToOutput() {
|
|||
}
|
||||
|
||||
if (useBufferedRendering_) {
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
#ifdef USING_GLES2
|
||||
glClearDepthf(0.0f);
|
||||
#else
|
||||
glClearDepth(0.0);
|
||||
#endif
|
||||
glClearStencil(0);
|
||||
// Hardly necessary to clear depth and stencil I guess...
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
draw_->Clear(Draw::FB_COLOR_BIT | Draw::FB_STENCIL_BIT | Draw::FB_DEPTH_BIT, 0, 0, 0);
|
||||
}
|
||||
|
||||
u32 offsetX = 0;
|
||||
|
@ -750,9 +748,9 @@ void FramebufferManagerGLES::CopyDisplayToOutput() {
|
|||
bool linearFilter = g_Config.iBufFilter == SCALE_LINEAR;
|
||||
// We are doing the DrawActiveTexture call directly to the backbuffer here. Hence, we must
|
||||
// flip V.
|
||||
GLSLProgram *program = draw2dprogram_;
|
||||
glsl_bind(program);
|
||||
std::swap(v0, v1);
|
||||
Bind2DShader();
|
||||
if (needBackBufferYSwap_)
|
||||
std::swap(v0, v1);
|
||||
if (cardboardSettings.enabled) {
|
||||
// Left Eye Image
|
||||
SetViewport2D(cardboardSettings.leftEyeXPosition, cardboardSettings.screenYPosition, cardboardSettings.screenWidth, cardboardSettings.screenHeight);
|
||||
|
@ -791,8 +789,9 @@ void FramebufferManagerGLES::CopyDisplayToOutput() {
|
|||
|
||||
// We are doing the DrawActiveTexture call directly to the backbuffer after here. Hence, we must
|
||||
// flip V.
|
||||
std::swap(v0, v1);
|
||||
glsl_bind(draw2dprogram_);
|
||||
if (needBackBufferYSwap_)
|
||||
std::swap(v0, v1);
|
||||
Bind2DShader();
|
||||
linearFilter = !postShaderIsUpscalingFilter_ && g_Config.iBufFilter == SCALE_LINEAR;
|
||||
if (g_Config.bEnableCardboard) {
|
||||
// Left Eye Image
|
||||
|
@ -816,7 +815,8 @@ void FramebufferManagerGLES::CopyDisplayToOutput() {
|
|||
} else {
|
||||
// We are doing the DrawActiveTexture call directly to the backbuffer here. Hence, we must
|
||||
// flip V.
|
||||
std::swap(v0, v1);
|
||||
if (needBackBufferYSwap_)
|
||||
std::swap(v0, v1);
|
||||
bool linearFilter = g_Config.iBufFilter == SCALE_LINEAR;
|
||||
|
||||
shaderManager_->DirtyLastShader(); // dirty lastShader_
|
||||
|
|
|
@ -113,7 +113,8 @@ protected:
|
|||
void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) override;
|
||||
|
||||
private:
|
||||
void MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height);
|
||||
void MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) override;
|
||||
void Bind2DShader() override;
|
||||
void BindPostShader(const PostShaderUniforms &uniforms) override;
|
||||
void CompileDraw2DProgram();
|
||||
void DestroyDraw2DProgram();
|
||||
|
|
|
@ -330,7 +330,7 @@ void FramebufferManagerVulkan::Init() {
|
|||
resized_ = true;
|
||||
}
|
||||
|
||||
VulkanTexture *FramebufferManagerVulkan::MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) {
|
||||
void FramebufferManagerVulkan::MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) {
|
||||
if (drawPixelsTex_ && (drawPixelsTexFormat_ != srcPixelFormat || drawPixelsTex_->GetWidth() != width || drawPixelsTex_->GetHeight() != height)) {
|
||||
delete drawPixelsTex_;
|
||||
drawPixelsTex_ = nullptr;
|
||||
|
@ -399,7 +399,6 @@ VulkanTexture *FramebufferManagerVulkan::MakePixelTexture(const u8 *srcPixels, G
|
|||
size_t offset = frameData_[curFrame_].push_->Push(data, width * height * 4, &buffer);
|
||||
drawPixelsTex_->UploadMip(0, width, height, buffer, (uint32_t)offset, width);
|
||||
drawPixelsTex_->EndCreate();
|
||||
return drawPixelsTex_;
|
||||
}
|
||||
|
||||
void FramebufferManagerVulkan::SetViewport2D(int x, int y, int w, int h) {
|
||||
|
@ -428,13 +427,15 @@ void FramebufferManagerVulkan::DrawPixels(VirtualFramebuffer *vfb, int dstX, int
|
|||
// TODO: Don't use the viewport mechanism for this.
|
||||
vkCmdSetViewport(curCmd_, 0, 1, &vp);
|
||||
|
||||
VulkanTexture *pixelTex = MakePixelTexture(srcPixels, srcPixelFormat, srcStride, width, height);
|
||||
MakePixelTexture(srcPixels, srcPixelFormat, srcStride, width, height);
|
||||
VulkanTexture *pixelTex = drawPixelsTex_;
|
||||
DrawTexture(pixelTex, dstX, dstY, width, height, vfb->bufferWidth, vfb->bufferHeight, 0.0f, 0.0f, 1.0f, 1.0f, pipelineBasicTex_, ROTATION_LOCKED_HORIZONTAL);
|
||||
textureCacheVulkan_->ForgetLastTexture();
|
||||
}
|
||||
|
||||
void FramebufferManagerVulkan::DrawFramebufferToOutput(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, bool applyPostShader) {
|
||||
VulkanTexture *pixelTex = MakePixelTexture(srcPixels, srcPixelFormat, srcStride, 512, 272);
|
||||
MakePixelTexture(srcPixels, srcPixelFormat, srcStride, 512, 272);
|
||||
VulkanTexture *pixelTex = drawPixelsTex_;
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, g_Config.iTexFiltering == TEX_FILTER_NEAREST ? GL_NEAREST : GL_LINEAR);
|
||||
|
||||
// This might draw directly at the backbuffer (if so, applyPostShader is set) so if there's a post shader, we need to apply it here.
|
||||
|
@ -545,6 +546,10 @@ void FramebufferManagerVulkan::DrawTexture(VulkanTexture *texture, float x, floa
|
|||
vkCmdDraw(cmd, 4, 1, 0, 0);
|
||||
}
|
||||
|
||||
void FramebufferManagerVulkan::Bind2DShader() {
|
||||
|
||||
}
|
||||
|
||||
void FramebufferManagerVulkan::RebindFramebuffer() {
|
||||
if (currentRenderVfb_ && currentRenderVfb_->fbo) {
|
||||
draw_->BindFramebufferAsRenderTarget(currentRenderVfb_->fbo);
|
||||
|
|
|
@ -126,6 +126,7 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
void Bind2DShader() override;
|
||||
void SetViewport2D(int x, int y, int w, int h);
|
||||
void DisableState() override {}
|
||||
void ClearBuffer(bool keepState = false) override;
|
||||
|
@ -139,7 +140,7 @@ protected:
|
|||
private:
|
||||
|
||||
// The returned texture does not need to be free'd, might be returned from a pool (currently single entry)
|
||||
VulkanTexture *MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height);
|
||||
void MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height);
|
||||
void DoNotifyDraw();
|
||||
|
||||
VkCommandBuffer AllocFrameCommandBuffer();
|
||||
|
|
Loading…
Add table
Reference in a new issue