Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Commit 4a03536

Browse files
committed
Version 3.2.0 [release 3.2.0]
1 parent eaae2df commit 4a03536

File tree

13 files changed

+291
-141
lines changed

13 files changed

+291
-141
lines changed

3rdparty/spirv-cross/spirv_cross.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,14 @@ bool Compiler::is_physical_pointer(const SPIRType &type) const
742742
return type.op == OpTypePointer && type.storage == StorageClassPhysicalStorageBuffer;
743743
}
744744

745+
bool Compiler::is_physical_or_buffer_pointer(const SPIRType &type) const
746+
{
747+
return type.op == OpTypePointer &&
748+
(type.storage == StorageClassPhysicalStorageBuffer || type.storage == StorageClassUniform ||
749+
type.storage == StorageClassStorageBuffer || type.storage == StorageClassWorkgroup ||
750+
type.storage == StorageClassPushConstant);
751+
}
752+
745753
bool Compiler::is_physical_pointer_to_buffer_block(const SPIRType &type) const
746754
{
747755
return is_physical_pointer(type) && get_pointee_type(type).self == type.parent_type &&

3rdparty/spirv-cross/spirv_cross.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ class Compiler
694694
bool is_array(const SPIRType &type) const;
695695
bool is_pointer(const SPIRType &type) const;
696696
bool is_physical_pointer(const SPIRType &type) const;
697+
bool is_physical_or_buffer_pointer(const SPIRType &type) const;
697698
bool is_physical_pointer_to_buffer_block(const SPIRType &type) const;
698699
static bool is_runtime_size_array(const SPIRType &type);
699700
uint32_t expression_type_id(uint32_t id) const;

3rdparty/spirv-cross/spirv_glsl.cpp

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5054,10 +5054,10 @@ void CompilerGLSL::emit_polyfills(uint32_t polyfills, bool relaxed)
50545054
// Returns a string representation of the ID, usable as a function arg.
50555055
// Default is to simply return the expression representation fo the arg ID.
50565056
// Subclasses may override to modify the return value.
5057-
string CompilerGLSL::to_func_call_arg(const SPIRFunction::Parameter &, uint32_t id)
5057+
string CompilerGLSL::to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id)
50585058
{
50595059
// BDA expects pointers through function interface.
5060-
if (is_physical_pointer(expression_type(id)))
5060+
if (!arg.alias_global_variable && is_physical_or_buffer_pointer(expression_type(id)))
50615061
return to_pointer_expression(id);
50625062

50635063
// Make sure that we use the name of the original variable, and not the parameter alias.
@@ -6899,6 +6899,16 @@ void CompilerGLSL::emit_uninitialized_temporary(uint32_t result_type, uint32_t r
68996899
}
69006900
}
69016901

6902+
bool CompilerGLSL::can_declare_inline_temporary(uint32_t id) const
6903+
{
6904+
if (!block_temporary_hoisting && current_continue_block && !hoisted_temporaries.count(id))
6905+
return false;
6906+
if (hoisted_temporaries.count(id))
6907+
return false;
6908+
6909+
return true;
6910+
}
6911+
69026912
string CompilerGLSL::declare_temporary(uint32_t result_type, uint32_t result_id)
69036913
{
69046914
auto &type = get<SPIRType>(result_type);
@@ -6976,6 +6986,42 @@ SPIRExpression &CompilerGLSL::emit_op(uint32_t result_type, uint32_t result_id,
69766986
}
69776987
}
69786988

6989+
void CompilerGLSL::emit_transposed_op(uint32_t result_type, uint32_t result_id, const string &rhs, bool forwarding)
6990+
{
6991+
if (forwarding && (forced_temporaries.find(result_id) == end(forced_temporaries)))
6992+
{
6993+
// Just forward it without temporary.
6994+
// If the forward is trivial, we do not force flushing to temporary for this expression.
6995+
forwarded_temporaries.insert(result_id);
6996+
auto &e = set<SPIRExpression>(result_id, rhs, result_type, true);
6997+
e.need_transpose = true;
6998+
}
6999+
else if (can_declare_inline_temporary(result_id))
7000+
{
7001+
// If expression isn't immutable, bind it to a temporary and make the new temporary immutable (they always are).
7002+
// Since the expression is transposed, we have to ensure the temporary is the transposed type.
7003+
7004+
auto &transposed_type_id = extra_sub_expressions[result_id];
7005+
if (!transposed_type_id)
7006+
{
7007+
auto dummy_type = get<SPIRType>(result_type);
7008+
std::swap(dummy_type.columns, dummy_type.vecsize);
7009+
transposed_type_id = ir.increase_bound_by(1);
7010+
set<SPIRType>(transposed_type_id, dummy_type);
7011+
}
7012+
7013+
statement(declare_temporary(transposed_type_id, result_id), rhs, ";");
7014+
auto &e = set<SPIRExpression>(result_id, to_name(result_id), result_type, true);
7015+
e.need_transpose = true;
7016+
}
7017+
else
7018+
{
7019+
// If we cannot declare the temporary because it's already been hoisted, we don't have the
7020+
// chance to override the temporary type ourselves. Just transpose() the expression.
7021+
emit_op(result_type, result_id, join("transpose(", rhs, ")"), forwarding);
7022+
}
7023+
}
7024+
69797025
void CompilerGLSL::emit_unary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op)
69807026
{
69817027
bool forward = should_forward(op0);
@@ -11586,7 +11632,7 @@ bool CompilerGLSL::should_dereference(uint32_t id)
1158611632
// If id is a variable but not a phi variable, we should not dereference it.
1158711633
// BDA passed around as parameters are always pointers.
1158811634
if (auto *var = maybe_get<SPIRVariable>(id))
11589-
return (var->parameter && is_physical_pointer(type)) || var->phi_variable;
11635+
return (var->parameter && is_physical_or_buffer_pointer(type)) || var->phi_variable;
1159011636

1159111637
if (auto *expr = maybe_get<SPIRExpression>(id))
1159211638
{
@@ -11622,8 +11668,8 @@ bool CompilerGLSL::should_dereference(uint32_t id)
1162211668
bool CompilerGLSL::should_dereference_caller_param(uint32_t id)
1162311669
{
1162411670
const auto &type = expression_type(id);
11625-
// BDA is always passed around as pointers.
11626-
if (is_physical_pointer(type))
11671+
// BDA is always passed around as pointers. Similarly, we need to pass variable buffer pointers as pointers.
11672+
if (is_physical_or_buffer_pointer(type))
1162711673
return false;
1162811674

1162911675
return should_dereference(id);
@@ -13512,8 +13558,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
1351213558
auto expr = join(enclose_expression(to_unpacked_row_major_matrix_expression(ops[3])), " * ",
1351313559
enclose_expression(to_unpacked_row_major_matrix_expression(ops[2])));
1351413560
bool forward = should_forward(ops[2]) && should_forward(ops[3]);
13515-
auto &e = emit_op(ops[0], ops[1], expr, forward);
13516-
e.need_transpose = true;
13561+
emit_transposed_op(ops[0], ops[1], expr, forward);
1351713562
a->need_transpose = true;
1351813563
b->need_transpose = true;
1351913564
inherit_expression_dependencies(ops[1], ops[2]);
@@ -13536,8 +13581,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
1353613581
auto expr = join(enclose_expression(to_unpacked_row_major_matrix_expression(ops[2])), " * ",
1353713582
to_enclosed_unpacked_expression(ops[3]));
1353813583
bool forward = should_forward(ops[2]) && should_forward(ops[3]);
13539-
auto &e = emit_op(ops[0], ops[1], expr, forward);
13540-
e.need_transpose = true;
13584+
emit_transposed_op(ops[0], ops[1], expr, forward);
1354113585
a->need_transpose = true;
1354213586
inherit_expression_dependencies(ops[1], ops[2]);
1354313587
inherit_expression_dependencies(ops[1], ops[3]);

3rdparty/spirv-cross/spirv_glsl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ class CompilerGLSL : public Compiler
775775
bool expression_read_implies_multiple_reads(uint32_t id) const;
776776
SPIRExpression &emit_op(uint32_t result_type, uint32_t result_id, const std::string &rhs, bool forward_rhs,
777777
bool suppress_usage_tracking = false);
778+
void emit_transposed_op(uint32_t result_type, uint32_t result_id, const std::string &rhs, bool forward_rhs);
778779

779780
void access_chain_internal_append_index(std::string &expr, uint32_t base, const SPIRType *type,
780781
AccessChainFlags flags, bool &access_chain_is_arrayed, uint32_t index);
@@ -817,6 +818,7 @@ class CompilerGLSL : public Compiler
817818
const char *index_to_swizzle(uint32_t index);
818819
std::string remap_swizzle(const SPIRType &result_type, uint32_t input_components, const std::string &expr);
819820
std::string declare_temporary(uint32_t type, uint32_t id);
821+
bool can_declare_inline_temporary(uint32_t id) const;
820822
void emit_uninitialized_temporary(uint32_t type, uint32_t id);
821823
SPIRExpression &emit_uninitialized_temporary_expression(uint32_t type, uint32_t id);
822824
virtual void append_global_func_args(const SPIRFunction &func, uint32_t index, SmallVector<std::string> &arglist);

3rdparty/spirv-cross/spirv_hlsl.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ string CompilerHLSL::type_to_glsl(const SPIRType &type, uint32_t id)
491491
case SPIRType::Double:
492492
return join("double", type.vecsize);
493493
case SPIRType::Int64:
494-
return join("i64vec", type.vecsize);
494+
return join("int64_t", type.vecsize);
495495
case SPIRType::UInt64:
496-
return join("u64vec", type.vecsize);
496+
return join("uint64_t", type.vecsize);
497497
default:
498498
return "???";
499499
}
@@ -1434,11 +1434,13 @@ bool CompilerHLSL::is_hlsl_aux_buffer_binding_used(HLSLAuxBinding binding) const
14341434
return false;
14351435
}
14361436

1437+
// axslcc spec
14371438
void CompilerHLSL::add_hlsl_sampler_state(uint32_t slot, const std::string &sampler_state_symbol)
14381439
{
14391440
sampler_registry.emplace(slot, sampler_state_symbol);
14401441
}
14411442

1443+
// axslcc spec
14421444
uint32_t CompilerHLSL::resolve_sampler_variable(uint32_t id) const
14431445
{
14441446
if (ir.ids[id].get_type() == TypeVariable)
@@ -1617,6 +1619,7 @@ void CompilerHLSL::replace_illegal_names()
16171619
"Texture3D", "TextureCube", "TextureCubeArray", "true", "typedef", "triangle",
16181620
"triangleadj", "TriangleStream", "uint", "uniform", "unorm", "unsigned",
16191621
"vector", "vertexfragment", "VertexShader", "vertices", "void", "volatile", "while",
1622+
"signed",
16201623
};
16211624

16221625
CompilerGLSL::replace_illegal_names(keywords);
@@ -1731,9 +1734,11 @@ void CompilerHLSL::emit_resources()
17311734
ir.for_each_typed_id<SPIRVariable>([&](uint32_t, SPIRVariable &var) {
17321735
auto &type = this->get<SPIRType>(var.basetype);
17331736

1737+
bool is_hidden = is_hidden_io_variable(var);
1738+
17341739
if (var.storage != StorageClassFunction && !var.remapped_variable && type.pointer &&
17351740
(var.storage == StorageClassInput || var.storage == StorageClassOutput) && !is_builtin_variable(var) &&
1736-
interface_variable_exists_in_entry_point(var.self))
1741+
interface_variable_exists_in_entry_point(var.self) && !is_hidden)
17371742
{
17381743
// Builtin variables are handled separately.
17391744
emit_interface_block_globally(var);
@@ -1769,8 +1774,10 @@ void CompilerHLSL::emit_resources()
17691774
if (var.storage != StorageClassInput && var.storage != StorageClassOutput)
17701775
return;
17711776

1777+
bool is_hidden = is_hidden_io_variable(var);
1778+
17721779
if (!var.remapped_variable && type.pointer && !is_builtin_variable(var) &&
1773-
interface_variable_exists_in_entry_point(var.self))
1780+
interface_variable_exists_in_entry_point(var.self) && !is_hidden)
17741781
{
17751782
if (block)
17761783
{
@@ -3504,10 +3511,12 @@ void CompilerHLSL::emit_hlsl_entry_point()
35043511
if (var.storage != StorageClassInput)
35053512
return;
35063513

3514+
bool is_hidden = is_hidden_io_variable(var);
3515+
35073516
bool need_matrix_unroll = var.storage == StorageClassInput && execution.model == ExecutionModelVertex;
35083517

35093518
if (!var.remapped_variable && type.pointer && !is_builtin_variable(var) &&
3510-
interface_variable_exists_in_entry_point(var.self))
3519+
interface_variable_exists_in_entry_point(var.self) && !is_hidden)
35113520
{
35123521
if (block)
35133522
{
@@ -7158,6 +7167,30 @@ bool CompilerHLSL::is_hlsl_force_storage_buffer_as_uav(ID id) const
71587167
return (force_uav_buffer_bindings.find({ desc_set, binding }) != force_uav_buffer_bindings.end());
71597168
}
71607169

7170+
bool CompilerHLSL::is_hidden_io_variable(const SPIRVariable &var) const
7171+
{
7172+
if (!is_hidden_variable(var))
7173+
return false;
7174+
7175+
// It is too risky to remove stage IO variables that are linkable since it affects link compatibility.
7176+
// For vertex inputs and fragment outputs, it's less of a concern and we want reflection data
7177+
// to match reality.
7178+
7179+
bool is_external_linkage =
7180+
(get_execution_model() == ExecutionModelVertex && var.storage == StorageClassInput) ||
7181+
(get_execution_model() == ExecutionModelFragment && var.storage == StorageClassOutput);
7182+
7183+
if (!is_external_linkage)
7184+
return false;
7185+
7186+
// Unused output I/O variables might still be required to implement framebuffer fetch.
7187+
if (var.storage == StorageClassOutput && !is_legacy() &&
7188+
location_is_framebuffer_fetch(get_decoration(var.self, DecorationLocation)) != 0)
7189+
return false;
7190+
7191+
return true;
7192+
}
7193+
71617194
void CompilerHLSL::set_hlsl_force_storage_buffer_as_uav(uint32_t desc_set, uint32_t binding)
71627195
{
71637196
SetBindingPair pair = { desc_set, binding };

3rdparty/spirv-cross/spirv_hlsl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ class CompilerHLSL : public CompilerGLSL
303303
SPIRType::BaseType get_builtin_basetype(BuiltIn builtin, SPIRType::BaseType default_type) override;
304304

305305
bool is_hlsl_force_storage_buffer_as_uav(ID id) const;
306+
bool is_hidden_io_variable(const SPIRVariable &var) const;
306307

307308
Options hlsl_options;
308309

0 commit comments

Comments
 (0)