Skip to content

Commit 9fd2fa8

Browse files
authored
Fixed shader_ids getting cleaned up by accident (Kenix3#574)
1 parent 9466d82 commit 9fd2fa8

File tree

3 files changed

+60
-54
lines changed

3 files changed

+60
-54
lines changed

src/graphic/Fast3D/gfx_cc.cpp

+18-19
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ void gfx_cc_get_features(uint64_t shader_id0, uint32_t shader_id1, struct CCFeat
44
for (int i = 0; i < 2; i++) {
55
for (int j = 0; j < 2; j++) {
66
for (int k = 0; k < 4; k++) {
7-
cc_features->c[i][j][k] = (shader_id0 >> (i * 32 + j * 16 + k * 4)) & 0xf;
7+
cc_features->c[i][j][k] = shader_id0 >> i * 32 + j * 16 + k * 4 & 0xf;
88
}
99
}
1010
}
1111

12-
cc_features->opt_alpha = (shader_id1 & SHADER_OPT_ALPHA) != 0;
13-
cc_features->opt_fog = (shader_id1 & SHADER_OPT_FOG) != 0;
14-
cc_features->opt_texture_edge = (shader_id1 & SHADER_OPT_TEXTURE_EDGE) != 0;
15-
cc_features->opt_noise = (shader_id1 & SHADER_OPT_NOISE) != 0;
16-
cc_features->opt_2cyc = (shader_id1 & SHADER_OPT_2CYC) != 0;
17-
cc_features->opt_alpha_threshold = (shader_id1 & SHADER_OPT_ALPHA_THRESHOLD) != 0;
18-
cc_features->opt_invisible = (shader_id1 & SHADER_OPT_INVISIBLE) != 0;
19-
cc_features->opt_grayscale = (shader_id1 & SHADER_OPT_GRAYSCALE) != 0;
12+
cc_features->opt_alpha = (shader_id1 & SHADER_OPT(ALPHA)) != 0;
13+
cc_features->opt_fog = (shader_id1 & SHADER_OPT(FOG)) != 0;
14+
cc_features->opt_texture_edge = (shader_id1 & SHADER_OPT(TEXTURE_EDGE)) != 0;
15+
cc_features->opt_noise = (shader_id1 & SHADER_OPT(NOISE)) != 0;
16+
cc_features->opt_2cyc = (shader_id1 & SHADER_OPT(_2CYC)) != 0;
17+
cc_features->opt_alpha_threshold = (shader_id1 & SHADER_OPT(ALPHA_THRESHOLD)) != 0;
18+
cc_features->opt_invisible = (shader_id1 & SHADER_OPT(INVISIBLE)) != 0;
19+
cc_features->opt_grayscale = (shader_id1 & SHADER_OPT(GRAYSCALE)) != 0;
2020

21-
cc_features->clamp[0][0] = (shader_id1 & SHADER_OPT_TEXEL0_CLAMP_S);
22-
cc_features->clamp[0][1] = (shader_id1 & SHADER_OPT_TEXEL0_CLAMP_T);
23-
cc_features->clamp[1][0] = (shader_id1 & SHADER_OPT_TEXEL1_CLAMP_S);
24-
cc_features->clamp[1][1] = (shader_id1 & SHADER_OPT_TEXEL1_CLAMP_T);
21+
cc_features->clamp[0][0] = shader_id1 & SHADER_OPT(TEXEL0_CLAMP_S);
22+
cc_features->clamp[0][1] = shader_id1 & SHADER_OPT(TEXEL0_CLAMP_T);
23+
cc_features->clamp[1][0] = shader_id1 & SHADER_OPT(TEXEL1_CLAMP_S);
24+
cc_features->clamp[1][1] = shader_id1 & SHADER_OPT(TEXEL1_CLAMP_T);
2525

2626
cc_features->used_textures[0] = false;
2727
cc_features->used_textures[1] = false;
@@ -56,21 +56,20 @@ void gfx_cc_get_features(uint64_t shader_id0, uint32_t shader_id1, struct CCFeat
5656
cc_features->do_multiply[c][1] = cc_features->c[c][1][1] == SHADER_0 && cc_features->c[c][1][3] == SHADER_0;
5757
cc_features->do_mix[c][0] = cc_features->c[c][0][1] == cc_features->c[c][0][3];
5858
cc_features->do_mix[c][1] = cc_features->c[c][1][1] == cc_features->c[c][1][3];
59-
cc_features->color_alpha_same[c] =
60-
((shader_id0 >> c * 32) & 0xffff) == ((shader_id0 >> (c * 32 + 16)) & 0xffff);
59+
cc_features->color_alpha_same[c] = (shader_id0 >> c * 32 & 0xffff) == (shader_id0 >> c * 32 + 16 & 0xffff);
6160
}
6261

63-
if (cc_features->used_textures[0] && (shader_id1 & SHADER_OPT_TEXEL0_MASK)) {
62+
if (cc_features->used_textures[0] && shader_id1 & SHADER_OPT(TEXEL0_MASK)) {
6463
cc_features->used_masks[0] = true;
6564
}
66-
if (cc_features->used_textures[1] && (shader_id1 & SHADER_OPT_TEXEL1_MASK)) {
65+
if (cc_features->used_textures[1] && shader_id1 & SHADER_OPT(TEXEL1_MASK)) {
6766
cc_features->used_masks[1] = true;
6867
}
6968

70-
if (cc_features->used_textures[0] && (shader_id1 & SHADER_OPT_TEXEL0_BLEND)) {
69+
if (cc_features->used_textures[0] && shader_id1 & SHADER_OPT(TEXEL0_BLEND)) {
7170
cc_features->used_blend[0] = true;
7271
}
73-
if (cc_features->used_textures[1] && (shader_id1 & SHADER_OPT_TEXEL1_BLEND)) {
72+
if (cc_features->used_textures[1] && shader_id1 & SHADER_OPT(TEXEL1_BLEND)) {
7473
cc_features->used_blend[1] = true;
7574
}
7675
}

src/graphic/Fast3D/gfx_cc.h

+23-16
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,29 @@ enum {
3737
SHADER_NOISE
3838
};
3939

40-
#define SHADER_OPT_ALPHA (1 << 0)
41-
#define SHADER_OPT_FOG (1 << 1)
42-
#define SHADER_OPT_TEXTURE_EDGE (1 << 2)
43-
#define SHADER_OPT_NOISE (1 << 3)
44-
#define SHADER_OPT_2CYC (1 << 4)
45-
#define SHADER_OPT_ALPHA_THRESHOLD (1 << 5)
46-
#define SHADER_OPT_INVISIBLE (1 << 6)
47-
#define SHADER_OPT_GRAYSCALE (1 << 7)
48-
#define SHADER_OPT_TEXEL0_CLAMP_S (1 << 8)
49-
#define SHADER_OPT_TEXEL0_CLAMP_T (1 << 9)
50-
#define SHADER_OPT_TEXEL1_CLAMP_S (1 << 10)
51-
#define SHADER_OPT_TEXEL1_CLAMP_T (1 << 11)
52-
#define SHADER_OPT_TEXEL0_MASK (1 << 12)
53-
#define SHADER_OPT_TEXEL1_MASK (1 << 13)
54-
#define SHADER_OPT_TEXEL0_BLEND (1 << 14)
55-
#define SHADER_OPT_TEXEL1_BLEND (1 << 15)
40+
#ifdef __cplusplus
41+
enum class ShaderOpts {
42+
ALPHA,
43+
FOG,
44+
TEXTURE_EDGE,
45+
NOISE,
46+
_2CYC,
47+
ALPHA_THRESHOLD,
48+
INVISIBLE,
49+
GRAYSCALE,
50+
TEXEL0_CLAMP_S,
51+
TEXEL0_CLAMP_T,
52+
TEXEL1_CLAMP_S,
53+
TEXEL1_CLAMP_T,
54+
TEXEL0_MASK,
55+
TEXEL1_MASK,
56+
TEXEL0_BLEND,
57+
TEXEL1_BLEND,
58+
MAX
59+
};
60+
61+
#define SHADER_OPT(opt) ((uint64_t)(1 << static_cast<int>(ShaderOpts::opt)))
62+
#endif
5663

5764
struct ColorCombinerKey {
5865
uint64_t combine_mode;

src/graphic/Fast3D/gfx_pc.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static const char* acmux_to_string(uint32_t acmux) {
249249
}
250250

251251
static void gfx_generate_cc(struct ColorCombiner* comb, const ColorCombinerKey& key) {
252-
bool is_2cyc = (key.options & (uint64_t)SHADER_OPT_2CYC) != 0;
252+
bool is_2cyc = (key.options & SHADER_OPT(_2CYC)) != 0;
253253

254254
uint8_t c[2][2][4];
255255
uint64_t shader_id0 = 0;
@@ -1459,51 +1459,51 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
14591459
}
14601460

14611461
if (use_alpha) {
1462-
cc_options |= (uint64_t)SHADER_OPT_ALPHA;
1462+
cc_options |= SHADER_OPT(ALPHA);
14631463
}
14641464
if (use_fog) {
1465-
cc_options |= (uint64_t)SHADER_OPT_FOG;
1465+
cc_options |= SHADER_OPT(FOG);
14661466
}
14671467
if (texture_edge) {
1468-
cc_options |= (uint64_t)SHADER_OPT_TEXTURE_EDGE;
1468+
cc_options |= SHADER_OPT(TEXTURE_EDGE);
14691469
}
14701470
if (use_noise) {
1471-
cc_options |= (uint64_t)SHADER_OPT_NOISE;
1471+
cc_options |= SHADER_OPT(NOISE);
14721472
}
14731473
if (use_2cyc) {
1474-
cc_options |= (uint64_t)SHADER_OPT_2CYC;
1474+
cc_options |= SHADER_OPT(_2CYC);
14751475
}
14761476
if (alpha_threshold) {
1477-
cc_options |= (uint64_t)SHADER_OPT_ALPHA_THRESHOLD;
1477+
cc_options |= SHADER_OPT(ALPHA_THRESHOLD);
14781478
}
14791479
if (invisible) {
1480-
cc_options |= (uint64_t)SHADER_OPT_INVISIBLE;
1480+
cc_options |= SHADER_OPT(INVISIBLE);
14811481
}
14821482
if (use_grayscale) {
1483-
cc_options |= (uint64_t)SHADER_OPT_GRAYSCALE;
1483+
cc_options |= SHADER_OPT(GRAYSCALE);
14841484
}
14851485
if (g_rdp.loaded_texture[0].masked) {
1486-
cc_options |= (uint64_t)SHADER_OPT_TEXEL0_MASK;
1486+
cc_options |= SHADER_OPT(TEXEL0_MASK);
14871487
}
14881488
if (g_rdp.loaded_texture[1].masked) {
1489-
cc_options |= (uint64_t)SHADER_OPT_TEXEL1_MASK;
1489+
cc_options |= SHADER_OPT(TEXEL1_MASK);
14901490
}
14911491
if (g_rdp.loaded_texture[0].blended) {
1492-
cc_options |= (uint64_t)SHADER_OPT_TEXEL0_BLEND;
1492+
cc_options |= SHADER_OPT(TEXEL0_BLEND);
14931493
}
14941494
if (g_rdp.loaded_texture[1].blended) {
1495-
cc_options |= (uint64_t)SHADER_OPT_TEXEL1_BLEND;
1496-
}
1497-
1498-
// If we are not using alpha, clear the alpha components of the combiner as they have no effect
1499-
if (!use_alpha) {
1500-
cc_options &= ~((0xfff << 16) | ((uint64_t)0xfff << 44));
1495+
cc_options |= SHADER_OPT(TEXEL1_BLEND);
15011496
}
15021497

15031498
ColorCombinerKey key;
15041499
key.combine_mode = g_rdp.combine_mode;
15051500
key.options = cc_options;
15061501

1502+
// If we are not using alpha, clear the alpha components of the combiner as they have no effect
1503+
if (!use_alpha) {
1504+
key.combine_mode &= ~((0xfff << 16) | ((uint64_t)0xfff << 44));
1505+
}
1506+
15071507
ColorCombiner* comb = gfx_lookup_or_create_color_combiner(key);
15081508

15091509
uint32_t tm = 0;
@@ -1587,7 +1587,7 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
15871587
struct ShaderProgram* prg = comb->prg[tm];
15881588
if (prg == NULL) {
15891589
comb->prg[tm] = prg =
1590-
gfx_lookup_or_create_shader_program(comb->shader_id0, comb->shader_id1 | (tm * SHADER_OPT_TEXEL0_CLAMP_S));
1590+
gfx_lookup_or_create_shader_program(comb->shader_id0, comb->shader_id1 | tm * SHADER_OPT(TEXEL0_CLAMP_S));
15911591
}
15921592
if (prg != rendering_state.shader_program) {
15931593
gfx_flush();

0 commit comments

Comments
 (0)