Avoid ugly workaround for separate shadow samplers in GLSL/HLSL.
This commit is contained in:
parent
a2f6679d13
commit
978901f9e4
@ -421,7 +421,7 @@ string CompilerCPP::argument_decl(const SPIRFunction::Parameter &arg)
|
||||
return join(constref ? "const " : "", base, " &", variable_name);
|
||||
}
|
||||
|
||||
string CompilerCPP::variable_decl(const SPIRType &type, const string &name)
|
||||
string CompilerCPP::variable_decl(const SPIRType &type, const string &name, uint32_t /* id */)
|
||||
{
|
||||
string base = type_to_glsl(type);
|
||||
remap_variable_type_name(type, name, base);
|
||||
|
@ -61,7 +61,7 @@ private:
|
||||
void emit_uniform(const SPIRVariable &var) override;
|
||||
void emit_shared(const SPIRVariable &var);
|
||||
void emit_block_struct(SPIRType &type);
|
||||
std::string variable_decl(const SPIRType &type, const std::string &name) override;
|
||||
std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id) override;
|
||||
|
||||
std::string argument_decl(const SPIRFunction::Parameter &arg);
|
||||
|
||||
|
@ -5852,9 +5852,9 @@ string CompilerGLSL::convert_row_major_matrix(string exp_str)
|
||||
return join("transpose(", exp_str, ")");
|
||||
}
|
||||
|
||||
string CompilerGLSL::variable_decl(const SPIRType &type, const string &name)
|
||||
string CompilerGLSL::variable_decl(const SPIRType &type, const string &name, uint32_t id)
|
||||
{
|
||||
string type_name = type_to_glsl(type);
|
||||
string type_name = type_to_glsl(type, id);
|
||||
remap_variable_type_name(type, name, type_name);
|
||||
return join(type_name, " ", name, type_to_array_glsl(type));
|
||||
}
|
||||
@ -5971,18 +5971,7 @@ string CompilerGLSL::argument_decl(const SPIRFunction::Parameter &arg)
|
||||
direction = "out ";
|
||||
}
|
||||
|
||||
// We need some special consideration for samplers.
|
||||
// The shadow qualifier for a sampler does not exist in SPIR-V, so the type might depend on which variable this is.
|
||||
SPIRType fake_type;
|
||||
const auto *tmp_type = &type;
|
||||
if (type.basetype == SPIRType::Sampler)
|
||||
{
|
||||
tmp_type = &fake_type;
|
||||
fake_type = type;
|
||||
fake_type.image.depth = comparison_samplers.count(arg.id) != 0;
|
||||
}
|
||||
|
||||
return join(direction, to_qualifiers_glsl(arg.id), variable_decl(*tmp_type, to_name(arg.id)));
|
||||
return join(direction, to_qualifiers_glsl(arg.id), variable_decl(type, to_name(arg.id), arg.id));
|
||||
}
|
||||
|
||||
string CompilerGLSL::variable_decl(const SPIRVariable &variable)
|
||||
@ -5990,18 +5979,9 @@ string CompilerGLSL::variable_decl(const SPIRVariable &variable)
|
||||
// Ignore the pointer type since GLSL doesn't have pointers.
|
||||
auto &type = get<SPIRType>(variable.basetype);
|
||||
|
||||
// We need some special consideration for samplers.
|
||||
// The shadow qualifier for a sampler does not exist in SPIR-V, so the type might depend on which variable this is.
|
||||
SPIRType fake_type;
|
||||
const auto *tmp_type = &type;
|
||||
if (type.basetype == SPIRType::Sampler)
|
||||
{
|
||||
tmp_type = &fake_type;
|
||||
fake_type = type;
|
||||
fake_type.image.depth = comparison_samplers.count(variable.self) != 0;
|
||||
}
|
||||
auto res = join(to_qualifiers_glsl(variable.self),
|
||||
variable_decl(type, to_name(variable.self), variable.self));
|
||||
|
||||
auto res = join(to_qualifiers_glsl(variable.self), variable_decl(*tmp_type, to_name(variable.self)));
|
||||
if (variable.loop_variable)
|
||||
res += join(" = ", to_expression(variable.static_expression));
|
||||
else if (variable.initializer)
|
||||
@ -6220,11 +6200,9 @@ string CompilerGLSL::type_to_glsl(const SPIRType &type, uint32_t id)
|
||||
return image_type_glsl(type, id);
|
||||
|
||||
case SPIRType::Sampler:
|
||||
// This is a hacky workaround. The sampler type in SPIR-V doesn't actually signal this distinction,
|
||||
// but in higher level code we need it.
|
||||
// The depth field is set by calling code based on the variable ID of the sampler, effectively reintroducing
|
||||
// this distinction into the type system.
|
||||
return type.image.depth ? "samplerShadow" : "sampler";
|
||||
return comparison_samplers.count(id) ? "samplerShadow" : "sampler";
|
||||
|
||||
case SPIRType::Void:
|
||||
return "void";
|
||||
|
@ -180,7 +180,7 @@ protected:
|
||||
std::string constant_op_expression(const SPIRConstantOp &cop);
|
||||
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 variable_decl(const SPIRType &type, const std::string &name, uint32_t id = 0);
|
||||
virtual std::string to_func_call_arg(uint32_t id);
|
||||
virtual std::string to_function_name(uint32_t img, const SPIRType &imgtype, bool is_fetch, bool is_gather,
|
||||
bool is_proj, bool has_array_offsets, bool has_offset, bool has_grad,
|
||||
|
@ -157,7 +157,7 @@ string CompilerHLSL::image_type_hlsl(const SPIRType &type)
|
||||
// The optional id parameter indicates the object whose type we are trying
|
||||
// to find the description for. It is optional. Most type descriptions do not
|
||||
// depend on a specific object's use of that type.
|
||||
string CompilerHLSL::type_to_glsl(const SPIRType &type, uint32_t /* id */)
|
||||
string CompilerHLSL::type_to_glsl(const SPIRType &type, uint32_t id)
|
||||
{
|
||||
// Ignore the pointer type since GLSL doesn't have pointers.
|
||||
|
||||
@ -175,7 +175,7 @@ string CompilerHLSL::type_to_glsl(const SPIRType &type, uint32_t /* id */)
|
||||
return image_type_hlsl(type);
|
||||
|
||||
case SPIRType::Sampler:
|
||||
return type.image.depth ? "SamplerComparisonState" : "SamplerState";
|
||||
return comparison_samplers.count(id) ? "SamplerComparisonState" : "SamplerState";
|
||||
|
||||
case SPIRType::Void:
|
||||
return "void";
|
||||
|
Loading…
Reference in New Issue
Block a user