mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
update spirv-cross
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2020 Arm Limited
|
||||
* Copyright 2015-2021 Arm Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,6 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_GLSL_HPP
|
||||
#define SPIRV_CROSS_GLSL_HPP
|
||||
|
||||
@@ -57,7 +64,8 @@ enum AccessChainFlagBits
|
||||
ACCESS_CHAIN_CHAIN_ONLY_BIT = 1 << 1,
|
||||
ACCESS_CHAIN_PTR_CHAIN_BIT = 1 << 2,
|
||||
ACCESS_CHAIN_SKIP_REGISTER_EXPRESSION_READ_BIT = 1 << 3,
|
||||
ACCESS_CHAIN_LITERAL_MSB_FORCE_ID = 1 << 4
|
||||
ACCESS_CHAIN_LITERAL_MSB_FORCE_ID = 1 << 4,
|
||||
ACCESS_CHAIN_FLATTEN_ALL_MEMBERS_BIT = 1 << 5
|
||||
};
|
||||
typedef uint32_t AccessChainFlags;
|
||||
|
||||
@@ -120,6 +128,10 @@ public:
|
||||
// which would otherwise be uninitialized will now be initialized to 0 instead.
|
||||
bool force_zero_initialized_variables = false;
|
||||
|
||||
// In GLSL, force use of I/O block flattening, similar to
|
||||
// what happens on legacy GLSL targets for blocks and structs.
|
||||
bool force_flattened_io_blocks = false;
|
||||
|
||||
enum Precision
|
||||
{
|
||||
DontCare,
|
||||
@@ -128,14 +140,16 @@ public:
|
||||
Highp
|
||||
};
|
||||
|
||||
struct
|
||||
struct VertexOptions
|
||||
{
|
||||
// GLSL: In vertex shaders, rewrite [0, w] depth (Vulkan/D3D style) to [-w, w] depth (GL style).
|
||||
// MSL: In vertex shaders, rewrite [-w, w] depth (GL style) to [0, w] depth.
|
||||
// HLSL: In vertex shaders, rewrite [-w, w] depth (GL style) to [0, w] depth.
|
||||
// "Vertex-like shader" here is any shader stage that can write BuiltInPosition.
|
||||
|
||||
// GLSL: In vertex-like shaders, rewrite [0, w] depth (Vulkan/D3D style) to [-w, w] depth (GL style).
|
||||
// MSL: In vertex-like shaders, rewrite [-w, w] depth (GL style) to [0, w] depth.
|
||||
// HLSL: In vertex-like shaders, rewrite [-w, w] depth (GL style) to [0, w] depth.
|
||||
bool fixup_clipspace = false;
|
||||
|
||||
// Inverts gl_Position.y or equivalent.
|
||||
// In vertex-like shaders, inverts gl_Position.y or equivalent.
|
||||
bool flip_vert_y = false;
|
||||
|
||||
// GLSL only, for HLSL version of this option, see CompilerHLSL.
|
||||
@@ -145,7 +159,7 @@ public:
|
||||
bool support_nonzero_base_instance = true;
|
||||
} vertex;
|
||||
|
||||
struct
|
||||
struct FragmentOptions
|
||||
{
|
||||
// Add precision mediump float in ES targets when emitting GLES source.
|
||||
// Add precision highp int in ES targets when emitting GLES source.
|
||||
@@ -237,6 +251,82 @@ public:
|
||||
bool variable_is_depth_or_compare(VariableID id) const;
|
||||
|
||||
protected:
|
||||
struct ShaderSubgroupSupportHelper
|
||||
{
|
||||
// lower enum value = greater priority
|
||||
enum Candidate
|
||||
{
|
||||
KHR_shader_subgroup_ballot,
|
||||
KHR_shader_subgroup_basic,
|
||||
KHR_shader_subgroup_vote,
|
||||
NV_gpu_shader_5,
|
||||
NV_shader_thread_group,
|
||||
NV_shader_thread_shuffle,
|
||||
ARB_shader_ballot,
|
||||
ARB_shader_group_vote,
|
||||
AMD_gcn_shader,
|
||||
|
||||
CandidateCount
|
||||
};
|
||||
|
||||
static const char *get_extension_name(Candidate c);
|
||||
static SmallVector<std::string> get_extra_required_extension_names(Candidate c);
|
||||
static const char *get_extra_required_extension_predicate(Candidate c);
|
||||
|
||||
enum Feature
|
||||
{
|
||||
SubgroupMask = 0,
|
||||
SubgroupSize = 1,
|
||||
SubgroupInvocationID = 2,
|
||||
SubgroupID = 3,
|
||||
NumSubgroups = 4,
|
||||
SubgroupBroadcast_First = 5,
|
||||
SubgroupBallotFindLSB_MSB = 6,
|
||||
SubgroupAll_Any_AllEqualBool = 7,
|
||||
SubgroupAllEqualT = 8,
|
||||
SubgroupElect = 9,
|
||||
SubgroupBarrier = 10,
|
||||
SubgroupMemBarrier = 11,
|
||||
SubgroupBallot = 12,
|
||||
SubgroupInverseBallot_InclBitCount_ExclBitCout = 13,
|
||||
SubgroupBallotBitExtract = 14,
|
||||
SubgroupBallotBitCount = 15,
|
||||
|
||||
FeatureCount
|
||||
};
|
||||
|
||||
using FeatureMask = uint32_t;
|
||||
static_assert(sizeof(FeatureMask) * 8u >= FeatureCount, "Mask type needs more bits.");
|
||||
|
||||
using CandidateVector = SmallVector<Candidate, CandidateCount>;
|
||||
using FeatureVector = SmallVector<Feature>;
|
||||
|
||||
static FeatureVector get_feature_dependencies(Feature feature);
|
||||
static FeatureMask get_feature_dependency_mask(Feature feature);
|
||||
static bool can_feature_be_implemented_without_extensions(Feature feature);
|
||||
static Candidate get_KHR_extension_for_feature(Feature feature);
|
||||
|
||||
struct Result
|
||||
{
|
||||
Result();
|
||||
uint32_t weights[CandidateCount];
|
||||
};
|
||||
|
||||
void request_feature(Feature feature);
|
||||
bool is_feature_requested(Feature feature) const;
|
||||
Result resolve() const;
|
||||
|
||||
static CandidateVector get_candidates_for_feature(Feature ft, const Result &r);
|
||||
|
||||
private:
|
||||
static CandidateVector get_candidates_for_feature(Feature ft);
|
||||
static FeatureMask build_mask(const SmallVector<Feature> &features);
|
||||
FeatureMask feature_mask = 0;
|
||||
};
|
||||
|
||||
// TODO remove this function when all subgroup ops are supported (or make it always return true)
|
||||
static bool is_supported_subgroup_op_in_opengl(spv::Op op);
|
||||
|
||||
void reset();
|
||||
void emit_function(SPIRFunction &func, const Bitset &return_flags);
|
||||
|
||||
@@ -267,9 +357,11 @@ protected:
|
||||
void build_workgroup_size(SmallVector<std::string> &arguments, const SpecializationConstant &x,
|
||||
const SpecializationConstant &y, const SpecializationConstant &z);
|
||||
|
||||
void request_subgroup_feature(ShaderSubgroupSupportHelper::Feature feature);
|
||||
|
||||
virtual void emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id);
|
||||
virtual void emit_texture_op(const Instruction &i);
|
||||
virtual std::string to_texture_op(const Instruction &i, bool *forward,
|
||||
virtual void emit_texture_op(const Instruction &i, bool sparse);
|
||||
virtual std::string to_texture_op(const Instruction &i, bool sparse, bool *forward,
|
||||
SmallVector<uint32_t> &inherited_expressions);
|
||||
virtual void emit_subgroup_op(const Instruction &i);
|
||||
virtual std::string type_to_glsl(const SPIRType &type, uint32_t id = 0);
|
||||
@@ -284,14 +376,42 @@ protected:
|
||||
virtual void emit_fixup();
|
||||
virtual std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id = 0);
|
||||
virtual std::string to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id);
|
||||
virtual std::string to_function_name(VariableID img, const SPIRType &imgtype, bool is_fetch, bool is_gather,
|
||||
bool is_proj, bool has_array_offsets, bool has_offset, bool has_grad,
|
||||
bool has_dref, uint32_t lod, uint32_t minlod);
|
||||
virtual std::string to_function_args(VariableID img, const SPIRType &imgtype, bool is_fetch, bool is_gather,
|
||||
bool is_proj, uint32_t coord, uint32_t coord_components, uint32_t dref,
|
||||
uint32_t grad_x, uint32_t grad_y, uint32_t lod, uint32_t coffset,
|
||||
uint32_t offset, uint32_t bias, uint32_t comp, uint32_t sample,
|
||||
uint32_t minlod, bool *p_forward);
|
||||
|
||||
struct TextureFunctionBaseArguments
|
||||
{
|
||||
// GCC 4.8 workarounds, it doesn't understand '{}' constructor here, use explicit default constructor.
|
||||
TextureFunctionBaseArguments() = default;
|
||||
VariableID img = 0;
|
||||
const SPIRType *imgtype = nullptr;
|
||||
bool is_fetch = false, is_gather = false, is_proj = false;
|
||||
};
|
||||
|
||||
struct TextureFunctionNameArguments
|
||||
{
|
||||
// GCC 4.8 workarounds, it doesn't understand '{}' constructor here, use explicit default constructor.
|
||||
TextureFunctionNameArguments() = default;
|
||||
TextureFunctionBaseArguments base;
|
||||
bool has_array_offsets = false, has_offset = false, has_grad = false;
|
||||
bool has_dref = false, is_sparse_feedback = false, has_min_lod = false;
|
||||
uint32_t lod = 0;
|
||||
};
|
||||
virtual std::string to_function_name(const TextureFunctionNameArguments &args);
|
||||
|
||||
struct TextureFunctionArguments
|
||||
{
|
||||
// GCC 4.8 workarounds, it doesn't understand '{}' constructor here, use explicit default constructor.
|
||||
TextureFunctionArguments() = default;
|
||||
TextureFunctionBaseArguments base;
|
||||
uint32_t coord = 0, coord_components = 0, dref = 0;
|
||||
uint32_t grad_x = 0, grad_y = 0, lod = 0, coffset = 0, offset = 0;
|
||||
uint32_t bias = 0, component = 0, sample = 0, sparse_texel = 0, min_lod = 0;
|
||||
bool nonuniform_expression = false;
|
||||
};
|
||||
virtual std::string to_function_args(const TextureFunctionArguments &args, bool *p_forward);
|
||||
|
||||
void emit_sparse_feedback_temporaries(uint32_t result_type_id, uint32_t id, uint32_t &feedback_id,
|
||||
uint32_t &texel_id);
|
||||
uint32_t get_sparse_feedback_texel_id(uint32_t id) const;
|
||||
virtual void emit_buffer_block(const SPIRVariable &type);
|
||||
virtual void emit_push_constant_block(const SPIRVariable &var);
|
||||
virtual void emit_uniform(const SPIRVariable &var);
|
||||
@@ -441,25 +561,34 @@ protected:
|
||||
bool supports_extensions = false;
|
||||
bool supports_empty_struct = false;
|
||||
bool array_is_value_type = true;
|
||||
bool buffer_offset_array_is_value_type = true;
|
||||
bool comparison_image_samples_scalar = false;
|
||||
bool native_pointers = false;
|
||||
bool support_small_type_sampling_result = false;
|
||||
bool support_case_fallthrough = true;
|
||||
bool use_array_constructor = false;
|
||||
bool needs_row_major_load_workaround = false;
|
||||
bool support_pointer_to_pointer = false;
|
||||
} backend;
|
||||
|
||||
void emit_struct(SPIRType &type);
|
||||
void emit_resources();
|
||||
void emit_extension_workarounds(spv::ExecutionModel model);
|
||||
void emit_buffer_block_native(const SPIRVariable &var);
|
||||
void emit_buffer_reference_block(SPIRType &type, bool forward_declaration);
|
||||
void emit_buffer_block_legacy(const SPIRVariable &var);
|
||||
void emit_buffer_block_flattened(const SPIRVariable &type);
|
||||
void fixup_implicit_builtin_block_names();
|
||||
void emit_declared_builtin_block(spv::StorageClass storage, spv::ExecutionModel model);
|
||||
bool should_force_emit_builtin_block(spv::StorageClass storage);
|
||||
void emit_push_constant_block_vulkan(const SPIRVariable &var);
|
||||
void emit_push_constant_block_glsl(const SPIRVariable &var);
|
||||
void emit_interface_block(const SPIRVariable &type);
|
||||
void emit_flattened_io_block(const SPIRVariable &var, const char *qual);
|
||||
void emit_flattened_io_block_struct(const std::string &basename, const SPIRType &type, const char *qual,
|
||||
const SmallVector<uint32_t> &indices);
|
||||
void emit_flattened_io_block_member(const std::string &basename, const SPIRType &type, const char *qual,
|
||||
const SmallVector<uint32_t> &indices);
|
||||
void emit_block_chain(SPIRBlock &block);
|
||||
void emit_hoisted_temporaries(SmallVector<std::pair<TypeID, ID>> &temporaries);
|
||||
std::string constant_value_macro_name(uint32_t id);
|
||||
@@ -522,6 +651,7 @@ protected:
|
||||
void emit_unary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op);
|
||||
bool expression_is_forwarded(uint32_t id) const;
|
||||
bool expression_suppresses_usage_tracking(uint32_t id) const;
|
||||
bool expression_read_implies_multiple_reads(uint32_t id) const;
|
||||
SPIRExpression &emit_op(uint32_t result_type, uint32_t result_id, const std::string &rhs, bool forward_rhs,
|
||||
bool suppress_usage_tracking = false);
|
||||
|
||||
@@ -531,6 +661,9 @@ protected:
|
||||
std::string access_chain_internal(uint32_t base, const uint32_t *indices, uint32_t count, AccessChainFlags flags,
|
||||
AccessChainMeta *meta);
|
||||
|
||||
virtual void prepare_access_chain_for_scalar_access(std::string &expr, const SPIRType &type,
|
||||
spv::StorageClass storage, bool &is_packed);
|
||||
|
||||
std::string access_chain(uint32_t base, const uint32_t *indices, uint32_t count, const SPIRType &target_type,
|
||||
AccessChainMeta *meta = nullptr, bool ptr_chain = false);
|
||||
|
||||
@@ -559,7 +692,7 @@ protected:
|
||||
SPIRExpression &emit_uninitialized_temporary_expression(uint32_t type, uint32_t id);
|
||||
void append_global_func_args(const SPIRFunction &func, uint32_t index, SmallVector<std::string> &arglist);
|
||||
std::string to_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_composite_constructor_expression(uint32_t id);
|
||||
std::string to_composite_constructor_expression(uint32_t id, bool uses_buffer_offset);
|
||||
std::string to_rerolled_array_expression(const std::string &expr, const SPIRType &type);
|
||||
std::string to_enclosed_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_unpacked_expression(uint32_t id, bool register_expression_read = true);
|
||||
@@ -569,15 +702,20 @@ protected:
|
||||
std::string to_pointer_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_enclosed_pointer_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_extract_component_expression(uint32_t id, uint32_t index);
|
||||
std::string to_extract_constant_composite_expression(uint32_t result_type, const SPIRConstant &c,
|
||||
const uint32_t *chain, uint32_t length);
|
||||
std::string enclose_expression(const std::string &expr);
|
||||
std::string dereference_expression(const SPIRType &expression_type, const std::string &expr);
|
||||
std::string address_of_expression(const std::string &expr);
|
||||
void strip_enclosed_expression(std::string &expr);
|
||||
std::string to_member_name(const SPIRType &type, uint32_t index);
|
||||
virtual std::string to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain);
|
||||
std::string to_multi_member_reference(const SPIRType &type, const SmallVector<uint32_t> &indices);
|
||||
std::string type_to_glsl_constructor(const SPIRType &type);
|
||||
std::string argument_decl(const SPIRFunction::Parameter &arg);
|
||||
virtual std::string to_qualifiers_glsl(uint32_t id);
|
||||
void fixup_io_block_patch_qualifiers(const SPIRVariable &var);
|
||||
void emit_output_variable_initializer(const SPIRVariable &var);
|
||||
const char *to_precision_qualifiers_glsl(uint32_t id);
|
||||
virtual const char *to_storage_qualifiers_glsl(const SPIRVariable &var);
|
||||
const char *flags_to_qualifiers_glsl(const SPIRType &type, const Bitset &flags);
|
||||
@@ -624,8 +762,7 @@ protected:
|
||||
|
||||
void replace_fragment_output(SPIRVariable &var);
|
||||
void replace_fragment_outputs();
|
||||
bool check_explicit_lod_allowed(uint32_t lod);
|
||||
std::string legacy_tex_op(const std::string &op, const SPIRType &imgtype, uint32_t lod, uint32_t id);
|
||||
std::string legacy_tex_op(const std::string &op, const SPIRType &imgtype, uint32_t id);
|
||||
|
||||
uint32_t indent = 0;
|
||||
|
||||
@@ -635,11 +772,16 @@ protected:
|
||||
std::unordered_set<uint32_t> flushed_phi_variables;
|
||||
|
||||
std::unordered_set<uint32_t> flattened_buffer_blocks;
|
||||
std::unordered_set<uint32_t> flattened_structs;
|
||||
std::unordered_map<uint32_t, bool> flattened_structs;
|
||||
|
||||
std::string load_flattened_struct(SPIRVariable &var);
|
||||
std::string to_flattened_struct_member(const SPIRVariable &var, uint32_t index);
|
||||
void store_flattened_struct(SPIRVariable &var, uint32_t value);
|
||||
ShaderSubgroupSupportHelper shader_subgroup_supporter;
|
||||
|
||||
std::string load_flattened_struct(const std::string &basename, const SPIRType &type);
|
||||
std::string to_flattened_struct_member(const std::string &basename, const SPIRType &type, uint32_t index);
|
||||
void store_flattened_struct(uint32_t lhs_id, uint32_t value);
|
||||
void store_flattened_struct(const std::string &basename, uint32_t rhs, const SPIRType &type,
|
||||
const SmallVector<uint32_t> &indices);
|
||||
std::string to_flattened_access_chain_expression(uint32_t id);
|
||||
|
||||
// Usage tracking. If a temporary is used more than once, use the temporary instead to
|
||||
// avoid AST explosion when SPIRV is generated with pure SSA and doesn't write stuff to variables.
|
||||
@@ -654,6 +796,10 @@ protected:
|
||||
// Currently used by NMin/Max/Clamp implementations.
|
||||
std::unordered_map<uint32_t, uint32_t> extra_sub_expressions;
|
||||
|
||||
SmallVector<TypeID> workaround_ubo_load_overload_types;
|
||||
void request_workaround_wrapper_overload(TypeID id);
|
||||
void rewrite_load_for_wrapped_row_major(std::string &expr, TypeID loaded_type, ID ptr);
|
||||
|
||||
uint32_t statement_count = 0;
|
||||
|
||||
inline bool is_legacy() const
|
||||
@@ -671,6 +817,12 @@ protected:
|
||||
return !options.es && options.version < 130;
|
||||
}
|
||||
|
||||
bool requires_transpose_2x2 = false;
|
||||
bool requires_transpose_3x3 = false;
|
||||
bool requires_transpose_4x4 = false;
|
||||
bool ray_tracing_is_khr = false;
|
||||
void ray_tracing_khr_fixup_locations();
|
||||
|
||||
bool args_will_forward(uint32_t id, const uint32_t *args, uint32_t num_args, bool pure);
|
||||
void register_call_out_argument(uint32_t id);
|
||||
void register_impure_function_call();
|
||||
@@ -712,8 +864,6 @@ protected:
|
||||
|
||||
virtual void declare_undefined_values();
|
||||
|
||||
static std::string sanitize_underscores(const std::string &str);
|
||||
|
||||
bool can_use_io_location(spv::StorageClass storage, bool block);
|
||||
const Instruction *get_next_instruction_in_block(const Instruction &instr);
|
||||
static uint32_t mask_relevant_memory_semantics(uint32_t semantics);
|
||||
@@ -726,16 +876,18 @@ protected:
|
||||
|
||||
// Builtins in GLSL are always specific signedness, but the SPIR-V can declare them
|
||||
// as either unsigned or signed.
|
||||
// Sometimes we will need to automatically perform bitcasts on load and store to make this work.
|
||||
virtual void bitcast_to_builtin_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type);
|
||||
virtual void bitcast_from_builtin_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type);
|
||||
// Sometimes we will need to automatically perform casts on load and store to make this work.
|
||||
virtual void cast_to_builtin_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type);
|
||||
virtual void cast_from_builtin_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type);
|
||||
void unroll_array_from_complex_load(uint32_t target_id, uint32_t source_id, std::string &expr);
|
||||
bool unroll_array_to_complex_store(uint32_t target_id, uint32_t source_id);
|
||||
void convert_non_uniform_expression(const SPIRType &type, std::string &expr);
|
||||
|
||||
void handle_store_to_invariant_variable(uint32_t store_id, uint32_t value_id);
|
||||
void disallow_forwarding_in_expression_chain(const SPIRExpression &expr);
|
||||
|
||||
bool expression_is_constant_null(uint32_t id) const;
|
||||
bool expression_is_non_value_type_array(uint32_t ptr);
|
||||
virtual void emit_store_statement(uint32_t lhs_expression, uint32_t rhs_expression);
|
||||
|
||||
uint32_t get_integer_width_for_instruction(const Instruction &instr) const;
|
||||
|
||||
Reference in New Issue
Block a user