MSL support textures and samplers as function args.
Add automatic sampler func arg when passing SampledImage type. Pass texture and sampler in thread address space.
This commit is contained in:
parent
14f4339b1c
commit
b321b83c8f
@ -1109,6 +1109,14 @@ void CompilerGLSL::emit_resources()
|
||||
statement("");
|
||||
}
|
||||
|
||||
// Returns a string representation of the ID, usable as a function arg.
|
||||
// Default is to simply return the expression representation fo the arg ID.
|
||||
// Subclasses may override to modify the return value.
|
||||
string CompilerGLSL::to_func_call_arg(uint32_t id)
|
||||
{
|
||||
return to_expression(id);
|
||||
}
|
||||
|
||||
string CompilerGLSL::to_expression(uint32_t id)
|
||||
{
|
||||
auto itr = invalid_expressions.find(id);
|
||||
@ -2691,7 +2699,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
||||
funexpr += to_name(func) + "(";
|
||||
for (uint32_t i = 0; i < length; i++)
|
||||
{
|
||||
funexpr += to_expression(arg[i]);
|
||||
funexpr += to_func_call_arg(arg[i]);
|
||||
if (i + 1 < length)
|
||||
funexpr += ", ";
|
||||
}
|
||||
|
@ -147,6 +147,7 @@ protected:
|
||||
virtual std::string constant_expression_vector(const SPIRConstant &c, uint32_t vector);
|
||||
virtual void emit_fixup();
|
||||
virtual std::string variable_decl(const SPIRType &type, const std::string &name);
|
||||
virtual std::string to_func_call_arg(uint32_t id);
|
||||
|
||||
std::unique_ptr<std::ostringstream> buffer;
|
||||
|
||||
|
@ -618,7 +618,7 @@ void CompilerMSL::emit_function_prototype(SPIRFunction &func, bool is_decl)
|
||||
{
|
||||
add_local_variable_name(arg.id);
|
||||
|
||||
bool is_uniform = false;
|
||||
bool is_uniform_struct = false;
|
||||
auto *var = maybe_get<SPIRVariable>(arg.id);
|
||||
if (var) {
|
||||
var->parameter = &arg; // Hold a pointer to the parameter so we can invalidate the readonly field if needed.
|
||||
@ -626,13 +626,20 @@ void CompilerMSL::emit_function_prototype(SPIRFunction &func, bool is_decl)
|
||||
// Check if this arg is one of the synthetic uniform args
|
||||
// created to handle uniform access inside the function
|
||||
auto &var_type = get<SPIRType>(var->basetype);
|
||||
is_uniform = (var_type.storage == StorageClassUniform ||
|
||||
var_type.storage == StorageClassUniformConstant ||
|
||||
var_type.storage == StorageClassPushConstant);
|
||||
is_uniform_struct = ((var_type.basetype == SPIRType::Struct) &&
|
||||
(var_type.storage == StorageClassUniform ||
|
||||
var_type.storage == StorageClassUniformConstant ||
|
||||
var_type.storage == StorageClassPushConstant));
|
||||
}
|
||||
|
||||
decl += (is_uniform ? "constant " : "thread ");
|
||||
decl += (is_uniform_struct ? "constant " : "thread ");
|
||||
decl += argument_decl(arg);
|
||||
|
||||
// Manufacture automatic sampler arg for SampledImage texture
|
||||
auto &arg_type = get<SPIRType>(arg.type);
|
||||
if (arg_type.basetype == SPIRType::SampledImage)
|
||||
decl += ", thread const sampler& " + to_sampler_expression(arg.id);
|
||||
|
||||
if (&arg != &func.arguments.back())
|
||||
decl += ", ";
|
||||
}
|
||||
@ -955,6 +962,21 @@ void CompilerMSL::emit_sampled_image_op(uint32_t result_type, uint32_t result_id
|
||||
meta[result_id].sampler = samp_id;
|
||||
}
|
||||
|
||||
// Returns a string representation of the ID, usable as a function arg.
|
||||
// Manufacture automatic sampler arg for SampledImage texture.
|
||||
string CompilerMSL::to_func_call_arg(uint32_t id)
|
||||
{
|
||||
string arg_str = CompilerGLSL::to_func_call_arg(id);
|
||||
|
||||
// Manufacture automatic sampler arg for SampledImage texture.
|
||||
auto &var = get<SPIRVariable>(id);
|
||||
auto &type = get<SPIRType>(var.basetype);
|
||||
if (type.basetype == SPIRType::SampledImage)
|
||||
arg_str += ", " + to_sampler_expression(id);
|
||||
|
||||
return arg_str;
|
||||
}
|
||||
|
||||
// If the ID represents a sampled image that has been assigned a sampler already,
|
||||
// generate an expression for the sampler, otherwise generate a fake sampler name
|
||||
// by appending a suffix to the expression constructed from the ID.
|
||||
|
@ -107,6 +107,7 @@ protected:
|
||||
std::string member_decl(const SPIRType &type, const SPIRType &member_type, uint32_t member) override;
|
||||
std::string constant_expression(const SPIRConstant &c) override;
|
||||
size_t get_declared_struct_member_size(const SPIRType &struct_type, uint32_t index) const override;
|
||||
std::string to_func_call_arg(uint32_t id) override;
|
||||
|
||||
void extract_builtins();
|
||||
void add_builtin(spv::BuiltIn builtin_type);
|
||||
|
Loading…
Reference in New Issue
Block a user