1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

rsx: Add the glsl files

- Generated from inline strings in GLSLCommon.cpp
This commit is contained in:
kd-11 2023-06-19 23:07:17 +03:00 committed by kd-11
parent 21f5976d35
commit cffcfad42a
10 changed files with 451 additions and 0 deletions

View File

@ -0,0 +1,10 @@
R"(
// Small structures that should be defined before any backend logic
struct sampler_info
{
vec4 scale_bias;
uint remap;
uint flags;
};
)"

View File

@ -0,0 +1,42 @@
R"(
#ifdef _32_BIT_OUTPUT
// Default. Used when we're not utilizing native fp16
#define round_to_8bit(v4) (floor(fma(v4, vec4(255.), vec4(0.5))) / vec4(255.))
#else
// FP16 version
#define round_to_8bit(v4) (floor(fma(v4, f16vec4(255.), f16vec4(0.5))) / f16vec4(255.))
#endif
#ifdef _DISABLE_EARLY_DISCARD
#define kill() _fragment_discard = true
#else
#define kill() discard
#endif
#ifdef _ENABLE_WPOS
vec4 get_wpos()
{
float abs_scale = abs(wpos_scale);
return (gl_FragCoord * vec4(abs_scale, wpos_scale, 1., 1.)) + vec4(0., wpos_bias, 0., 0.);
}
#endif
// Required by all fragment shaders for alpha test
bool comparison_passes(const in float a, const in float b, const in uint func)
{
switch (func)
{
default:
case 0: return false; //never
case 1: return (CMP_FIXUP(a) < CMP_FIXUP(b)); //less
case 2: return (CMP_FIXUP(a) == CMP_FIXUP(b)); //equal
case 3: return (CMP_FIXUP(a) <= CMP_FIXUP(b)); //lequal
case 4: return (CMP_FIXUP(a) > CMP_FIXUP(b)); //greater
case 5: return (CMP_FIXUP(a) != CMP_FIXUP(b)); //nequal
case 6: return (CMP_FIXUP(a) >= CMP_FIXUP(b)); //gequal
case 7: return true; //always
}
}
)"

View File

@ -0,0 +1,69 @@
R"(
#define ZS_READ(index, coord) vec2(texture(TEX_NAME(index), coord).r, float(texture(TEX_NAME_STENCIL(index), coord).x))
#define TEX1D_Z24X8_RGBA8(index, coord1) process_texel(convert_z24x8_to_rgba8(ZS_READ(index, COORD_SCALE1(index, coord1)), texture_parameters[index].remap, TEX_FLAGS(index)), TEX_FLAGS(index))
#define TEX2D_Z24X8_RGBA8(index, coord2) process_texel(convert_z24x8_to_rgba8(ZS_READ(index, COORD_SCALE2(index, coord2)), texture_parameters[index].remap, TEX_FLAGS(index)), TEX_FLAGS(index))
#define TEX3D_Z24X8_RGBA8(index, coord3) process_texel(convert_z24x8_to_rgba8(ZS_READ(index, COORD_SCALE3(index, coord3)), texture_parameters[index].remap, TEX_FLAGS(index)), TEX_FLAGS(index))
// NOTE: Memory layout is fetched as byteswapped BGRA [GBAR] (GOW collection, DS2, DeS)
// The A component (Z) is useless (should contain stencil8 or just 1)
vec4 decode_depth24(const in float depth_value, const in bool depth_float)
{
uint value;
if (!depth_float)
{
value = uint(depth_value * 16777215.);
}
else
{
value = _get_bits(floatBitsToUint(depth_value), 7, 24);
}
uint b = _get_bits(value, 0, 8);
uint g = _get_bits(value, 8, 8);
uint r = _get_bits(value, 16, 8);
const vec4 color = vec4(float(g), float(b) , 1., float(r));
const vec4 scale = vec4(255., 255., 1., 255.);
return color / scale;
}
vec4 remap_vector(const in vec4 color, const in uint remap)
{
vec4 result;
if (_get_bits(remap, 0, 8) == 0xE4)
{
result = color;
}
else
{
uvec4 remap_channel = uvec4(remap) >> uvec4(2, 4, 6, 0);
remap_channel &= 3;
remap_channel = (remap_channel + 3) % 4; // Map A-R-G-B to R-G-B-A
// Generate remapped result
result.a = color[remap_channel.a];
result.r = color[remap_channel.r];
result.g = color[remap_channel.g];
result.b = color[remap_channel.b];
}
if (_get_bits(remap, 8, 8) == 0xAA)
return result;
uvec4 remap_select = uvec4(remap) >> uvec4(10, 12, 14, 8);
remap_select &= 3;
bvec4 choice = lessThan(remap_select, uvec4(2));
return _select(result, vec4(remap_select), choice);
}
vec4 convert_z24x8_to_rgba8(const in vec2 depth_stencil, const in uint remap, const in uint flags)
{
vec4 result = decode_depth24(depth_stencil.x, _test_bit(flags, DEPTH_FLOAT));
result.z = depth_stencil.y / 255.;
if (remap == 0xAAE4)
return result;
return remap_vector(result, remap);
}
)"

View File

@ -0,0 +1,18 @@
R"(
#define ZCOMPARE_FUNC(index) _get_bits(TEX_FLAGS(index), DEPTH_COMPARE, 3)
#define ZS_READ_MS(index, coord) vec2(sampleTexture2DMS(TEX_NAME(index), coord, index).r, float(sampleTexture2DMS(TEX_NAME_STENCIL(index), coord, index).x))
#define TEX2D_MS(index, coord2) process_texel(sampleTexture2DMS(TEX_NAME(index), coord2, index), TEX_FLAGS(index))
#define TEX2D_SHADOW_MS(index, coord3) vec4(comparison_passes(sampleTexture2DMS(TEX_NAME(index), coord3.xy, index).x, coord3.z, ZCOMPARE_FUNC(index)))
#define TEX2D_SHADOWPROJ_MS(index, coord4) TEX2D_SHADOW_MS(index, (coord4.xyz / coord4.w))
#define TEX2D_Z24X8_RGBA8_MS(index, coord2) process_texel(convert_z24x8_to_rgba8(ZS_READ_MS(index, coord2), texture_parameters[index].remap, TEX_FLAGS(index)), TEX_FLAGS(index))\n;
vec3 compute2x2DownsampleWeights(const in float coord, const in float uv_step, const in float actual_step)
{
const float next_sample_point = coord + actual_step;
const float next_coord_step = fma(floor(coord / uv_step), uv_step, uv_step);
const float next_coord_step_plus_one = next_coord_step + uv_step;
vec3 weights = vec3(next_coord_step, min(next_coord_step_plus_one, next_sample_point), max(next_coord_step_plus_one, next_sample_point)) - vec3(coord, next_coord_step, next_coord_step_plus_one);
return weights / actual_step;
}
)"

View File

@ -0,0 +1,94 @@
R"(
vec4 texelFetch2DMS(in _MSAA_SAMPLER_TYPE_ tex, const in vec2 sample_count, const in ivec2 icoords, const in int index, const in ivec2 offset)
{
const vec2 resolve_coords = vec2(icoords + offset);
const vec2 aa_coords = floor(resolve_coords / sample_count); // AA coords = real_coords / sample_count
const vec2 sample_loc = fma(aa_coords, -sample_count, resolve_coords); // Sample ID = real_coords % sample_count
const float sample_index = fma(sample_loc.y, sample_count.y, sample_loc.x);
return texelFetch(tex, ivec2(aa_coords), int(sample_index));
}
vec4 sampleTexture2DMS(in _MSAA_SAMPLER_TYPE_ tex, const in vec2 coords, const in int index)
{
const uint flags = TEX_FLAGS(index);
const vec2 normalized_coords = COORD_SCALE2(index, coords);
const vec2 sample_count = vec2(2., textureSamples(tex) * 0.5);
const vec2 image_size = textureSize(tex) * sample_count;
const ivec2 icoords = ivec2(normalized_coords * image_size);
const vec4 sample0 = texelFetch2DMS(tex, sample_count, icoords, index, ivec2(0));
if (_get_bits(flags, FILTERED_MAG_BIT, 2) == 0)
{
return sample0;
}
// Bilinear scaling, with upto 2x2 downscaling with simple weights
const vec2 uv_step = 1.0 / vec2(image_size);
const vec2 actual_step = vec2(dFdx(normalized_coords.x), dFdy(normalized_coords.y));
const bvec2 no_filter = lessThan(abs(uv_step - actual_step), vec2(0.000001));
if (no_filter.x && no_filter.y)
{
return sample0;
}
vec4 a, b;
float factor;
const vec4 sample2 = texelFetch2DMS(tex, sample_count, icoords, index, ivec2(0, 1)); // Top left
if (no_filter.x)
{
// No scaling, 1:1
a = sample0;
b = sample2;
}
else
{
// Filter required, sample more data
const vec4 sample1 = texelFetch2DMS(tex, sample_count, icoords, index, ivec2(1, 0)); // Bottom right
const vec4 sample3 = texelFetch2DMS(tex, sample_count, icoords, index, ivec2(1, 1)); // Top right
if (actual_step.x > uv_step.x)
{
// Downscale in X, centered
const vec3 weights = compute2x2DownsampleWeights(normalized_coords.x, uv_step.x, actual_step.x);
const vec4 sample4 = texelFetch2DMS(tex, sample_count, icoords, index, ivec2(2, 0)); // Further bottom right
a = fma(sample0, weights.xxxx, sample1 * weights.y) + (sample4 * weights.z); // Weighted sum
if (!no_filter.y)
{
const vec4 sample5 = texelFetch2DMS(tex, sample_count, icoords, index, ivec2(2, 1)); // Further top right
b = fma(sample2, weights.xxxx, sample3 * weights.y) + (sample5 * weights.z); // Weighted sum
}
}
else if (actual_step.x < uv_step.x)
{
// Upscale in X
factor = fract(normalized_coords.x * image_size.x);
a = mix(sample0, sample1, factor);
b = mix(sample2, sample3, factor);
}
}
if (no_filter.y)
{
// 1:1 no scale
return a;
}
else if (actual_step.y > uv_step.y)
{
// Downscale in Y
const vec3 weights = compute2x2DownsampleWeights(normalized_coords.y, uv_step.y, actual_step.y);
// We only have 2 rows computed for performance reasons, so combine rows 1 and 2
return a * weights.x + b * (weights.y + weights.z);
}
else if (actual_step.y < uv_step.y)
{
// Upscale in Y
factor = fract(normalized_coords.y * image_size.y);
return mix(a, b, factor);
}
}
)"

View File

@ -0,0 +1,98 @@
R"(
#ifdef _ENABLE_TEXTURE_EXPAND
uint _texture_flag_override = 0;
#define _enable_texture_expand() _texture_flag_override = SIGN_EXPAND_MASK
#define _disable_texture_expand() _texture_flag_override = 0
#define TEX_FLAGS(index) (texture_parameters[index].flags | _texture_flag_override)
#else
#define TEX_FLAGS(index) texture_parameters[index].flags
#endif
#define TEX_NAME(index) tex##index
#define TEX_NAME_STENCIL(index) tex##index##_stencil
#define COORD_SCALE1(index, coord1) ((coord1 + texture_parameters[index].scale_bias.w) * texture_parameters[index].scale_bias.x)
#define COORD_SCALE2(index, coord2) ((coord2 + texture_parameters[index].scale_bias.w) * texture_parameters[index].scale_bias.xy)
#define COORD_SCALE3(index, coord3) ((coord3 + texture_parameters[index].scale_bias.w) * texture_parameters[index].scale_bias.xyz)
#define TEX1D(index, coord1) process_texel(texture(TEX_NAME(index), COORD_SCALE1(index, coord1)), TEX_FLAGS(index))
#define TEX1D_BIAS(index, coord1, bias) process_texel(texture(TEX_NAME(index), COORD_SCALE1(index, coord1), bias), TEX_FLAGS(index))
#define TEX1D_LOD(index, coord1, lod) process_texel(textureLod(TEX_NAME(index), COORD_SCALE1(index, coord1), lod), TEX_FLAGS(index))
#define TEX1D_GRAD(index, coord1, dpdx, dpdy) process_texel(textureGrad(TEX_NAME(index), COORD_SCALE1(index, coord1), dpdx, dpdy), TEX_FLAGS(index))
#define TEX1D_PROJ(index, coord4) process_texel(textureProj(TEX_NAME(index), vec2(COORD_SCALE1(index, coord4.x), coord4.w)), TEX_FLAGS(index))
#define TEX2D(index, coord2) process_texel(texture(TEX_NAME(index), COORD_SCALE2(index, coord2)), TEX_FLAGS(index))
#define TEX2D_BIAS(index, coord2, bias) process_texel(texture(TEX_NAME(index), COORD_SCALE2(index, coord2), bias), TEX_FLAGS(index))
#define TEX2D_LOD(index, coord2, lod) process_texel(textureLod(TEX_NAME(index), COORD_SCALE2(index, coord2), lod), TEX_FLAGS(index))
#define TEX2D_GRAD(index, coord2, dpdx, dpdy) process_texel(textureGrad(TEX_NAME(index), COORD_SCALE2(index, coord2), dpdx, dpdy), TEX_FLAGS(index))
#define TEX2D_PROJ(index, coord4) process_texel(textureProj(TEX_NAME(index), vec4(COORD_SCALE2(index, coord4.xy), coord4.z, coord4.w)), TEX_FLAGS(index))
#ifdef _EMULATED_TEXSHADOW
#define SHADOW_COORD(index, coord3) vec3(COORD_SCALE2(index, coord3.xy), _test_bit(TEX_FLAGS(index), DEPTH_FLOAT)? coord3.z : min(float(coord3.z), 1.0))
#define SHADOW_COORD4(index, coord4) vec4(SHADOW_COORD(index, coord4.xyz), coord4.w)
#define SHADOW_COORD_PROJ(index, coord4) vec4(COORD_SCALE2(index, coord4.xy), _test_bit(TEX_FLAGS(index), DEPTH_FLOAT)? coord4.z : min(coord4.z, coord4.w), coord4.w)
#define TEX2D_SHADOW(index, coord3) texture(TEX_NAME(index), SHADOW_COORD(index, coord3))
#define TEX3D_SHADOW(index, coord4) texture(TEX_NAME(index), SHADOW_COORD4(index, coord4))
#define TEX2D_SHADOWPROJ(index, coord4) textureProj(TEX_NAME(index), SHADOW_COORD_PROJ(index, coord4))
#else
#define TEX2D_SHADOW(index, coord3) texture(TEX_NAME(index), vec3(COORD_SCALE2(index, coord3.xy), coord3.z))
#define TEX3D_SHADOW(index, coord4) texture(TEX_NAME(index), vec4(COORD_SCALE3(index, coord4.xyz), coord4.w))
#define TEX2D_SHADOWPROJ(index, coord4) textureProj(TEX_NAME(index), vec4(COORD_SCALE2(index, coord4.xy), coord4.zw))
#endif
#define TEX3D(index, coord3) process_texel(texture(TEX_NAME(index), COORD_SCALE3(index, coord3)), TEX_FLAGS(index))
#define TEX3D_BIAS(index, coord3, bias) process_texel(texture(TEX_NAME(index), COORD_SCALE3(index, coord3), bias), TEX_FLAGS(index))
#define TEX3D_LOD(index, coord3, lod) process_texel(textureLod(TEX_NAME(index), COORD_SCALE3(index, coord3), lod), TEX_FLAGS(index))
#define TEX3D_GRAD(index, coord3, dpdx, dpdy) process_texel(textureGrad(TEX_NAME(index), COORD_SCALE3(index, coord3), dpdx, dpdy), TEX_FLAGS(index))
#define TEX3D_PROJ(index, coord4) process_texel(texture(TEX_NAME(index), COORD_SCALE3(index, coord4.xyz) / coord4.w), TEX_FLAGS(index))
vec4 process_texel(in vec4 rgba, const in uint control_bits)
{
if (control_bits == 0)
{
return rgba;
}
if (_test_bit(control_bits, ALPHAKILL))
{
// Alphakill
if (rgba.a < 0.000001)
{
_kill();
return rgba;
}
}
if (_test_bit(control_bits, RENORMALIZE))
{
// Renormalize to 8-bit (PS3) accuracy
rgba = floor(rgba * 255.);
rgba /= 255.;
}
uvec4 mask;
vec4 convert;
uint op_mask = control_bits & uint(SIGN_EXPAND_MASK);
if (op_mask != 0)
{
// Expand to signed normalized
mask = uvec4(op_mask) & uvec4(EXPAND_R_MASK, EXPAND_G_MASK, EXPAND_B_MASK, EXPAND_A_MASK);
convert = (rgba * 2.f - 1.f);
rgba = _select(rgba, convert, notEqual(mask, uvec4(0)));
}
op_mask = control_bits & uint(GAMMA_CTRL_MASK);
if (op_mask != 0u)
{
// Gamma correction
mask = uvec4(op_mask) & uvec4(GAMMA_R_MASK, GAMMA_G_MASK, GAMMA_B_MASK, GAMMA_A_MASK);
convert = srgb_to_linear(rgba);
return _select(rgba, convert, notEqual(mask, uvec4(0)));
}
return rgba;
}
)"

View File

@ -0,0 +1,27 @@
R"(
#define _select mix
#define _saturate(x) clamp(x, 0., 1.)
#define _get_bits(x, off, count) bitfieldExtract(x, off, count)
#define _set_bits(x, y, off, count) bitfieldInsert(x, y, off, count)
#define _test_bit(x, y) (_get_bits(x, y, 1) != 0)
#define _rand(seed) fract(sin(dot(seed.xy, vec2(12.9898f, 78.233f))) * 43758.5453f)
#ifdef _GPU_LOW_PRECISION_COMPARE
#define CMP_FIXUP(a) (sign(a) * 16. + a)
#else
#define CMP_FIXUP(a) (a)
#endif
#ifdef _ENABLE_LIT_EMULATION
vec4 lit_legacy(const in vec4 val)
{
vec4 clamped_val = vec4(max(val.xy, vec2(0.)), val.zw);
return vec4(
1.,
clamped_val.x,
exp2(clamped_val.w * log2(max(clamped_val.y, 0.0000000001))) * sign(clamped_val.x),
1.);
}
#endif
)"

View File

@ -0,0 +1,58 @@
R"(
#ifdef _FORCE_POSITION_INVARIANCE
invariant gl_Position;
#endif
#ifdef _EMULATE_ZCLIP_XFORM_STANDARD
// Technically the depth value here is the 'final' depth that should be stored in the Z buffer.
// Forward mapping eqn is d' = d * (f - n) + n, where d' is the stored Z value (this) and d is the normalized API value.
vec4 apply_zclip_xform(
const in vec4 pos,
const in float near_plane,
const in float far_plane)
{
if (pos.w != 0.0)
{
const float real_n = min(far_plane, near_plane);
const float real_f = max(far_plane, near_plane);
const double depth_range = double(real_f - real_n);
const double inv_range = (depth_range > 0.000001) ? (1.0 / (depth_range * pos.w)) : 0.0;
const double actual_d = (double(pos.z) - double(real_n * pos.w)) * inv_range;
const double nearest_d = floor(actual_d + 0.5);
const double epsilon = (inv_range * pos.w) / 16777215.; // Epsilon value is the minimum discernable change in Z that should affect the stored Z
const double d = _select(actual_d, nearest_d, abs(actual_d - nearest_d) < epsilon);
return vec4(pos.xy, float(d * pos.w), pos.w);
}
else
{
return pos; // Only values where Z=0 can ever pass this clip
}
}
#elif defined(_EMULATE_ZCLIP_XFORM_FALLBACK)
vec4 apply_zclip_xform(
const in vec4 pos,
const in float near_plane,
const in float far_plane)
{
float d = float(pos.z / pos.w);
if (d < 0.f && d >= near_plane)
{
// Clamp
d = 0.f;
}
else if (d > 1.f && d <= far_plane)
{
// Compress Z and store towards highest end of the range
d = min(1., 0.99 + (0.01 * (pos.z - near_plane) / (far_plane - near_plane)));
}
else // This catch-call also handles w=0 since d=inf
{
return pos;
}
return vec4(pos.x, pos.y, d * pos.w, pos.w);
}\n
#endif
)"

View File

@ -904,6 +904,14 @@
<None Include="Emu\RSX\Program\GLSLSnippets\GPUDeswizzle.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\OverlayRenderFS.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\OverlayRenderVS.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXDefines2.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXFragmentPrologue.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXFragmentTextureDepthConversion.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXFragmentTextureMSAAOps.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXFragmentTextureMSAAOpsInternal.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXFragmentTextureOps.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXProgramCommon.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXVertexPrologue.glsl" />
<None Include="Emu\RSX\Program\GLSLSnippets\ShuffleBytes.glsl" />
</ItemGroup>
<PropertyGroup Label="UserMacros" />

View File

@ -85,6 +85,9 @@
<Filter Include="Emu\GPU\RSX\Overlays\HomeMenu\Pages">
<UniqueIdentifier>{017e5a5d-b190-4032-baed-57f8020861a5}</UniqueIdentifier>
</Filter>
<Filter Include="Emu\GPU\RSX\Program\Snippets\RSXProg">
<UniqueIdentifier>{f990b0be-adbd-4a1c-b8c7-d6f963d5b629}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Crypto\aes.cpp">
@ -2403,5 +2406,29 @@
<None Include="Emu\RSX\Program\GLSLSnippets\OverlayRenderFS.glsl">
<Filter>Emu\GPU\RSX\Program\Snippets</Filter>
</None>
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXFragmentPrologue.glsl">
<Filter>Emu\GPU\RSX\Program\Snippets\RSXProg</Filter>
</None>
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXFragmentTextureDepthConversion.glsl">
<Filter>Emu\GPU\RSX\Program\Snippets\RSXProg</Filter>
</None>
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXFragmentTextureOps.glsl">
<Filter>Emu\GPU\RSX\Program\Snippets\RSXProg</Filter>
</None>
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXProgramCommon.glsl">
<Filter>Emu\GPU\RSX\Program\Snippets\RSXProg</Filter>
</None>
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXVertexPrologue.glsl">
<Filter>Emu\GPU\RSX\Program\Snippets\RSXProg</Filter>
</None>
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXFragmentTextureMSAAOps.glsl">
<Filter>Emu\GPU\RSX\Program\Snippets\RSXProg</Filter>
</None>
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXFragmentTextureMSAAOpsInternal.glsl">
<Filter>Emu\GPU\RSX\Program\Snippets\RSXProg</Filter>
</None>
<None Include="Emu\RSX\Program\GLSLSnippets\RSXProg\RSXDefines2.glsl">
<Filter>Emu\GPU\RSX\Program\Snippets\RSXProg</Filter>
</None>
</ItemGroup>
</Project>