summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorPokechu22 <Pokechu022@gmail.com>2021-07-24 15:58:55 -0700
committerPokechu22 <Pokechu022@gmail.com>2021-11-17 20:04:34 -0800
commit9ef228503abe24820985e431ef942c6ebb312442 (patch)
tree2c8385d24e0c684fffa21d5f5abd54acd875827c /Source/Core
parenta273b655661bfc09e5c6a81a681aab3f130699cc (diff)
VideoCommon: Provide raw texdims to shaders
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/VideoCommon/ConstantManager.h2
-rw-r--r--Source/Core/VideoCommon/PixelShaderGen.cpp11
-rw-r--r--Source/Core/VideoCommon/PixelShaderManager.cpp13
-rw-r--r--Source/Core/VideoCommon/UberShaderPixel.cpp9
4 files changed, 17 insertions, 18 deletions
diff --git a/Source/Core/VideoCommon/ConstantManager.h b/Source/Core/VideoCommon/ConstantManager.h
index fe80767112..6046450dec 100644
--- a/Source/Core/VideoCommon/ConstantManager.h
+++ b/Source/Core/VideoCommon/ConstantManager.h
@@ -21,7 +21,7 @@ struct PixelShaderConstants
std::array<int4, 4> colors;
std::array<int4, 4> kcolors;
int4 alpha;
- std::array<float4, 8> texdims;
+ std::array<uint4, 8> texdims;
std::array<int4, 2> zbias;
std::array<int4, 2> indtexscale;
std::array<int4, 6> indtexmtx;
diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp
index 97adb46a97..6f11c605fd 100644
--- a/Source/Core/VideoCommon/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/PixelShaderGen.cpp
@@ -393,7 +393,7 @@ void WritePixelShaderCommonHeader(ShaderCode& out, APIType api_type,
out.Write("\tint4 " I_COLORS "[4];\n"
"\tint4 " I_KCOLORS "[4];\n"
"\tint4 " I_ALPHA ";\n"
- "\tfloat4 " I_TEXDIMS "[8];\n"
+ "\tint4 " I_TEXDIMS "[8];\n"
"\tint4 " I_ZBIAS "[2];\n"
"\tint4 " I_INDTEXSCALE "[2];\n"
"\tint4 " I_INDTEXMTX "[6];\n"
@@ -812,7 +812,7 @@ ShaderCode GeneratePixelShaderCode(APIType api_type, const ShaderHostConfig& hos
{
out.Write("\tint2 fixpoint_uv{} = int2(", i);
out.Write("(tex{}.z == 0.0 ? tex{}.xy : tex{}.xy / tex{}.z)", i, i, i, i);
- out.Write(" * " I_TEXDIMS "[{}].zw);\n", i);
+ out.Write(" * float2(" I_TEXDIMS "[{}].zw * 128));\n", i);
// TODO: S24 overflows here?
}
}
@@ -1436,13 +1436,14 @@ static void SampleTexture(ShaderCode& out, std::string_view texcoords, std::stri
if (api_type == APIType::D3D)
{
- out.Write("iround(255.0 * Tex[{}].Sample(samp[{}], float3({}.xy * " I_TEXDIMS
- "[{}].xy, {}))).{};\n",
+ out.Write("iround(255.0 * Tex[{}].Sample(samp[{}], float3({}.xy / float2(" I_TEXDIMS
+ "[{}].xy * 128), {}))).{};\n",
texmap, texmap, texcoords, texmap, stereo ? "layer" : "0.0", texswap);
}
else
{
- out.Write("iround(255.0 * texture(samp[{}], float3({}.xy * " I_TEXDIMS "[{}].xy, {}))).{};\n",
+ out.Write("iround(255.0 * texture(samp[{}], float3({}.xy / float2(" I_TEXDIMS
+ "[{}].xy * 128), {}))).{};\n",
texmap, texcoords, texmap, stereo ? "layer" : "0.0", texswap);
}
}
diff --git a/Source/Core/VideoCommon/PixelShaderManager.cpp b/Source/Core/VideoCommon/PixelShaderManager.cpp
index 436db9dd50..3a232903af 100644
--- a/Source/Core/VideoCommon/PixelShaderManager.cpp
+++ b/Source/Core/VideoCommon/PixelShaderManager.cpp
@@ -273,16 +273,13 @@ void PixelShaderManager::SetDestAlphaChanged()
void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height)
{
- float rwidth = 1.0f / (width * 128.0f);
- float rheight = 1.0f / (height * 128.0f);
-
// TODO: move this check out to callee. There we could just call this function on texture changes
// or better, use textureSize() in glsl
- if (constants.texdims[texmapid][0] != rwidth || constants.texdims[texmapid][1] != rheight)
+ if (constants.texdims[texmapid][0] != width || constants.texdims[texmapid][1] != height)
dirty = true;
- constants.texdims[texmapid][0] = rwidth;
- constants.texdims[texmapid][1] = rheight;
+ constants.texdims[texmapid][0] = width;
+ constants.texdims[texmapid][1] = height;
}
void PixelShaderManager::SetZTextureBias()
@@ -382,8 +379,8 @@ void PixelShaderManager::SetZTextureOpChanged()
void PixelShaderManager::SetTexCoordChanged(u8 texmapid)
{
TCoordInfo& tc = bpmem.texcoords[texmapid];
- constants.texdims[texmapid][2] = (float)(tc.s.scale_minus_1 + 1) * 128.0f;
- constants.texdims[texmapid][3] = (float)(tc.t.scale_minus_1 + 1) * 128.0f;
+ constants.texdims[texmapid][2] = tc.s.scale_minus_1 + 1;
+ constants.texdims[texmapid][3] = tc.t.scale_minus_1 + 1;
dirty = true;
}
diff --git a/Source/Core/VideoCommon/UberShaderPixel.cpp b/Source/Core/VideoCommon/UberShaderPixel.cpp
index c124a0b5db..833bbe1d0f 100644
--- a/Source/Core/VideoCommon/UberShaderPixel.cpp
+++ b/Source/Core/VideoCommon/UberShaderPixel.cpp
@@ -301,8 +301,8 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
" else\n"
" fixedPoint_uv = fixedPoint_uv >> " I_INDTEXSCALE "[{} >> 1].zw;\n"
"\n"
- " {} = sampleTexture(texmap, float3(float2(fixedPoint_uv) * " I_TEXDIMS
- "[texmap].xy, {})).abg;\n"
+ " {} = sampleTexture(texmap, float3(float2(fixedPoint_uv) / float2(" I_TEXDIMS
+ "[texmap].xy * 128), {})).abg;\n"
"}}",
in_index_name, in_index_name, in_index_name, in_index_name, out_var_name,
stereo ? "float(layer)" : "0.0");
@@ -786,7 +786,7 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
{
out.Write(" int2 fixpoint_uv{} = int2(", i);
out.Write("(tex{}.z == 0.0 ? tex{}.xy : tex{}.xy / tex{}.z)", i, i, i, i);
- out.Write(" * " I_TEXDIMS "[{}].zw);\n", i);
+ out.Write(" * float2(" I_TEXDIMS "[{}].zw * 128));\n", i);
// TODO: S24 overflows here?
}
@@ -910,7 +910,8 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
" uint sampler_num = {};\n",
BitfieldExtract<&TwoTevStageOrders::texmap0>("ss.order"));
out.Write("\n"
- " float2 uv = (float2(tevcoord.xy)) * " I_TEXDIMS "[sampler_num].xy;\n");
+ " float2 uv = (float2(tevcoord.xy)) / float2(" I_TEXDIMS
+ "[sampler_num].xy * 128);\n");
out.Write(" int4 color = sampleTexture(sampler_num, float3(uv, {}));\n",
stereo ? "float(layer)" : "0.0");
out.Write(" uint swap = {};\n",