Skip to content

Commit

Permalink
Get rid of the bool, not worth it.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 10, 2023
1 parent d927fa6 commit 4686b51
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Core/Util/PPGeDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ bool PPGeImage::Load() {
unsigned char *textureData;
int success;
if (filename_.empty()) {
success = pngLoadPtr(Memory::GetPointerRange(png_, size_), size_, &width_, &height_, &textureData);
success = pngLoadPtr(Memory::GetPointerRange(png_, (u32)size_), size_, &width_, &height_, &textureData);
} else {
std::vector<u8> pngData;
if (pspFileSystem.ReadEntireFile(filename_, pngData) < 0) {
Expand Down
10 changes: 6 additions & 4 deletions GPU/Common/FragmentShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
if (texFunc == GE_TEXFUNC_BLEND) {
WRITE(p, "float3 u_texenv : register(c%i);\n", CONST_PS_TEXENV);
}
WRITE(p, "bool u_texAlpha : register(b%i);\n", CONST_PS_TEXALPHA); // NOTE! "b" register, not "c"!
WRITE(p, "float u_texNoAlpha : register(c%i);\n", CONST_PS_TEX_NO_ALPHA);
}
WRITE(p, "float3 u_fogcolor : register(c%i);\n", CONST_PS_FOGCOLOR);
if (texture3D) {
Expand Down Expand Up @@ -354,7 +354,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
WRITE(p, "uniform sampler2D tex;\n");
}
*uniformMask |= DIRTY_TEXALPHA;
WRITE(p, "uniform bool u_texAlpha;\n");
WRITE(p, "uniform float u_texNoAlpha;\n");
}

if (readFramebufferTex) {
Expand Down Expand Up @@ -824,7 +824,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
WRITE(p, " vec4 p = v_color0;\n");

if (texFunc != GE_TEXFUNC_REPLACE) {
WRITE(p, " if (!u_texAlpha) { t.a = 1.0; }\n");
WRITE(p, " t.a = max(t.a, u_texNoAlpha);\n");
}

switch (texFunc) {
Expand All @@ -838,7 +838,9 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
WRITE(p, " vec4 v = vec4(mix(p.rgb, u_texenv.rgb, t.rgb), p.a * t.a) + s;\n");
break;
case GE_TEXFUNC_REPLACE:
WRITE(p, " vec4 v = (u_texAlpha ? t : vec4(t.rgb, p.a)) + s;\n");
WRITE(p, " vec4 r = t;\n");
WRITE(p, " r.a = mix(r.a, p.a, u_texNoAlpha);\n");
WRITE(p, " vec4 v = r + s;\n");
break;
case GE_TEXFUNC_ADD:
case GE_TEXFUNC_UNKNOWN1:
Expand Down
4 changes: 2 additions & 2 deletions GPU/Common/FragmentShaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ struct FShaderID;
#define CONST_PS_TEXCLAMP 8
#define CONST_PS_TEXCLAMPOFF 9
#define CONST_PS_MIPBIAS 10
#define CONST_PS_TEX_NO_ALPHA 11

// For stencil upload
#define BCONST_PS_STENCILVALUE 11
#define BCONST_PS_STENCILVALUE 12

// D3D9 bool constants, they have their own register space.
#define CONST_PS_TEXALPHA 0


// Can technically be deduced from the fragment shader ID, but this is safer.
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/ShaderUniforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
}

if (dirtyUniforms & DIRTY_TEXALPHA) {
ub->texAlpha = gstate.isTextureAlphaUsed() ? 1 : 0;
ub->texNoAlpha = gstate.isTextureAlphaUsed() ? 0.0f : 1.0f;
}

if (dirtyUniforms & DIRTY_STENCILREPLACEVALUE) {
Expand Down
6 changes: 3 additions & 3 deletions 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 448 bytes.
// Currently 496 bytes.
// Every line here is a 4-float.
struct alignas(16) UB_VS_FS_Base {
float proj[16];
Expand All @@ -39,7 +39,7 @@ struct alignas(16) UB_VS_FS_Base {
float blendFixB[3]; float rotation;
float texClamp[4];
float texClampOffset[2]; float fogCoef[2];
uint32_t texAlpha; float pad[3];
float texNoAlpha; float pad[3];
// 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).
};
Expand All @@ -66,7 +66,7 @@ R"( mat4 u_proj;
vec4 u_texclamp;
vec2 u_texclampoff;
vec2 u_fogcoef;
bool u_texAlpha; float pad0; float pad1; float pad2;
float u_texNoAlpha; float pad0; float pad1; float pad2;
)";

// 512 bytes. Would like to shrink more. Some colors only have 8-bit precision and we expand
Expand Down
3 changes: 2 additions & 1 deletion GPU/Directx9/ShaderManagerDX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ void ShaderManagerDX9::PSUpdateUniforms(u64 dirtyUniforms) {
PSSetFloat(CONST_PS_STENCILREPLACE, (float)gstate.getStencilTestRef() * (1.0f / 255.0f));
}
if (dirtyUniforms & DIRTY_TEXALPHA) {
PSSetBool(CONST_PS_TEXALPHA, gstate.isTextureAlphaUsed());
// NOTE: Reversed value, more efficient in shader.
PSSetFloat(CONST_PS_TEX_NO_ALPHA, gstate.isTextureAlphaUsed() ? 0.0f : 1.0f);
}
if (dirtyUniforms & DIRTY_SHADERBLEND) {
PSSetColorUniform3(CONST_PS_BLENDFIXA, gstate.getFixA());
Expand Down
4 changes: 2 additions & 2 deletions GPU/GLES/ShaderManagerGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ LinkedShader::LinkedShader(GLRenderManager *render, VShaderID VSID, Shader *vs,
queries.push_back({ &u_uvscaleoffset, "u_uvscaleoffset" });
queries.push_back({ &u_texclamp, "u_texclamp" });
queries.push_back({ &u_texclampoff, "u_texclampoff" });
queries.push_back({ &u_texAlpha, "u_texAlpha" });
queries.push_back({ &u_texNoAlpha, "u_texNoAlpha" });
queries.push_back({ &u_lightControl, "u_lightControl" });

for (int i = 0; i < 4; i++) {
Expand Down Expand Up @@ -446,7 +446,7 @@ void LinkedShader::UpdateUniforms(const ShaderID &vsid, bool useBufferedRenderin
SetColorUniform3(render_, &u_texenv, gstate.texenvcolor);
}
if (dirty & DIRTY_TEXALPHA) {
SetBoolUniform(render_, &u_texAlpha, gstate.isTextureAlphaUsed());
render_->SetUniformF1(&u_texNoAlpha, gstate.isTextureAlphaUsed() ? 0.0f : 1.0f);
}
if (dirty & DIRTY_ALPHACOLORREF) {
if (shaderLanguage.bitwiseOps) {
Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/ShaderManagerGLES.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class LinkedShader {
int u_uvscaleoffset;
int u_texclamp;
int u_texclampoff;
int u_texAlpha;
int u_texNoAlpha;

// Lighting
int u_lightControl;
Expand Down

0 comments on commit 4686b51

Please sign in to comment.