- replaced MIN/MAX in common code.

This commit is contained in:
Christoph Oelckers 2021-10-30 10:46:17 +02:00
commit eb69bbcae0
63 changed files with 200 additions and 236 deletions

View file

@ -219,8 +219,8 @@ void PolyFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function<void(
IntRect bounds;
bounds.left = bounds.top = 0;
bounds.width = std::min(tex->GetWidth(), image->GetWidth());
bounds.height = std::min(tex->GetHeight(), image->GetHeight());
bounds.width = min(tex->GetWidth(), image->GetWidth());
bounds.height = min(tex->GetHeight(), image->GetHeight());
renderFunc(bounds);

View file

@ -100,10 +100,10 @@ void PolyTriangleThreadData::SetScissor(int x, int y, int w, int h)
void PolyTriangleThreadData::UpdateClip()
{
clip.left = MAX(MAX(viewport_x, scissor.left), 0);
clip.top = MAX(MAX(viewport_y, scissor.top), 0);
clip.right = MIN(MIN(viewport_x + viewport_width, scissor.right), dest_width);
clip.bottom = MIN(MIN(viewport_y + viewport_height, scissor.bottom), dest_height);
clip.left = max(max(viewport_x, scissor.left), 0);
clip.top = max(max(viewport_y, scissor.top), 0);
clip.right = min(min(viewport_x + viewport_width, scissor.right), dest_width);
clip.bottom = min(min(viewport_y + viewport_height, scissor.bottom), dest_height);
}
void PolyTriangleThreadData::PushStreamData(const StreamData &data, const PolyPushConstants &constants)
@ -206,11 +206,11 @@ void PolyTriangleThreadData::SetStencil(int stencilRef, int op)
StencilTestValue = stencilRef;
if (op == SOP_Increment)
{
StencilWriteValue = MIN(stencilRef + 1, (int)255);
StencilWriteValue = min(stencilRef + 1, (int)255);
}
else if (op == SOP_Decrement)
{
StencilWriteValue = MAX(stencilRef - 1, (int)0);
StencilWriteValue = max(stencilRef - 1, (int)0);
}
else // SOP_Keep
{
@ -453,8 +453,8 @@ void PolyTriangleThreadData::DrawShadedLine(const ShadedTriVertex *const* vert)
{
float clipdistance1 = clipdistance[0 * numclipdistances + p];
float clipdistance2 = clipdistance[1 * numclipdistances + p];
if (clipdistance1 < 0.0f) t1 = MAX(-clipdistance1 / (clipdistance2 - clipdistance1), t1);
if (clipdistance2 < 0.0f) t2 = MIN(1.0f + clipdistance2 / (clipdistance1 - clipdistance2), t2);
if (clipdistance1 < 0.0f) t1 = max(-clipdistance1 / (clipdistance2 - clipdistance1), t1);
if (clipdistance2 < 0.0f) t2 = min(1.0f + clipdistance2 / (clipdistance1 - clipdistance2), t2);
if (t1 >= t2)
return;
}
@ -792,8 +792,8 @@ int PolyTriangleThreadData::ClipEdge(const ShadedTriVertex *const* verts)
// Clip halfspace
if ((clipdistance1 >= 0.0f || clipdistance2 >= 0.0f) && outputverts + 1 < max_additional_vertices)
{
float t1 = (clipdistance1 < 0.0f) ? MAX(-clipdistance1 / (clipdistance2 - clipdistance1), 0.0f) : 0.0f;
float t2 = (clipdistance2 < 0.0f) ? MIN(1.0f + clipdistance2 / (clipdistance1 - clipdistance2), 1.0f) : 1.0f;
float t1 = (clipdistance1 < 0.0f) ? max(-clipdistance1 / (clipdistance2 - clipdistance1), 0.0f) : 0.0f;
float t2 = (clipdistance2 < 0.0f) ? min(1.0f + clipdistance2 / (clipdistance1 - clipdistance2), 1.0f) : 1.0f;
// add t1 vertex
for (int k = 0; k < 3; k++)

View file

@ -85,16 +85,16 @@ public:
int skipped_by_thread(int first_line)
{
int clip_first_line = MAX(first_line, numa_start_y);
int clip_first_line = max(first_line, numa_start_y);
int core_skip = (num_cores - (clip_first_line - core) % num_cores) % num_cores;
return clip_first_line + core_skip - first_line;
}
int count_for_thread(int first_line, int count)
{
count = MIN(count, numa_end_y - first_line);
count = min(count, numa_end_y - first_line);
int c = (count - skipped_by_thread(first_line) + num_cores - 1) / num_cores;
return MAX(c, 0);
return max(c, 0);
}
struct Scanline

View file

@ -336,10 +336,10 @@ void BlendColorAdd_Src_One(int y, int x0, int x1, PolyTriangleThreadData* thread
uint32_t srcscale = APART(src);
srcscale += srcscale >> 7;
uint32_t a = MIN<int32_t>((((APART(src) * srcscale) + 127) >> 8) + APART(dst), 255);
uint32_t r = MIN<int32_t>((((RPART(src) * srcscale) + 127) >> 8) + RPART(dst), 255);
uint32_t g = MIN<int32_t>((((GPART(src) * srcscale) + 127) >> 8) + GPART(dst), 255);
uint32_t b = MIN<int32_t>((((BPART(src) * srcscale) + 127) >> 8) + BPART(dst), 255);
uint32_t a = min<int32_t>((((APART(src) * srcscale) + 127) >> 8) + APART(dst), 255);
uint32_t r = min<int32_t>((((RPART(src) * srcscale) + 127) >> 8) + RPART(dst), 255);
uint32_t g = min<int32_t>((((GPART(src) * srcscale) + 127) >> 8) + GPART(dst), 255);
uint32_t b = min<int32_t>((((BPART(src) * srcscale) + 127) >> 8) + BPART(dst), 255);
line[x] = MAKEARGB(a, r, g, b);
}
@ -382,10 +382,10 @@ void BlendColorAdd_SrcCol_One(int y, int x0, int x1, PolyTriangleThreadData* thr
srcscale_g += srcscale_g >> 7;
srcscale_b += srcscale_b >> 7;
uint32_t a = MIN<int32_t>((((APART(src) * srcscale_a) + 127) >> 8) + APART(dst), 255);
uint32_t r = MIN<int32_t>((((RPART(src) * srcscale_r) + 127) >> 8) + RPART(dst), 255);
uint32_t g = MIN<int32_t>((((GPART(src) * srcscale_g) + 127) >> 8) + GPART(dst), 255);
uint32_t b = MIN<int32_t>((((BPART(src) * srcscale_b) + 127) >> 8) + BPART(dst), 255);
uint32_t a = min<int32_t>((((APART(src) * srcscale_a) + 127) >> 8) + APART(dst), 255);
uint32_t r = min<int32_t>((((RPART(src) * srcscale_r) + 127) >> 8) + RPART(dst), 255);
uint32_t g = min<int32_t>((((GPART(src) * srcscale_g) + 127) >> 8) + GPART(dst), 255);
uint32_t b = min<int32_t>((((BPART(src) * srcscale_b) + 127) >> 8) + BPART(dst), 255);
line[x] = MAKEARGB(a, r, g, b);
}
@ -514,10 +514,10 @@ void BlendColorRevSub_Src_One(int y, int x0, int x1, PolyTriangleThreadData* thr
uint32_t srcscale = APART(src);
srcscale += srcscale >> 7;
uint32_t a = MAX<int32_t>(APART(dst) - (((APART(src) * srcscale) + 127) >> 8), 0);
uint32_t r = MAX<int32_t>(RPART(dst) - (((RPART(src) * srcscale) + 127) >> 8), 0);
uint32_t g = MAX<int32_t>(GPART(dst) - (((GPART(src) * srcscale) + 127) >> 8), 0);
uint32_t b = MAX<int32_t>(BPART(dst) - (((BPART(src) * srcscale) + 127) >> 8), 0);
uint32_t a = max<int32_t>(APART(dst) - (((APART(src) * srcscale) + 127) >> 8), 0);
uint32_t r = max<int32_t>(RPART(dst) - (((RPART(src) * srcscale) + 127) >> 8), 0);
uint32_t g = max<int32_t>(GPART(dst) - (((GPART(src) * srcscale) + 127) >> 8), 0);
uint32_t b = max<int32_t>(BPART(dst) - (((BPART(src) * srcscale) + 127) >> 8), 0);
line[x] = MAKEARGB(a, r, g, b);
}

View file

@ -124,7 +124,7 @@ static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
// L = light-pos
// dist = sqrt(dot(L, L))
// distance_attenuation = 1 - MIN(dist * (1/radius), 1)
// distance_attenuation = 1 - min(dist * (1/radius), 1)
__m128 Lx = _mm_sub_ps(lightposX, _mm_loadu_ps(&worldposX[x]));
__m128 Ly = _mm_sub_ps(lightposY, _mm_loadu_ps(&worldposY[x]));
__m128 Lz = _mm_sub_ps(lightposZ, _mm_loadu_ps(&worldposZ[x]));
@ -179,7 +179,7 @@ static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
// L = light-pos
// dist = sqrt(dot(L, L))
// distance_attenuation = 1 - MIN(dist * (1/radius), 1)
// distance_attenuation = 1 - min(dist * (1/radius), 1)
float Lx = lightposX - worldposX[x];
float Ly = lightposY - worldposY[x];
float Lz = lightposZ - worldposZ[x];
@ -191,7 +191,7 @@ static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
float rcp_dist = _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ss(dist2)));
#endif
float dist = dist2 * rcp_dist;
float distance_attenuation = 256.0f - MIN(dist * light_radius, 256.0f);
float distance_attenuation = 256.0f - min(dist * light_radius, 256.0f);
// The simple light type
float simple_attenuation = distance_attenuation;
@ -202,7 +202,7 @@ static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
Ly *= rcp_dist;
Lz *= rcp_dist;
float dotNL = worldnormalX * Lx + worldnormalY * Ly + worldnormalZ * Lz;
float point_attenuation = MAX(dotNL, 0.0f) * distance_attenuation;
float point_attenuation = max(dotNL, 0.0f) * distance_attenuation;
uint32_t attenuation = (uint32_t)(is_attenuated ? (int32_t)point_attenuation : (int32_t)simple_attenuation);
@ -211,9 +211,9 @@ static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
lit_b += (BPART(light_color) * attenuation) >> 8;
}
lit_r = MIN<uint32_t>(lit_r, 255);
lit_g = MIN<uint32_t>(lit_g, 255);
lit_b = MIN<uint32_t>(lit_b, 255);
lit_r = min<uint32_t>(lit_r, 255);
lit_g = min<uint32_t>(lit_g, 255);
lit_b = min<uint32_t>(lit_b, 255);
lightarray[x] = MAKEARGB(lit_a, lit_r, lit_g, lit_b);
// Palette version:
@ -255,7 +255,7 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
uint32_t* lightarray = thread->scanline.lightarray;
for (int x = x0; x < x1; x++)
{
uint32_t l = MIN(lightpos >> 8, 256);
uint32_t l = min(lightpos >> 8, 256);
uint32_t r = vColorR[x];
uint32_t g = vColorG[x];
@ -273,9 +273,9 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
g += (uint32_t)(constants->uDynLightColor.Y * 255.0f);
b += (uint32_t)(constants->uDynLightColor.Z * 255.0f);
r = MIN<uint32_t>(r, 255);
g = MIN<uint32_t>(g, 255);
b = MIN<uint32_t>(b, 255);
r = min<uint32_t>(r, 255);
g = min<uint32_t>(g, 255);
b = min<uint32_t>(b, 255);
}
lightarray[x] = MAKEARGB(a, r, g, b);
@ -287,7 +287,7 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
uint32_t* lightarray = thread->scanline.lightarray;
for (int x = x0; x < x1; x++)
{
uint32_t l = MIN((FRACUNIT - clamp<fixed_t>(shade - MIN(maxvis, lightpos), 0, maxlight)) >> 8, 256);
uint32_t l = min((FRACUNIT - clamp<fixed_t>(shade - min(maxvis, lightpos), 0, maxlight)) >> 8, 256);
uint32_t r = vColorR[x];
uint32_t g = vColorG[x];
uint32_t b = vColorB[x];
@ -304,9 +304,9 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
g += (uint32_t)(constants->uDynLightColor.Y * 255.0f);
b += (uint32_t)(constants->uDynLightColor.Z * 255.0f);
r = MIN<uint32_t>(r, 255);
g = MIN<uint32_t>(g, 255);
b = MIN<uint32_t>(b, 255);
r = min<uint32_t>(r, 255);
g = min<uint32_t>(g, 255);
b = min<uint32_t>(b, 255);
}
lightarray[x] = MAKEARGB(a, r, g, b);
@ -327,7 +327,7 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
uint32_t g = thread->scanline.vColorG[x];
uint32_t b = thread->scanline.vColorB[x];
float fogdist = MAX(16.0f, w[x]);
float fogdist = max(16.0f, w[x]);
float fogfactor = std::exp2(constants->uFogDensity * fogdist);
// brightening around the player for light mode 2:
@ -365,9 +365,9 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
g += (uint32_t)(constants->uDynLightColor.Y * 255.0f);
b += (uint32_t)(constants->uDynLightColor.Z * 255.0f);
r = MIN<uint32_t>(r, 255);
g = MIN<uint32_t>(g, 255);
b = MIN<uint32_t>(b, 255);
r = min<uint32_t>(r, 255);
g = min<uint32_t>(g, 255);
b = min<uint32_t>(b, 255);
}
lightarray[x] = MAKEARGB(a, r, g, b);

View file

@ -291,9 +291,9 @@ static void FuncNormal_AddColor(int x0, int x1, PolyTriangleThreadData* thread)
uint32_t texel = fragcolor[x];
fragcolor[x] = MAKEARGB(
APART(texel),
MIN(r + RPART(texel), (uint32_t)255),
MIN(g + GPART(texel), (uint32_t)255),
MIN(b + BPART(texel), (uint32_t)255));
min(r + RPART(texel), (uint32_t)255),
min(g + GPART(texel), (uint32_t)255),
min(b + BPART(texel), (uint32_t)255));
}
}
@ -309,9 +309,9 @@ static void FuncNormal_AddObjectColor(int x0, int x1, PolyTriangleThreadData* th
uint32_t texel = fragcolor[x];
fragcolor[x] = MAKEARGB(
APART(texel),
MIN((r * RPART(texel)) >> 8, (uint32_t)255),
MIN((g * GPART(texel)) >> 8, (uint32_t)255),
MIN((b * BPART(texel)) >> 8, (uint32_t)255));
min((r * RPART(texel)) >> 8, (uint32_t)255),
min((g * GPART(texel)) >> 8, (uint32_t)255),
min((b * BPART(texel)) >> 8, (uint32_t)255));
}
}
@ -331,9 +331,9 @@ static void FuncNormal_AddObjectColor2(int x0, int x1, PolyTriangleThreadData* t
uint32_t texel = fragcolor[x];
fragcolor[x] = MAKEARGB(
APART(texel),
MIN((r * RPART(texel)) >> 8, (uint32_t)255),
MIN((g * GPART(texel)) >> 8, (uint32_t)255),
MIN((b * BPART(texel)) >> 8, (uint32_t)255));
min((r * RPART(texel)) >> 8, (uint32_t)255),
min((g * GPART(texel)) >> 8, (uint32_t)255),
min((b * BPART(texel)) >> 8, (uint32_t)255));
}
}
@ -473,7 +473,7 @@ static void GetLightColor(int x0, int x1, PolyTriangleThreadData* thread)
mulG += mulG >> 7;
mulB += mulB >> 7;
float fogdist = MAX(16.0f, w[x]);
float fogdist = max(16.0f, w[x]);
float fogfactor = std::exp2(uFogDensity * fogdist);
uint32_t a = (APART(fg) * mulA + 127) >> 8;
@ -512,7 +512,7 @@ static void MainFP(int x0, int x1, PolyTriangleThreadData* thread)
float fogfactor = 0.0f;
if (constants->uFogEnabled != 0)
{
fogdist = MAX(16.0f, w[x]);
fogdist = max(16.0f, w[x]);
fogfactor = std::exp2(constants->uFogDensity * fogdist);
}
frag = vec4(uFogColor.rgb, (1.0 - fogfactor) * frag.a * 0.75 * vColor.a);*/
@ -594,9 +594,9 @@ static void MainFP(int x0, int x1, PolyTriangleThreadData* thread)
b = (BPART(fragcolor[x]) * b + 127) >> 8;
// frag.rgb = frag.rgb + uFogColor.rgb;
r = MIN(r + fogR, (uint32_t)255);
g = MIN(g + fogG, (uint32_t)255);
b = MIN(b + fogB, (uint32_t)255);
r = min(r + fogR, (uint32_t)255);
g = min(g + fogG, (uint32_t)255);
b = min(b + fogB, (uint32_t)255);
fragcolor[x] = MAKEARGB(a, r, g, b);
}

View file

@ -207,17 +207,17 @@ void ScreenTriangle::Draw(const TriDrawTriangleArgs* args, PolyTriangleThreadDat
SortVertices(args, sortedVertices);
int clipleft = thread->clip.left;
int cliptop = MAX(thread->clip.top, thread->numa_start_y);
int cliptop = max(thread->clip.top, thread->numa_start_y);
int clipright = thread->clip.right;
int clipbottom = MIN(thread->clip.bottom, thread->numa_end_y);
int clipbottom = min(thread->clip.bottom, thread->numa_end_y);
int topY = (int)(sortedVertices[0]->y + 0.5f);
int midY = (int)(sortedVertices[1]->y + 0.5f);
int bottomY = (int)(sortedVertices[2]->y + 0.5f);
topY = MAX(topY, cliptop);
midY = MIN(midY, clipbottom);
bottomY = MIN(bottomY, clipbottom);
topY = max(topY, cliptop);
midY = min(midY, clipbottom);
bottomY = min(bottomY, clipbottom);
if (topY >= bottomY)
return;