Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Common/GPU/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void ShaderLanguageDesc::Init(ShaderLanguage lang) {
lastFragData = nullptr;
gles = false;
forceMatrix4x4 = true;
depthMinusOneToOne = true;
break;
case GLSL_3xx:
// Just used in the shader test.
Expand All @@ -67,6 +68,7 @@ void ShaderLanguageDesc::Init(ShaderLanguage lang) {
gles = true;
forceMatrix4x4 = true;
glslES30 = true;
depthMinusOneToOne = true;
break;
case GLSL_VULKAN:
fragColor0 = "fragColor0";
Expand All @@ -86,6 +88,7 @@ void ShaderLanguageDesc::Init(ShaderLanguage lang) {
forceMatrix4x4 = false;
coefsFromBuffers = true;
vertexIndex = true;
depthMinusOneToOne = false;
break;
case HLSL_D3D11:
fragColor0 = "outfragment.target";
Expand All @@ -107,6 +110,7 @@ void ShaderLanguageDesc::Init(ShaderLanguage lang) {
coefsFromBuffers = true;
vsOutPrefix = "Out.";
viewportYSign = "-";
depthMinusOneToOne = false;
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions Common/GPU/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct ShaderLanguageDesc {
const char *vsOutPrefix = "";
const char *viewportYSign = "";

bool depthMinusOneToOne = false;
bool vertexIndex = false;
bool glslES30 = false; // really glslES30Features. TODO: Clean this up.
bool bitwiseOps = false;
Expand Down
3 changes: 3 additions & 0 deletions Common/GPU/ShaderWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ void ShaderWriter::EndVSMain(Slice<VaryingDef> varyings) {
if (strlen(lang_.viewportYSign)) {
F(" gl_Position.y *= %s1.0;\n", lang_.viewportYSign);
}
if (lang_.depthMinusOneToOne) {
F(" gl_Position.z = gl_Position.z * 2.0 - gl_Position.w;\n"); // homogenous math... looks confusing.
}
C(" vs_out.pos = gl_Position;\n");
for (auto &varying : varyings) {
F(" vs_out.%s = %s;\n", varying.name, varying.name);
Expand Down
4 changes: 4 additions & 0 deletions Common/GPU/Vulkan/VulkanContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ class VulkanContext {
return winsys_;
}

bool SupportsPreRotation() const {
return surfCapabilities_.supportedTransforms != VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
}

private:
bool ChooseQueue();

Expand Down
1 change: 1 addition & 0 deletions Common/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enum class Log {
GeDebugger,
UI,
IAP,
CwCheats,

sceAudio,
sceCtrl,
Expand Down
1 change: 1 addition & 0 deletions Common/Log/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static const char * const g_logTypeNames[] = {
"GEDEBUGGER",
"UI",
"IAP",
"CWCHEATS",
"SCEAUDIO",
"SCECTRL",
"SCEDISP",
Expand Down
2 changes: 1 addition & 1 deletion Common/Math/lin/matrix4x4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void Matrix4x4::setViewFrame(const Vec3 &pos, const Vec3 &vRight, const Vec3 &vV
ww = 1.0f;
}

void Matrix4x4::setOrtho(float left, float right, float bottom, float top, float near, float far) {
void Matrix4x4::setOrthoGL(float left, float right, float bottom, float top, float near, float far) {
empty();
xx = 2.0f / (right - left);
yy = 2.0f / (top - bottom);
Expand Down
2 changes: 1 addition & 1 deletion Common/Math/lin/matrix4x4.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Matrix4x4 {
ww = 1.0f;
}

void setOrtho(float left, float right, float bottom, float top, float near, float far);
void setOrthoGL(float left, float right, float bottom, float top, float near, float far);
void setOrthoD3D(float left, float right, float bottom, float top, float near, float far);
void setOrthoVulkan(float left, float right, float top, float bottom, float near, float far);

Expand Down
2 changes: 1 addition & 1 deletion Common/System/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Lin::Matrix4x4 ComputeOrthoMatrix(float xres, float yres, CoordConvention coordC
break;
case CoordConvention::OpenGL:
default:
ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
ortho.setOrthoGL(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
break;
}
// Compensate for rotated display if needed.
Expand Down
6 changes: 1 addition & 5 deletions Common/UI/Notice.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ class NoticeView : public UI::InertView {
level_ = level;
text_ = text;
}
void SetSquishy(bool squishy) {
squishy_ = squishy;
}
void SetWrapText(bool wrapText) {
wrapText_ = wrapText;
}
Expand All @@ -53,8 +50,7 @@ class NoticeView : public UI::InertView {
std::string iconName_;
NoticeLevel level_;
mutable float height1_ = 0.0f;
bool squishy_ = false;
bool wrapText_ = false;
bool wrapText_ = true;
};

ImageID GetOSDIcon(NoticeLevel level);
Expand Down
1 change: 1 addition & 0 deletions Common/UI/PopupScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ void AskForInput(ScreenManager *screenManager, RequesterToken token, UI::View *s

PopupTextInputChoice::PopupTextInputChoice(RequesterToken token, std::string *value, std::string_view title, std::string_view placeholder, int maxLen, ScreenManager *screenManager, LayoutParams *layoutParams)
: AbstractChoiceWithValueDisplay(title, layoutParams), screenManager_(screenManager), value_(value), placeHolder_(placeholder), maxLen_(maxLen), token_(token), restriction_(StringRestriction::None) {
_dbg_assert_(value);
OnClick.Handle(this, &PopupTextInputChoice::HandleClick);
}

Expand Down
4 changes: 2 additions & 2 deletions GPU/Common/FramebufferManagerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3185,9 +3185,9 @@ bool GetOutputFramebuffer(Draw::DrawContext *draw, GPUDebugBuffer &buffer) {
if (fmt != Draw::DataFormat::B8G8R8A8_UNORM)
fmt = Draw::DataFormat::R8G8B8A8_UNORM;

bool flipped = g_Config.iGPUBackend == (int)GPUBackend::OPENGL;
bool flipY = g_Config.iGPUBackend == (int)GPUBackend::OPENGL;

buffer.Allocate(w, h, fmt == Draw::DataFormat::R8G8B8A8_UNORM ? GPU_DBG_FORMAT_8888 : GPU_DBG_FORMAT_8888_BGRA, flipped);
buffer.Allocate(w, h, fmt == Draw::DataFormat::R8G8B8A8_UNORM ? GPU_DBG_FORMAT_8888 : GPU_DBG_FORMAT_8888_BGRA, flipY);
buffer.SetIsBackbuffer(true);
return draw->CopyFramebufferToMemory(nullptr, Draw::Aspect::COLOR_BIT, 0, 0, w, h, fmt, buffer.GetData(), w, Draw::ReadbackMode::BLOCK, "GetOutputFramebuffer");
}
Expand Down
78 changes: 40 additions & 38 deletions GPU/Common/ShaderUniforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@

using namespace Lin;

static void ConvertProjMatrixToVulkan(Matrix4x4 &in) {
static void ConvertProjMatrixToZeroToOneDepth(Matrix4x4 &in) {
const Vec3 trans(gstate_c.vpXOffset, gstate_c.vpYOffset, gstate_c.vpZOffset * 0.5f + 0.5f);
const Vec3 scale(gstate_c.vpWidthScale, gstate_c.vpHeightScale, gstate_c.vpDepthScale * 0.5f);
in.translateAndScale(trans, scale);
}

static void ConvertProjMatrixToD3D11(Matrix4x4 &in) {
const Vec3 trans(gstate_c.vpXOffset, -gstate_c.vpYOffset, gstate_c.vpZOffset * 0.5f + 0.5f);
const Vec3 scale(gstate_c.vpWidthScale, -gstate_c.vpHeightScale, gstate_c.vpDepthScale * 0.5f);
in.translateAndScale(trans, scale);
}

void CalcCullRange(float minValues[4], float maxValues[4], bool flipViewport, bool hasNegZ) {
// Account for the projection viewport adjustment when viewport is too large.
auto reverseViewportX = [](float x) {
Expand Down Expand Up @@ -72,6 +66,40 @@ void CalcCullRange(float minValues[4], float maxValues[4], bool flipViewport, bo
maxValues[3] = NAN;
}

// TODO: This will be removed later.
static inline void FlipProjMatrix(Matrix4x4 & in) {
const bool invertedY = gstate_c.vpHeight < 0;
if (invertedY) {
in[1] = -in[1];
in[5] = -in[5];
in[9] = -in[9];
in[13] = -in[13];
}
const bool invertedX = gstate_c.vpWidth < 0;
if (invertedX) {
in[0] = -in[0];
in[4] = -in[4];
in[8] = -in[8];
in[12] = -in[12];
}
}

void UpdateRotation(float rotMatrix[4], bool useBufferedRendering) {
if (!gstate_c.Use(GPU_USE_PRE_ROTATION) || useBufferedRendering) {
rotMatrix[0] = 1.0f;
rotMatrix[1] = 0.0f;
rotMatrix[2] = 0.0f;
rotMatrix[3] = 1.0f;
} else {
const DisplayRotation rotation = g_display.rotation;
// The others are ROTATE_90 and so on.
rotMatrix[0] = rotation == DisplayRotation::ROTATE_0 ? 1.0 : (rotation == DisplayRotation::ROTATE_180 ? -1.0 : 0.0);
rotMatrix[1] = rotation == DisplayRotation::ROTATE_90 ? 1.0 : (rotation == DisplayRotation::ROTATE_270 ? -1.0 : 0.0);
rotMatrix[2] = rotation == DisplayRotation::ROTATE_270 ? 1.0 : (rotation == DisplayRotation::ROTATE_90 ? -1.0 : 0.0);
rotMatrix[3] = rotation == DisplayRotation::ROTATE_0 ? 1.0 : (rotation == DisplayRotation::ROTATE_180 ? -1.0 : 0.0);
}
}

void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipViewport, bool useBufferedRendering) {
if (dirtyUniforms & DIRTY_TEXENV) {
Uint8x3ToFloat3(ub->texEnvColor, gstate.texenvcolor);
Expand Down Expand Up @@ -115,44 +143,16 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
Matrix4x4 flippedMatrix;
memcpy(&flippedMatrix, gstate.projMatrix, 16 * sizeof(float));

const bool invertedY = gstate_c.vpHeight < 0;
if (invertedY) {
flippedMatrix[1] = -flippedMatrix[1];
flippedMatrix[5] = -flippedMatrix[5];
flippedMatrix[9] = -flippedMatrix[9];
flippedMatrix[13] = -flippedMatrix[13];
}
const bool invertedX = gstate_c.vpWidth < 0;
if (invertedX) {
flippedMatrix[0] = -flippedMatrix[0];
flippedMatrix[4] = -flippedMatrix[4];
flippedMatrix[8] = -flippedMatrix[8];
flippedMatrix[12] = -flippedMatrix[12];
}
if (flipViewport) {
ConvertProjMatrixToD3D11(flippedMatrix);
} else {
ConvertProjMatrixToVulkan(flippedMatrix);
}

if (!useBufferedRendering && g_display.rotation != DisplayRotation::ROTATE_0) {
flippedMatrix = flippedMatrix * g_display.rot_matrix;
}
FlipProjMatrix(flippedMatrix);
ConvertProjMatrixToZeroToOneDepth(flippedMatrix);
CopyMatrix4x4(ub->proj, flippedMatrix.getReadPtr());

ub->rotation = useBufferedRendering ? 0 : (float)g_display.rotation;
}

if (dirtyUniforms & DIRTY_PROJTHROUGHMATRIX) {
Matrix4x4 proj_through;
if (flipViewport) {
proj_through.setOrthoD3D(0.0f, gstate_c.curRTWidth, gstate_c.curRTHeight, 0, 0, 1);
} else {
proj_through.setOrthoVulkan(0.0f, gstate_c.curRTWidth, 0, gstate_c.curRTHeight, 0, 1);
}
if (!useBufferedRendering && g_display.rotation != DisplayRotation::ROTATE_0) {
proj_through = proj_through * g_display.rot_matrix;
}
proj_through.setOrthoVulkan(0.0f, gstate_c.curRTWidth, 0, gstate_c.curRTHeight, 0, 1);

// Negative RT offsets come from split framebuffers (Killzone)
if (gstate_c.curRTOffsetX < 0 || gstate_c.curRTOffsetY < 0) {
Expand All @@ -161,6 +161,8 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
}

CopyMatrix4x4(ub->proj_through, proj_through.getReadPtr());

ub->rotation = useBufferedRendering ? 0 : (float)g_display.rotation;
}

// Transform
Expand Down
5 changes: 4 additions & 1 deletion GPU/Common/ShaderUniforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum : uint64_t {
DIRTY_MATDIFFUSE | DIRTY_MATSPECULAR | DIRTY_MATEMISSIVE | DIRTY_AMBIENT,
};

// Currently 496 bytes.
// Currently 480 bytes.
// Every line here is a 4-float.
struct alignas(16) UB_VS_FS_Base {
float proj[16];
Expand All @@ -43,6 +43,7 @@ struct alignas(16) UB_VS_FS_Base {
// VR stuff is to go here, later. For normal drawing, we can then get away
// with just uploading the first 448 bytes of the struct (up to and including fogCoef).
};
static_assert(sizeof(UB_VS_FS_Base) == 480, "UB_VS_FS_Base should be 480 bytes");

static const char * const ub_baseStr =
R"( mat4 u_proj;
Expand Down Expand Up @@ -84,6 +85,7 @@ struct alignas(16) UB_VS_Lights {
float lightDiffuse[4][4];
float lightSpecular[4][4];
};
static_assert(sizeof(UB_VS_Lights) == 512); // it's ok to optimize this, it's just an assumption check.

static const char * const ub_vs_lightsStr =
R"( vec4 u_ambient;
Expand All @@ -105,6 +107,7 @@ R"( vec4 u_ambient;
struct alignas(16) UB_VS_Bones {
float bones[8][12];
};
static_assert(sizeof(UB_VS_Bones) == 384); // No way to optimize this further.

static const char * const ub_vs_bonesStr =
R"( mat3x4 u_bone0; mat3x4 u_bone1; mat3x4 u_bone2; mat3x4 u_bone3; mat3x4 u_bone4; mat3x4 u_bone5; mat3x4 u_bone6; mat3x4 u_bone7; mat3x4 u_bone8;
Expand Down
28 changes: 6 additions & 22 deletions GPU/Common/SoftwareTransformCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,15 @@ static void SwapUVs(TransformedVertex &a, TransformedVertex &b) {

// Note: 0 is BR and 2 is TL.

static void RotateUV(TransformedVertex v[4], bool flippedY) {
// We use the transformed tl/br coordinates to figure out whether they're flipped or not.
float ySign = flippedY ? -1.0 : 1.0;

static void RotateUV(TransformedVertex v[4]) {
const float x1 = v[2].x;
const float x2 = v[0].x;
const float y1 = v[2].y * ySign;
const float y2 = v[0].y * ySign;

if ((x1 < x2 && y1 < y2) || (x1 > x2 && y1 > y2))
SwapUVs(v[1], v[3]);
}
const float y1 = v[2].y;
const float y2 = v[0].y;

static void RotateUVThrough(TransformedVertex v[4]) {
float x1 = v[2].x;
float x2 = v[0].x;
float y1 = v[2].y;
float y2 = v[0].y;

if ((x1 < x2 && y1 > y2) || (x1 > x2 && y1 < y2))
if ((x1 < x2 && y1 > y2) || (x1 > x2 && y1 < y2)) {
SwapUVs(v[1], v[3]);
}
}

// Clears on the PSP are best done by drawing a series of vertical strips
Expand Down Expand Up @@ -658,11 +646,7 @@ bool SoftwareTransform::ExpandRectangles(int vertexCount, int &numDecodedVerts,
trans[3].v = transVtxBR.v * vscale;

// That's the four corners. Now process UV rotation.
if (throughmode) {
RotateUVThrough(trans);
} else {
RotateUV(trans, params_.flippedY);
}
RotateUV(trans);

// Triangle: BR-TR-TL
indsOut[0] = i * 2 + 0;
Expand Down
Loading
Loading