summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2015-05-06 22:42:06 +0200
committerJules Blok <jules.blok@gmail.com>2015-05-08 14:32:16 +0200
commit0f2c72f0f844c219e168faa7de8dd515f8723fdc (patch)
tree5b05c1fc8ea173688cf0a2945dc1cc5c9743fe2d /Source/Core
parentb0770e2a0c2e391139db1365ca3658ada0f87da0 (diff)
VideoCommon: Clamp integer conversions.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/VideoBackends/D3D/PixelShaderCache.cpp4
-rw-r--r--Source/Core/VideoBackends/OGL/TextureCache.cpp2
-rw-r--r--Source/Core/VideoCommon/TextureConversionShader.cpp10
3 files changed, 8 insertions, 8 deletions
diff --git a/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp b/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp
index b6bbff313b..eef2fdbe7a 100644
--- a/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp
+++ b/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp
@@ -146,7 +146,7 @@ const char depth_matrix_program[] = {
" in float4 pos : SV_Position,\n"
" in float3 uv0 : TEXCOORD0){\n"
" float4 texcol = Tex0.Sample(samp0,uv0);\n"
- " int depth = int(floor(texcol.x * 16777216.0));\n"
+ " int depth = clamp(int(texcol.x * 16777216.0), 0, 0xFFFFFF);\n"
// Convert to Z24 format
" int4 workspace;\n"
@@ -180,7 +180,7 @@ const char depth_matrix_program_msaa[] = {
" for(int i = 0; i < SAMPLES; ++i)\n"
" texcol += Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), i);\n"
" texcol /= SAMPLES;\n"
- " int depth = int(floor(texcol.x * 16777216.0));\n"
+ " int depth = clamp(int(texcol.x * 16777216.0), 0, 0xFFFFFF);\n"
// Convert to Z24 format
" int4 workspace;\n"
diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp
index a904ca64af..177d33432d 100644
--- a/Source/Core/VideoBackends/OGL/TextureCache.cpp
+++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp
@@ -294,7 +294,7 @@ void TextureCache::CompileShaders()
"\n"
"void main(){\n"
" vec4 texcol = texture(samp9, vec3(f_uv0.xy, %s));\n"
- " int depth = int(floor(texcol.x * 16777216.0));\n"
+ " int depth = clamp(int(texcol.x * 16777216.0), 0, 0xFFFFFF);\n"
// Convert to Z24 format
" ivec4 workspace;\n"
diff --git a/Source/Core/VideoCommon/TextureConversionShader.cpp b/Source/Core/VideoCommon/TextureConversionShader.cpp
index 18e5c258c0..844710c3ee 100644
--- a/Source/Core/VideoCommon/TextureConversionShader.cpp
+++ b/Source/Core/VideoCommon/TextureConversionShader.cpp
@@ -487,7 +487,7 @@ static void WriteZ16Encoder(char*& p,API_TYPE ApiType)
WriteSampleColor(p, "r", "depth", 0, ApiType);
- WRITE(p, " depth *= 16777216.0;\n");
+ WRITE(p, " depth = clamp(depth * 16777216.0, 0, 0xFFFFFF);\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
WRITE(p, " depth -= expanded.r * 256.0 * 256.0;\n");
WRITE(p, " expanded.g = floor(depth / 256.0);\n");
@@ -497,7 +497,7 @@ static void WriteZ16Encoder(char*& p,API_TYPE ApiType)
WriteSampleColor(p, "r", "depth", 1, ApiType);
- WRITE(p, " depth *= 16777216.0;\n");
+ WRITE(p, " depth = clamp(depth * 16777216.0, 0, 0xFFFFFF);\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
WRITE(p, " depth -= expanded.r * 256.0 * 256.0;\n");
WRITE(p, " expanded.g = floor(depth / 256.0);\n");
@@ -519,7 +519,7 @@ static void WriteZ16LEncoder(char*& p,API_TYPE ApiType)
WriteSampleColor(p, "r", "depth", 0, ApiType);
- WRITE(p, " depth *= 16777216.0;\n");
+ WRITE(p, " depth = clamp(depth * 16777216.0, 0, 0xFFFFFF);\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
WRITE(p, " depth -= expanded.r * 256.0 * 256.0;\n");
WRITE(p, " expanded.g = floor(depth / 256.0);\n");
@@ -531,7 +531,7 @@ static void WriteZ16LEncoder(char*& p,API_TYPE ApiType)
WriteSampleColor(p, "r", "depth", 1, ApiType);
- WRITE(p, " depth *= 16777216.0;\n");
+ WRITE(p, " depth = clamp(depth * 16777216.0, 0, 0xFFFFFF);\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
WRITE(p, " depth -= expanded.r * 256.0 * 256.0;\n");
WRITE(p, " expanded.g = floor(depth / 256.0);\n");
@@ -558,7 +558,7 @@ static void WriteZ24Encoder(char*& p, API_TYPE ApiType)
for (int i = 0; i < 2; i++)
{
- WRITE(p, " depth%i *= 16777216.0;\n", i);
+ WRITE(p, " depth%i = clamp(depth%i * 16777216.0, 0, 0xFFFFFF);\n", i, i);
WRITE(p, " expanded%i.r = floor(depth%i / (256.0 * 256.0));\n", i, i);
WRITE(p, " depth%i -= expanded%i.r * 256.0 * 256.0;\n", i, i);