Merge pull request #5946 from stenzek/ubershader-stereo-texture-samples

UberShaderPixel: Fix sampling of EFB copies in stereo modes
This commit is contained in:
Jules Blok 2017-09-03 12:26:52 +02:00 committed by GitHub
commit 75574ec6cc
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,9 +242,8 @@ 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"
@ -261,14 +258,17 @@ ShaderCode GenPixelShader(APIType ApiType, const ShaderHostConfig& host_config,
" 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, float2(fixedPoint_uv) * " I_TEXDIMS "[texmap].xy).abg;\n" " %s = sampleTexture(texmap, float3(float2(fixedPoint_uv) * " I_TEXDIMS
" }\n" "[texmap].xy, %s)).abg;\n",
in_index_name, in_index_name, in_index_name, in_index_name, out_var_name,
stereo ? "float(layer)" : "0.0");
out.Write(" }\n"
" else\n" " else\n"
" {\n" " {\n"
" %s = int3(0, 0, 0);\n" " %s = int3(0, 0, 0);\n"
" }\n" " }\n"
"}\n", "}\n",
in_index_name, in_index_name, in_index_name, in_index_name, out_var_name, out_var_name); 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"