VideoCommon: Provide raw texdims to shaders
This commit is contained in:
parent
a273b65566
commit
9ef228503a
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue