Build new IDs for shadow arguments.

This commit is contained in:
Hans-Kristian Arntzen 2016-09-11 12:36:12 +02:00
parent a5f0abdc11
commit 948930b171
3 changed files with 35 additions and 6 deletions

View File

@ -448,6 +448,7 @@ struct SPIRFunction : IVariant
// or a global ID.
struct CombinedImageSamplerParameter
{
uint32_t id;
uint32_t texture_id;
uint32_t sampler_id;
bool global_texture;
@ -457,6 +458,11 @@ struct SPIRFunction : IVariant
uint32_t return_type;
uint32_t function_type;
std::vector<Parameter> arguments;
// Can be used by backends to add magic arguments.
// Currently used by combined image/sampler implementation.
std::vector<Parameter> shadow_arguments;
std::vector<uint32_t> local_variables;
uint32_t entry_block = 0;
std::vector<uint32_t> blocks;

View File

@ -2407,7 +2407,7 @@ void Compiler::CombinedImageSamplerHandler::register_combined_image_sampler(SPIR
// or a parameter in our own function. If both are global, they will not need a parameter,
// otherwise, add it to our list.
SPIRFunction::CombinedImageSamplerParameter param = {
texture_id, sampler_id, true, true,
0u, texture_id, sampler_id, true, true,
};
auto texture_itr = find_if(begin(caller.arguments), end(caller.arguments),
@ -2437,7 +2437,33 @@ void Compiler::CombinedImageSamplerHandler::register_combined_image_sampler(SPIR
});
if (itr == end(caller.combined_parameters))
{
uint32_t id = compiler.increase_bound_by(2);
auto type_id = id + 0;
auto combined_id = id + 1;
auto &base = compiler.expression_type(sampler_id);
auto &type = compiler.set<SPIRType>(type_id);
type = base;
type.pointer = true;
type.storage = StorageClassUniformConstant;
// Build new variable.
compiler.set<SPIRVariable>(combined_id, type_id, StorageClassFunction, 0);
// Inherit RelaxedPrecision (and potentially other useful flags if deemed relevant).
auto &new_flags = compiler.meta[combined_id].decoration.decoration_flags;
auto old_flags = compiler.meta[sampler_id].decoration.decoration_flags;
new_flags = old_flags & (1ull << DecorationRelaxedPrecision);
param.id = combined_id;
compiler.set_name(combined_id,
join("SPIRV_Cross_Combined", compiler.to_name(texture_id), compiler.to_name(sampler_id)));
caller.combined_parameters.push_back(param);
caller.shadow_arguments.push_back({ type_id, combined_id, 0u, 0u });
}
}
bool Compiler::CombinedImageSamplerHandler::handle(Op opcode, const uint32_t *args, uint32_t length)
@ -2552,8 +2578,7 @@ bool Compiler::CombinedImageSamplerHandler::handle(Op opcode, const uint32_t *ar
type.storage = StorageClassUniformConstant;
// Build new variable.
auto &var = compiler.set<SPIRVariable>(combined_id, type_id, StorageClassUniformConstant, 0);
var.storage = StorageClassUniformConstant;
compiler.set<SPIRVariable>(combined_id, type_id, StorageClassUniformConstant, 0);
// Inherit RelaxedPrecision (and potentially other useful flags if deemed relevant).
auto &new_flags = compiler.meta[combined_id].decoration.decoration_flags;

View File

@ -1905,7 +1905,6 @@ void CompilerGLSL::emit_sampled_image_op(uint32_t result_type, uint32_t result_i
if (image_itr != end(args) || sampler_itr != end(args))
{
// If any parameter originates from a parameter, we will find it in our argument list.
uint32_t param_index = 0;
bool global_texture = image_itr == end(args);
bool global_sampler = sampler_itr == end(args);
uint32_t texture_id = global_texture ? image_id : (image_itr - begin(args));
@ -1920,8 +1919,7 @@ void CompilerGLSL::emit_sampled_image_op(uint32_t result_type, uint32_t result_i
if (itr != end(combined))
{
param_index = itr - begin(combined);
emit_op(result_type, result_id, join("PARAMETER", param_index), true, false);
emit_op(result_type, result_id, to_expression(itr->id), true, false);
}
else
{