2016-03-02 20:09:16 +03:00
|
|
|
/*
|
2018-02-01 01:08:43 +03:00
|
|
|
* Copyright 2015-2018 ARM Limited
|
2016-03-02 20:09:16 +03:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-11-11 20:04:14 +03:00
|
|
|
#ifndef SPIRV_CROSS_GLSL_HPP
|
|
|
|
#define SPIRV_CROSS_GLSL_HPP
|
2016-03-02 20:09:16 +03:00
|
|
|
|
2016-04-04 10:36:04 +03:00
|
|
|
#include "spirv_cross.hpp"
|
2018-02-07 17:56:47 +03:00
|
|
|
#include <limits>
|
2016-03-02 20:09:16 +03:00
|
|
|
#include <sstream>
|
|
|
|
#include <unordered_map>
|
2016-05-23 14:30:02 +03:00
|
|
|
#include <unordered_set>
|
2016-03-02 20:09:16 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2016-04-04 10:36:04 +03:00
|
|
|
namespace spirv_cross
|
2016-03-02 20:09:16 +03:00
|
|
|
{
|
2016-05-05 10:33:18 +03:00
|
|
|
enum PlsFormat
|
|
|
|
{
|
|
|
|
PlsNone = 0,
|
|
|
|
|
|
|
|
PlsR11FG11FB10F,
|
|
|
|
PlsR32F,
|
|
|
|
PlsRG16F,
|
|
|
|
PlsRGB10A2,
|
|
|
|
PlsRGBA8,
|
|
|
|
PlsRG16,
|
|
|
|
|
|
|
|
PlsRGBA8I,
|
|
|
|
PlsRG16I,
|
|
|
|
|
|
|
|
PlsRGB10A2UI,
|
|
|
|
PlsRGBA8UI,
|
|
|
|
PlsRG16UI,
|
|
|
|
PlsR32UI
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PlsRemap
|
|
|
|
{
|
|
|
|
uint32_t id;
|
|
|
|
PlsFormat format;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CompilerGLSL : public Compiler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Options
|
|
|
|
{
|
2017-09-08 10:56:06 +03:00
|
|
|
// The shading language version. Corresponds to #version $VALUE.
|
2016-05-05 10:33:18 +03:00
|
|
|
uint32_t version = 450;
|
2017-09-08 10:56:06 +03:00
|
|
|
|
|
|
|
// Emit the OpenGL ES shading language instead of desktop OpenGL.
|
2016-05-05 10:33:18 +03:00
|
|
|
bool es = false;
|
2017-09-08 10:56:06 +03:00
|
|
|
|
|
|
|
// Debug option to always emit temporary variables for all expressions.
|
2016-05-05 10:33:18 +03:00
|
|
|
bool force_temporary = false;
|
|
|
|
|
2016-05-05 11:16:22 +03:00
|
|
|
// If true, Vulkan GLSL features are used instead of GL-compatible features.
|
|
|
|
// Mostly useful for debugging SPIR-V files.
|
|
|
|
bool vulkan_semantics = false;
|
|
|
|
|
2017-05-22 16:30:43 +03:00
|
|
|
// If true, gl_PerVertex is explicitly redeclared in vertex, geometry and tessellation shaders.
|
|
|
|
// The members of gl_PerVertex is determined by which built-ins are declared by the shader.
|
|
|
|
// This option is ignored in ES versions, as redeclaration in ES is not required, and it depends on a different extension
|
|
|
|
// (EXT_shader_io_blocks) which makes things a bit more fuzzy.
|
|
|
|
bool separate_shader_objects = false;
|
|
|
|
|
2017-05-22 17:52:25 +03:00
|
|
|
// Flattens multidimensional arrays, e.g. float foo[a][b][c] into single-dimensional arrays,
|
|
|
|
// e.g. float foo[a * b * c].
|
|
|
|
// This function does not change the actual SPIRType of any object.
|
|
|
|
// Only the generated code, including declarations of interface variables are changed to be single array dimension.
|
2017-05-22 18:40:00 +03:00
|
|
|
bool flatten_multidimensional_arrays = false;
|
2017-05-22 17:52:25 +03:00
|
|
|
|
2017-09-08 10:56:06 +03:00
|
|
|
// For older desktop GLSL targets than version 420, the
|
|
|
|
// GL_ARB_shading_language_420pack extensions is used to be able to support
|
|
|
|
// layout(binding) on UBOs and samplers.
|
|
|
|
// If disabled on older targets, binding decorations will be stripped.
|
|
|
|
bool enable_420pack_extension = true;
|
|
|
|
|
2016-05-05 10:33:18 +03:00
|
|
|
enum Precision
|
|
|
|
{
|
|
|
|
DontCare,
|
|
|
|
Lowp,
|
|
|
|
Mediump,
|
|
|
|
Highp
|
|
|
|
};
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2017-08-03 14:02:59 +03:00
|
|
|
// 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.
|
|
|
|
bool fixup_clipspace = false;
|
|
|
|
|
|
|
|
// Inverts gl_Position.y or equivalent.
|
|
|
|
bool flip_vert_y = false;
|
2016-05-05 10:33:18 +03:00
|
|
|
} vertex;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
// Add precision mediump float in ES targets when emitting GLES source.
|
|
|
|
// Add precision highp int in ES targets when emitting GLES source.
|
|
|
|
Precision default_float_precision = Mediump;
|
|
|
|
Precision default_int_precision = Highp;
|
|
|
|
} fragment;
|
|
|
|
};
|
|
|
|
|
|
|
|
void remap_pixel_local_storage(std::vector<PlsRemap> inputs, std::vector<PlsRemap> outputs)
|
|
|
|
{
|
|
|
|
pls_inputs = std::move(inputs);
|
|
|
|
pls_outputs = std::move(outputs);
|
|
|
|
remap_pls_variables();
|
|
|
|
}
|
|
|
|
|
|
|
|
CompilerGLSL(std::vector<uint32_t> spirv_)
|
|
|
|
: Compiler(move(spirv_))
|
|
|
|
{
|
2017-04-01 17:08:19 +03:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
CompilerGLSL(const uint32_t *ir, size_t word_count)
|
|
|
|
: Compiler(ir, word_count)
|
|
|
|
{
|
|
|
|
init();
|
2016-05-05 10:33:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const Options &get_options() const
|
|
|
|
{
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
void set_options(Options &opts)
|
|
|
|
{
|
|
|
|
options = opts;
|
|
|
|
}
|
2016-11-27 20:34:04 +03:00
|
|
|
|
2016-05-05 10:33:18 +03:00
|
|
|
std::string compile() override;
|
|
|
|
|
2016-11-27 20:34:04 +03:00
|
|
|
// Returns the current string held in the conversion buffer. Useful for
|
|
|
|
// capturing what has been converted so far when compile() throws an error.
|
|
|
|
std::string get_partial_source();
|
|
|
|
|
2016-07-06 10:58:01 +03:00
|
|
|
// Adds a line to be added right after #version in GLSL backend.
|
|
|
|
// This is useful for enabling custom extensions which are outside the scope of SPIRV-Cross.
|
|
|
|
// This can be combined with variable remapping.
|
|
|
|
// A new-line will be added.
|
|
|
|
//
|
|
|
|
// While add_header_line() is a more generic way of adding arbitrary text to the header
|
|
|
|
// of a GLSL file, require_extension() should be used when adding extensions since it will
|
|
|
|
// avoid creating collisions with SPIRV-Cross generated extensions.
|
|
|
|
//
|
|
|
|
// Code added via add_header_line() is typically backend-specific.
|
|
|
|
void add_header_line(const std::string &str);
|
|
|
|
|
|
|
|
// Adds an extension which is required to run this shader, e.g.
|
|
|
|
// require_extension("GL_KHR_my_extension");
|
|
|
|
void require_extension(const std::string &ext);
|
|
|
|
|
2016-12-07 08:02:15 +03:00
|
|
|
// Legacy GLSL compatibility method.
|
2017-01-21 12:27:14 +03:00
|
|
|
// Takes a uniform or push constant variable and flattens it into a (i|u)vec4 array[N]; array instead.
|
|
|
|
// For this to work, all types in the block must be the same basic type, e.g. mixing vec2 and vec4 is fine, but
|
|
|
|
// mixing int and float is not.
|
2016-12-07 08:02:15 +03:00
|
|
|
// The name of the uniform array will be the same as the interface block name.
|
|
|
|
void flatten_buffer_block(uint32_t id);
|
|
|
|
|
2016-05-05 10:33:18 +03:00
|
|
|
protected:
|
|
|
|
void reset();
|
|
|
|
void emit_function(SPIRFunction &func, uint64_t return_flags);
|
|
|
|
|
2017-11-22 21:27:03 +03:00
|
|
|
bool has_extension(const std::string &ext) const;
|
|
|
|
|
2016-05-05 10:33:18 +03:00
|
|
|
// Virtualize methods which need to be overridden by subclass targets like C++ and such.
|
|
|
|
virtual void emit_function_prototype(SPIRFunction &func, uint64_t return_flags);
|
2017-10-20 17:18:02 +03:00
|
|
|
|
|
|
|
// Kinda ugly way to let opcodes peek at their neighbor instructions for trivial peephole scenarios.
|
|
|
|
const SPIRBlock *current_emitting_block = nullptr;
|
|
|
|
|
2016-10-28 01:47:17 +03:00
|
|
|
virtual void emit_instruction(const Instruction &instr);
|
2017-10-20 17:18:02 +03:00
|
|
|
void emit_block_instructions(const SPIRBlock &block);
|
2016-11-12 12:04:50 +03:00
|
|
|
virtual void emit_glsl_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
|
|
|
uint32_t count);
|
2017-11-22 21:27:03 +03:00
|
|
|
virtual void emit_spv_amd_shader_ballot_op(uint32_t result_type, uint32_t result_id, uint32_t op,
|
|
|
|
const uint32_t *args, uint32_t count);
|
|
|
|
virtual void emit_spv_amd_shader_explicit_vertex_parameter_op(uint32_t result_type, uint32_t result_id, uint32_t op,
|
|
|
|
const uint32_t *args, uint32_t count);
|
|
|
|
virtual void emit_spv_amd_shader_trinary_minmax_op(uint32_t result_type, uint32_t result_id, uint32_t op,
|
|
|
|
const uint32_t *args, uint32_t count);
|
2017-11-21 16:04:57 +03:00
|
|
|
virtual void emit_spv_amd_gcn_shader_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
|
|
|
uint32_t count);
|
2016-05-05 10:33:18 +03:00
|
|
|
virtual void emit_header();
|
|
|
|
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);
|
2017-05-30 03:45:05 +03:00
|
|
|
virtual std::string type_to_glsl(const SPIRType &type, uint32_t id = 0);
|
2017-07-24 11:07:02 +03:00
|
|
|
virtual std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage);
|
2017-03-11 20:17:22 +03:00
|
|
|
virtual void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index,
|
2017-11-27 18:00:56 +03:00
|
|
|
const std::string &qualifier = "", uint32_t base_offset = 0);
|
2017-05-30 03:45:05 +03:00
|
|
|
virtual std::string image_type_glsl(const SPIRType &type, uint32_t id = 0);
|
2016-05-05 10:33:18 +03:00
|
|
|
virtual std::string constant_expression(const SPIRConstant &c);
|
2016-10-03 16:54:02 +03:00
|
|
|
std::string constant_op_expression(const SPIRConstantOp &cop);
|
2016-05-05 10:33:18 +03:00
|
|
|
virtual std::string constant_expression_vector(const SPIRConstant &c, uint32_t vector);
|
|
|
|
virtual void emit_fixup();
|
2017-06-17 11:54:59 +03:00
|
|
|
virtual std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id = 0);
|
2016-10-24 16:24:24 +03:00
|
|
|
virtual std::string to_func_call_arg(uint32_t id);
|
2016-12-29 02:36:42 +03:00
|
|
|
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,
|
2017-03-24 11:26:02 +03:00
|
|
|
bool has_dref, uint32_t lod);
|
2016-12-29 02:36:42 +03:00
|
|
|
virtual std::string to_function_args(uint32_t 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,
|
|
|
|
bool *p_forward);
|
2017-01-24 11:17:43 +03:00
|
|
|
virtual void emit_buffer_block(const SPIRVariable &type);
|
|
|
|
virtual void emit_push_constant_block(const SPIRVariable &var);
|
2017-01-24 11:23:22 +03:00
|
|
|
virtual void emit_uniform(const SPIRVariable &var);
|
2017-03-01 21:07:40 +03:00
|
|
|
virtual std::string unpack_expression_type(std::string expr_str, const SPIRType &type);
|
2016-05-05 10:33:18 +03:00
|
|
|
|
|
|
|
std::unique_ptr<std::ostringstream> buffer;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void statement_inner(T &&t)
|
|
|
|
{
|
|
|
|
(*buffer) << std::forward<T>(t);
|
|
|
|
statement_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename... Ts>
|
|
|
|
inline void statement_inner(T &&t, Ts &&... ts)
|
|
|
|
{
|
|
|
|
(*buffer) << std::forward<T>(t);
|
|
|
|
statement_count++;
|
|
|
|
statement_inner(std::forward<Ts>(ts)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Ts>
|
|
|
|
inline void statement(Ts &&... ts)
|
|
|
|
{
|
2018-01-15 12:26:12 +03:00
|
|
|
if (force_recompile)
|
|
|
|
{
|
|
|
|
// Do not bother emitting code while force_recompile is active.
|
|
|
|
// We will compile again.
|
|
|
|
statement_count++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-05 10:33:18 +03:00
|
|
|
if (redirect_statement)
|
|
|
|
redirect_statement->push_back(join(std::forward<Ts>(ts)...));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < indent; i++)
|
|
|
|
(*buffer) << " ";
|
|
|
|
|
|
|
|
statement_inner(std::forward<Ts>(ts)...);
|
|
|
|
(*buffer) << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Ts>
|
|
|
|
inline void statement_no_indent(Ts &&... ts)
|
|
|
|
{
|
|
|
|
auto old_indent = indent;
|
|
|
|
indent = 0;
|
|
|
|
statement(std::forward<Ts>(ts)...);
|
|
|
|
indent = old_indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used for implementing continue blocks where
|
|
|
|
// we want to obtain a list of statements we can merge
|
|
|
|
// on a single line separated by comma.
|
|
|
|
std::vector<std::string> *redirect_statement = nullptr;
|
|
|
|
const SPIRBlock *current_continue_block = nullptr;
|
|
|
|
|
|
|
|
void begin_scope();
|
|
|
|
void end_scope();
|
|
|
|
void end_scope_decl();
|
|
|
|
void end_scope_decl(const std::string &decl);
|
|
|
|
|
|
|
|
Options options;
|
|
|
|
|
|
|
|
std::string type_to_array_glsl(const SPIRType &type);
|
2016-10-03 18:17:11 +03:00
|
|
|
std::string to_array_size(const SPIRType &type, uint32_t index);
|
|
|
|
uint32_t to_array_size_literal(const SPIRType &type, uint32_t index) const;
|
2016-05-05 10:33:18 +03:00
|
|
|
std::string variable_decl(const SPIRVariable &variable);
|
2017-02-24 13:15:34 +03:00
|
|
|
std::string variable_decl_function_local(SPIRVariable &variable);
|
2016-05-05 10:33:18 +03:00
|
|
|
|
2016-05-23 13:25:09 +03:00
|
|
|
void add_local_variable_name(uint32_t id);
|
|
|
|
void add_resource_name(uint32_t id);
|
|
|
|
void add_member_name(SPIRType &type, uint32_t name);
|
2016-12-11 19:01:08 +03:00
|
|
|
|
2018-01-05 00:33:45 +03:00
|
|
|
virtual bool is_non_native_row_major_matrix(uint32_t id);
|
|
|
|
virtual bool member_is_non_native_row_major_matrix(const SPIRType &type, uint32_t index);
|
2017-11-06 05:34:42 +03:00
|
|
|
bool member_is_packed_type(const SPIRType &type, uint32_t index) const;
|
2018-02-12 00:52:57 +03:00
|
|
|
virtual std::string convert_row_major_matrix(std::string exp_str, const SPIRType &exp_type, bool is_packed);
|
2016-12-11 19:01:08 +03:00
|
|
|
|
2016-05-23 13:25:09 +03:00
|
|
|
std::unordered_set<std::string> local_variable_names;
|
|
|
|
std::unordered_set<std::string> resource_names;
|
2016-05-05 10:33:18 +03:00
|
|
|
|
|
|
|
bool processing_entry_point = false;
|
|
|
|
|
|
|
|
// Can be overriden by subclass backends for trivial things which
|
|
|
|
// shouldn't need polymorphism.
|
|
|
|
struct BackendVariations
|
|
|
|
{
|
2016-10-27 17:20:01 +03:00
|
|
|
std::string discard_literal = "discard";
|
2016-05-05 10:33:18 +03:00
|
|
|
bool float_literal_suffix = false;
|
2016-07-27 11:59:00 +03:00
|
|
|
bool double_literal_suffix = true;
|
2016-05-05 10:33:18 +03:00
|
|
|
bool uint32_t_literal_suffix = true;
|
2016-07-27 12:27:00 +03:00
|
|
|
bool long_long_literal_suffix = false;
|
2016-05-05 10:33:18 +03:00
|
|
|
const char *basic_int_type = "int";
|
|
|
|
const char *basic_uint_type = "uint";
|
|
|
|
bool swizzle_is_function = false;
|
|
|
|
bool shared_is_implied = false;
|
2016-05-23 10:15:49 +03:00
|
|
|
bool flexible_member_array_supported = true;
|
2016-05-23 13:25:09 +03:00
|
|
|
bool explicit_struct_type = false;
|
2016-05-28 14:09:26 +03:00
|
|
|
bool use_initializer_list = false;
|
2018-01-23 18:36:20 +03:00
|
|
|
bool use_typed_initializer_list = false;
|
|
|
|
bool can_declare_struct_inline = true;
|
2018-02-02 12:10:17 +03:00
|
|
|
bool can_declare_arrays_inline = true;
|
2016-12-14 10:12:52 +03:00
|
|
|
bool native_row_major_matrix = true;
|
2016-09-23 19:57:18 +03:00
|
|
|
bool use_constructor_splatting = true;
|
2017-05-04 11:28:30 +03:00
|
|
|
bool boolean_mix_support = true;
|
2017-12-06 12:25:30 +03:00
|
|
|
bool allow_precision_qualifiers = false;
|
2017-12-12 13:03:46 +03:00
|
|
|
bool can_swizzle_scalar = false;
|
2018-01-09 11:16:33 +03:00
|
|
|
bool force_gl_in_out_block = false;
|
2018-02-05 14:37:41 +03:00
|
|
|
bool can_return_array = true;
|
2018-02-13 22:44:40 +03:00
|
|
|
bool allow_truncated_access_chain = false;
|
2016-05-05 10:33:18 +03:00
|
|
|
} backend;
|
|
|
|
|
2016-05-23 13:25:09 +03:00
|
|
|
void emit_struct(SPIRType &type);
|
2016-05-05 10:33:18 +03:00
|
|
|
void emit_resources();
|
2017-01-17 23:18:35 +03:00
|
|
|
void emit_buffer_block_native(const SPIRVariable &var);
|
2017-01-13 18:31:13 +03:00
|
|
|
void emit_buffer_block_legacy(const SPIRVariable &var);
|
2017-01-17 23:18:35 +03:00
|
|
|
void emit_buffer_block_flattened(const SPIRVariable &type);
|
2017-05-22 16:30:43 +03:00
|
|
|
void emit_declared_builtin_block(spv::StorageClass storage, spv::ExecutionModel model);
|
2016-05-05 11:16:22 +03:00
|
|
|
void emit_push_constant_block_vulkan(const SPIRVariable &var);
|
|
|
|
void emit_push_constant_block_glsl(const SPIRVariable &var);
|
2016-05-05 10:33:18 +03:00
|
|
|
void emit_interface_block(const SPIRVariable &type);
|
2017-03-06 16:01:51 +03:00
|
|
|
void emit_flattened_io_block(const SPIRVariable &var, const char *qual);
|
2016-05-05 10:33:18 +03:00
|
|
|
void emit_block_chain(SPIRBlock &block);
|
2016-10-03 13:52:56 +03:00
|
|
|
void emit_specialization_constant(const SPIRConstant &constant);
|
2016-05-05 10:33:18 +03:00
|
|
|
std::string emit_continue_block(uint32_t continue_block);
|
|
|
|
bool attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method method);
|
|
|
|
void propagate_loop_dominators(const SPIRBlock &block);
|
|
|
|
|
|
|
|
void branch(uint32_t from, uint32_t to);
|
|
|
|
void branch(uint32_t from, uint32_t cond, uint32_t true_block, uint32_t false_block);
|
|
|
|
void flush_phi(uint32_t from, uint32_t to);
|
|
|
|
bool flush_phi_required(uint32_t from, uint32_t to);
|
|
|
|
void flush_variable_declaration(uint32_t id);
|
2016-11-11 20:04:14 +03:00
|
|
|
void flush_undeclared_variables(SPIRBlock &block);
|
2016-05-05 10:33:18 +03:00
|
|
|
|
|
|
|
bool should_forward(uint32_t id);
|
|
|
|
void emit_mix_op(uint32_t result_type, uint32_t id, uint32_t left, uint32_t right, uint32_t lerp);
|
2016-10-03 16:54:02 +03:00
|
|
|
bool to_trivial_mix_op(const SPIRType &type, std::string &op, uint32_t left, uint32_t right, uint32_t lerp);
|
2016-05-05 10:33:18 +03:00
|
|
|
void emit_quaternary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
|
|
|
uint32_t op3, const char *op);
|
|
|
|
void emit_trinary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
|
|
|
const char *op);
|
|
|
|
void emit_binary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
2016-05-11 00:39:41 +03:00
|
|
|
void emit_binary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op,
|
|
|
|
SPIRType::BaseType input_type, bool skip_cast_if_equal_type);
|
2016-05-05 10:33:18 +03:00
|
|
|
void emit_unary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op);
|
2017-03-24 17:00:48 +03:00
|
|
|
void emit_unrolled_unary_op(uint32_t result_type, uint32_t result_id, uint32_t operand, const char *op);
|
2016-05-05 10:33:18 +03:00
|
|
|
void emit_binary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
2017-03-21 00:38:05 +03:00
|
|
|
void emit_unrolled_binary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
2016-05-11 00:39:41 +03:00
|
|
|
void emit_binary_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op,
|
|
|
|
SPIRType::BaseType input_type, bool skip_cast_if_equal_type);
|
|
|
|
|
|
|
|
SPIRType binary_op_bitcast_helper(std::string &cast_op0, std::string &cast_op1, SPIRType::BaseType &input_type,
|
|
|
|
uint32_t op0, uint32_t op1, bool skip_cast_if_equal_type);
|
|
|
|
|
2016-05-05 10:33:18 +03:00
|
|
|
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);
|
|
|
|
SPIRExpression &emit_op(uint32_t result_type, uint32_t result_id, const std::string &rhs, bool forward_rhs,
|
2016-12-05 12:22:54 +03:00
|
|
|
bool suppress_usage_tracking = false);
|
2017-02-23 21:03:07 +03:00
|
|
|
std::string access_chain_internal(uint32_t base, const uint32_t *indices, uint32_t count, bool index_is_literal,
|
2018-01-06 01:46:56 +03:00
|
|
|
bool chain_only = false, bool *need_transpose = nullptr,
|
|
|
|
bool *result_is_packed = nullptr);
|
2017-01-20 19:33:59 +03:00
|
|
|
std::string access_chain(uint32_t base, const uint32_t *indices, uint32_t count, const SPIRType &target_type,
|
2018-01-06 01:46:56 +03:00
|
|
|
bool *need_transpose = nullptr, bool *result_is_packed = nullptr);
|
2017-01-20 19:33:59 +03:00
|
|
|
|
|
|
|
std::string flattened_access_chain(uint32_t base, const uint32_t *indices, uint32_t count,
|
2017-01-24 18:42:19 +03:00
|
|
|
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
|
|
|
bool need_transpose);
|
2017-01-20 19:33:59 +03:00
|
|
|
std::string flattened_access_chain_struct(uint32_t base, const uint32_t *indices, uint32_t count,
|
|
|
|
const SPIRType &target_type, uint32_t offset);
|
|
|
|
std::string flattened_access_chain_matrix(uint32_t base, const uint32_t *indices, uint32_t count,
|
2017-01-22 11:21:22 +03:00
|
|
|
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
|
|
|
bool need_transpose);
|
2017-01-24 18:42:19 +03:00
|
|
|
std::string flattened_access_chain_vector(uint32_t base, const uint32_t *indices, uint32_t count,
|
|
|
|
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
|
|
|
bool need_transpose);
|
2017-08-10 16:36:30 +03:00
|
|
|
std::pair<std::string, uint32_t> flattened_access_chain_offset(const SPIRType &basetype, const uint32_t *indices,
|
2017-01-20 19:33:59 +03:00
|
|
|
uint32_t count, uint32_t offset,
|
2017-08-28 10:01:03 +03:00
|
|
|
uint32_t word_stride, bool *need_transpose = nullptr,
|
2017-01-21 14:47:26 +03:00
|
|
|
uint32_t *matrix_stride = nullptr);
|
2016-05-05 10:33:18 +03:00
|
|
|
|
|
|
|
const char *index_to_swizzle(uint32_t index);
|
2017-10-24 10:23:29 +03:00
|
|
|
std::string remap_swizzle(const SPIRType &result_type, uint32_t input_components, const std::string &expr);
|
2016-05-05 10:33:18 +03:00
|
|
|
std::string declare_temporary(uint32_t type, uint32_t id);
|
2016-10-24 16:24:24 +03:00
|
|
|
void append_global_func_args(const SPIRFunction &func, uint32_t index, std::vector<std::string> &arglist);
|
2016-05-05 10:33:18 +03:00
|
|
|
std::string to_expression(uint32_t id);
|
2016-12-05 12:22:54 +03:00
|
|
|
std::string to_enclosed_expression(uint32_t id);
|
2017-05-22 17:52:25 +03:00
|
|
|
std::string enclose_expression(const std::string &expr);
|
2016-12-07 01:03:35 +03:00
|
|
|
void strip_enclosed_expression(std::string &expr);
|
2016-05-05 10:33:18 +03:00
|
|
|
std::string to_member_name(const SPIRType &type, uint32_t index);
|
|
|
|
std::string type_to_glsl_constructor(const SPIRType &type);
|
|
|
|
std::string argument_decl(const SPIRFunction::Parameter &arg);
|
2017-11-06 05:34:42 +03:00
|
|
|
virtual std::string to_qualifiers_glsl(uint32_t id);
|
2016-05-05 10:33:18 +03:00
|
|
|
const char *to_precision_qualifiers_glsl(uint32_t id);
|
2017-02-24 13:15:34 +03:00
|
|
|
virtual const char *to_storage_qualifiers_glsl(const SPIRVariable &var);
|
2016-05-05 10:33:18 +03:00
|
|
|
const char *flags_to_precision_qualifiers_glsl(const SPIRType &type, uint64_t flags);
|
|
|
|
const char *format_to_glsl(spv::ImageFormat format);
|
2017-03-07 18:18:43 +03:00
|
|
|
virtual std::string layout_for_member(const SPIRType &type, uint32_t index);
|
2017-03-20 11:48:43 +03:00
|
|
|
virtual std::string to_interpolation_qualifiers(uint64_t flags);
|
2016-05-05 10:33:18 +03:00
|
|
|
uint64_t combined_decoration_for_member(const SPIRType &type, uint32_t index);
|
|
|
|
std::string layout_for_variable(const SPIRVariable &variable);
|
2016-09-11 13:54:08 +03:00
|
|
|
std::string to_combined_image_sampler(uint32_t image_id, uint32_t samp_id);
|
2017-05-07 13:36:14 +03:00
|
|
|
virtual bool skip_argument(uint32_t id) const;
|
2018-02-05 14:37:41 +03:00
|
|
|
virtual void emit_array_copy(const std::string &lhs, uint32_t rhs_id);
|
2016-05-05 10:33:18 +03:00
|
|
|
|
2017-11-27 18:00:56 +03:00
|
|
|
bool buffer_is_packing_standard(const SPIRType &type, BufferPackingStandard packing, uint32_t start_offset = 0,
|
|
|
|
uint32_t end_offset = std::numeric_limits<uint32_t>::max());
|
2017-10-10 11:12:27 +03:00
|
|
|
uint32_t type_to_packed_base_size(const SPIRType &type, BufferPackingStandard packing);
|
|
|
|
uint32_t type_to_packed_alignment(const SPIRType &type, uint64_t flags, BufferPackingStandard packing);
|
|
|
|
uint32_t type_to_packed_array_stride(const SPIRType &type, uint64_t flags, BufferPackingStandard packing);
|
|
|
|
uint32_t type_to_packed_size(const SPIRType &type, uint64_t flags, BufferPackingStandard packing);
|
2016-05-05 10:33:18 +03:00
|
|
|
|
2016-05-11 00:39:41 +03:00
|
|
|
std::string bitcast_glsl(const SPIRType &result_type, uint32_t arg);
|
2017-03-24 16:13:59 +03:00
|
|
|
virtual std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type);
|
2017-09-19 17:08:25 +03:00
|
|
|
|
|
|
|
std::string bitcast_expression(SPIRType::BaseType target_type, uint32_t arg);
|
2017-09-19 17:09:19 +03:00
|
|
|
std::string bitcast_expression(const SPIRType &target_type, SPIRType::BaseType expr_type, const std::string &expr);
|
2017-09-19 17:08:25 +03:00
|
|
|
|
2018-01-22 11:52:57 +03:00
|
|
|
std::string build_composite_combiner(uint32_t result_type, const uint32_t *elems, uint32_t length);
|
2016-05-05 10:33:18 +03:00
|
|
|
bool remove_duplicate_swizzle(std::string &op);
|
|
|
|
bool remove_unity_swizzle(uint32_t base, std::string &op);
|
|
|
|
|
|
|
|
// Can modify flags to remote readonly/writeonly if image type
|
|
|
|
// and force recompile.
|
|
|
|
bool check_atomic_image(uint32_t id);
|
|
|
|
|
2017-11-06 05:34:42 +03:00
|
|
|
virtual void replace_illegal_names();
|
2016-08-13 01:14:52 +03:00
|
|
|
|
2016-05-05 10:33:18 +03:00
|
|
|
void replace_fragment_output(SPIRVariable &var);
|
|
|
|
void replace_fragment_outputs();
|
2017-03-23 16:43:54 +03:00
|
|
|
bool check_explicit_lod_allowed(uint32_t lod);
|
2017-03-23 11:55:32 +03:00
|
|
|
std::string legacy_tex_op(const std::string &op, const SPIRType &imgtype, uint32_t lod);
|
2016-05-05 10:33:18 +03:00
|
|
|
|
|
|
|
uint32_t indent = 0;
|
|
|
|
|
|
|
|
std::unordered_set<uint32_t> emitted_functions;
|
|
|
|
|
2016-12-07 08:02:15 +03:00
|
|
|
std::unordered_set<uint32_t> flattened_buffer_blocks;
|
2017-02-22 22:17:58 +03:00
|
|
|
std::unordered_set<uint32_t> flattened_structs;
|
|
|
|
|
2017-02-23 21:24:59 +03:00
|
|
|
std::string load_flattened_struct(SPIRVariable &var);
|
2018-01-09 12:36:04 +03:00
|
|
|
std::string to_flattened_struct_member(const SPIRVariable &var, uint32_t index);
|
2017-02-22 22:17:58 +03:00
|
|
|
void store_flattened_struct(SPIRVariable &var, uint32_t value);
|
2016-12-07 08:02:15 +03:00
|
|
|
|
2016-05-05 10:33:18 +03:00
|
|
|
// 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.
|
|
|
|
std::unordered_map<uint32_t, uint32_t> expression_usage_counts;
|
|
|
|
void track_expression_read(uint32_t id);
|
|
|
|
|
2017-11-22 21:27:03 +03:00
|
|
|
std::vector<std::string> forced_extensions;
|
2016-07-06 10:58:01 +03:00
|
|
|
std::vector<std::string> header_lines;
|
2016-05-05 10:33:18 +03:00
|
|
|
|
|
|
|
uint32_t statement_count;
|
|
|
|
|
|
|
|
inline bool is_legacy() const
|
|
|
|
{
|
|
|
|
return (options.es && options.version < 300) || (!options.es && options.version < 130);
|
|
|
|
}
|
|
|
|
|
2016-09-17 15:33:16 +03:00
|
|
|
inline bool is_legacy_es() const
|
|
|
|
{
|
2016-09-17 16:56:23 +03:00
|
|
|
return options.es && options.version < 300;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool is_legacy_desktop() const
|
|
|
|
{
|
|
|
|
return !options.es && options.version < 130;
|
2016-09-17 15:33:16 +03:00
|
|
|
}
|
|
|
|
|
2016-05-05 10:33:18 +03:00
|
|
|
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();
|
|
|
|
|
|
|
|
// GL_EXT_shader_pixel_local_storage support.
|
|
|
|
std::vector<PlsRemap> pls_inputs;
|
|
|
|
std::vector<PlsRemap> pls_outputs;
|
|
|
|
std::string pls_decl(const PlsRemap &variable);
|
|
|
|
const char *to_pls_qualifiers_glsl(const SPIRVariable &variable);
|
|
|
|
void emit_pls();
|
|
|
|
void remap_pls_variables();
|
2016-05-23 13:25:09 +03:00
|
|
|
|
|
|
|
void add_variable(std::unordered_set<std::string> &variables, uint32_t id);
|
2017-12-01 16:20:51 +03:00
|
|
|
void add_variable(std::unordered_set<std::string> &variables, std::string &name);
|
2016-07-06 12:04:06 +03:00
|
|
|
void check_function_call_constraints(const uint32_t *args, uint32_t length);
|
2016-07-12 15:33:04 +03:00
|
|
|
void handle_invalid_expression(uint32_t id);
|
2016-07-27 11:59:00 +03:00
|
|
|
void find_static_extensions();
|
2016-12-15 19:14:47 +03:00
|
|
|
|
|
|
|
std::string emit_for_loop_initializers(const SPIRBlock &block);
|
2018-01-16 12:27:58 +03:00
|
|
|
bool for_loop_initializers_are_same_type(const SPIRBlock &block);
|
2016-12-16 15:14:22 +03:00
|
|
|
bool optimize_read_modify_write(const std::string &lhs, const std::string &rhs);
|
2017-01-05 20:16:33 +03:00
|
|
|
void fixup_image_load_store_access();
|
2017-03-24 12:03:11 +03:00
|
|
|
|
|
|
|
bool type_is_empty(const SPIRType &type);
|
2017-04-01 17:08:19 +03:00
|
|
|
|
2017-11-16 06:44:42 +03:00
|
|
|
virtual void declare_undefined_values();
|
2017-08-02 11:33:03 +03:00
|
|
|
|
2017-10-10 14:15:49 +03:00
|
|
|
static std::string sanitize_underscores(const std::string &str);
|
|
|
|
|
2017-10-19 15:17:18 +03:00
|
|
|
bool can_use_io_location(spv::StorageClass storage);
|
2018-01-09 14:07:07 +03:00
|
|
|
const Instruction *get_next_instruction_in_block(const Instruction &instr);
|
2018-01-09 14:41:13 +03:00
|
|
|
static uint32_t mask_relevant_memory_semantics(uint32_t semantics);
|
2017-10-19 15:17:18 +03:00
|
|
|
|
2017-04-01 17:08:19 +03:00
|
|
|
private:
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
if (source.known)
|
|
|
|
{
|
|
|
|
options.es = source.es;
|
|
|
|
options.version = source.version;
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 10:33:18 +03:00
|
|
|
};
|
2016-03-02 20:09:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|