GPU: Cleanup presentation flipping a bit.

This commit is contained in:
Unknown W. Brackets 2020-05-11 23:28:50 -07:00
parent cb0f8cb373
commit 03e3a935da
4 changed files with 30 additions and 30 deletions

View file

@ -782,15 +782,13 @@ void FramebufferManagerCommon::DrawFramebufferToOutput(const u8 *srcPixels, GEBu
if (needBackBufferYSwap_) {
flags |= OutputFlags::BACKBUFFER_FLIPPED;
}
// DrawActiveTexture reverses these, probably to match "up".
if (GetGPUBackend() == GPUBackend::DIRECT3D9 || GetGPUBackend() == GPUBackend::DIRECT3D11) {
flags |= OutputFlags::POSITION_FLIPPED;
}
PostShaderUniforms uniforms{};
presentation_->CalculatePostShaderUniforms(512, 272, textureCache_->VideoIsPlaying(), &uniforms);
// TODO: DrawActiveTexture reverses these, but I'm not sure why? Investigate.
if (GetGPUBackend() == GPUBackend::DIRECT3D9 || GetGPUBackend() == GPUBackend::DIRECT3D11) {
std::swap(v0, v1);
}
presentation_->SourceTexture(pixelsTex);
presentation_->CopyToOutput(flags, uvRotation, u0, v0, u1, v1, uniforms);
pixelsTex->Release();
@ -950,18 +948,15 @@ void FramebufferManagerCommon::CopyDisplayToOutput(bool reallyDirty) {
if (needBackBufferYSwap_) {
flags |= OutputFlags::BACKBUFFER_FLIPPED;
}
// DrawActiveTexture reverses these, probably to match "up".
if (GetGPUBackend() == GPUBackend::DIRECT3D9 || GetGPUBackend() == GPUBackend::DIRECT3D11) {
flags |= OutputFlags::POSITION_FLIPPED;
}
PostShaderUniforms uniforms{};
int actualWidth = (vfb->bufferWidth * vfb->renderWidth) / vfb->width;
int actualHeight = (vfb->bufferHeight * vfb->renderHeight) / vfb->height;
presentation_->CalculatePostShaderUniforms(actualWidth, actualHeight, textureCache_->VideoIsPlaying(), &uniforms);
// DrawActiveTexture reverses these, probably to match "up".
// TODO: Maybe use a flag instead.
if (GetGPUBackend() == GPUBackend::DIRECT3D9 || GetGPUBackend() == GPUBackend::DIRECT3D11) {
std::swap(v0, v1);
}
presentation_->SourceFramebuffer(vfb->fbo);
presentation_->CopyToOutput(flags, uvRotation, u0, v0, u1, v1, uniforms);
} else if (useBufferedRendering_) {

View file

@ -461,7 +461,7 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u
y += 0.5f;
}
if (flags & OutputFlags::BACKBUFFER_FLIPPED) {
if ((flags & OutputFlags::BACKBUFFER_FLIPPED) || (flags & OutputFlags::POSITION_FLIPPED)) {
std::swap(v0, v1);
}
@ -490,13 +490,14 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u
// Vertical and Vertical180 needed swapping after we changed the coordinate system.
switch (uvRotation) {
case ROTATION_LOCKED_HORIZONTAL180: rotation = 2; break;
case ROTATION_LOCKED_VERTICAL: rotation = 1; break;
case ROTATION_LOCKED_VERTICAL180: rotation = 3; break;
case ROTATION_LOCKED_VERTICAL: rotation = 3; break;
case ROTATION_LOCKED_VERTICAL180: rotation = 1; break;
}
// TODO: This doesn't make sense... but Vulkan is flipped only in portrait? Investigate.
if (GetGPUBackend() == GPUBackend::VULKAN && (rotation & 1) != 0) {
rotation ^= 2;
// If we flipped, we rotate the other way.
if ((flags & OutputFlags::BACKBUFFER_FLIPPED) || (flags & OutputFlags::POSITION_FLIPPED)) {
if ((rotation & 1) != 0)
rotation ^= 2;
}
for (int i = 0; i < 4; i++) {
@ -538,7 +539,7 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u
Draw::SamplerState *sampler = useNearest ? samplerNearest_ : samplerLinear_;
draw_->BindSamplerStates(0, 1, &sampler);
bool flipped = GetGPUBackend() == GPUBackend::DIRECT3D9 || GetGPUBackend() == GPUBackend::DIRECT3D11;
bool flipped = flags & OutputFlags::POSITION_FLIPPED;
float post_v0 = !flipped ? 1.0f : 0.0f;
float post_v1 = !flipped ? 0.0f : 1.0f;
verts[4] = { -1, -1, 0, 0, post_v1, 0xFFFFFFFF }; // TL

View file

@ -56,6 +56,7 @@ enum class OutputFlags {
NEAREST = 0x0001,
RB_SWIZZLE = 0x0002,
BACKBUFFER_FLIPPED = 0x0004,
POSITION_FLIPPED = 0x0008,
};
inline OutputFlags operator | (const OutputFlags &lhs, const OutputFlags &rhs) {

View file

@ -172,8 +172,8 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) {
return;
float u0 = 0.0f;
float u1;
float v0 = 1.0f;
float v1 = 0.0f;
float v0 = 0.0f;
float v1 = 1.0f;
if (fbTex) {
fbTex->Release();
@ -220,8 +220,8 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) {
}
u0 = 64.5f / (float)desc.width;
u1 = 447.5f / (float)desc.width;
v1 = 16.0f / (float)desc.height;
v0 = 240.0f / (float)desc.height;
v0 = 16.0f / (float)desc.height;
v1 = 240.0f / (float)desc.height;
} else if (!Memory::IsValidAddress(displayFramebuf_) || srcwidth == 0 || srcheight == 0) {
hasImage = false;
u1 = 1.0f;
@ -262,17 +262,20 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) {
fbTex = draw_->CreateTexture(desc);
if (GetGPUBackend() == GPUBackend::VULKAN) {
std::swap(v0, v1);
}
if (GetGPUBackend() == GPUBackend::OPENGL) {
std::swap(v0, v1);
switch (GetGPUBackend()) {
case GPUBackend::OPENGL:
outputFlags |= OutputFlags::BACKBUFFER_FLIPPED;
break;
case GPUBackend::DIRECT3D9:
case GPUBackend::DIRECT3D11:
outputFlags |= OutputFlags::POSITION_FLIPPED;
break;
case GPUBackend::VULKAN:
break;
}
PostShaderUniforms uniforms{};
presentation_->CalculatePostShaderUniforms(desc.width, desc.height, false, &uniforms);
presentation_->SourceTexture(fbTex);
presentation_->CopyToOutput(outputFlags, g_Config.iInternalScreenRotation, u0, v0, u1, v1, uniforms);
}