rsx: Do not emit format conversion code in shaders if the feature is unused
- The sampling logic has become increasingly complex yet it is needed very rarely
This commit is contained in:
@@ -237,6 +237,7 @@ void GLFragmentDecompilerThread::insertGlobalFunctions(std::stringstream &OS)
|
|||||||
m_shader_props.require_tex3D_ops = properties.has_tex3D;
|
m_shader_props.require_tex3D_ops = properties.has_tex3D;
|
||||||
m_shader_props.require_shadowProj_ops = properties.shadow_sampler_mask != 0 && properties.has_texShadowProj;
|
m_shader_props.require_shadowProj_ops = properties.shadow_sampler_mask != 0 && properties.has_texShadowProj;
|
||||||
m_shader_props.require_alpha_kill = !!(m_prog.ctrl & RSX_SHADER_CONTROL_TEXTURE_ALPHA_KILL);
|
m_shader_props.require_alpha_kill = !!(m_prog.ctrl & RSX_SHADER_CONTROL_TEXTURE_ALPHA_KILL);
|
||||||
|
m_shader_props.require_color_format_convert = !!(m_prog.ctrl & RSX_SHADER_CONTROL_TEXTURE_FORMAT_CONVERT);
|
||||||
|
|
||||||
glsl::insert_glsl_legacy_function(OS, m_shader_props);
|
glsl::insert_glsl_legacy_function(OS, m_shader_props);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -408,6 +408,11 @@ namespace glsl
|
|||||||
enabled_options.push_back("_ENABLE_TEXTURE_ALPHA_KILL");
|
enabled_options.push_back("_ENABLE_TEXTURE_ALPHA_KILL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props.require_color_format_convert)
|
||||||
|
{
|
||||||
|
enabled_options.push_back("_ENABLE_FORMAT_CONVERSION");
|
||||||
|
}
|
||||||
|
|
||||||
program_common::define_glsl_switches(OS, enabled_options);
|
program_common::define_glsl_switches(OS, enabled_options);
|
||||||
enabled_options.clear();
|
enabled_options.clear();
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,10 @@ R"(
|
|||||||
_texture_bx2_active = false; \
|
_texture_bx2_active = false; \
|
||||||
} while (false)
|
} while (false)
|
||||||
#define TEX_FLAGS(index) ((TEX_PARAM(index).flags & ~(_texture_flag_erase)) | _texture_flag_override)
|
#define TEX_FLAGS(index) ((TEX_PARAM(index).flags & ~(_texture_flag_erase)) | _texture_flag_override)
|
||||||
#else
|
#elif defined(_ENABLE_TEXTURE_ALPHA_KILL) || defined(_ENABLE_FORMAT_CONVERSION)
|
||||||
#define TEX_FLAGS(index) (TEX_PARAM(index).flags)
|
#define TEX_FLAGS(index) (TEX_PARAM(index).flags)
|
||||||
|
#else
|
||||||
|
#define TEX_FLAGS(index) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TEX_NAME(index) tex##index
|
#define TEX_NAME(index) tex##index
|
||||||
@@ -193,6 +195,8 @@ vec4 _texcoord_xform_shadow(const in vec4 coord4, const in sampler_info params)
|
|||||||
|
|
||||||
#endif // _EMULATE_SHADOW
|
#endif // _EMULATE_SHADOW
|
||||||
|
|
||||||
|
#ifdef _ENABLE_FORMAT_CONVERSION
|
||||||
|
|
||||||
vec4 _sext_unorm8x4(const in vec4 x)
|
vec4 _sext_unorm8x4(const in vec4 x)
|
||||||
{
|
{
|
||||||
// TODO: Handle clamped sign-extension
|
// TODO: Handle clamped sign-extension
|
||||||
@@ -285,4 +289,27 @@ vec4 _process_texel(in vec4 rgba, const in uint control_bits)
|
|||||||
return rgba;
|
return rgba;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif defined(_ENABLE_TEXTURE_ALPHA_KILL)
|
||||||
|
|
||||||
|
vec4 _process_texel(in vec4 rgba, const in uint control_bits)
|
||||||
|
{
|
||||||
|
if (_test_bit(control_bits, ALPHAKILL))
|
||||||
|
{
|
||||||
|
// Alphakill
|
||||||
|
if (rgba.a < 0.000001)
|
||||||
|
{
|
||||||
|
_kill();
|
||||||
|
return rgba;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rgba;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define _process_texel(rgba, control) rgba
|
||||||
|
|
||||||
|
#endif // _ENABLE_FORMAT_CONVERSION
|
||||||
|
|
||||||
)"
|
)"
|
||||||
|
|||||||
@@ -60,5 +60,6 @@ namespace glsl
|
|||||||
bool require_tex3D_ops : 1; // Include 3D texture stuff (including cubemap)
|
bool require_tex3D_ops : 1; // Include 3D texture stuff (including cubemap)
|
||||||
bool require_shadowProj_ops : 1; // Include shadow2DProj projection textures (1D is unsupported anyway)
|
bool require_shadowProj_ops : 1; // Include shadow2DProj projection textures (1D is unsupported anyway)
|
||||||
bool require_alpha_kill : 1; // Include alpha kill checking code
|
bool require_alpha_kill : 1; // Include alpha kill checking code
|
||||||
|
bool require_color_format_convert : 1; // Include colorspace conversion code
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2315,6 +2315,7 @@ namespace rsx
|
|||||||
case CELL_GCM_TEXTURE_R5G6B5:
|
case CELL_GCM_TEXTURE_R5G6B5:
|
||||||
case CELL_GCM_TEXTURE_R6G5B5:
|
case CELL_GCM_TEXTURE_R6G5B5:
|
||||||
texture_control |= (1 << texture_control_bits::RENORMALIZE);
|
texture_control |= (1 << texture_control_bits::RENORMALIZE);
|
||||||
|
current_fragment_program.ctrl |= RSX_SHADER_CONTROL_TEXTURE_FORMAT_CONVERT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -2326,8 +2327,15 @@ namespace rsx
|
|||||||
texture_control |= format_ex.texel_remap_control;
|
texture_control |= format_ex.texel_remap_control;
|
||||||
texture_control |= format_ex.features << texture_control_bits::FORMAT_FEATURES_OFFSET;
|
texture_control |= format_ex.features << texture_control_bits::FORMAT_FEATURES_OFFSET;
|
||||||
|
|
||||||
|
if (format_ex.texel_remap_control)
|
||||||
|
{
|
||||||
|
current_fragment_program.ctrl |= RSX_SHADER_CONTROL_TEXTURE_FORMAT_CONVERT;
|
||||||
|
}
|
||||||
|
|
||||||
if (current_fp_metadata.bx2_texture_reads_mask)
|
if (current_fp_metadata.bx2_texture_reads_mask)
|
||||||
{
|
{
|
||||||
|
current_fragment_program.ctrl |= RSX_SHADER_CONTROL_TEXTURE_FORMAT_CONVERT;
|
||||||
|
|
||||||
const u32 remap_hi = tex.decoded_remap().shuffle_mask_bits(0xFu);
|
const u32 remap_hi = tex.decoded_remap().shuffle_mask_bits(0xFu);
|
||||||
current_fragment_program.texture_params[i].remap &= ~(0xFu << 16u);
|
current_fragment_program.texture_params[i].remap &= ~(0xFu << 16u);
|
||||||
current_fragment_program.texture_params[i].remap |= (remap_hi << 16u);
|
current_fragment_program.texture_params[i].remap |= (remap_hi << 16u);
|
||||||
|
|||||||
@@ -336,6 +336,7 @@ void VKFragmentDecompilerThread::insertGlobalFunctions(std::stringstream &OS)
|
|||||||
m_shader_props.require_tex3D_ops = properties.has_tex3D;
|
m_shader_props.require_tex3D_ops = properties.has_tex3D;
|
||||||
m_shader_props.require_shadowProj_ops = properties.shadow_sampler_mask != 0 && properties.has_texShadowProj;
|
m_shader_props.require_shadowProj_ops = properties.shadow_sampler_mask != 0 && properties.has_texShadowProj;
|
||||||
m_shader_props.require_alpha_kill = !!(m_prog.ctrl & RSX_SHADER_CONTROL_TEXTURE_ALPHA_KILL);
|
m_shader_props.require_alpha_kill = !!(m_prog.ctrl & RSX_SHADER_CONTROL_TEXTURE_ALPHA_KILL);
|
||||||
|
m_shader_props.require_color_format_convert = !!(m_prog.ctrl & RSX_SHADER_CONTROL_TEXTURE_FORMAT_CONVERT);
|
||||||
|
|
||||||
// Declare global constants
|
// Declare global constants
|
||||||
if (m_shader_props.require_fog_read)
|
if (m_shader_props.require_fog_read)
|
||||||
|
|||||||
@@ -468,6 +468,8 @@ namespace gcm
|
|||||||
|
|
||||||
RSX_SHADER_CONTROL_DISABLE_EARLY_Z = 0x2000000, // Do not allow early-Z optimizations on this shader
|
RSX_SHADER_CONTROL_DISABLE_EARLY_Z = 0x2000000, // Do not allow early-Z optimizations on this shader
|
||||||
|
|
||||||
|
RSX_SHADER_CONTROL_TEXTURE_FORMAT_CONVERT = 0x4000000, // Allow format conversions (BX2, SNORM, SRGB, RENORM)
|
||||||
|
|
||||||
// Meta
|
// Meta
|
||||||
RSX_SHADER_CONTROL_META_USES_DISCARD = (RSX_SHADER_CONTROL_USES_KIL | RSX_SHADER_CONTROL_TEXTURE_ALPHA_KILL | RSX_SHADER_CONTROL_ALPHA_TEST | RSX_SHADER_CONTROL_POLYGON_STIPPLE | RSX_SHADER_CONTROL_ALPHA_TO_COVERAGE)
|
RSX_SHADER_CONTROL_META_USES_DISCARD = (RSX_SHADER_CONTROL_USES_KIL | RSX_SHADER_CONTROL_TEXTURE_ALPHA_KILL | RSX_SHADER_CONTROL_ALPHA_TEST | RSX_SHADER_CONTROL_POLYGON_STIPPLE | RSX_SHADER_CONTROL_ALPHA_TO_COVERAGE)
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user