Compare commits
2 Commits
5d159645ec
...
cae2dd177c
Author | SHA1 | Date | |
---|---|---|---|
cae2dd177c | |||
8c8ec50885 |
200
spirv_cfg.hpp
200
spirv_cfg.hpp
@ -33,135 +33,135 @@ class Compiler;
|
|||||||
class CFG
|
class CFG
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CFG(Compiler &compiler, const SPIRFunction &function);
|
CFG(Compiler &compiler, const SPIRFunction &function);
|
||||||
|
|
||||||
Compiler &get_compiler()
|
Compiler &get_compiler()
|
||||||
{
|
{
|
||||||
return compiler;
|
return compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Compiler &get_compiler() const
|
const Compiler &get_compiler() const
|
||||||
{
|
{
|
||||||
return compiler;
|
return compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SPIRFunction &get_function() const
|
const SPIRFunction &get_function() const
|
||||||
{
|
{
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t get_immediate_dominator(uint32_t block) const
|
uint32_t get_immediate_dominator(uint32_t block) const
|
||||||
{
|
{
|
||||||
auto itr = immediate_dominators.find(block);
|
auto itr = immediate_dominators.find(block);
|
||||||
if (itr != std::end(immediate_dominators))
|
if (itr != std::end(immediate_dominators))
|
||||||
return itr->second;
|
return itr->second;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_reachable(uint32_t block) const
|
bool is_reachable(uint32_t block) const
|
||||||
{
|
{
|
||||||
return visit_order.count(block) != 0;
|
return visit_order.count(block) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t get_visit_order(uint32_t block) const
|
uint32_t get_visit_order(uint32_t block) const
|
||||||
{
|
{
|
||||||
auto itr = visit_order.find(block);
|
auto itr = visit_order.find(block);
|
||||||
assert(itr != std::end(visit_order));
|
assert(itr != std::end(visit_order));
|
||||||
int v = itr->second.get();
|
int v = itr->second.get();
|
||||||
assert(v > 0);
|
assert(v > 0);
|
||||||
return uint32_t(v);
|
return uint32_t(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t find_common_dominator(uint32_t a, uint32_t b) const;
|
uint32_t find_common_dominator(uint32_t a, uint32_t b) const;
|
||||||
|
|
||||||
const SmallVector<uint32_t> &get_preceding_edges(uint32_t block) const
|
const SmallVector<uint32_t> &get_preceding_edges(uint32_t block) const
|
||||||
{
|
{
|
||||||
auto itr = preceding_edges.find(block);
|
auto itr = preceding_edges.find(block);
|
||||||
if (itr != std::end(preceding_edges))
|
if (itr != std::end(preceding_edges))
|
||||||
return itr->second;
|
return itr->second;
|
||||||
else
|
else
|
||||||
return empty_vector;
|
return empty_vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SmallVector<uint32_t> &get_succeeding_edges(uint32_t block) const
|
const SmallVector<uint32_t> &get_succeeding_edges(uint32_t block) const
|
||||||
{
|
{
|
||||||
auto itr = succeeding_edges.find(block);
|
auto itr = succeeding_edges.find(block);
|
||||||
if (itr != std::end(succeeding_edges))
|
if (itr != std::end(succeeding_edges))
|
||||||
return itr->second;
|
return itr->second;
|
||||||
else
|
else
|
||||||
return empty_vector;
|
return empty_vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Op>
|
template <typename Op>
|
||||||
void walk_from(std::unordered_set<uint32_t> &seen_blocks, uint32_t block, const Op &op) const
|
void walk_from(std::unordered_set<uint32_t> &seen_blocks, uint32_t block, const Op &op) const
|
||||||
{
|
{
|
||||||
if (seen_blocks.count(block))
|
if (seen_blocks.count(block))
|
||||||
return;
|
return;
|
||||||
seen_blocks.insert(block);
|
seen_blocks.insert(block);
|
||||||
|
|
||||||
if (op(block))
|
if (op(block))
|
||||||
{
|
{
|
||||||
for (auto b : get_succeeding_edges(block))
|
for (auto b : get_succeeding_edges(block))
|
||||||
walk_from(seen_blocks, b, op);
|
walk_from(seen_blocks, b, op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t find_loop_dominator(uint32_t block) const;
|
uint32_t find_loop_dominator(uint32_t block) const;
|
||||||
|
|
||||||
bool node_terminates_control_flow_in_sub_graph(BlockID from, BlockID to) const;
|
bool node_terminates_control_flow_in_sub_graph(BlockID from, BlockID to) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct VisitOrder
|
struct VisitOrder
|
||||||
{
|
{
|
||||||
int &get()
|
int &get()
|
||||||
{
|
{
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int &get() const
|
const int &get() const
|
||||||
{
|
{
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int v = -1;
|
int v = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler &compiler;
|
Compiler &compiler;
|
||||||
const SPIRFunction &func;
|
const SPIRFunction &func;
|
||||||
std::unordered_map<uint32_t, SmallVector<uint32_t>> preceding_edges;
|
std::unordered_map<uint32_t, SmallVector<uint32_t>> preceding_edges;
|
||||||
std::unordered_map<uint32_t, SmallVector<uint32_t>> succeeding_edges;
|
std::unordered_map<uint32_t, SmallVector<uint32_t>> succeeding_edges;
|
||||||
std::unordered_map<uint32_t, uint32_t> immediate_dominators;
|
std::unordered_map<uint32_t, uint32_t> immediate_dominators;
|
||||||
std::unordered_map<uint32_t, VisitOrder> visit_order;
|
std::unordered_map<uint32_t, VisitOrder> visit_order;
|
||||||
SmallVector<uint32_t> post_order;
|
SmallVector<uint32_t> post_order;
|
||||||
SmallVector<uint32_t> empty_vector;
|
SmallVector<uint32_t> empty_vector;
|
||||||
|
|
||||||
void add_branch(uint32_t from, uint32_t to);
|
void add_branch(uint32_t from, uint32_t to);
|
||||||
void build_post_order_visit_order();
|
void build_post_order_visit_order();
|
||||||
void build_immediate_dominators();
|
void build_immediate_dominators();
|
||||||
bool post_order_visit(uint32_t block);
|
bool post_order_visit(uint32_t block);
|
||||||
uint32_t visit_count = 0;
|
uint32_t visit_count = 0;
|
||||||
|
|
||||||
bool is_back_edge(uint32_t to) const;
|
bool is_back_edge(uint32_t to) const;
|
||||||
bool has_visited_forward_edge(uint32_t to) const;
|
bool has_visited_forward_edge(uint32_t to) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DominatorBuilder
|
class DominatorBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DominatorBuilder(const CFG &cfg);
|
DominatorBuilder(const CFG &cfg);
|
||||||
|
|
||||||
void add_block(uint32_t block);
|
void add_block(uint32_t block);
|
||||||
uint32_t get_dominator() const
|
uint32_t get_dominator() const
|
||||||
{
|
{
|
||||||
return dominator;
|
return dominator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lift_continue_block_dominator();
|
void lift_continue_block_dominator();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const CFG &cfg;
|
const CFG &cfg;
|
||||||
uint32_t dominator = 0;
|
uint32_t dominator = 0;
|
||||||
};
|
};
|
||||||
} // namespace SPIRV_CROSS_NAMESPACE
|
} // namespace SPIRV_CROSS_NAMESPACE
|
||||||
|
|
||||||
|
2064
spirv_cross.hpp
2064
spirv_cross.hpp
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -49,12 +49,12 @@ inline void
|
|||||||
report_and_abort(const std::string &msg)
|
report_and_abort(const std::string &msg)
|
||||||
{
|
{
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
(void)msg;
|
(void)msg;
|
||||||
#else
|
#else
|
||||||
fprintf(stderr, "There was a compiler error: %s\n", msg.c_str());
|
fprintf(stderr, "There was a compiler error: %s\n", msg.c_str());
|
||||||
#endif
|
#endif
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SPIRV_CROSS_THROW(x) report_and_abort(x)
|
#define SPIRV_CROSS_THROW(x) report_and_abort(x)
|
||||||
@ -62,15 +62,15 @@ report_and_abort(const std::string &msg)
|
|||||||
class CompilerError : public std::runtime_error
|
class CompilerError : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CompilerError(const std::string &str)
|
explicit CompilerError(const std::string &str)
|
||||||
: std::runtime_error(str)
|
: std::runtime_error(str)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit CompilerError(const char *str)
|
explicit CompilerError(const char *str)
|
||||||
: std::runtime_error(str)
|
: std::runtime_error(str)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SPIRV_CROSS_THROW(x) throw CompilerError(x)
|
#define SPIRV_CROSS_THROW(x) throw CompilerError(x)
|
||||||
|
@ -39,217 +39,217 @@ namespace SPIRV_CROSS_NAMESPACE
|
|||||||
class ParsedIR
|
class ParsedIR
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// This must be destroyed after the "ids" vector.
|
// This must be destroyed after the "ids" vector.
|
||||||
std::unique_ptr<ObjectPoolGroup> pool_group;
|
std::unique_ptr<ObjectPoolGroup> pool_group;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ParsedIR();
|
ParsedIR();
|
||||||
|
|
||||||
// Due to custom allocations from object pools, we cannot use a default copy constructor.
|
// Due to custom allocations from object pools, we cannot use a default copy constructor.
|
||||||
ParsedIR(const ParsedIR &other);
|
ParsedIR(const ParsedIR &other);
|
||||||
ParsedIR &operator=(const ParsedIR &other);
|
ParsedIR &operator=(const ParsedIR &other);
|
||||||
|
|
||||||
// Moves are unproblematic, but we need to implement it anyways, since MSVC 2013 does not understand
|
// Moves are unproblematic, but we need to implement it anyways, since MSVC 2013 does not understand
|
||||||
// how to default-implement these.
|
// how to default-implement these.
|
||||||
ParsedIR(ParsedIR &&other) SPIRV_CROSS_NOEXCEPT;
|
ParsedIR(ParsedIR &&other) SPIRV_CROSS_NOEXCEPT;
|
||||||
ParsedIR &operator=(ParsedIR &&other) SPIRV_CROSS_NOEXCEPT;
|
ParsedIR &operator=(ParsedIR &&other) SPIRV_CROSS_NOEXCEPT;
|
||||||
|
|
||||||
// Resizes ids, meta and block_meta.
|
// Resizes ids, meta and block_meta.
|
||||||
void set_id_bounds(uint32_t bounds);
|
void set_id_bounds(uint32_t bounds);
|
||||||
|
|
||||||
// The raw SPIR-V, instructions and opcodes refer to this by offset + count.
|
// The raw SPIR-V, instructions and opcodes refer to this by offset + count.
|
||||||
std::vector<uint32_t> spirv;
|
std::vector<uint32_t> spirv;
|
||||||
|
|
||||||
// Holds various data structures which inherit from IVariant.
|
// Holds various data structures which inherit from IVariant.
|
||||||
SmallVector<Variant> ids;
|
SmallVector<Variant> ids;
|
||||||
|
|
||||||
// Various meta data for IDs, decorations, names, etc.
|
// Various meta data for IDs, decorations, names, etc.
|
||||||
std::unordered_map<ID, Meta> meta;
|
std::unordered_map<ID, Meta> meta;
|
||||||
|
|
||||||
// Holds all IDs which have a certain type.
|
// Holds all IDs which have a certain type.
|
||||||
// This is needed so we can iterate through a specific kind of resource quickly,
|
// This is needed so we can iterate through a specific kind of resource quickly,
|
||||||
// and in-order of module declaration.
|
// and in-order of module declaration.
|
||||||
SmallVector<ID> ids_for_type[TypeCount];
|
SmallVector<ID> ids_for_type[TypeCount];
|
||||||
|
|
||||||
// Special purpose lists which contain a union of types.
|
// Special purpose lists which contain a union of types.
|
||||||
// This is needed so we can declare specialization constants and structs in an interleaved fashion,
|
// This is needed so we can declare specialization constants and structs in an interleaved fashion,
|
||||||
// among other things.
|
// among other things.
|
||||||
// Constants can be undef or of struct type, and struct array sizes can use specialization constants.
|
// Constants can be undef or of struct type, and struct array sizes can use specialization constants.
|
||||||
SmallVector<ID> ids_for_constant_undef_or_type;
|
SmallVector<ID> ids_for_constant_undef_or_type;
|
||||||
SmallVector<ID> ids_for_constant_or_variable;
|
SmallVector<ID> ids_for_constant_or_variable;
|
||||||
|
|
||||||
// We need to keep track of the width the Ops that contains a type for the
|
// We need to keep track of the width the Ops that contains a type for the
|
||||||
// OpSwitch instruction, since this one doesn't contains the type in the
|
// OpSwitch instruction, since this one doesn't contains the type in the
|
||||||
// instruction itself. And in some case we need to cast the condition to
|
// instruction itself. And in some case we need to cast the condition to
|
||||||
// wider types. We only need the width to do the branch fixup since the
|
// wider types. We only need the width to do the branch fixup since the
|
||||||
// type check itself can be done at runtime
|
// type check itself can be done at runtime
|
||||||
std::unordered_map<ID, uint32_t> load_type_width;
|
std::unordered_map<ID, uint32_t> load_type_width;
|
||||||
|
|
||||||
// Declared capabilities and extensions in the SPIR-V module.
|
// Declared capabilities and extensions in the SPIR-V module.
|
||||||
// Not really used except for reflection at the moment.
|
// Not really used except for reflection at the moment.
|
||||||
SmallVector<spv::Capability> declared_capabilities;
|
SmallVector<spv::Capability> declared_capabilities;
|
||||||
SmallVector<std::string> declared_extensions;
|
SmallVector<std::string> declared_extensions;
|
||||||
|
|
||||||
// Meta data about blocks. The cross-compiler needs to query if a block is either of these types.
|
// Meta data about blocks. The cross-compiler needs to query if a block is either of these types.
|
||||||
// It is a bitset as there can be more than one tag per block.
|
// It is a bitset as there can be more than one tag per block.
|
||||||
enum BlockMetaFlagBits
|
enum BlockMetaFlagBits
|
||||||
{
|
{
|
||||||
BLOCK_META_LOOP_HEADER_BIT = 1 << 0,
|
BLOCK_META_LOOP_HEADER_BIT = 1 << 0,
|
||||||
BLOCK_META_CONTINUE_BIT = 1 << 1,
|
BLOCK_META_CONTINUE_BIT = 1 << 1,
|
||||||
BLOCK_META_LOOP_MERGE_BIT = 1 << 2,
|
BLOCK_META_LOOP_MERGE_BIT = 1 << 2,
|
||||||
BLOCK_META_SELECTION_MERGE_BIT = 1 << 3,
|
BLOCK_META_SELECTION_MERGE_BIT = 1 << 3,
|
||||||
BLOCK_META_MULTISELECT_MERGE_BIT = 1 << 4
|
BLOCK_META_MULTISELECT_MERGE_BIT = 1 << 4
|
||||||
};
|
};
|
||||||
using BlockMetaFlags = uint8_t;
|
using BlockMetaFlags = uint8_t;
|
||||||
SmallVector<BlockMetaFlags> block_meta;
|
SmallVector<BlockMetaFlags> block_meta;
|
||||||
std::unordered_map<BlockID, BlockID> continue_block_to_loop_header;
|
std::unordered_map<BlockID, BlockID> continue_block_to_loop_header;
|
||||||
|
|
||||||
// Normally, we'd stick SPIREntryPoint in ids array, but it conflicts with SPIRFunction.
|
// Normally, we'd stick SPIREntryPoint in ids array, but it conflicts with SPIRFunction.
|
||||||
// Entry points can therefore be seen as some sort of meta structure.
|
// Entry points can therefore be seen as some sort of meta structure.
|
||||||
std::unordered_map<FunctionID, SPIREntryPoint> entry_points;
|
std::unordered_map<FunctionID, SPIREntryPoint> entry_points;
|
||||||
FunctionID default_entry_point = 0;
|
FunctionID default_entry_point = 0;
|
||||||
|
|
||||||
struct Source
|
struct Source
|
||||||
{
|
{
|
||||||
uint32_t version = 0;
|
uint32_t version = 0;
|
||||||
bool es = false;
|
bool es = false;
|
||||||
bool known = false;
|
bool known = false;
|
||||||
bool hlsl = false;
|
bool hlsl = false;
|
||||||
|
|
||||||
Source() = default;
|
Source() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
Source source;
|
Source source;
|
||||||
|
|
||||||
spv::AddressingModel addressing_model = spv::AddressingModelMax;
|
spv::AddressingModel addressing_model = spv::AddressingModelMax;
|
||||||
spv::MemoryModel memory_model = spv::MemoryModelMax;
|
spv::MemoryModel memory_model = spv::MemoryModelMax;
|
||||||
|
|
||||||
// Decoration handling methods.
|
// Decoration handling methods.
|
||||||
// Can be useful for simple "raw" reflection.
|
// Can be useful for simple "raw" reflection.
|
||||||
// However, most members are here because the Parser needs most of these,
|
// However, most members are here because the Parser needs most of these,
|
||||||
// and might as well just have the whole suite of decoration/name handling in one place.
|
// and might as well just have the whole suite of decoration/name handling in one place.
|
||||||
void set_name(ID id, const std::string &name);
|
void set_name(ID id, const std::string &name);
|
||||||
const std::string &get_name(ID id) const;
|
const std::string &get_name(ID id) const;
|
||||||
void set_decoration(ID id, spv::Decoration decoration, uint32_t argument = 0);
|
void set_decoration(ID id, spv::Decoration decoration, uint32_t argument = 0);
|
||||||
void set_decoration_string(ID id, spv::Decoration decoration, const std::string &argument);
|
void set_decoration_string(ID id, spv::Decoration decoration, const std::string &argument);
|
||||||
bool has_decoration(ID id, spv::Decoration decoration) const;
|
bool has_decoration(ID id, spv::Decoration decoration) const;
|
||||||
uint32_t get_decoration(ID id, spv::Decoration decoration) const;
|
uint32_t get_decoration(ID id, spv::Decoration decoration) const;
|
||||||
const std::string &get_decoration_string(ID id, spv::Decoration decoration) const;
|
const std::string &get_decoration_string(ID id, spv::Decoration decoration) const;
|
||||||
const Bitset &get_decoration_bitset(ID id) const;
|
const Bitset &get_decoration_bitset(ID id) const;
|
||||||
void unset_decoration(ID id, spv::Decoration decoration);
|
void unset_decoration(ID id, spv::Decoration decoration);
|
||||||
|
|
||||||
// Decoration handling methods (for members of a struct).
|
// Decoration handling methods (for members of a struct).
|
||||||
void set_member_name(TypeID id, uint32_t index, const std::string &name);
|
void set_member_name(TypeID id, uint32_t index, const std::string &name);
|
||||||
const std::string &get_member_name(TypeID id, uint32_t index) const;
|
const std::string &get_member_name(TypeID id, uint32_t index) const;
|
||||||
void set_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration, uint32_t argument = 0);
|
void set_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration, uint32_t argument = 0);
|
||||||
void set_member_decoration_string(TypeID id, uint32_t index, spv::Decoration decoration,
|
void set_member_decoration_string(TypeID id, uint32_t index, spv::Decoration decoration,
|
||||||
const std::string &argument);
|
const std::string &argument);
|
||||||
uint32_t get_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
uint32_t get_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
||||||
const std::string &get_member_decoration_string(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
const std::string &get_member_decoration_string(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
||||||
bool has_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
bool has_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
||||||
const Bitset &get_member_decoration_bitset(TypeID id, uint32_t index) const;
|
const Bitset &get_member_decoration_bitset(TypeID id, uint32_t index) const;
|
||||||
void unset_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration);
|
void unset_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration);
|
||||||
|
|
||||||
void mark_used_as_array_length(ID id);
|
void mark_used_as_array_length(ID id);
|
||||||
uint32_t increase_bound_by(uint32_t count);
|
uint32_t increase_bound_by(uint32_t count);
|
||||||
Bitset get_buffer_block_flags(const SPIRVariable &var) const;
|
Bitset get_buffer_block_flags(const SPIRVariable &var) const;
|
||||||
Bitset get_buffer_block_type_flags(const SPIRType &type) const;
|
Bitset get_buffer_block_type_flags(const SPIRType &type) const;
|
||||||
|
|
||||||
void add_typed_id(Types type, ID id);
|
void add_typed_id(Types type, ID id);
|
||||||
void remove_typed_id(Types type, ID id);
|
void remove_typed_id(Types type, ID id);
|
||||||
|
|
||||||
class LoopLock
|
class LoopLock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit LoopLock(uint32_t *counter);
|
explicit LoopLock(uint32_t *counter);
|
||||||
LoopLock(const LoopLock &) = delete;
|
LoopLock(const LoopLock &) = delete;
|
||||||
void operator=(const LoopLock &) = delete;
|
void operator=(const LoopLock &) = delete;
|
||||||
LoopLock(LoopLock &&other) SPIRV_CROSS_NOEXCEPT;
|
LoopLock(LoopLock &&other) SPIRV_CROSS_NOEXCEPT;
|
||||||
LoopLock &operator=(LoopLock &&other) SPIRV_CROSS_NOEXCEPT;
|
LoopLock &operator=(LoopLock &&other) SPIRV_CROSS_NOEXCEPT;
|
||||||
~LoopLock();
|
~LoopLock();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t *lock = nullptr;
|
uint32_t *lock = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This must be held while iterating over a type ID array.
|
// This must be held while iterating over a type ID array.
|
||||||
// It is undefined if someone calls set<>() while we're iterating over a data structure, so we must
|
// It is undefined if someone calls set<>() while we're iterating over a data structure, so we must
|
||||||
// make sure that this case is avoided.
|
// make sure that this case is avoided.
|
||||||
|
|
||||||
// If we have a hard lock, it is an error to call set<>(), and an exception is thrown.
|
// If we have a hard lock, it is an error to call set<>(), and an exception is thrown.
|
||||||
// If we have a soft lock, we silently ignore any additions to the typed arrays.
|
// If we have a soft lock, we silently ignore any additions to the typed arrays.
|
||||||
// This should only be used for physical ID remapping where we need to create an ID, but we will never
|
// This should only be used for physical ID remapping where we need to create an ID, but we will never
|
||||||
// care about iterating over them.
|
// care about iterating over them.
|
||||||
LoopLock create_loop_hard_lock() const;
|
LoopLock create_loop_hard_lock() const;
|
||||||
LoopLock create_loop_soft_lock() const;
|
LoopLock create_loop_soft_lock() const;
|
||||||
|
|
||||||
template <typename T, typename Op>
|
template <typename T, typename Op>
|
||||||
void for_each_typed_id(const Op &op)
|
void for_each_typed_id(const Op &op)
|
||||||
{
|
{
|
||||||
auto loop_lock = create_loop_hard_lock();
|
auto loop_lock = create_loop_hard_lock();
|
||||||
for (auto &id : ids_for_type[T::type])
|
for (auto &id : ids_for_type[T::type])
|
||||||
{
|
{
|
||||||
if (ids[id].get_type() == static_cast<Types>(T::type))
|
if (ids[id].get_type() == static_cast<Types>(T::type))
|
||||||
op(id, get<T>(id));
|
op(id, get<T>(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename Op>
|
template <typename T, typename Op>
|
||||||
void for_each_typed_id(const Op &op) const
|
void for_each_typed_id(const Op &op) const
|
||||||
{
|
{
|
||||||
auto loop_lock = create_loop_hard_lock();
|
auto loop_lock = create_loop_hard_lock();
|
||||||
for (auto &id : ids_for_type[T::type])
|
for (auto &id : ids_for_type[T::type])
|
||||||
{
|
{
|
||||||
if (ids[id].get_type() == static_cast<Types>(T::type))
|
if (ids[id].get_type() == static_cast<Types>(T::type))
|
||||||
op(id, get<T>(id));
|
op(id, get<T>(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void reset_all_of_type()
|
void reset_all_of_type()
|
||||||
{
|
{
|
||||||
reset_all_of_type(static_cast<Types>(T::type));
|
reset_all_of_type(static_cast<Types>(T::type));
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_all_of_type(Types type);
|
void reset_all_of_type(Types type);
|
||||||
|
|
||||||
Meta *find_meta(ID id);
|
Meta *find_meta(ID id);
|
||||||
const Meta *find_meta(ID id) const;
|
const Meta *find_meta(ID id) const;
|
||||||
|
|
||||||
const std::string &get_empty_string() const
|
const std::string &get_empty_string() const
|
||||||
{
|
{
|
||||||
return empty_string;
|
return empty_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
void make_constant_null(uint32_t id, uint32_t type, bool add_to_typed_id_set);
|
void make_constant_null(uint32_t id, uint32_t type, bool add_to_typed_id_set);
|
||||||
|
|
||||||
void fixup_reserved_names();
|
void fixup_reserved_names();
|
||||||
|
|
||||||
static void sanitize_underscores(std::string &str);
|
static void sanitize_underscores(std::string &str);
|
||||||
static void sanitize_identifier(std::string &str, bool member, bool allow_reserved_prefixes);
|
static void sanitize_identifier(std::string &str, bool member, bool allow_reserved_prefixes);
|
||||||
static bool is_globally_reserved_identifier(std::string &str, bool allow_reserved_prefixes);
|
static bool is_globally_reserved_identifier(std::string &str, bool allow_reserved_prefixes);
|
||||||
|
|
||||||
uint32_t get_spirv_version() const;
|
uint32_t get_spirv_version() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T &get(uint32_t id)
|
T &get(uint32_t id)
|
||||||
{
|
{
|
||||||
return variant_get<T>(ids[id]);
|
return variant_get<T>(ids[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T &get(uint32_t id) const
|
const T &get(uint32_t id) const
|
||||||
{
|
{
|
||||||
return variant_get<T>(ids[id]);
|
return variant_get<T>(ids[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
mutable uint32_t loop_iteration_depth_hard = 0;
|
mutable uint32_t loop_iteration_depth_hard = 0;
|
||||||
mutable uint32_t loop_iteration_depth_soft = 0;
|
mutable uint32_t loop_iteration_depth_soft = 0;
|
||||||
std::string empty_string;
|
std::string empty_string;
|
||||||
Bitset cleared_bitset;
|
Bitset cleared_bitset;
|
||||||
|
|
||||||
std::unordered_set<uint32_t> meta_needing_name_fixup;
|
std::unordered_set<uint32_t> meta_needing_name_fixup;
|
||||||
};
|
};
|
||||||
} // namespace SPIRV_CROSS_NAMESPACE
|
} // namespace SPIRV_CROSS_NAMESPACE
|
||||||
|
|
||||||
|
1948
spirv_glsl.hpp
1948
spirv_glsl.hpp
File diff suppressed because it is too large
Load Diff
568
spirv_hlsl.hpp
568
spirv_hlsl.hpp
@ -32,8 +32,8 @@ namespace SPIRV_CROSS_NAMESPACE
|
|||||||
// Interface which remaps vertex inputs to a fixed semantic name to make linking easier.
|
// Interface which remaps vertex inputs to a fixed semantic name to make linking easier.
|
||||||
struct HLSLVertexAttributeRemap
|
struct HLSLVertexAttributeRemap
|
||||||
{
|
{
|
||||||
uint32_t location;
|
uint32_t location;
|
||||||
std::string semantic;
|
std::string semantic;
|
||||||
};
|
};
|
||||||
// Specifying a root constant (d3d12) or push constant range (vulkan).
|
// Specifying a root constant (d3d12) or push constant range (vulkan).
|
||||||
//
|
//
|
||||||
@ -41,38 +41,38 @@ struct HLSLVertexAttributeRemap
|
|||||||
// Both values need to be multiple of 4.
|
// Both values need to be multiple of 4.
|
||||||
struct RootConstants
|
struct RootConstants
|
||||||
{
|
{
|
||||||
uint32_t start;
|
uint32_t start;
|
||||||
uint32_t end;
|
uint32_t end;
|
||||||
|
|
||||||
uint32_t binding;
|
uint32_t binding;
|
||||||
uint32_t space;
|
uint32_t space;
|
||||||
};
|
};
|
||||||
|
|
||||||
// For finer control, decorations may be removed from specific resources instead with unset_decoration().
|
// For finer control, decorations may be removed from specific resources instead with unset_decoration().
|
||||||
enum HLSLBindingFlagBits
|
enum HLSLBindingFlagBits
|
||||||
{
|
{
|
||||||
HLSL_BINDING_AUTO_NONE_BIT = 0,
|
HLSL_BINDING_AUTO_NONE_BIT = 0,
|
||||||
|
|
||||||
// Push constant (root constant) resources will be declared as CBVs (b-space) without a register() declaration.
|
// Push constant (root constant) resources will be declared as CBVs (b-space) without a register() declaration.
|
||||||
// A register will be automatically assigned by the D3D compiler, but must therefore be reflected in D3D-land.
|
// A register will be automatically assigned by the D3D compiler, but must therefore be reflected in D3D-land.
|
||||||
// Push constants do not normally have a DecorationBinding set, but if they do, this can be used to ignore it.
|
// Push constants do not normally have a DecorationBinding set, but if they do, this can be used to ignore it.
|
||||||
HLSL_BINDING_AUTO_PUSH_CONSTANT_BIT = 1 << 0,
|
HLSL_BINDING_AUTO_PUSH_CONSTANT_BIT = 1 << 0,
|
||||||
|
|
||||||
// cbuffer resources will be declared as CBVs (b-space) without a register() declaration.
|
// cbuffer resources will be declared as CBVs (b-space) without a register() declaration.
|
||||||
// A register will be automatically assigned, but must be reflected in D3D-land.
|
// A register will be automatically assigned, but must be reflected in D3D-land.
|
||||||
HLSL_BINDING_AUTO_CBV_BIT = 1 << 1,
|
HLSL_BINDING_AUTO_CBV_BIT = 1 << 1,
|
||||||
|
|
||||||
// All SRVs (t-space) will be declared without a register() declaration.
|
// All SRVs (t-space) will be declared without a register() declaration.
|
||||||
HLSL_BINDING_AUTO_SRV_BIT = 1 << 2,
|
HLSL_BINDING_AUTO_SRV_BIT = 1 << 2,
|
||||||
|
|
||||||
// All UAVs (u-space) will be declared without a register() declaration.
|
// All UAVs (u-space) will be declared without a register() declaration.
|
||||||
HLSL_BINDING_AUTO_UAV_BIT = 1 << 3,
|
HLSL_BINDING_AUTO_UAV_BIT = 1 << 3,
|
||||||
|
|
||||||
// All samplers (s-space) will be declared without a register() declaration.
|
// All samplers (s-space) will be declared without a register() declaration.
|
||||||
HLSL_BINDING_AUTO_SAMPLER_BIT = 1 << 4,
|
HLSL_BINDING_AUTO_SAMPLER_BIT = 1 << 4,
|
||||||
|
|
||||||
// No resources will be declared with register().
|
// No resources will be declared with register().
|
||||||
HLSL_BINDING_AUTO_ALL = 0x7fffffff
|
HLSL_BINDING_AUTO_ALL = 0x7fffffff
|
||||||
};
|
};
|
||||||
using HLSLBindingFlags = uint32_t;
|
using HLSLBindingFlags = uint32_t;
|
||||||
|
|
||||||
@ -87,327 +87,327 @@ using HLSLBindingFlags = uint32_t;
|
|||||||
// For deeper control of push constants, set_root_constant_layouts() can be used instead.
|
// For deeper control of push constants, set_root_constant_layouts() can be used instead.
|
||||||
struct HLSLResourceBinding
|
struct HLSLResourceBinding
|
||||||
{
|
{
|
||||||
spv::ExecutionModel stage = spv::ExecutionModelMax;
|
spv::ExecutionModel stage = spv::ExecutionModelMax;
|
||||||
uint32_t desc_set = 0;
|
uint32_t desc_set = 0;
|
||||||
uint32_t binding = 0;
|
uint32_t binding = 0;
|
||||||
|
|
||||||
struct Binding
|
struct Binding
|
||||||
{
|
{
|
||||||
uint32_t register_space = 0;
|
uint32_t register_space = 0;
|
||||||
uint32_t register_binding = 0;
|
uint32_t register_binding = 0;
|
||||||
} cbv, uav, srv, sampler;
|
} cbv, uav, srv, sampler;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum HLSLAuxBinding
|
enum HLSLAuxBinding
|
||||||
{
|
{
|
||||||
HLSL_AUX_BINDING_BASE_VERTEX_INSTANCE = 0
|
HLSL_AUX_BINDING_BASE_VERTEX_INSTANCE = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
class CompilerHLSL : public CompilerGLSL
|
class CompilerHLSL : public CompilerGLSL
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Options
|
struct Options
|
||||||
{
|
{
|
||||||
uint32_t shader_model = 30; // TODO: map ps_4_0_level_9_0,... somehow
|
uint32_t shader_model = 30; // TODO: map ps_4_0_level_9_0,... somehow
|
||||||
|
|
||||||
// Allows the PointSize builtin in SM 4.0+, and ignores it, as PointSize is not supported in SM 4+.
|
// Allows the PointSize builtin in SM 4.0+, and ignores it, as PointSize is not supported in SM 4+.
|
||||||
bool point_size_compat = false;
|
bool point_size_compat = false;
|
||||||
|
|
||||||
// Allows the PointCoord builtin, returns float2(0.5, 0.5), as PointCoord is not supported in HLSL.
|
// Allows the PointCoord builtin, returns float2(0.5, 0.5), as PointCoord is not supported in HLSL.
|
||||||
bool point_coord_compat = false;
|
bool point_coord_compat = false;
|
||||||
|
|
||||||
// If true, the backend will assume that VertexIndex and InstanceIndex will need to apply
|
// If true, the backend will assume that VertexIndex and InstanceIndex will need to apply
|
||||||
// a base offset, and you will need to fill in a cbuffer with offsets.
|
// a base offset, and you will need to fill in a cbuffer with offsets.
|
||||||
// Set to false if you know you will never use base instance or base vertex
|
// Set to false if you know you will never use base instance or base vertex
|
||||||
// functionality as it might remove an internal cbuffer.
|
// functionality as it might remove an internal cbuffer.
|
||||||
bool support_nonzero_base_vertex_base_instance = false;
|
bool support_nonzero_base_vertex_base_instance = false;
|
||||||
|
|
||||||
// Forces a storage buffer to always be declared as UAV, even if the readonly decoration is used.
|
// Forces a storage buffer to always be declared as UAV, even if the readonly decoration is used.
|
||||||
// By default, a readonly storage buffer will be declared as ByteAddressBuffer (SRV) instead.
|
// By default, a readonly storage buffer will be declared as ByteAddressBuffer (SRV) instead.
|
||||||
// Alternatively, use set_hlsl_force_storage_buffer_as_uav to specify individually.
|
// Alternatively, use set_hlsl_force_storage_buffer_as_uav to specify individually.
|
||||||
bool force_storage_buffer_as_uav = false;
|
bool force_storage_buffer_as_uav = false;
|
||||||
|
|
||||||
// Forces any storage image type marked as NonWritable to be considered an SRV instead.
|
// Forces any storage image type marked as NonWritable to be considered an SRV instead.
|
||||||
// For this to work with function call parameters, NonWritable must be considered to be part of the type system
|
// For this to work with function call parameters, NonWritable must be considered to be part of the type system
|
||||||
// so that NonWritable image arguments are also translated to Texture rather than RWTexture.
|
// so that NonWritable image arguments are also translated to Texture rather than RWTexture.
|
||||||
bool nonwritable_uav_texture_as_srv = false;
|
bool nonwritable_uav_texture_as_srv = false;
|
||||||
|
|
||||||
// Enables native 16-bit types. Needs SM 6.2.
|
// Enables native 16-bit types. Needs SM 6.2.
|
||||||
// Uses half/int16_t/uint16_t instead of min16* types.
|
// Uses half/int16_t/uint16_t instead of min16* types.
|
||||||
// Also adds support for 16-bit load-store from (RW)ByteAddressBuffer.
|
// Also adds support for 16-bit load-store from (RW)ByteAddressBuffer.
|
||||||
bool enable_16bit_types = false;
|
bool enable_16bit_types = false;
|
||||||
|
|
||||||
// If matrices are used as IO variables, flatten the attribute declaration to use
|
// If matrices are used as IO variables, flatten the attribute declaration to use
|
||||||
// TEXCOORD{N,N+1,N+2,...} rather than TEXCOORDN_{0,1,2,3}.
|
// TEXCOORD{N,N+1,N+2,...} rather than TEXCOORDN_{0,1,2,3}.
|
||||||
// If add_vertex_attribute_remap is used and this feature is used,
|
// If add_vertex_attribute_remap is used and this feature is used,
|
||||||
// the semantic name will be queried once per active location.
|
// the semantic name will be queried once per active location.
|
||||||
bool flatten_matrix_vertex_input_semantics = false;
|
bool flatten_matrix_vertex_input_semantics = false;
|
||||||
|
|
||||||
// Rather than emitting main() for the entry point, use the name in SPIR-V.
|
// Rather than emitting main() for the entry point, use the name in SPIR-V.
|
||||||
bool use_entry_point_name = false;
|
bool use_entry_point_name = false;
|
||||||
|
|
||||||
// Preserve (RW)StructuredBuffer types if the input source was HLSL.
|
// Preserve (RW)StructuredBuffer types if the input source was HLSL.
|
||||||
// This relies on UserTypeGOOGLE to encode the buffer type either as "structuredbuffer" or "rwstructuredbuffer"
|
// This relies on UserTypeGOOGLE to encode the buffer type either as "structuredbuffer" or "rwstructuredbuffer"
|
||||||
// whereas the type can be extended with an optional subtype, e.g. "structuredbuffer:int".
|
// whereas the type can be extended with an optional subtype, e.g. "structuredbuffer:int".
|
||||||
bool preserve_structured_buffers = false;
|
bool preserve_structured_buffers = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit CompilerHLSL(std::vector<uint32_t> spirv_)
|
explicit CompilerHLSL(std::vector<uint32_t> spirv_)
|
||||||
: CompilerGLSL(std::move(spirv_))
|
: CompilerGLSL(std::move(spirv_))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilerHLSL(const uint32_t *ir_, size_t size)
|
CompilerHLSL(const uint32_t *ir_, size_t size)
|
||||||
: CompilerGLSL(ir_, size)
|
: CompilerGLSL(ir_, size)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit CompilerHLSL(const ParsedIR &ir_)
|
explicit CompilerHLSL(const ParsedIR &ir_)
|
||||||
: CompilerGLSL(ir_)
|
: CompilerGLSL(ir_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit CompilerHLSL(ParsedIR &&ir_)
|
explicit CompilerHLSL(ParsedIR &&ir_)
|
||||||
: CompilerGLSL(std::move(ir_))
|
: CompilerGLSL(std::move(ir_))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const Options &get_hlsl_options() const
|
const Options &get_hlsl_options() const
|
||||||
{
|
{
|
||||||
return hlsl_options;
|
return hlsl_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_hlsl_options(const Options &opts)
|
void set_hlsl_options(const Options &opts)
|
||||||
{
|
{
|
||||||
hlsl_options = opts;
|
hlsl_options = opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally specify a custom root constant layout.
|
// Optionally specify a custom root constant layout.
|
||||||
//
|
//
|
||||||
// Push constants ranges will be split up according to the
|
// Push constants ranges will be split up according to the
|
||||||
// layout specified.
|
// layout specified.
|
||||||
void set_root_constant_layouts(std::vector<RootConstants> layout);
|
void set_root_constant_layouts(std::vector<RootConstants> layout);
|
||||||
|
|
||||||
// Compiles and remaps vertex attributes at specific locations to a fixed semantic.
|
// Compiles and remaps vertex attributes at specific locations to a fixed semantic.
|
||||||
// The default is TEXCOORD# where # denotes location.
|
// The default is TEXCOORD# where # denotes location.
|
||||||
// Matrices are unrolled to vectors with notation ${SEMANTIC}_#, where # denotes row.
|
// Matrices are unrolled to vectors with notation ${SEMANTIC}_#, where # denotes row.
|
||||||
// $SEMANTIC is either TEXCOORD# or a semantic name specified here.
|
// $SEMANTIC is either TEXCOORD# or a semantic name specified here.
|
||||||
void add_vertex_attribute_remap(const HLSLVertexAttributeRemap &vertex_attributes);
|
void add_vertex_attribute_remap(const HLSLVertexAttributeRemap &vertex_attributes);
|
||||||
std::string compile() override;
|
std::string compile() override;
|
||||||
|
|
||||||
// This is a special HLSL workaround for the NumWorkGroups builtin.
|
// This is a special HLSL workaround for the NumWorkGroups builtin.
|
||||||
// This does not exist in HLSL, so the calling application must create a dummy cbuffer in
|
// This does not exist in HLSL, so the calling application must create a dummy cbuffer in
|
||||||
// which the application will store this builtin.
|
// which the application will store this builtin.
|
||||||
// The cbuffer layout will be:
|
// The cbuffer layout will be:
|
||||||
// cbuffer SPIRV_Cross_NumWorkgroups : register(b#, space#) { uint3 SPIRV_Cross_NumWorkgroups_count; };
|
// cbuffer SPIRV_Cross_NumWorkgroups : register(b#, space#) { uint3 SPIRV_Cross_NumWorkgroups_count; };
|
||||||
// This must be called before compile().
|
// This must be called before compile().
|
||||||
// The function returns 0 if NumWorkGroups builtin is not statically used in the shader from the current entry point.
|
// The function returns 0 if NumWorkGroups builtin is not statically used in the shader from the current entry point.
|
||||||
// If non-zero, this returns the variable ID of a cbuffer which corresponds to
|
// If non-zero, this returns the variable ID of a cbuffer which corresponds to
|
||||||
// the cbuffer declared above. By default, no binding or descriptor set decoration is set,
|
// the cbuffer declared above. By default, no binding or descriptor set decoration is set,
|
||||||
// so the calling application should declare explicit bindings on this ID before calling compile().
|
// so the calling application should declare explicit bindings on this ID before calling compile().
|
||||||
VariableID remap_num_workgroups_builtin();
|
VariableID remap_num_workgroups_builtin();
|
||||||
|
|
||||||
// Controls how resource bindings are declared in the output HLSL.
|
// Controls how resource bindings are declared in the output HLSL.
|
||||||
void set_resource_binding_flags(HLSLBindingFlags flags);
|
void set_resource_binding_flags(HLSLBindingFlags flags);
|
||||||
|
|
||||||
// resource is a resource binding to indicate the HLSL CBV, SRV, UAV or sampler binding
|
// resource is a resource binding to indicate the HLSL CBV, SRV, UAV or sampler binding
|
||||||
// to use for a particular SPIR-V description set
|
// to use for a particular SPIR-V description set
|
||||||
// and binding. If resource bindings are provided,
|
// and binding. If resource bindings are provided,
|
||||||
// is_hlsl_resource_binding_used() will return true after calling ::compile() if
|
// is_hlsl_resource_binding_used() will return true after calling ::compile() if
|
||||||
// the set/binding combination was used by the HLSL code.
|
// the set/binding combination was used by the HLSL code.
|
||||||
void add_hlsl_resource_binding(const HLSLResourceBinding &resource);
|
void add_hlsl_resource_binding(const HLSLResourceBinding &resource);
|
||||||
bool is_hlsl_resource_binding_used(spv::ExecutionModel model, uint32_t set, uint32_t binding) const;
|
bool is_hlsl_resource_binding_used(spv::ExecutionModel model, uint32_t set, uint32_t binding) const;
|
||||||
|
|
||||||
// Controls which storage buffer bindings will be forced to be declared as UAVs.
|
// Controls which storage buffer bindings will be forced to be declared as UAVs.
|
||||||
void set_hlsl_force_storage_buffer_as_uav(uint32_t desc_set, uint32_t binding);
|
void set_hlsl_force_storage_buffer_as_uav(uint32_t desc_set, uint32_t binding);
|
||||||
|
|
||||||
// By default, these magic buffers are not assigned a specific binding.
|
// By default, these magic buffers are not assigned a specific binding.
|
||||||
void set_hlsl_aux_buffer_binding(HLSLAuxBinding binding, uint32_t register_index, uint32_t register_space);
|
void set_hlsl_aux_buffer_binding(HLSLAuxBinding binding, uint32_t register_index, uint32_t register_space);
|
||||||
void unset_hlsl_aux_buffer_binding(HLSLAuxBinding binding);
|
void unset_hlsl_aux_buffer_binding(HLSLAuxBinding binding);
|
||||||
bool is_hlsl_aux_buffer_binding_used(HLSLAuxBinding binding) const;
|
bool is_hlsl_aux_buffer_binding_used(HLSLAuxBinding binding) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string type_to_glsl(const SPIRType &type, uint32_t id = 0) override;
|
std::string type_to_glsl(const SPIRType &type, uint32_t id = 0) override;
|
||||||
std::string image_type_hlsl(const SPIRType &type, uint32_t id);
|
std::string image_type_hlsl(const SPIRType &type, uint32_t id);
|
||||||
std::string image_type_hlsl_modern(const SPIRType &type, uint32_t id);
|
std::string image_type_hlsl_modern(const SPIRType &type, uint32_t id);
|
||||||
std::string image_type_hlsl_legacy(const SPIRType &type, uint32_t id);
|
std::string image_type_hlsl_legacy(const SPIRType &type, uint32_t id);
|
||||||
void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override;
|
void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override;
|
||||||
void emit_hlsl_entry_point();
|
void emit_hlsl_entry_point();
|
||||||
void emit_header() override;
|
void emit_header() override;
|
||||||
void emit_resources();
|
void emit_resources();
|
||||||
void emit_interface_block_globally(const SPIRVariable &type);
|
void emit_interface_block_globally(const SPIRVariable &type);
|
||||||
void emit_interface_block_in_struct(const SPIRVariable &var, std::unordered_set<uint32_t> &active_locations);
|
void emit_interface_block_in_struct(const SPIRVariable &var, std::unordered_set<uint32_t> &active_locations);
|
||||||
void emit_interface_block_member_in_struct(const SPIRVariable &var, uint32_t member_index, uint32_t location,
|
void emit_interface_block_member_in_struct(const SPIRVariable &var, uint32_t member_index, uint32_t location,
|
||||||
std::unordered_set<uint32_t> &active_locations);
|
std::unordered_set<uint32_t> &active_locations);
|
||||||
void emit_builtin_inputs_in_struct();
|
void emit_builtin_inputs_in_struct();
|
||||||
void emit_builtin_outputs_in_struct();
|
void emit_builtin_outputs_in_struct();
|
||||||
void emit_builtin_primitive_outputs_in_struct();
|
void emit_builtin_primitive_outputs_in_struct();
|
||||||
void emit_texture_op(const Instruction &i, bool sparse) override;
|
void emit_texture_op(const Instruction &i, bool sparse) override;
|
||||||
void emit_instruction(const Instruction &instruction) override;
|
void emit_instruction(const Instruction &instruction) override;
|
||||||
void emit_glsl_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
void emit_glsl_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
||||||
uint32_t count) override;
|
uint32_t count) override;
|
||||||
void emit_buffer_block(const SPIRVariable &type) override;
|
void emit_buffer_block(const SPIRVariable &type) override;
|
||||||
void emit_push_constant_block(const SPIRVariable &var) override;
|
void emit_push_constant_block(const SPIRVariable &var) override;
|
||||||
void emit_uniform(const SPIRVariable &var) override;
|
void emit_uniform(const SPIRVariable &var) override;
|
||||||
void emit_modern_uniform(const SPIRVariable &var);
|
void emit_modern_uniform(const SPIRVariable &var);
|
||||||
void emit_legacy_uniform(const SPIRVariable &var);
|
void emit_legacy_uniform(const SPIRVariable &var);
|
||||||
void emit_specialization_constants_and_structs();
|
void emit_specialization_constants_and_structs();
|
||||||
void emit_composite_constants();
|
void emit_composite_constants();
|
||||||
void emit_fixup() override;
|
void emit_fixup() override;
|
||||||
std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage) override;
|
std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage) override;
|
||||||
std::string layout_for_member(const SPIRType &type, uint32_t index) override;
|
std::string layout_for_member(const SPIRType &type, uint32_t index) override;
|
||||||
std::string to_interpolation_qualifiers(const Bitset &flags) override;
|
std::string to_interpolation_qualifiers(const Bitset &flags) override;
|
||||||
std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type) override;
|
std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type) override;
|
||||||
bool emit_complex_bitcast(uint32_t result_type, uint32_t id, uint32_t op0) override;
|
bool emit_complex_bitcast(uint32_t result_type, uint32_t id, uint32_t op0) override;
|
||||||
std::string to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id) override;
|
std::string to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id) override;
|
||||||
std::string to_sampler_expression(uint32_t id);
|
std::string to_sampler_expression(uint32_t id);
|
||||||
std::string to_resource_binding(const SPIRVariable &var);
|
std::string to_resource_binding(const SPIRVariable &var);
|
||||||
std::string to_resource_binding_sampler(const SPIRVariable &var);
|
std::string to_resource_binding_sampler(const SPIRVariable &var);
|
||||||
std::string to_resource_register(HLSLBindingFlagBits flag, char space, uint32_t binding, uint32_t set);
|
std::string to_resource_register(HLSLBindingFlagBits flag, char space, uint32_t binding, uint32_t set);
|
||||||
std::string to_initializer_expression(const SPIRVariable &var) override;
|
std::string to_initializer_expression(const SPIRVariable &var) override;
|
||||||
void emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id) override;
|
void emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id) override;
|
||||||
void emit_access_chain(const Instruction &instruction);
|
void emit_access_chain(const Instruction &instruction);
|
||||||
void emit_load(const Instruction &instruction);
|
void emit_load(const Instruction &instruction);
|
||||||
void read_access_chain(std::string *expr, const std::string &lhs, const SPIRAccessChain &chain);
|
void read_access_chain(std::string *expr, const std::string &lhs, const SPIRAccessChain &chain);
|
||||||
void read_access_chain_struct(const std::string &lhs, const SPIRAccessChain &chain);
|
void read_access_chain_struct(const std::string &lhs, const SPIRAccessChain &chain);
|
||||||
void read_access_chain_array(const std::string &lhs, const SPIRAccessChain &chain);
|
void read_access_chain_array(const std::string &lhs, const SPIRAccessChain &chain);
|
||||||
void write_access_chain(const SPIRAccessChain &chain, uint32_t value, const SmallVector<uint32_t> &composite_chain);
|
void write_access_chain(const SPIRAccessChain &chain, uint32_t value, const SmallVector<uint32_t> &composite_chain);
|
||||||
void write_access_chain_struct(const SPIRAccessChain &chain, uint32_t value,
|
void write_access_chain_struct(const SPIRAccessChain &chain, uint32_t value,
|
||||||
const SmallVector<uint32_t> &composite_chain);
|
const SmallVector<uint32_t> &composite_chain);
|
||||||
void write_access_chain_array(const SPIRAccessChain &chain, uint32_t value,
|
void write_access_chain_array(const SPIRAccessChain &chain, uint32_t value,
|
||||||
const SmallVector<uint32_t> &composite_chain);
|
const SmallVector<uint32_t> &composite_chain);
|
||||||
std::string write_access_chain_value(uint32_t value, const SmallVector<uint32_t> &composite_chain, bool enclose);
|
std::string write_access_chain_value(uint32_t value, const SmallVector<uint32_t> &composite_chain, bool enclose);
|
||||||
void emit_store(const Instruction &instruction);
|
void emit_store(const Instruction &instruction);
|
||||||
void emit_atomic(const uint32_t *ops, uint32_t length, spv::Op op);
|
void emit_atomic(const uint32_t *ops, uint32_t length, spv::Op op);
|
||||||
void emit_subgroup_op(const Instruction &i) override;
|
void emit_subgroup_op(const Instruction &i) override;
|
||||||
void emit_block_hints(const SPIRBlock &block) override;
|
void emit_block_hints(const SPIRBlock &block) override;
|
||||||
|
|
||||||
void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index, const std::string &qualifier,
|
void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index, const std::string &qualifier,
|
||||||
uint32_t base_offset = 0) override;
|
uint32_t base_offset = 0) override;
|
||||||
void emit_rayquery_function(const char *commited, const char *candidate, const uint32_t *ops);
|
void emit_rayquery_function(const char *commited, const char *candidate, const uint32_t *ops);
|
||||||
void emit_mesh_tasks(SPIRBlock &block) override;
|
void emit_mesh_tasks(SPIRBlock &block) override;
|
||||||
|
|
||||||
const char *to_storage_qualifiers_glsl(const SPIRVariable &var) override;
|
const char *to_storage_qualifiers_glsl(const SPIRVariable &var) override;
|
||||||
void replace_illegal_names() override;
|
void replace_illegal_names() override;
|
||||||
|
|
||||||
SPIRType::BaseType get_builtin_basetype(spv::BuiltIn builtin, SPIRType::BaseType default_type) override;
|
SPIRType::BaseType get_builtin_basetype(spv::BuiltIn builtin, SPIRType::BaseType default_type) override;
|
||||||
|
|
||||||
bool is_hlsl_force_storage_buffer_as_uav(ID id) const;
|
bool is_hlsl_force_storage_buffer_as_uav(ID id) const;
|
||||||
|
|
||||||
Options hlsl_options;
|
Options hlsl_options;
|
||||||
|
|
||||||
// TODO: Refactor this to be more similar to MSL, maybe have some common system in place?
|
// TODO: Refactor this to be more similar to MSL, maybe have some common system in place?
|
||||||
bool requires_op_fmod = false;
|
bool requires_op_fmod = false;
|
||||||
bool requires_fp16_packing = false;
|
bool requires_fp16_packing = false;
|
||||||
bool requires_uint2_packing = false;
|
bool requires_uint2_packing = false;
|
||||||
bool requires_explicit_fp16_packing = false;
|
bool requires_explicit_fp16_packing = false;
|
||||||
bool requires_unorm8_packing = false;
|
bool requires_unorm8_packing = false;
|
||||||
bool requires_snorm8_packing = false;
|
bool requires_snorm8_packing = false;
|
||||||
bool requires_unorm16_packing = false;
|
bool requires_unorm16_packing = false;
|
||||||
bool requires_snorm16_packing = false;
|
bool requires_snorm16_packing = false;
|
||||||
bool requires_bitfield_insert = false;
|
bool requires_bitfield_insert = false;
|
||||||
bool requires_bitfield_extract = false;
|
bool requires_bitfield_extract = false;
|
||||||
bool requires_inverse_2x2 = false;
|
bool requires_inverse_2x2 = false;
|
||||||
bool requires_inverse_3x3 = false;
|
bool requires_inverse_3x3 = false;
|
||||||
bool requires_inverse_4x4 = false;
|
bool requires_inverse_4x4 = false;
|
||||||
bool requires_scalar_reflect = false;
|
bool requires_scalar_reflect = false;
|
||||||
bool requires_scalar_refract = false;
|
bool requires_scalar_refract = false;
|
||||||
bool requires_scalar_faceforward = false;
|
bool requires_scalar_faceforward = false;
|
||||||
|
|
||||||
struct TextureSizeVariants
|
struct TextureSizeVariants
|
||||||
{
|
{
|
||||||
// MSVC 2013 workaround.
|
// MSVC 2013 workaround.
|
||||||
TextureSizeVariants()
|
TextureSizeVariants()
|
||||||
{
|
{
|
||||||
srv = 0;
|
srv = 0;
|
||||||
for (auto &unorm : uav)
|
for (auto &unorm : uav)
|
||||||
for (auto &u : unorm)
|
for (auto &u : unorm)
|
||||||
u = 0;
|
u = 0;
|
||||||
}
|
}
|
||||||
uint64_t srv;
|
uint64_t srv;
|
||||||
uint64_t uav[3][4];
|
uint64_t uav[3][4];
|
||||||
} required_texture_size_variants;
|
} required_texture_size_variants;
|
||||||
|
|
||||||
void require_texture_query_variant(uint32_t var_id);
|
void require_texture_query_variant(uint32_t var_id);
|
||||||
void emit_texture_size_variants(uint64_t variant_mask, const char *vecsize_qualifier, bool uav,
|
void emit_texture_size_variants(uint64_t variant_mask, const char *vecsize_qualifier, bool uav,
|
||||||
const char *type_qualifier);
|
const char *type_qualifier);
|
||||||
|
|
||||||
enum TextureQueryVariantDim
|
enum TextureQueryVariantDim
|
||||||
{
|
{
|
||||||
Query1D = 0,
|
Query1D = 0,
|
||||||
Query1DArray,
|
Query1DArray,
|
||||||
Query2D,
|
Query2D,
|
||||||
Query2DArray,
|
Query2DArray,
|
||||||
Query3D,
|
Query3D,
|
||||||
QueryBuffer,
|
QueryBuffer,
|
||||||
QueryCube,
|
QueryCube,
|
||||||
QueryCubeArray,
|
QueryCubeArray,
|
||||||
Query2DMS,
|
Query2DMS,
|
||||||
Query2DMSArray,
|
Query2DMSArray,
|
||||||
QueryDimCount
|
QueryDimCount
|
||||||
};
|
};
|
||||||
|
|
||||||
enum TextureQueryVariantType
|
enum TextureQueryVariantType
|
||||||
{
|
{
|
||||||
QueryTypeFloat = 0,
|
QueryTypeFloat = 0,
|
||||||
QueryTypeInt = 16,
|
QueryTypeInt = 16,
|
||||||
QueryTypeUInt = 32,
|
QueryTypeUInt = 32,
|
||||||
QueryTypeCount = 3
|
QueryTypeCount = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BitcastType
|
enum BitcastType
|
||||||
{
|
{
|
||||||
TypeNormal,
|
TypeNormal,
|
||||||
TypePackUint2x32,
|
TypePackUint2x32,
|
||||||
TypeUnpackUint64
|
TypeUnpackUint64
|
||||||
};
|
};
|
||||||
|
|
||||||
void analyze_meshlet_writes();
|
void analyze_meshlet_writes();
|
||||||
void analyze_meshlet_writes(uint32_t func_id, uint32_t id_per_vertex, uint32_t id_per_primitive,
|
void analyze_meshlet_writes(uint32_t func_id, uint32_t id_per_vertex, uint32_t id_per_primitive,
|
||||||
std::unordered_set<uint32_t> &processed_func_ids);
|
std::unordered_set<uint32_t> &processed_func_ids);
|
||||||
|
|
||||||
BitcastType get_bitcast_type(uint32_t result_type, uint32_t op0);
|
BitcastType get_bitcast_type(uint32_t result_type, uint32_t op0);
|
||||||
|
|
||||||
void emit_builtin_variables();
|
void emit_builtin_variables();
|
||||||
bool require_output = false;
|
bool require_output = false;
|
||||||
bool require_input = false;
|
bool require_input = false;
|
||||||
SmallVector<HLSLVertexAttributeRemap> remap_vertex_attributes;
|
SmallVector<HLSLVertexAttributeRemap> remap_vertex_attributes;
|
||||||
|
|
||||||
uint32_t type_to_consumed_locations(const SPIRType &type) const;
|
uint32_t type_to_consumed_locations(const SPIRType &type) const;
|
||||||
|
|
||||||
std::string to_semantic(uint32_t location, spv::ExecutionModel em, spv::StorageClass sc);
|
std::string to_semantic(uint32_t location, spv::ExecutionModel em, spv::StorageClass sc);
|
||||||
|
|
||||||
uint32_t num_workgroups_builtin = 0;
|
uint32_t num_workgroups_builtin = 0;
|
||||||
HLSLBindingFlags resource_binding_flags = 0;
|
HLSLBindingFlags resource_binding_flags = 0;
|
||||||
|
|
||||||
// Custom root constant layout, which should be emitted
|
// Custom root constant layout, which should be emitted
|
||||||
// when translating push constant ranges.
|
// when translating push constant ranges.
|
||||||
std::vector<RootConstants> root_constants_layout;
|
std::vector<RootConstants> root_constants_layout;
|
||||||
|
|
||||||
void validate_shader_model();
|
void validate_shader_model();
|
||||||
|
|
||||||
std::string get_unique_identifier();
|
std::string get_unique_identifier();
|
||||||
uint32_t unique_identifier_count = 0;
|
uint32_t unique_identifier_count = 0;
|
||||||
|
|
||||||
std::unordered_map<StageSetBinding, std::pair<HLSLResourceBinding, bool>, InternalHasher> resource_bindings;
|
std::unordered_map<StageSetBinding, std::pair<HLSLResourceBinding, bool>, InternalHasher> resource_bindings;
|
||||||
void remap_hlsl_resource_binding(HLSLBindingFlagBits type, uint32_t &desc_set, uint32_t &binding);
|
void remap_hlsl_resource_binding(HLSLBindingFlagBits type, uint32_t &desc_set, uint32_t &binding);
|
||||||
|
|
||||||
std::unordered_set<SetBindingPair, InternalHasher> force_uav_buffer_bindings;
|
std::unordered_set<SetBindingPair, InternalHasher> force_uav_buffer_bindings;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint32_t register_index = 0;
|
uint32_t register_index = 0;
|
||||||
uint32_t register_space = 0;
|
uint32_t register_space = 0;
|
||||||
bool explicit_binding = false;
|
bool explicit_binding = false;
|
||||||
bool used = false;
|
bool used = false;
|
||||||
} base_vertex_info;
|
} base_vertex_info;
|
||||||
|
|
||||||
// Returns true if the specified ID has a UserTypeGOOGLE decoration for StructuredBuffer or RWStructuredBuffer resources.
|
// Returns true if the specified ID has a UserTypeGOOGLE decoration for StructuredBuffer or RWStructuredBuffer resources.
|
||||||
bool is_user_type_structured(uint32_t id) const override;
|
bool is_user_type_structured(uint32_t id) const override;
|
||||||
|
|
||||||
std::vector<TypeID> composite_selection_workaround_types;
|
std::vector<TypeID> composite_selection_workaround_types;
|
||||||
|
|
||||||
std::string get_inner_entry_point_name() const;
|
std::string get_inner_entry_point_name() const;
|
||||||
};
|
};
|
||||||
} // namespace SPIRV_CROSS_NAMESPACE
|
} // namespace SPIRV_CROSS_NAMESPACE
|
||||||
|
|
||||||
|
2358
spirv_msl.hpp
2358
spirv_msl.hpp
File diff suppressed because it is too large
Load Diff
106
spirv_parser.hpp
106
spirv_parser.hpp
@ -32,71 +32,71 @@ namespace SPIRV_CROSS_NAMESPACE
|
|||||||
class Parser
|
class Parser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Parser(const uint32_t *spirv_data, size_t word_count);
|
Parser(const uint32_t *spirv_data, size_t word_count);
|
||||||
Parser(std::vector<uint32_t> spirv);
|
Parser(std::vector<uint32_t> spirv);
|
||||||
|
|
||||||
void parse();
|
void parse();
|
||||||
|
|
||||||
ParsedIR &get_parsed_ir()
|
ParsedIR &get_parsed_ir()
|
||||||
{
|
{
|
||||||
return ir;
|
return ir;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ParsedIR ir;
|
ParsedIR ir;
|
||||||
SPIRFunction *current_function = nullptr;
|
SPIRFunction *current_function = nullptr;
|
||||||
SPIRBlock *current_block = nullptr;
|
SPIRBlock *current_block = nullptr;
|
||||||
// For workarounds.
|
// For workarounds.
|
||||||
bool ignore_trailing_block_opcodes = false;
|
bool ignore_trailing_block_opcodes = false;
|
||||||
|
|
||||||
void parse(const Instruction &instr);
|
void parse(const Instruction &instr);
|
||||||
const uint32_t *stream(const Instruction &instr) const;
|
const uint32_t *stream(const Instruction &instr) const;
|
||||||
|
|
||||||
template <typename T, typename... P>
|
template <typename T, typename... P>
|
||||||
T &set(uint32_t id, P &&... args)
|
T &set(uint32_t id, P &&... args)
|
||||||
{
|
{
|
||||||
ir.add_typed_id(static_cast<Types>(T::type), id);
|
ir.add_typed_id(static_cast<Types>(T::type), id);
|
||||||
auto &var = variant_set<T>(ir.ids[id], std::forward<P>(args)...);
|
auto &var = variant_set<T>(ir.ids[id], std::forward<P>(args)...);
|
||||||
var.self = id;
|
var.self = id;
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T &get(uint32_t id)
|
T &get(uint32_t id)
|
||||||
{
|
{
|
||||||
return variant_get<T>(ir.ids[id]);
|
return variant_get<T>(ir.ids[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T *maybe_get(uint32_t id)
|
T *maybe_get(uint32_t id)
|
||||||
{
|
{
|
||||||
if (ir.ids[id].get_type() == static_cast<Types>(T::type))
|
if (ir.ids[id].get_type() == static_cast<Types>(T::type))
|
||||||
return &get<T>(id);
|
return &get<T>(id);
|
||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T &get(uint32_t id) const
|
const T &get(uint32_t id) const
|
||||||
{
|
{
|
||||||
return variant_get<T>(ir.ids[id]);
|
return variant_get<T>(ir.ids[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T *maybe_get(uint32_t id) const
|
const T *maybe_get(uint32_t id) const
|
||||||
{
|
{
|
||||||
if (ir.ids[id].get_type() == T::type)
|
if (ir.ids[id].get_type() == T::type)
|
||||||
return &get<T>(id);
|
return &get<T>(id);
|
||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must be an ordered data structure so we always pick the same type aliases.
|
// This must be an ordered data structure so we always pick the same type aliases.
|
||||||
SmallVector<uint32_t> global_struct_cache;
|
SmallVector<uint32_t> global_struct_cache;
|
||||||
SmallVector<std::pair<uint32_t, uint32_t>> forward_pointer_fixups;
|
SmallVector<std::pair<uint32_t, uint32_t>> forward_pointer_fixups;
|
||||||
|
|
||||||
bool types_are_logically_equivalent(const SPIRType &a, const SPIRType &b) const;
|
bool types_are_logically_equivalent(const SPIRType &a, const SPIRType &b) const;
|
||||||
bool variable_storage_is_aliased(const SPIRVariable &v) const;
|
bool variable_storage_is_aliased(const SPIRVariable &v) const;
|
||||||
};
|
};
|
||||||
} // namespace SPIRV_CROSS_NAMESPACE
|
} // namespace SPIRV_CROSS_NAMESPACE
|
||||||
|
|
||||||
|
@ -36,54 +36,54 @@ namespace SPIRV_CROSS_NAMESPACE
|
|||||||
{
|
{
|
||||||
class CompilerReflection : public CompilerGLSL
|
class CompilerReflection : public CompilerGLSL
|
||||||
{
|
{
|
||||||
using Parent = CompilerGLSL;
|
using Parent = CompilerGLSL;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CompilerReflection(std::vector<uint32_t> spirv_)
|
explicit CompilerReflection(std::vector<uint32_t> spirv_)
|
||||||
: Parent(std::move(spirv_))
|
: Parent(std::move(spirv_))
|
||||||
{
|
{
|
||||||
options.vulkan_semantics = true;
|
options.vulkan_semantics = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilerReflection(const uint32_t *ir_, size_t word_count)
|
CompilerReflection(const uint32_t *ir_, size_t word_count)
|
||||||
: Parent(ir_, word_count)
|
: Parent(ir_, word_count)
|
||||||
{
|
{
|
||||||
options.vulkan_semantics = true;
|
options.vulkan_semantics = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit CompilerReflection(const ParsedIR &ir_)
|
explicit CompilerReflection(const ParsedIR &ir_)
|
||||||
: CompilerGLSL(ir_)
|
: CompilerGLSL(ir_)
|
||||||
{
|
{
|
||||||
options.vulkan_semantics = true;
|
options.vulkan_semantics = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit CompilerReflection(ParsedIR &&ir_)
|
explicit CompilerReflection(ParsedIR &&ir_)
|
||||||
: CompilerGLSL(std::move(ir_))
|
: CompilerGLSL(std::move(ir_))
|
||||||
{
|
{
|
||||||
options.vulkan_semantics = true;
|
options.vulkan_semantics = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_format(const std::string &format);
|
void set_format(const std::string &format);
|
||||||
std::string compile() override;
|
std::string compile() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::string execution_model_to_str(spv::ExecutionModel model);
|
static std::string execution_model_to_str(spv::ExecutionModel model);
|
||||||
|
|
||||||
void emit_entry_points();
|
void emit_entry_points();
|
||||||
void emit_types();
|
void emit_types();
|
||||||
void emit_resources();
|
void emit_resources();
|
||||||
void emit_specialization_constants();
|
void emit_specialization_constants();
|
||||||
|
|
||||||
void emit_type(uint32_t type_id, bool &emitted_open_tag);
|
void emit_type(uint32_t type_id, bool &emitted_open_tag);
|
||||||
void emit_type_member(const SPIRType &type, uint32_t index);
|
void emit_type_member(const SPIRType &type, uint32_t index);
|
||||||
void emit_type_member_qualifiers(const SPIRType &type, uint32_t index);
|
void emit_type_member_qualifiers(const SPIRType &type, uint32_t index);
|
||||||
void emit_type_array(const SPIRType &type);
|
void emit_type_array(const SPIRType &type);
|
||||||
void emit_resources(const char *tag, const SmallVector<Resource> &resources);
|
void emit_resources(const char *tag, const SmallVector<Resource> &resources);
|
||||||
bool type_is_reference(const SPIRType &type) const;
|
bool type_is_reference(const SPIRType &type) const;
|
||||||
|
|
||||||
std::string to_member_name(const SPIRType &type, uint32_t index) const;
|
std::string to_member_name(const SPIRType &type, uint32_t index) const;
|
||||||
|
|
||||||
std::shared_ptr<simple_json::Stream> json_stream;
|
std::shared_ptr<simple_json::Stream> json_stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace SPIRV_CROSS_NAMESPACE
|
} // namespace SPIRV_CROSS_NAMESPACE
|
||||||
|
Loading…
Reference in New Issue
Block a user