Skip to content

Commit c3bc3ad

Browse files
committed
Updated spirv-cross.
1 parent 1687187 commit c3bc3ad

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

3rdparty/spirv-cross/main.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ struct CLIArguments
682682
bool msl_readwrite_texture_fences = true;
683683
bool msl_agx_manual_cube_grad_fixup = false;
684684
bool msl_input_attachment_is_ds_attachment = false;
685+
bool msl_disable_rasterization = false;
686+
bool msl_auto_disable_rasterization = false;
685687
const char *msl_combined_sampler_suffix = nullptr;
686688
bool glsl_emit_push_constant_as_ubo = false;
687689
bool glsl_emit_ubo_as_plain_uniforms = false;
@@ -983,7 +985,9 @@ static void print_help_msl()
983985
"\t\tAll released Apple Silicon GPUs to date ignore one of the three partial derivatives\n"
984986
"\t\tbased on the selected major axis, and expect the remaining derivatives to be\n"
985987
"\t\tpartially transformed. This fixup gives correct results on Apple Silicon.\n"
986-
"\t[--msl-combined-sampler-suffix <suffix>]:\n\t\tUses a custom suffix for combined samplers.\n");
988+
"\t[--msl-combined-sampler-suffix <suffix>]:\n\t\tUses a custom suffix for combined samplers.\n"
989+
"\t[--msl-disable-rasterization]:\n\t\tDisables rasterization and returns void from vertex-like entry points.\n"
990+
"\t[--msl-auto-disable-rasterization]:\n\t\tDisables rasterization if BuiltInPosition is not written.\n");
987991
// clang-format on
988992
}
989993

@@ -1265,6 +1269,8 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
12651269
msl_opts.input_attachment_is_ds_attachment = args.msl_input_attachment_is_ds_attachment;
12661270
msl_opts.readwrite_texture_fences = args.msl_readwrite_texture_fences;
12671271
msl_opts.agx_manual_cube_grad_fixup = args.msl_agx_manual_cube_grad_fixup;
1272+
msl_opts.disable_rasterization = args.msl_disable_rasterization;
1273+
msl_opts.auto_disable_rasterization = args.msl_auto_disable_rasterization;
12681274
msl_comp->set_msl_options(msl_opts);
12691275
for (auto &v : args.msl_discrete_descriptor_sets)
12701276
msl_comp->add_discrete_descriptor_set(v);
@@ -1830,6 +1836,8 @@ static int main_inner(int argc, char *argv[])
18301836
cbs.add("--msl-replace-recursive-inputs",
18311837
[&args](CLIParser &) { args.msl_replace_recursive_inputs = true; });
18321838
cbs.add("--msl-input-attachment-is-ds-attachment", [&args](CLIParser &) { args.msl_input_attachment_is_ds_attachment = true; });
1839+
cbs.add("--msl-disable-rasterization", [&args](CLIParser &) { args.msl_disable_rasterization = true; });
1840+
cbs.add("--msl-auto-disable-rasterization", [&args](CLIParser &) { args.msl_auto_disable_rasterization = true; });
18331841
cbs.add("--extension", [&args](CLIParser &parser) { args.extensions.push_back(parser.next_string()); });
18341842
cbs.add("--rename-entry-point", [&args](CLIParser &parser) {
18351843
auto old_name = parser.next_string();

3rdparty/spirv-cross/spirv_cross_c.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ spvc_result spvc_compiler_options_set_uint(spvc_compiler_options options, spvc_c
569569
options->msl.disable_rasterization = value != 0;
570570
break;
571571

572+
case SPVC_COMPILER_OPTION_MSL_AUTO_DISABLE_RASTERIZATION:
573+
options->msl.auto_disable_rasterization = value != 0;
574+
break;
575+
572576
case SPVC_COMPILER_OPTION_MSL_CAPTURE_OUTPUT_TO_BUFFER:
573577
options->msl.capture_output_to_buffer = value != 0;
574578
break;

3rdparty/spirv-cross/spirv_cross_c.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extern "C" {
4040
/* Bumped if ABI or API breaks backwards compatibility. */
4141
#define SPVC_C_API_VERSION_MAJOR 0
4242
/* Bumped if APIs or enumerations are added in a backwards compatible way. */
43-
#define SPVC_C_API_VERSION_MINOR 64
43+
#define SPVC_C_API_VERSION_MINOR 65
4444
/* Bumped if internal implementation details change. */
4545
#define SPVC_C_API_VERSION_PATCH 0
4646

@@ -748,6 +748,8 @@ typedef enum spvc_compiler_option
748748
SPVC_COMPILER_OPTION_HLSL_USE_ENTRY_POINT_NAME = 90 | SPVC_COMPILER_OPTION_HLSL_BIT,
749749
SPVC_COMPILER_OPTION_HLSL_PRESERVE_STRUCTURED_BUFFERS = 91 | SPVC_COMPILER_OPTION_HLSL_BIT,
750750

751+
SPVC_COMPILER_OPTION_MSL_AUTO_DISABLE_RASTERIZATION = 92 | SPVC_COMPILER_OPTION_MSL_BIT,
752+
751753
SPVC_COMPILER_OPTION_INT_MAX = 0x7fffffff
752754
} spvc_compiler_option;
753755

3rdparty/spirv-cross/spirv_glsl.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -9824,7 +9824,17 @@ string CompilerGLSL::builtin_to_glsl(BuiltIn builtin, StorageClass storage)
98249824
case BuiltInInvocationId:
98259825
return "gl_InvocationID";
98269826
case BuiltInLayer:
9827+
{
9828+
auto model = get_execution_model();
9829+
if (model == ExecutionModelVertex || model == ExecutionModelTessellationEvaluation)
9830+
{
9831+
if (options.es)
9832+
require_extension_internal("GL_NV_viewport_array2");
9833+
else
9834+
require_extension_internal("GL_ARB_shader_viewport_layer_array");
9835+
}
98279836
return "gl_Layer";
9837+
}
98289838
case BuiltInViewportIndex:
98299839
return "gl_ViewportIndex";
98309840
case BuiltInTessLevelOuter:
@@ -17869,6 +17879,14 @@ void CompilerGLSL::emit_block_chain(SPIRBlock &block)
1786917879

1787017880
case SPIRBlock::Unreachable:
1787117881
{
17882+
// If the entry point ends with unreachable and has a return value, insert a return
17883+
// statement to avoid potential compiler errors from non-void functions without a return value.
17884+
if (block.return_value)
17885+
{
17886+
statement("return ", to_unpacked_expression(block.return_value), ";");
17887+
break;
17888+
}
17889+
1787217890
// Avoid emitting false fallthrough, which can happen for
1787317891
// if (cond) break; else discard; inside a case label.
1787417892
// Discard is not always implementable as a terminator.

3rdparty/spirv-cross/spirv_msl.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ void CompilerMSL::build_implicit_builtins()
10031003
// If we're returning a struct from a vertex-like entry point, we must return a position attribute.
10041004
bool need_position = (get_execution_model() == ExecutionModelVertex || is_tese_shader()) &&
10051005
!capture_output_to_buffer && !get_is_rasterization_disabled() &&
1006+
!msl_options.auto_disable_rasterization &&
10061007
!active_output_builtins.get(BuiltInPosition);
10071008

10081009
if (need_position)
@@ -1039,6 +1040,10 @@ void CompilerMSL::build_implicit_builtins()
10391040
});
10401041
need_position = has_output && !active_output_builtins.get(BuiltInPosition);
10411042
}
1043+
else if (!active_output_builtins.get(BuiltInPosition) && msl_options.auto_disable_rasterization)
1044+
{
1045+
is_rasterization_disabled = true;
1046+
}
10421047

10431048
if (need_position)
10441049
{
@@ -4219,8 +4224,9 @@ uint32_t CompilerMSL::add_interface_block(StorageClass storage, bool patch)
42194224
// If the entry point should return the output struct, set the entry function
42204225
// to return the output interface struct, otherwise to return nothing.
42214226
// Watch out for the rare case where the terminator of the last entry point block is a
4222-
// Kill, instead of a Return. Based on SPIR-V's block-domination rules, we assume that
4223-
// any block that has a Kill will also have a terminating Return, except the last block.
4227+
// Kill or Unreachable, instead of a Return. Based on SPIR-V's block-domination rules,
4228+
// we assume that any block that has a Kill will also have a terminating Return, except
4229+
// the last block.
42244230
// Indicate the output var requires early initialization.
42254231
bool ep_should_return_output = !get_is_rasterization_disabled();
42264232
uint32_t rtn_id = ep_should_return_output ? ib_var_id : 0;
@@ -4230,7 +4236,8 @@ uint32_t CompilerMSL::add_interface_block(StorageClass storage, bool patch)
42304236
for (auto &blk_id : entry_func.blocks)
42314237
{
42324238
auto &blk = get<SPIRBlock>(blk_id);
4233-
if (blk.terminator == SPIRBlock::Return || (blk.terminator == SPIRBlock::Kill && blk_id == entry_func.blocks.back()))
4239+
auto last_blk_return = blk.terminator == SPIRBlock::Kill || blk.terminator == SPIRBlock::Unreachable;
4240+
if (blk.terminator == SPIRBlock::Return || (last_blk_return && blk_id == entry_func.blocks.back()))
42344241
blk.return_value = rtn_id;
42354242
}
42364243
vars_needing_early_declaration.push_back(ib_var_id);
@@ -15584,6 +15591,9 @@ const std::unordered_set<std::string> &CompilerMSL::get_illegal_func_names()
1558415591
{
1558515592
static const unordered_set<string> illegal_func_names = {
1558615593
"main",
15594+
"fragment",
15595+
"vertex",
15596+
"kernel",
1558715597
"saturate",
1558815598
"assert",
1558915599
"fmin3",

3rdparty/spirv-cross/spirv_msl.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ class CompilerMSL : public CompilerGLSL
536536
// if the fragment does not modify the depth value.
537537
bool input_attachment_is_ds_attachment = false;
538538

539+
// If BuiltInPosition is not written, automatically disable rasterization.
540+
// The result can be queried with get_is_rasterization_disabled.
541+
bool auto_disable_rasterization = false;
542+
539543
bool is_ios() const
540544
{
541545
return platform == iOS;

0 commit comments

Comments
 (0)