UberShaderPixel: Fix sampling of EFB copies in stereo modes

This commit is contained in:
Stenzek 2017-08-20 18:02:31 +10:00
parent 8d7f28e79b
commit a7f217c3f4
1 changed files with 37 additions and 38 deletions

View File

@ -182,17 +182,16 @@ ShaderCode GenPixelShader(APIType ApiType, const ShaderHostConfig& host_config,
{ {
// Doesn't look like directx supports this. Oh well the code path is here just incase it // Doesn't look like directx supports this. Oh well the code path is here just incase it
// supports this in the future. // supports this in the future.
out.Write("int4 sampleTexture(uint sampler_num, float2 uv) {\n"); out.Write("int4 sampleTexture(uint sampler_num, float3 uv) {\n");
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan) if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
out.Write(" return iround(texture(samp[sampler_num], float3(uv, 0.0)) * 255.0);\n"); out.Write(" return iround(texture(samp[sampler_num], uv) * 255.0);\n");
else if (ApiType == APIType::D3D) else if (ApiType == APIType::D3D)
out.Write(" return iround(Tex[sampler_num].Sample(samp[sampler_num], float3(uv, 0.0)) * " out.Write(" return iround(Tex[sampler_num].Sample(samp[sampler_num], uv) * 255.0);\n");
"255.0);\n");
out.Write("}\n\n"); out.Write("}\n\n");
} }
else else
{ {
out.Write("int4 sampleTexture(uint sampler_num, float2 uv) {\n" out.Write("int4 sampleTexture(uint sampler_num, float3 uv) {\n"
" // This is messy, but DirectX, OpenGl 3.3 and Opengl ES 3.0 doesn't support " " // This is messy, but DirectX, OpenGl 3.3 and Opengl ES 3.0 doesn't support "
"dynamic indexing of the sampler array\n" "dynamic indexing of the sampler array\n"
" // With any luck the shader compiler will optimise this if the hardware supports " " // With any luck the shader compiler will optimise this if the hardware supports "
@ -201,10 +200,9 @@ ShaderCode GenPixelShader(APIType ApiType, const ShaderHostConfig& host_config,
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan) if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
out.Write(" case %du: return iround(texture(samp[%d], float3(uv, 0.0)) * 255.0);\n", i, i); out.Write(" case %du: return iround(texture(samp[%d], uv) * 255.0);\n", i, i);
else if (ApiType == APIType::D3D) else if (ApiType == APIType::D3D)
out.Write(" case %du: return iround(Tex[%d].Sample(samp[%d], float3(uv, 0.0)) * 255.0);\n", out.Write(" case %du: return iround(Tex[%d].Sample(samp[%d], uv) * 255.0);\n", i, i, i);
i, i, i);
} }
out.Write(" }\n" out.Write(" }\n"
"}\n\n"); "}\n\n");
@ -244,31 +242,33 @@ ShaderCode GenPixelShader(APIType ApiType, const ShaderHostConfig& host_config,
// ====================== // ======================
// Indirect Lookup // Indirect Lookup
// ====================== // ======================
auto LookupIndirectTexture = [&out](const char* out_var_name, const char* in_index_name) { auto LookupIndirectTexture = [&out, stereo](const char* out_var_name, const char* in_index_name) {
out.Write( out.Write("{\n"
"{\n" " uint iref = bpmem_iref(%s);\n"
" uint iref = bpmem_iref(%s);\n" " if ( iref != 0u)\n"
" if ( iref != 0u)\n" " {\n"
" {\n" " uint texcoord = bitfieldExtract(iref, 0, 3);\n"
" uint texcoord = bitfieldExtract(iref, 0, 3);\n" " uint texmap = bitfieldExtract(iref, 8, 3);\n"
" uint texmap = bitfieldExtract(iref, 8, 3);\n" " float3 uv = getTexCoord(texcoord);\n"
" float3 uv = getTexCoord(texcoord);\n" " int2 fixedPoint_uv = int2((uv.z == 0.0 ? uv.xy : (uv.xy / uv.z)) * " I_TEXDIMS
" int2 fixedPoint_uv = int2((uv.z == 0.0 ? uv.xy : (uv.xy / uv.z)) * " I_TEXDIMS "[texcoord].zw);\n"
"[texcoord].zw);\n" "\n"
"\n" " if ((%s & 1u) == 0u)\n"
" if ((%s & 1u) == 0u)\n" " fixedPoint_uv = fixedPoint_uv >> " I_INDTEXSCALE "[%s >> 1].xy;\n"
" fixedPoint_uv = fixedPoint_uv >> " I_INDTEXSCALE "[%s >> 1].xy;\n" " else\n"
" else\n" " fixedPoint_uv = fixedPoint_uv >> " I_INDTEXSCALE "[%s >> 1].zw;\n"
" fixedPoint_uv = fixedPoint_uv >> " I_INDTEXSCALE "[%s >> 1].zw;\n" "\n"
"\n" " %s = sampleTexture(texmap, float3(float2(fixedPoint_uv) * " I_TEXDIMS
" %s = sampleTexture(texmap, float2(fixedPoint_uv) * " I_TEXDIMS "[texmap].xy).abg;\n" "[texmap].xy, %s)).abg;\n",
" }\n" in_index_name, in_index_name, in_index_name, in_index_name, out_var_name,
" else\n" stereo ? "float(layer)" : "0.0");
" {\n" out.Write(" }\n"
" %s = int3(0, 0, 0);\n" " else\n"
" }\n" " {\n"
"}\n", " %s = int3(0, 0, 0);\n"
in_index_name, in_index_name, in_index_name, in_index_name, out_var_name, out_var_name); " }\n"
"}\n",
out_var_name);
}; };
// ====================== // ======================
@ -837,11 +837,10 @@ ShaderCode GenPixelShader(APIType ApiType, const ShaderHostConfig& host_config,
" uint sampler_num = %s;\n", " uint sampler_num = %s;\n",
BitfieldExtract("ss.order", TwoTevStageOrders().texmap0).c_str()); BitfieldExtract("ss.order", TwoTevStageOrders().texmap0).c_str());
out.Write("\n" out.Write("\n"
" float2 uv = (float2(tevcoord.xy)) * " I_TEXDIMS "[sampler_num].xy;\n" " float2 uv = (float2(tevcoord.xy)) * " I_TEXDIMS "[sampler_num].xy;\n");
"\n" out.Write(" int4 color = sampleTexture(sampler_num, float3(uv, %s));\n",
" int4 color = sampleTexture(sampler_num, uv);\n" stereo ? "float(layer)" : "0.0");
"\n" out.Write(" uint swap = %s;\n",
" uint swap = %s;\n",
BitfieldExtract("ss.ac", TevStageCombiner().alphaC.tswap).c_str()); BitfieldExtract("ss.ac", TevStageCombiner().alphaC.tswap).c_str());
out.Write(" s.TexColor = Swizzle(swap, color);\n"); out.Write(" s.TexColor = Swizzle(swap, color);\n");
out.Write(" } else {\n" out.Write(" } else {\n"