Skip to content

Commit fa4d8b6

Browse files
committed
GLSL: SPIRFunction::used_as_lambda for SPV_NV_cooperative_matrix2 lambdas
1 parent dd9535d commit fa4d8b6

File tree

5 files changed

+19
-30
lines changed

5 files changed

+19
-30
lines changed

spirv_common.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,6 @@ struct SPIRFunction : IVariant
10281028
// read and write counts as access to the function arguments
10291029
// is not local to the function in question.
10301030
bool alias_global_variable;
1031-
spv::StorageClass storage;
1032-
bool force_const;
10331031
};
10341032

10351033
// When calling a function, and we're remapping separate image samplers,
@@ -1061,6 +1059,9 @@ struct SPIRFunction : IVariant
10611059
BlockID entry_block = 0;
10621060
SmallVector<BlockID> blocks;
10631061
SmallVector<CombinedImageSamplerParameter> combined_parameters;
1062+
// SPV_NV_cooperative_matrix2 uses lambdas where all parameters need
1063+
// to be annotated as `const in`
1064+
bool used_as_lambda = false;
10641065

10651066
struct EntryLine
10661067
{
@@ -1077,7 +1078,7 @@ struct SPIRFunction : IVariant
10771078
void add_parameter(TypeID parameter_type, ID id, bool alias_global_variable = false)
10781079
{
10791080
// Arguments are read-only until proven otherwise.
1080-
arguments.push_back({ parameter_type, id, 0u, 0u, alias_global_variable, spv::StorageClassGeneric, false });
1081+
arguments.push_back({ parameter_type, id, 0u, 0u, alias_global_variable });
10811082
}
10821083

10831084
// Hooks to be run when the function returns.

spirv_cross.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2983,7 +2983,7 @@ void Compiler::CombinedImageSamplerHandler::register_combined_image_sampler(SPIR
29832983
join("SPIRV_Cross_Combined", compiler.to_name(image_id), compiler.to_name(sampler_id)));
29842984

29852985
caller.combined_parameters.push_back(param);
2986-
caller.shadow_arguments.push_back({ ptr_type_id, combined_id, 0u, 0u, true, StorageClassGeneric, false });
2986+
caller.shadow_arguments.push_back({ ptr_type_id, combined_id, 0u, 0u, true });
29872987
}
29882988
}
29892989

spirv_glsl.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15927,11 +15927,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
1592715927
auto called_func = maybe_get_called_function(instruction);
1592815928
if (called_func)
1592915929
{
15930-
for (auto &par : called_func->arguments)
15931-
{
15932-
par.storage = StorageClassInput;
15933-
par.force_const = true;
15934-
}
15930+
called_func->used_as_lambda = true;
1593515931
}
1593615932
break;
1593715933
}
@@ -15976,11 +15972,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
1597615972
auto called_func = maybe_get_called_function(instruction);
1597715973
if (called_func)
1597815974
{
15979-
for (auto &par : called_func->arguments)
15980-
{
15981-
par.storage = StorageClassInput;
15982-
par.force_const = true;
15983-
}
15975+
called_func->used_as_lambda = true;
1598415976
}
1598515977
break;
1598615978
}
@@ -16020,11 +16012,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
1602016012
auto called_func = maybe_get_called_function(instruction);
1602116013
if (called_func)
1602216014
{
16023-
for (auto &par : called_func->arguments)
16024-
{
16025-
par.storage = StorageClassInput;
16026-
par.force_const = true;
16027-
}
16015+
called_func->used_as_lambda = true;
1602816016
}
1602916017

1603016018
register_read(id, ops[2], false);
@@ -16682,13 +16670,13 @@ string CompilerGLSL::to_qualifiers_glsl(uint32_t id)
1668216670
return res;
1668316671
}
1668416672

16685-
string CompilerGLSL::argument_decl(const SPIRFunction::Parameter &arg)
16673+
string CompilerGLSL::argument_decl(const SPIRFunction::Parameter &arg, bool is_lambda)
1668616674
{
1668716675
// glslangValidator seems to make all arguments pointer no matter what which is rather bizarre ...
1668816676
auto &type = expression_type(arg.id);
1668916677
const char *direction = "";
16690-
const char *constness = arg.force_const ? "const " : "";
16691-
if (arg.storage == StorageClassInput)
16678+
const char *constness = is_lambda ? "const " : "";
16679+
if (is_lambda == StorageClassInput)
1669216680
{
1669316681
direction = "in ";
1669416682
}
@@ -17611,7 +17599,7 @@ void CompilerGLSL::emit_function_prototype(SPIRFunction &func, const Bitset &ret
1761117599
// Since we want to make the GLSL debuggable and somewhat sane, use fallback names for variables which are duplicates.
1761217600
add_local_variable_name(arg.id);
1761317601

17614-
arglist.push_back(argument_decl(arg));
17602+
arglist.push_back(argument_decl(arg, func.used_as_lambda));
1761517603

1761617604
// Hold a pointer to the parameter so we can invalidate the readonly field if needed.
1761717605
auto *var = maybe_get<SPIRVariable>(arg.id);
@@ -17627,7 +17615,7 @@ void CompilerGLSL::emit_function_prototype(SPIRFunction &func, const Bitset &ret
1762717615
// Since we want to make the GLSL debuggable and somewhat sane, use fallback names for variables which are duplicates.
1762817616
add_local_variable_name(arg.id);
1762917617

17630-
arglist.push_back(argument_decl(arg));
17618+
arglist.push_back(argument_decl(arg, func.used_as_lambda));
1763117619

1763217620
// Hold a pointer to the parameter so we can invalidate the readonly field if needed.
1763317621
auto *var = maybe_get<SPIRVariable>(arg.id);

spirv_glsl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ class CompilerGLSL : public Compiler
837837
virtual std::string to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain_is_resolved);
838838
std::string to_multi_member_reference(const SPIRType &type, const SmallVector<uint32_t> &indices);
839839
std::string type_to_glsl_constructor(const SPIRType &type);
840-
std::string argument_decl(const SPIRFunction::Parameter &arg);
840+
std::string argument_decl(const SPIRFunction::Parameter &arg, bool is_lambda);
841841
virtual std::string to_qualifiers_glsl(uint32_t id);
842842
void fixup_io_block_patch_primitive_qualifiers(const SPIRVariable &var);
843843
void emit_output_variable_initializer(const SPIRVariable &var);

spirv_hlsl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ void CompilerHLSL::analyze_meshlet_writes(uint32_t func_id, uint32_t id_per_vert
25562556
// basetype is effectively ignored here since we declare the argument
25572557
// with explicit types. Just pass down a valid type.
25582558
func.arguments.push_back({ expression_type_id(iarg.id), iarg.id,
2559-
iarg.read_count, iarg.write_count, true, StorageClassGeneric, false });
2559+
iarg.read_count, iarg.write_count, true });
25602560
}
25612561
}
25622562
break;
@@ -2600,9 +2600,9 @@ void CompilerHLSL::analyze_meshlet_writes(uint32_t func_id, uint32_t id_per_vert
26002600
// with explicit types. Just pass down a valid type.
26012601
uint32_t type_id = expression_type_id(var_id);
26022602
if (var->storage == StorageClassTaskPayloadWorkgroupEXT)
2603-
func.arguments.push_back({ type_id, var_id, 1u, 0u, true, StorageClassGeneric, false });
2603+
func.arguments.push_back({ type_id, var_id, 1u, 0u, true });
26042604
else
2605-
func.arguments.push_back({ type_id, var_id, 1u, 1u, true, StorageClassGeneric, false });
2605+
func.arguments.push_back({ type_id, var_id, 1u, 1u, true });
26062606
}
26072607
}
26082608
break;
@@ -3107,7 +3107,7 @@ void CompilerHLSL::emit_function_prototype(SPIRFunction &func, const Bitset &ret
31073107
// Since we want to make the GLSL debuggable and somewhat sane, use fallback names for variables which are duplicates.
31083108
add_local_variable_name(arg.id);
31093109

3110-
arglist.push_back(argument_decl(arg));
3110+
arglist.push_back(argument_decl(arg, func.used_as_lambda));
31113111

31123112
// Flatten a combined sampler to two separate arguments in modern HLSL.
31133113
auto &arg_type = get<SPIRType>(arg.type);
@@ -3133,7 +3133,7 @@ void CompilerHLSL::emit_function_prototype(SPIRFunction &func, const Bitset &ret
31333133
// Since we want to make the GLSL debuggable and somewhat sane, use fallback names for variables which are duplicates.
31343134
add_local_variable_name(arg.id);
31353135

3136-
arglist.push_back(argument_decl(arg));
3136+
arglist.push_back(argument_decl(arg, func.used_as_lambda));
31373137

31383138
// Hold a pointer to the parameter so we can invalidate the readonly field if needed.
31393139
auto *var = maybe_get<SPIRVariable>(arg.id);

0 commit comments

Comments
 (0)