vk: Fix shader compiler issues caused by broken preprocessor macro expansion

This commit is contained in:
kd-11
2025-08-17 19:25:30 +03:00
committed by kd-11
parent 87677cfc85
commit 51e1ff4976
4 changed files with 29 additions and 22 deletions
@@ -553,7 +553,7 @@ void main()
ur1 = (1u << ur1); // address mask ur1 = (1u << ur1); // address mask
uvr0.x = (ur0 >> 7u); // address to uvec4 row (each row has 32x4 bits) uvr0.x = (ur0 >> 7u); // address to uvec4 row (each row has 32x4 bits)
#ifdef VULKAN #ifdef VULKAN
uvr0.x += fs_stipple_pattern_array_offset; // Address base offset. Only applies to vulkan. uvr0.x += _fs_stipple_pattern_array_offset; // Address base offset. Only applies to vulkan.
#endif #endif
ur0 = (ur0 >> 5u) & 3u; // address to uvec4 word (address / 32) % 4 ur0 = (ur0 >> 5u) & 3u; // address to uvec4 word (address / 32) % 4
@@ -9,7 +9,7 @@ R"(
const uint bit_offset = (address & 31u); const uint bit_offset = (address & 31u);
#ifdef VULKAN #ifdef VULKAN
// In vulkan we have a unified array with a dynamic offset // In vulkan we have a unified array with a dynamic offset
const uint word_index = _get_bits(address, 7, 3) + fs_stipple_pattern_array_offset; const uint word_index = _get_bits(address, 7, 3) + _fs_stipple_pattern_array_offset;
#else #else
const uint word_index = _get_bits(address, 7, 3); const uint word_index = _get_bits(address, 7, 3);
#endif #endif
+17 -14
View File
@@ -251,11 +251,12 @@ void VKFragmentDecompilerThread::insertConstants(std::stringstream & OS)
" draw_parameters_t draw_parameters[];\n" " draw_parameters_t draw_parameters[];\n"
"};\n\n" "};\n\n"
"#define get_draw_params() draw_parameters[draw_parameters_offset]\n" "draw_parameters_t get_draw_params() { return draw_parameters[draw_parameters_offset]; }\n\n"
"#define fs_constants_offset get_draw_params().fs_constants_offset\n"
"#define fs_context_offset get_draw_params().fs_context_offset\n" "#define _fs_constants_offset get_draw_params().fs_constants_offset\n"
"#define fs_texture_base_index get_draw_params().fs_texture_base_index\n" "#define _fs_context_offset get_draw_params().fs_context_offset\n"
"#define fs_stipple_pattern_array_offset get_draw_params().fs_stipple_pattern_offset\n\n"; "#define _fs_texture_base_index get_draw_params().fs_texture_base_index\n"
"#define _fs_stipple_pattern_array_offset get_draw_params().fs_stipple_pattern_offset\n\n";
if (!properties.constant_offsets.empty()) if (!properties.constant_offsets.empty())
{ {
@@ -263,7 +264,7 @@ void VKFragmentDecompilerThread::insertConstants(std::stringstream & OS)
OS << "{\n"; OS << "{\n";
OS << " vec4 fc[];\n"; OS << " vec4 fc[];\n";
OS << "};\n"; OS << "};\n";
OS << "#define _fetch_constant(x) fc[x + fs_constants_offset]\n\n"; OS << "#define _fetch_constant(x) fc[x + _fs_constants_offset]\n\n";
} }
OS << OS <<
@@ -341,19 +342,20 @@ void VKFragmentDecompilerThread::insertGlobalFunctions(std::stringstream &OS)
if (m_shader_props.require_fog_read) if (m_shader_props.require_fog_read)
{ {
OS << OS <<
"#define fog_param0 fs_contexts[fs_context_offset].fog_param0\n" "#define fog_param0 fs_contexts[_fs_context_offset].fog_param0\n"
"#define fog_param1 fs_contexts[fs_context_offset].fog_param1\n" "#define fog_param1 fs_contexts[_fs_context_offset].fog_param1\n"
"#define fog_mode fs_contexts[fs_context_offset].fog_mode\n\n"; "#define fog_mode fs_contexts[_fs_context_offset].fog_mode\n\n";
} }
if (m_shader_props.require_wpos) if (m_shader_props.require_wpos)
{ {
OS << OS <<
"#define wpos_scale fs_contexts[fs_context_offset].wpos_scale\n" "#define wpos_scale fs_contexts[_fs_context_offset].wpos_scale\n"
"#define wpos_bias fs_contexts[fs_context_offset].wpos_bias\n\n"; "#define wpos_bias fs_contexts[_fs_context_offset].wpos_bias\n\n";
} }
OS << "#define texture_base_index fs_texture_base_index\n\n"; OS <<
"#define texture_base_index _fs_texture_base_index\n\n";
glsl::insert_glsl_legacy_function(OS, m_shader_props); glsl::insert_glsl_legacy_function(OS, m_shader_props);
} }
@@ -448,9 +450,10 @@ void VKFragmentDecompilerThread::insertMainEnd(std::stringstream & OS)
OS << "void main()\n"; OS << "void main()\n";
OS << "{\n"; OS << "{\n";
// FIXME: Workaround
OS << OS <<
" const uint rop_control = fs_contexts[fs_context_offset].rop_control;\n" " const uint rop_control = fs_contexts[_fs_context_offset].rop_control;\n"
" const float alpha_ref = fs_contexts[fs_context_offset].alpha_ref;\n\n"; " const float alpha_ref = fs_contexts[_fs_context_offset].alpha_ref;\n\n";
::glsl::insert_rop_init(OS); ::glsl::insert_rop_init(OS);
+10 -6
View File
@@ -178,11 +178,11 @@ namespace vk
comp.insertConstants(builder); comp.insertConstants(builder);
builder << builder <<
"#define fog_param0 fs_contexts[fs_context_offset].fog_param0\n" "#define fog_param0 fs_contexts[_fs_context_offset].fog_param0\n"
"#define fog_param1 fs_contexts[fs_context_offset].fog_param1\n" "#define fog_param1 fs_contexts[_fs_context_offset].fog_param1\n"
"#define fog_mode fs_contexts[fs_context_offset].fog_mode\n" "#define fog_mode fs_contexts[_fs_context_offset].fog_mode\n"
"#define wpos_scale fs_contexts[fs_context_offset].wpos_scale\n" "#define wpos_scale fs_contexts[_fs_context_offset].wpos_scale\n"
"#define wpos_bias fs_contexts[fs_context_offset].wpos_bias\n\n"; "#define wpos_bias fs_contexts[_fs_context_offset].wpos_bias\n\n";
if (compiler_options & program_common::interpreter::COMPILER_OPT_ENABLE_ALPHA_TEST_GE) if (compiler_options & program_common::interpreter::COMPILER_OPT_ENABLE_ALPHA_TEST_GE)
{ {
@@ -260,7 +260,7 @@ namespace vk
"#define SAMPLER2D(index) sampler2D_array[index]\n" "#define SAMPLER2D(index) sampler2D_array[index]\n"
"#define SAMPLER3D(index) sampler3D_array[index]\n" "#define SAMPLER3D(index) sampler3D_array[index]\n"
"#define SAMPLERCUBE(index) samplerCube_array[index]\n" "#define SAMPLERCUBE(index) samplerCube_array[index]\n"
"#define texture_base_index fs_texture_base_index\n\n"; "#define texture_base_index _fs_texture_base_index\n\n";
} }
builder << builder <<
@@ -273,6 +273,10 @@ namespace vk
" uvec4 fp_instructions[];\n" " uvec4 fp_instructions[];\n"
"};\n\n"; "};\n\n";
builder <<
" uint rop_control = fs_contexts[_fs_context_offset].rop_control;\n"
" float alpha_ref = fs_contexts[_fs_context_offset].alpha_ref;\n\n";
builder << program_common::interpreter::get_fragment_interpreter(); builder << program_common::interpreter::get_fragment_interpreter();
const std::string s = builder.str(); const std::string s = builder.str();