2016-03-02 17:09:16 +00:00
|
|
|
/*
|
2021-01-14 15:07:49 +00:00
|
|
|
* Copyright 2015-2021 Arm Limited
|
2021-05-08 08:47:48 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
2016-03-02 17:09:16 +00: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.
|
|
|
|
*/
|
|
|
|
|
2020-11-25 14:22:08 +00:00
|
|
|
/*
|
|
|
|
* At your option, you may choose to accept this material under either:
|
|
|
|
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
|
|
|
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
|
|
|
*/
|
|
|
|
|
2016-11-11 17:04:14 +00:00
|
|
|
#ifndef SPIRV_CROSS_GLSL_HPP
|
|
|
|
#define SPIRV_CROSS_GLSL_HPP
|
2016-03-02 17:09:16 +00:00
|
|
|
|
2019-03-21 14:26:46 +00:00
|
|
|
#include "GLSL.std.450.h"
|
2019-04-02 09:19:03 +00:00
|
|
|
#include "spirv_cross.hpp"
|
2016-03-02 17:09:16 +00:00
|
|
|
#include <unordered_map>
|
2016-05-23 11:30:02 +00:00
|
|
|
#include <unordered_set>
|
2016-03-02 17:09:16 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2019-03-29 09:29:44 +00:00
|
|
|
namespace SPIRV_CROSS_NAMESPACE
|
2016-03-02 17:09:16 +00:00
|
|
|
{
|
2016-05-05 07:33:18 +00:00
|
|
|
enum PlsFormat
|
|
|
|
{
|
|
|
|
PlsNone = 0,
|
|
|
|
|
|
|
|
PlsR11FG11FB10F,
|
|
|
|
PlsR32F,
|
|
|
|
PlsRG16F,
|
|
|
|
PlsRGB10A2,
|
|
|
|
PlsRGBA8,
|
|
|
|
PlsRG16,
|
|
|
|
|
|
|
|
PlsRGBA8I,
|
|
|
|
PlsRG16I,
|
|
|
|
|
|
|
|
PlsRGB10A2UI,
|
|
|
|
PlsRGBA8UI,
|
|
|
|
PlsRG16UI,
|
|
|
|
PlsR32UI
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PlsRemap
|
|
|
|
{
|
|
|
|
uint32_t id;
|
|
|
|
PlsFormat format;
|
|
|
|
};
|
|
|
|
|
2019-01-17 09:30:13 +00:00
|
|
|
enum AccessChainFlagBits
|
|
|
|
{
|
|
|
|
ACCESS_CHAIN_INDEX_IS_LITERAL_BIT = 1 << 0,
|
|
|
|
ACCESS_CHAIN_CHAIN_ONLY_BIT = 1 << 1,
|
|
|
|
ACCESS_CHAIN_PTR_CHAIN_BIT = 1 << 2,
|
2020-01-08 13:17:28 +00:00
|
|
|
ACCESS_CHAIN_SKIP_REGISTER_EXPRESSION_READ_BIT = 1 << 3,
|
2020-07-03 11:12:05 +00:00
|
|
|
ACCESS_CHAIN_LITERAL_MSB_FORCE_ID = 1 << 4,
|
2021-04-06 09:35:04 +00:00
|
|
|
ACCESS_CHAIN_FLATTEN_ALL_MEMBERS_BIT = 1 << 5,
|
|
|
|
ACCESS_CHAIN_FORCE_COMPOSITE_BIT = 1 << 6
|
2019-01-17 09:30:13 +00:00
|
|
|
};
|
|
|
|
typedef uint32_t AccessChainFlags;
|
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
class CompilerGLSL : public Compiler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Options
|
|
|
|
{
|
2017-09-08 07:56:06 +00:00
|
|
|
// The shading language version. Corresponds to #version $VALUE.
|
2016-05-05 07:33:18 +00:00
|
|
|
uint32_t version = 450;
|
2017-09-08 07:56:06 +00:00
|
|
|
|
|
|
|
// Emit the OpenGL ES shading language instead of desktop OpenGL.
|
2016-05-05 07:33:18 +00:00
|
|
|
bool es = false;
|
2017-09-08 07:56:06 +00:00
|
|
|
|
|
|
|
// Debug option to always emit temporary variables for all expressions.
|
2016-05-05 07:33:18 +00:00
|
|
|
bool force_temporary = false;
|
2022-02-16 11:12:27 +00:00
|
|
|
// Debug option, can be increased in an attempt to workaround SPIRV-Cross bugs temporarily.
|
|
|
|
// If this limit has to be increased, it points to an implementation bug.
|
|
|
|
// In certain scenarios, the maximum number of debug iterations may increase beyond this limit
|
|
|
|
// as long as we can prove we're making certain kinds of forward progress.
|
|
|
|
uint32_t force_recompile_max_debug_iterations = 3;
|
2016-05-05 07:33:18 +00:00
|
|
|
|
2016-05-05 08:16:22 +00: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 13:30:43 +00: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 14:52:25 +00: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 15:40:00 +00:00
|
|
|
bool flatten_multidimensional_arrays = false;
|
2017-05-22 14:52:25 +00:00
|
|
|
|
2017-09-08 07:56:06 +00: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;
|
|
|
|
|
2019-03-19 09:58:37 +00:00
|
|
|
// In non-Vulkan GLSL, emit push constant blocks as UBOs rather than plain uniforms.
|
|
|
|
bool emit_push_constant_as_uniform_buffer = false;
|
|
|
|
|
2019-05-11 14:30:33 +00:00
|
|
|
// Always emit uniform blocks as plain uniforms, regardless of the GLSL version, even when UBOs are supported.
|
|
|
|
// Does not apply to shader storage or push constant blocks.
|
|
|
|
bool emit_uniform_buffer_as_plain_uniforms = false;
|
|
|
|
|
2019-05-28 11:41:46 +00:00
|
|
|
// Emit OpLine directives if present in the module.
|
|
|
|
// May not correspond exactly to original source, but should be a good approximation.
|
2019-06-02 14:20:21 +00:00
|
|
|
bool emit_line_directives = false;
|
2019-05-28 11:41:46 +00:00
|
|
|
|
2020-03-04 15:15:01 +00:00
|
|
|
// In cases where readonly/writeonly decoration are not used at all,
|
|
|
|
// we try to deduce which qualifier(s) we should actually used, since actually emitting
|
|
|
|
// read-write decoration is very rare, and older glslang/HLSL compilers tend to just emit readwrite as a matter of fact.
|
|
|
|
// The default (true) is to enable automatic deduction for these cases, but if you trust the decorations set
|
|
|
|
// by the SPIR-V, it's recommended to set this to false.
|
|
|
|
bool enable_storage_image_qualifier_deduction = true;
|
|
|
|
|
2020-03-26 10:21:23 +00:00
|
|
|
// On some targets (WebGPU), uninitialized variables are banned.
|
|
|
|
// If this is enabled, all variables (temporaries, Private, Function)
|
|
|
|
// which would otherwise be uninitialized will now be initialized to 0 instead.
|
|
|
|
bool force_zero_initialized_variables = false;
|
|
|
|
|
2020-07-28 13:15:24 +00:00
|
|
|
// In GLSL, force use of I/O block flattening, similar to
|
|
|
|
// what happens on legacy GLSL targets for blocks and structs.
|
|
|
|
bool force_flattened_io_blocks = false;
|
|
|
|
|
2022-03-03 10:04:45 +00:00
|
|
|
// For opcodes where we have to perform explicit additional nan checks, very ugly code is generated.
|
|
|
|
// If we opt-in, ignore these requirements.
|
|
|
|
// In opcodes like NClamp/NMin/NMax and FP compare, ignore NaN behavior.
|
|
|
|
// Use FClamp/FMin/FMax semantics for clamps and lets implementation choose ordered or unordered
|
|
|
|
// compares.
|
|
|
|
bool relax_nan_checks = false;
|
|
|
|
|
2022-08-24 03:07:12 +00:00
|
|
|
// Loading row-major matrices from UBOs on older AMD Windows OpenGL drivers is problematic.
|
|
|
|
// To load these types correctly, we must generate a wrapper. them in a dummy function which only purpose is to
|
|
|
|
// ensure row_major decoration is actually respected.
|
|
|
|
// This workaround may cause significant performance degeneration on some Android devices.
|
|
|
|
bool enable_row_major_load_workaround = true;
|
|
|
|
|
2021-06-28 10:55:37 +00:00
|
|
|
// If non-zero, controls layout(num_views = N) in; in GL_OVR_multiview2.
|
|
|
|
uint32_t ovr_multiview_view_count = 0;
|
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
enum Precision
|
|
|
|
{
|
|
|
|
DontCare,
|
|
|
|
Lowp,
|
|
|
|
Mediump,
|
|
|
|
Highp
|
|
|
|
};
|
|
|
|
|
2020-07-11 11:35:44 +00:00
|
|
|
struct VertexOptions
|
2016-05-05 07:33:18 +00:00
|
|
|
{
|
2020-09-28 12:09:39 +00:00
|
|
|
// "Vertex-like shader" here is any shader stage that can write BuiltInPosition.
|
|
|
|
|
|
|
|
// GLSL: In vertex-like shaders, rewrite [0, w] depth (Vulkan/D3D style) to [-w, w] depth (GL style).
|
|
|
|
// MSL: In vertex-like shaders, rewrite [-w, w] depth (GL style) to [0, w] depth.
|
|
|
|
// HLSL: In vertex-like shaders, rewrite [-w, w] depth (GL style) to [0, w] depth.
|
2017-08-03 11:02:59 +00:00
|
|
|
bool fixup_clipspace = false;
|
|
|
|
|
2020-09-28 12:09:39 +00:00
|
|
|
// In vertex-like shaders, inverts gl_Position.y or equivalent.
|
2017-08-03 11:02:59 +00:00
|
|
|
bool flip_vert_y = false;
|
2018-06-22 08:01:38 +00:00
|
|
|
|
2019-01-11 09:32:14 +00:00
|
|
|
// GLSL only, for HLSL version of this option, see CompilerHLSL.
|
2018-06-22 08:01:38 +00:00
|
|
|
// If true, the backend will assume that InstanceIndex will need to apply
|
|
|
|
// a base instance offset. Set to false if you know you will never use base instance
|
|
|
|
// functionality as it might remove some internal uniforms.
|
|
|
|
bool support_nonzero_base_instance = true;
|
2016-05-05 07:33:18 +00:00
|
|
|
} vertex;
|
|
|
|
|
2020-07-11 11:35:44 +00:00
|
|
|
struct FragmentOptions
|
2016-05-05 07:33:18 +00:00
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
2019-04-09 10:46:23 +00:00
|
|
|
void remap_pixel_local_storage(std::vector<PlsRemap> inputs, std::vector<PlsRemap> outputs)
|
2016-05-05 07:33:18 +00:00
|
|
|
{
|
|
|
|
pls_inputs = std::move(inputs);
|
|
|
|
pls_outputs = std::move(outputs);
|
|
|
|
remap_pls_variables();
|
|
|
|
}
|
|
|
|
|
2020-03-19 13:20:37 +00:00
|
|
|
// Redirect a subpassInput reading from input_attachment_index to instead load its value from
|
|
|
|
// the color attachment at location = color_location. Requires ESSL.
|
2021-05-21 12:21:13 +00:00
|
|
|
// If coherent, uses GL_EXT_shader_framebuffer_fetch, if not, uses noncoherent variant.
|
|
|
|
void remap_ext_framebuffer_fetch(uint32_t input_attachment_index, uint32_t color_location, bool coherent);
|
2020-03-19 13:20:37 +00:00
|
|
|
|
2019-04-09 10:46:23 +00:00
|
|
|
explicit CompilerGLSL(std::vector<uint32_t> spirv_)
|
2019-04-02 09:19:03 +00:00
|
|
|
: Compiler(std::move(spirv_))
|
2016-05-05 07:33:18 +00:00
|
|
|
{
|
2017-04-01 14:08:19 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2018-10-05 09:30:57 +00:00
|
|
|
CompilerGLSL(const uint32_t *ir_, size_t word_count)
|
|
|
|
: Compiler(ir_, word_count)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit CompilerGLSL(const ParsedIR &ir_)
|
|
|
|
: Compiler(ir_)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit CompilerGLSL(ParsedIR &&ir_)
|
|
|
|
: Compiler(std::move(ir_))
|
2017-04-01 14:08:19 +00:00
|
|
|
{
|
|
|
|
init();
|
2016-05-05 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 14:25:25 +00:00
|
|
|
const Options &get_common_options() const
|
|
|
|
{
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_common_options(const Options &opts)
|
|
|
|
{
|
|
|
|
options = opts;
|
|
|
|
}
|
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
std::string compile() override;
|
|
|
|
|
2016-11-27 17:34:04 +00: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 07:58:01 +00: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 05:02:15 +00:00
|
|
|
// Legacy GLSL compatibility method.
|
2017-01-21 09:27:14 +00: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 05:02:15 +00:00
|
|
|
// The name of the uniform array will be the same as the interface block name.
|
2019-09-05 10:43:40 +00:00
|
|
|
void flatten_buffer_block(VariableID id);
|
2016-12-07 05:02:15 +00:00
|
|
|
|
2020-04-03 10:26:42 +00:00
|
|
|
// After compilation, query if a variable ID was used as a depth resource.
|
|
|
|
// This is meaningful for MSL since descriptor types depend on this knowledge.
|
|
|
|
// Cases which return true:
|
|
|
|
// - Images which are declared with depth = 1 image type.
|
|
|
|
// - Samplers which are statically used at least once with Dref opcodes.
|
|
|
|
// - Images which are statically used at least once with Dref opcodes.
|
|
|
|
bool variable_is_depth_or_compare(VariableID id) const;
|
|
|
|
|
2021-03-25 17:08:49 +00:00
|
|
|
// If a shader output is active in this stage, but inactive in a subsequent stage,
|
|
|
|
// this can be signalled here. This can be used to work around certain cross-stage matching problems
|
|
|
|
// which plagues MSL and HLSL in certain scenarios.
|
|
|
|
// An output which matches one of these will not be emitted in stage output interfaces, but rather treated as a private
|
|
|
|
// variable.
|
|
|
|
// This option is only meaningful for MSL and HLSL, since GLSL matches by location directly.
|
|
|
|
// Masking builtins only takes effect if the builtin in question is part of the stage output interface.
|
|
|
|
void mask_stage_output_by_location(uint32_t location, uint32_t component);
|
|
|
|
void mask_stage_output_by_builtin(spv::BuiltIn builtin);
|
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
protected:
|
2020-10-08 10:14:52 +00:00
|
|
|
struct ShaderSubgroupSupportHelper
|
|
|
|
{
|
|
|
|
// lower enum value = greater priority
|
|
|
|
enum Candidate
|
|
|
|
{
|
|
|
|
KHR_shader_subgroup_ballot,
|
|
|
|
KHR_shader_subgroup_basic,
|
|
|
|
KHR_shader_subgroup_vote,
|
|
|
|
NV_gpu_shader_5,
|
|
|
|
NV_shader_thread_group,
|
|
|
|
NV_shader_thread_shuffle,
|
|
|
|
ARB_shader_ballot,
|
|
|
|
ARB_shader_group_vote,
|
|
|
|
AMD_gcn_shader,
|
|
|
|
|
|
|
|
CandidateCount
|
|
|
|
};
|
|
|
|
|
2020-10-08 10:41:01 +00:00
|
|
|
static const char *get_extension_name(Candidate c);
|
2020-10-08 10:14:52 +00:00
|
|
|
static SmallVector<std::string> get_extra_required_extension_names(Candidate c);
|
2020-10-08 10:41:01 +00:00
|
|
|
static const char *get_extra_required_extension_predicate(Candidate c);
|
2020-10-08 10:14:52 +00:00
|
|
|
|
|
|
|
enum Feature
|
|
|
|
{
|
2020-12-11 11:24:34 +00:00
|
|
|
SubgroupMask = 0,
|
|
|
|
SubgroupSize = 1,
|
|
|
|
SubgroupInvocationID = 2,
|
|
|
|
SubgroupID = 3,
|
|
|
|
NumSubgroups = 4,
|
|
|
|
SubgroupBroadcast_First = 5,
|
|
|
|
SubgroupBallotFindLSB_MSB = 6,
|
|
|
|
SubgroupAll_Any_AllEqualBool = 7,
|
|
|
|
SubgroupAllEqualT = 8,
|
|
|
|
SubgroupElect = 9,
|
|
|
|
SubgroupBarrier = 10,
|
|
|
|
SubgroupMemBarrier = 11,
|
|
|
|
SubgroupBallot = 12,
|
|
|
|
SubgroupInverseBallot_InclBitCount_ExclBitCout = 13,
|
|
|
|
SubgroupBallotBitExtract = 14,
|
|
|
|
SubgroupBallotBitCount = 15,
|
2020-10-08 10:14:52 +00:00
|
|
|
|
|
|
|
FeatureCount
|
|
|
|
};
|
|
|
|
|
|
|
|
using FeatureMask = uint32_t;
|
|
|
|
static_assert(sizeof(FeatureMask) * 8u >= FeatureCount, "Mask type needs more bits.");
|
|
|
|
|
2020-10-08 10:41:01 +00:00
|
|
|
using CandidateVector = SmallVector<Candidate, CandidateCount>;
|
|
|
|
using FeatureVector = SmallVector<Feature>;
|
2020-10-08 10:14:52 +00:00
|
|
|
|
2020-10-08 10:41:01 +00:00
|
|
|
static FeatureVector get_feature_dependencies(Feature feature);
|
2020-10-08 10:14:52 +00:00
|
|
|
static FeatureMask get_feature_dependency_mask(Feature feature);
|
2020-10-08 10:41:01 +00:00
|
|
|
static bool can_feature_be_implemented_without_extensions(Feature feature);
|
2020-10-08 10:14:52 +00:00
|
|
|
static Candidate get_KHR_extension_for_feature(Feature feature);
|
|
|
|
|
|
|
|
struct Result
|
|
|
|
{
|
|
|
|
Result();
|
2020-10-08 10:41:01 +00:00
|
|
|
uint32_t weights[CandidateCount];
|
2020-10-08 10:14:52 +00:00
|
|
|
};
|
|
|
|
|
2020-10-08 10:41:01 +00:00
|
|
|
void request_feature(Feature feature);
|
|
|
|
bool is_feature_requested(Feature feature) const;
|
2020-10-08 10:14:52 +00:00
|
|
|
Result resolve() const;
|
|
|
|
|
2020-10-08 10:41:01 +00:00
|
|
|
static CandidateVector get_candidates_for_feature(Feature ft, const Result &r);
|
2020-10-08 10:14:52 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-08 10:41:01 +00:00
|
|
|
static CandidateVector get_candidates_for_feature(Feature ft);
|
|
|
|
static FeatureMask build_mask(const SmallVector<Feature> &features);
|
|
|
|
FeatureMask feature_mask = 0;
|
2020-10-08 10:14:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// TODO remove this function when all subgroup ops are supported (or make it always return true)
|
2020-10-08 10:41:01 +00:00
|
|
|
static bool is_supported_subgroup_op_in_opengl(spv::Op op);
|
2020-10-08 10:14:52 +00:00
|
|
|
|
2022-01-17 13:12:01 +00:00
|
|
|
void reset(uint32_t iteration_count);
|
2018-03-12 12:09:25 +00:00
|
|
|
void emit_function(SPIRFunction &func, const Bitset &return_flags);
|
2016-05-05 07:33:18 +00:00
|
|
|
|
2017-11-22 18:27:03 +00:00
|
|
|
bool has_extension(const std::string &ext) const;
|
2018-04-05 12:42:52 +00:00
|
|
|
void require_extension_internal(const std::string &ext);
|
2017-11-22 18:27:03 +00:00
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
// Virtualize methods which need to be overridden by subclass targets like C++ and such.
|
2018-03-12 12:09:25 +00:00
|
|
|
virtual void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags);
|
2017-10-20 14:18:02 +00:00
|
|
|
|
2018-03-12 16:34:54 +00:00
|
|
|
SPIRBlock *current_emitting_block = nullptr;
|
2022-07-22 13:29:48 +00:00
|
|
|
SmallVector<SPIRBlock *> current_emitting_switch_stack;
|
2019-06-20 10:14:19 +00:00
|
|
|
bool current_emitting_switch_fallthrough = false;
|
2017-10-20 14:18:02 +00:00
|
|
|
|
2016-10-27 22:47:17 +00:00
|
|
|
virtual void emit_instruction(const Instruction &instr);
|
2022-04-29 11:49:02 +00:00
|
|
|
struct TemporaryCopy
|
|
|
|
{
|
|
|
|
uint32_t dst_id;
|
|
|
|
uint32_t src_id;
|
|
|
|
};
|
|
|
|
TemporaryCopy handle_instruction_precision(const Instruction &instr);
|
2018-03-12 16:34:54 +00:00
|
|
|
void emit_block_instructions(SPIRBlock &block);
|
2022-03-03 10:04:45 +00:00
|
|
|
|
|
|
|
// For relax_nan_checks.
|
|
|
|
GLSLstd450 get_remapped_glsl_op(GLSLstd450 std450_op) const;
|
|
|
|
spv::Op get_remapped_spirv_op(spv::Op op) const;
|
|
|
|
|
2016-11-12 09:04:50 +00: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 18:27:03 +00: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 13:04:57 +00: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 07:33:18 +00:00
|
|
|
virtual void emit_header();
|
2019-05-28 11:41:46 +00:00
|
|
|
void emit_line_directive(uint32_t file_id, uint32_t line_literal);
|
2019-04-02 09:19:03 +00:00
|
|
|
void build_workgroup_size(SmallVector<std::string> &arguments, const SpecializationConstant &x,
|
2018-11-01 10:23:33 +00:00
|
|
|
const SpecializationConstant &y, const SpecializationConstant &z);
|
2018-11-01 09:53:00 +00:00
|
|
|
|
2020-10-08 10:14:52 +00:00
|
|
|
void request_subgroup_feature(ShaderSubgroupSupportHelper::Feature feature);
|
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
virtual void emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id);
|
2020-06-04 13:50:28 +00:00
|
|
|
virtual void emit_texture_op(const Instruction &i, bool sparse);
|
|
|
|
virtual std::string to_texture_op(const Instruction &i, bool sparse, bool *forward,
|
MSL: Add support for sampler Y'CbCr conversion.
This change introduces functions and in one case, a class, to support
the `VK_KHR_sampler_ycbcr_conversion` extension. Except in the case of
GBGR8 and BGRG8 formats, for which Metal natively supports implicit
chroma reconstruction, we're on our own here. We have to do everything
ourselves. Much of the complexity comes from the need to support
multiple planes, which must now be passed to functions that use the
corresponding combined image-samplers. The rest is from the actual
Y'CbCr conversion itself, which requires additional post-processing of
the sample retrieved from the image.
Passing sampled images to a function was a particular problem. To
support this, I've added a new class which is emitted to MSL shaders
that pass sampled images with Y'CbCr conversions attached around. It
can handle sampled images with or without Y'CbCr conversion. This is an
awful abomination that should not exist, but I'm worried that there's
some shader out there which does this. This support requires Metal 2.0
to work properly, because it uses default-constructed texture objects,
which were only added in MSL 2. I'm not even going to get into arrays of
combined image-samplers--that's a whole other can of worms. They are
deliberately unsupported in this change.
I've taken the liberty of refactoring the support for texture swizzling
while I'm at it. It's now treated as a post-processing step similar to
Y'CbCr conversion. I'd like to think this is cleaner than having
everything in `to_function_name()`/`to_function_args()`. It still looks
really hairy, though. I did, however, get rid of the explicit type
arguments to `spvGatherSwizzle()`/`spvGatherCompareSwizzle()`.
Update the C API. In addition to supporting this new functionality, add
some compiler options that I added in previous changes, but for which I
neglected to update the C API.
2019-08-02 20:11:19 +00:00
|
|
|
SmallVector<uint32_t> &inherited_expressions);
|
2018-04-10 14:13:33 +00:00
|
|
|
virtual void emit_subgroup_op(const Instruction &i);
|
2017-05-30 00:45:05 +00:00
|
|
|
virtual std::string type_to_glsl(const SPIRType &type, uint32_t id = 0);
|
2017-07-24 08:07:02 +00:00
|
|
|
virtual std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage);
|
2017-03-11 17:17:22 +00:00
|
|
|
virtual void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index,
|
2017-11-27 15:00:56 +00:00
|
|
|
const std::string &qualifier = "", uint32_t base_offset = 0);
|
2019-07-22 08:23:39 +00:00
|
|
|
virtual void emit_struct_padding_target(const SPIRType &type);
|
2017-05-30 00:45:05 +00:00
|
|
|
virtual std::string image_type_glsl(const SPIRType &type, uint32_t id = 0);
|
2022-01-17 16:33:57 +00:00
|
|
|
std::string constant_expression(const SPIRConstant &c, bool inside_block_like_struct_scope = false);
|
2021-09-03 22:20:49 +00:00
|
|
|
virtual std::string constant_op_expression(const SPIRConstantOp &cop);
|
2016-05-05 07:33:18 +00:00
|
|
|
virtual std::string constant_expression_vector(const SPIRConstant &c, uint32_t vector);
|
|
|
|
virtual void emit_fixup();
|
2017-06-17 08:54:59 +00:00
|
|
|
virtual std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id = 0);
|
2021-04-06 13:50:02 +00:00
|
|
|
virtual bool variable_decl_is_remapped_storage(const SPIRVariable &var, spv::StorageClass storage) const;
|
MSL: Add support for sampler Y'CbCr conversion.
This change introduces functions and in one case, a class, to support
the `VK_KHR_sampler_ycbcr_conversion` extension. Except in the case of
GBGR8 and BGRG8 formats, for which Metal natively supports implicit
chroma reconstruction, we're on our own here. We have to do everything
ourselves. Much of the complexity comes from the need to support
multiple planes, which must now be passed to functions that use the
corresponding combined image-samplers. The rest is from the actual
Y'CbCr conversion itself, which requires additional post-processing of
the sample retrieved from the image.
Passing sampled images to a function was a particular problem. To
support this, I've added a new class which is emitted to MSL shaders
that pass sampled images with Y'CbCr conversions attached around. It
can handle sampled images with or without Y'CbCr conversion. This is an
awful abomination that should not exist, but I'm worried that there's
some shader out there which does this. This support requires Metal 2.0
to work properly, because it uses default-constructed texture objects,
which were only added in MSL 2. I'm not even going to get into arrays of
combined image-samplers--that's a whole other can of worms. They are
deliberately unsupported in this change.
I've taken the liberty of refactoring the support for texture swizzling
while I'm at it. It's now treated as a post-processing step similar to
Y'CbCr conversion. I'd like to think this is cleaner than having
everything in `to_function_name()`/`to_function_args()`. It still looks
really hairy, though. I did, however, get rid of the explicit type
arguments to `spvGatherSwizzle()`/`spvGatherCompareSwizzle()`.
Update the C API. In addition to supporting this new functionality, add
some compiler options that I added in previous changes, but for which I
neglected to update the C API.
2019-08-02 20:11:19 +00:00
|
|
|
virtual std::string to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id);
|
2020-06-05 13:49:17 +00:00
|
|
|
|
|
|
|
struct TextureFunctionBaseArguments
|
|
|
|
{
|
|
|
|
// GCC 4.8 workarounds, it doesn't understand '{}' constructor here, use explicit default constructor.
|
|
|
|
TextureFunctionBaseArguments() = default;
|
|
|
|
VariableID img = 0;
|
|
|
|
const SPIRType *imgtype = nullptr;
|
|
|
|
bool is_fetch = false, is_gather = false, is_proj = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextureFunctionNameArguments
|
|
|
|
{
|
|
|
|
// GCC 4.8 workarounds, it doesn't understand '{}' constructor here, use explicit default constructor.
|
|
|
|
TextureFunctionNameArguments() = default;
|
|
|
|
TextureFunctionBaseArguments base;
|
|
|
|
bool has_array_offsets = false, has_offset = false, has_grad = false;
|
|
|
|
bool has_dref = false, is_sparse_feedback = false, has_min_lod = false;
|
|
|
|
uint32_t lod = 0;
|
|
|
|
};
|
|
|
|
virtual std::string to_function_name(const TextureFunctionNameArguments &args);
|
|
|
|
|
|
|
|
struct TextureFunctionArguments
|
|
|
|
{
|
|
|
|
// GCC 4.8 workarounds, it doesn't understand '{}' constructor here, use explicit default constructor.
|
|
|
|
TextureFunctionArguments() = default;
|
|
|
|
TextureFunctionBaseArguments base;
|
|
|
|
uint32_t coord = 0, coord_components = 0, dref = 0;
|
2023-01-12 15:24:49 +00:00
|
|
|
uint32_t grad_x = 0, grad_y = 0, lod = 0, offset = 0;
|
2020-06-05 13:49:17 +00:00
|
|
|
uint32_t bias = 0, component = 0, sample = 0, sparse_texel = 0, min_lod = 0;
|
2020-12-07 12:00:15 +00:00
|
|
|
bool nonuniform_expression = false;
|
2020-06-05 13:49:17 +00:00
|
|
|
};
|
|
|
|
virtual std::string to_function_args(const TextureFunctionArguments &args, bool *p_forward);
|
|
|
|
|
2020-07-01 09:42:58 +00:00
|
|
|
void emit_sparse_feedback_temporaries(uint32_t result_type_id, uint32_t id, uint32_t &feedback_id,
|
|
|
|
uint32_t &texel_id);
|
2020-06-05 13:49:17 +00:00
|
|
|
uint32_t get_sparse_feedback_texel_id(uint32_t id) const;
|
2017-01-24 08:17:43 +00:00
|
|
|
virtual void emit_buffer_block(const SPIRVariable &type);
|
|
|
|
virtual void emit_push_constant_block(const SPIRVariable &var);
|
2017-01-24 08:23:22 +00:00
|
|
|
virtual void emit_uniform(const SPIRVariable &var);
|
2019-07-23 10:23:41 +00:00
|
|
|
virtual std::string unpack_expression_type(std::string expr_str, const SPIRType &type, uint32_t physical_type_id,
|
2019-07-19 11:03:08 +00:00
|
|
|
bool packed_type, bool row_major);
|
2016-05-05 07:33:18 +00:00
|
|
|
|
2019-10-22 15:06:16 +00:00
|
|
|
virtual bool builtin_translates_to_nonarray(spv::BuiltIn builtin) const;
|
|
|
|
|
2020-01-08 09:48:30 +00:00
|
|
|
void emit_copy_logical_type(uint32_t lhs_id, uint32_t lhs_type_id, uint32_t rhs_id, uint32_t rhs_type_id,
|
2020-01-06 11:29:44 +00:00
|
|
|
SmallVector<uint32_t> chain);
|
2020-01-06 10:47:26 +00:00
|
|
|
|
2019-04-02 09:19:03 +00:00
|
|
|
StringStream<> buffer;
|
2016-05-05 07:33:18 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void statement_inner(T &&t)
|
|
|
|
{
|
2019-04-02 09:19:03 +00:00
|
|
|
buffer << std::forward<T>(t);
|
2016-05-05 07:33:18 +00:00
|
|
|
statement_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename... Ts>
|
|
|
|
inline void statement_inner(T &&t, Ts &&... ts)
|
|
|
|
{
|
2019-04-02 09:19:03 +00:00
|
|
|
buffer << std::forward<T>(t);
|
2016-05-05 07:33:18 +00:00
|
|
|
statement_count++;
|
|
|
|
statement_inner(std::forward<Ts>(ts)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Ts>
|
|
|
|
inline void statement(Ts &&... ts)
|
|
|
|
{
|
2019-04-05 10:06:10 +00:00
|
|
|
if (is_forcing_recompilation())
|
2018-01-15 09:26:12 +00:00
|
|
|
{
|
|
|
|
// Do not bother emitting code while force_recompile is active.
|
|
|
|
// We will compile again.
|
|
|
|
statement_count++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
if (redirect_statement)
|
2019-04-05 10:06:10 +00:00
|
|
|
{
|
2016-05-05 07:33:18 +00:00
|
|
|
redirect_statement->push_back(join(std::forward<Ts>(ts)...));
|
2019-04-05 10:06:10 +00:00
|
|
|
statement_count++;
|
|
|
|
}
|
2016-05-05 07:33:18 +00:00
|
|
|
else
|
|
|
|
{
|
2018-06-19 15:14:31 +00:00
|
|
|
for (uint32_t i = 0; i < indent; i++)
|
2019-04-02 09:19:03 +00:00
|
|
|
buffer << " ";
|
2016-05-05 07:33:18 +00:00
|
|
|
statement_inner(std::forward<Ts>(ts)...);
|
2019-04-02 09:19:03 +00:00
|
|
|
buffer << '\n';
|
2016-05-05 07:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2019-04-02 09:19:03 +00:00
|
|
|
SmallVector<std::string> *redirect_statement = nullptr;
|
2016-05-05 07:33:18 +00:00
|
|
|
const SPIRBlock *current_continue_block = nullptr;
|
2022-04-29 11:49:02 +00:00
|
|
|
bool block_temporary_hoisting = false;
|
2016-05-05 07:33:18 +00:00
|
|
|
|
|
|
|
void begin_scope();
|
|
|
|
void end_scope();
|
MSL: Support dynamic offsets for buffers in argument buffers.
Vulkan has two types of buffer descriptors,
`VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC` and
`VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC`, which allow the client to
offset the buffers by an amount given when the descriptor set is bound
to a pipeline. Metal provides no direct support for this when the buffer
in question is in an argument buffer, so once again we're on our own.
These offsets cannot be stored or associated in any way with the
argument buffer itself, because they are set at bind time. Different
pipelines may have different offsets set. Therefore, we must use a
separate buffer, not in any argument buffer, to hold these offsets. Then
the shader must manually offset the buffer pointer.
This change fully supports arrays, including arrays of arrays, even
though Vulkan forbids them. It does not, however, support runtime
arrays. Perhaps later.
2019-09-06 04:14:12 +00:00
|
|
|
void end_scope(const std::string &trailer);
|
2016-05-05 07:33:18 +00:00
|
|
|
void end_scope_decl();
|
|
|
|
void end_scope_decl(const std::string &decl);
|
|
|
|
|
|
|
|
Options options;
|
|
|
|
|
2019-09-23 22:05:04 +00:00
|
|
|
virtual std::string type_to_array_glsl(
|
|
|
|
const SPIRType &type); // Allow Metal to use the array<T> template to make arrays a value type
|
2016-10-03 15:17:11 +00: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;
|
2018-11-01 13:56:25 +00:00
|
|
|
uint32_t to_array_size_literal(const SPIRType &type) const;
|
2019-09-18 18:03:54 +00:00
|
|
|
virtual std::string variable_decl(const SPIRVariable &variable); // Threadgroup arrays can't have a wrapper type
|
2017-02-24 10:15:34 +00:00
|
|
|
std::string variable_decl_function_local(SPIRVariable &variable);
|
2016-05-05 07:33:18 +00:00
|
|
|
|
2016-05-23 10:25:09 +00: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);
|
2018-02-23 13:13:46 +00:00
|
|
|
void add_function_overload(const SPIRFunction &func);
|
2016-12-11 16:01:08 +00:00
|
|
|
|
2018-01-04 21:33:45 +00: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);
|
2019-07-23 10:23:41 +00:00
|
|
|
bool member_is_remapped_physical_type(const SPIRType &type, uint32_t index) const;
|
|
|
|
bool member_is_packed_physical_type(const SPIRType &type, uint32_t index) const;
|
|
|
|
virtual std::string convert_row_major_matrix(std::string exp_str, const SPIRType &exp_type,
|
2023-01-26 19:21:27 +00:00
|
|
|
uint32_t physical_type_id, bool is_packed,
|
|
|
|
bool relaxed = false);
|
2016-12-11 16:01:08 +00:00
|
|
|
|
2016-05-23 10:25:09 +00:00
|
|
|
std::unordered_set<std::string> local_variable_names;
|
|
|
|
std::unordered_set<std::string> resource_names;
|
2018-08-21 09:29:08 +00:00
|
|
|
std::unordered_set<std::string> block_input_names;
|
|
|
|
std::unordered_set<std::string> block_output_names;
|
|
|
|
std::unordered_set<std::string> block_ubo_names;
|
|
|
|
std::unordered_set<std::string> block_ssbo_names;
|
2019-01-04 11:15:43 +00:00
|
|
|
std::unordered_set<std::string> block_names; // A union of all block_*_names.
|
2018-02-23 13:13:46 +00:00
|
|
|
std::unordered_map<std::string, std::unordered_set<uint64_t>> function_overloads;
|
2019-02-13 15:39:59 +00:00
|
|
|
std::unordered_map<uint32_t, std::string> preserved_aliases;
|
|
|
|
void preserve_alias_on_reset(uint32_t id);
|
|
|
|
void reset_name_caches();
|
2016-05-05 07:33:18 +00: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 14:20:01 +00:00
|
|
|
std::string discard_literal = "discard";
|
2019-07-13 20:57:33 +00:00
|
|
|
std::string demote_literal = "demote";
|
MSL: Support SPV_KHR_variable_pointers.
This allows shaders to declare and use pointer-type variables. Pointers
may be loaded and stored, be the result of an `OpSelect`, be passed to
and returned from functions, and even be passed as inputs to the `OpPhi`
instruction. All types of pointers may be used as variable pointers.
Variable pointers to storage buffers and workgroup memory may even be
loaded from and stored to, as though they were ordinary variables. In
addition, this enables using an interior pointer to an array as though
it were an array pointer itself using the `OpPtrAccessChain`
instruction.
This is a rather large and involved change, mostly because this is
somewhat complicated with a lot of moving parts. It's a wonder
SPIRV-Cross's output is largely unchanged. Indeed, many of these changes
are to accomplish exactly that! Perhaps the largest source of changes
was the violation of the assumption that, when emitting types, the
pointer type didn't matter.
One of the test cases added by the change doesn't optimize very well;
the output of `spirv-opt` here is invalid SPIR-V. I need to file a bug
with SPIRV-Tools about this.
I wanted to test that variable pointers to images worked too, but I
couldn't figure out how to propagate the access qualifier properly--in
MSL, it's part of the type, so getting this right is important. I've
punted on that for now.
2018-12-03 08:06:33 +00:00
|
|
|
std::string null_pointer_literal = "";
|
2016-05-05 07:33:18 +00:00
|
|
|
bool float_literal_suffix = false;
|
2016-07-27 08:59:00 +00:00
|
|
|
bool double_literal_suffix = true;
|
2016-05-05 07:33:18 +00:00
|
|
|
bool uint32_t_literal_suffix = true;
|
2016-07-27 09:27:00 +00:00
|
|
|
bool long_long_literal_suffix = false;
|
2016-05-05 07:33:18 +00:00
|
|
|
const char *basic_int_type = "int";
|
|
|
|
const char *basic_uint_type = "uint";
|
2018-10-31 14:43:03 +00:00
|
|
|
const char *basic_int8_type = "int8_t";
|
|
|
|
const char *basic_uint8_type = "uint8_t";
|
|
|
|
const char *basic_int16_type = "int16_t";
|
|
|
|
const char *basic_uint16_type = "uint16_t";
|
2018-11-02 19:39:55 +00:00
|
|
|
const char *int16_t_literal_suffix = "s";
|
|
|
|
const char *uint16_t_literal_suffix = "us";
|
2019-05-02 08:54:34 +00:00
|
|
|
const char *nonuniform_qualifier = "nonuniformEXT";
|
2019-07-11 04:46:40 +00:00
|
|
|
const char *boolean_mix_function = "mix";
|
2016-05-05 07:33:18 +00:00
|
|
|
bool swizzle_is_function = false;
|
|
|
|
bool shared_is_implied = false;
|
2019-05-13 12:58:27 +00:00
|
|
|
bool unsized_array_supported = true;
|
2016-05-23 10:25:09 +00:00
|
|
|
bool explicit_struct_type = false;
|
2016-05-28 11:09:26 +00:00
|
|
|
bool use_initializer_list = false;
|
2018-01-23 15:36:20 +00:00
|
|
|
bool use_typed_initializer_list = false;
|
|
|
|
bool can_declare_struct_inline = true;
|
2018-02-02 09:10:17 +00:00
|
|
|
bool can_declare_arrays_inline = true;
|
2016-12-14 07:12:52 +00:00
|
|
|
bool native_row_major_matrix = true;
|
2016-09-23 16:57:18 +00:00
|
|
|
bool use_constructor_splatting = true;
|
2017-12-06 09:25:30 +00:00
|
|
|
bool allow_precision_qualifiers = false;
|
2017-12-12 10:03:46 +00:00
|
|
|
bool can_swizzle_scalar = false;
|
2018-01-09 08:16:33 +00:00
|
|
|
bool force_gl_in_out_block = false;
|
2022-10-10 22:16:45 +00:00
|
|
|
bool force_merged_mesh_block = false;
|
2018-02-05 11:37:41 +00:00
|
|
|
bool can_return_array = true;
|
2018-02-13 19:44:40 +00:00
|
|
|
bool allow_truncated_access_chain = false;
|
2018-02-23 12:06:20 +00:00
|
|
|
bool supports_extensions = false;
|
2018-04-05 14:26:54 +00:00
|
|
|
bool supports_empty_struct = false;
|
2018-09-12 08:25:51 +00:00
|
|
|
bool array_is_value_type = true;
|
2022-01-17 16:33:57 +00:00
|
|
|
bool array_is_value_type_in_buffer_blocks = true;
|
2019-02-22 11:02:11 +00:00
|
|
|
bool comparison_image_samples_scalar = false;
|
2019-04-24 12:12:50 +00:00
|
|
|
bool native_pointers = false;
|
2019-06-27 13:04:22 +00:00
|
|
|
bool support_small_type_sampling_result = false;
|
2019-06-27 13:10:17 +00:00
|
|
|
bool support_case_fallthrough = true;
|
2019-10-26 15:57:34 +00:00
|
|
|
bool use_array_constructor = false;
|
2020-10-14 13:51:49 +00:00
|
|
|
bool needs_row_major_load_workaround = false;
|
2021-02-26 11:50:24 +00:00
|
|
|
bool support_pointer_to_pointer = false;
|
2021-05-07 10:28:08 +00:00
|
|
|
bool support_precise_qualifier = false;
|
2021-11-18 19:08:59 +00:00
|
|
|
bool support_64bit_switch = false;
|
2022-01-05 14:53:51 +00:00
|
|
|
bool workgroup_size_is_hidden = false;
|
2022-04-29 11:49:02 +00:00
|
|
|
bool requires_relaxed_precision_analysis = false;
|
2022-10-31 12:05:56 +00:00
|
|
|
bool implicit_c_integer_promotion_rules = false;
|
2016-05-05 07:33:18 +00:00
|
|
|
} backend;
|
|
|
|
|
2016-05-23 10:25:09 +00:00
|
|
|
void emit_struct(SPIRType &type);
|
2016-05-05 07:33:18 +00:00
|
|
|
void emit_resources();
|
2020-10-08 10:14:52 +00:00
|
|
|
void emit_extension_workarounds(spv::ExecutionModel model);
|
2023-01-26 19:21:27 +00:00
|
|
|
void emit_polyfills(uint32_t polyfills, bool relaxed);
|
2017-01-17 20:18:35 +00:00
|
|
|
void emit_buffer_block_native(const SPIRVariable &var);
|
2021-11-07 14:43:57 +00:00
|
|
|
void emit_buffer_reference_block(uint32_t type_id, bool forward_declaration);
|
2017-01-13 15:31:13 +00:00
|
|
|
void emit_buffer_block_legacy(const SPIRVariable &var);
|
2017-01-17 20:18:35 +00:00
|
|
|
void emit_buffer_block_flattened(const SPIRVariable &type);
|
2022-09-02 14:31:04 +00:00
|
|
|
void fixup_implicit_builtin_block_names(spv::ExecutionModel model);
|
2017-05-22 13:30:43 +00:00
|
|
|
void emit_declared_builtin_block(spv::StorageClass storage, spv::ExecutionModel model);
|
2020-01-27 11:56:48 +00:00
|
|
|
bool should_force_emit_builtin_block(spv::StorageClass storage);
|
2016-05-05 08:16:22 +00:00
|
|
|
void emit_push_constant_block_vulkan(const SPIRVariable &var);
|
|
|
|
void emit_push_constant_block_glsl(const SPIRVariable &var);
|
2016-05-05 07:33:18 +00:00
|
|
|
void emit_interface_block(const SPIRVariable &type);
|
2017-03-06 13:01:51 +00:00
|
|
|
void emit_flattened_io_block(const SPIRVariable &var, const char *qual);
|
2020-07-03 11:12:05 +00:00
|
|
|
void emit_flattened_io_block_struct(const std::string &basename, const SPIRType &type, const char *qual,
|
|
|
|
const SmallVector<uint32_t> &indices);
|
|
|
|
void emit_flattened_io_block_member(const std::string &basename, const SPIRType &type, const char *qual,
|
|
|
|
const SmallVector<uint32_t> &indices);
|
2016-05-05 07:33:18 +00:00
|
|
|
void emit_block_chain(SPIRBlock &block);
|
2019-09-05 10:43:40 +00:00
|
|
|
void emit_hoisted_temporaries(SmallVector<std::pair<TypeID, ID>> &temporaries);
|
2018-10-30 06:31:32 +00:00
|
|
|
std::string constant_value_macro_name(uint32_t id);
|
2022-01-05 14:53:51 +00:00
|
|
|
int get_constant_mapping_to_workgroup_component(const SPIRConstant &constant) const;
|
2018-07-05 11:25:57 +00:00
|
|
|
void emit_constant(const SPIRConstant &constant);
|
2018-05-15 12:20:16 +00:00
|
|
|
void emit_specialization_constant_op(const SPIRConstantOp &constant);
|
2019-03-06 11:17:38 +00:00
|
|
|
std::string emit_continue_block(uint32_t continue_block, bool follow_true_block, bool follow_false_block);
|
2016-05-05 07:33:18 +00:00
|
|
|
bool attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method method);
|
|
|
|
|
2019-09-05 10:43:40 +00:00
|
|
|
void branch(BlockID from, BlockID to);
|
|
|
|
void branch_to_continue(BlockID from, BlockID to);
|
|
|
|
void branch(BlockID from, uint32_t cond, BlockID true_block, BlockID false_block);
|
|
|
|
void flush_phi(BlockID from, BlockID to);
|
2016-05-05 07:33:18 +00:00
|
|
|
void flush_variable_declaration(uint32_t id);
|
2016-11-11 17:04:14 +00:00
|
|
|
void flush_undeclared_variables(SPIRBlock &block);
|
2019-06-25 08:45:15 +00:00
|
|
|
void emit_variable_temporary_copies(const SPIRVariable &var);
|
2016-05-05 07:33:18 +00:00
|
|
|
|
MSL: Support SPV_KHR_variable_pointers.
This allows shaders to declare and use pointer-type variables. Pointers
may be loaded and stored, be the result of an `OpSelect`, be passed to
and returned from functions, and even be passed as inputs to the `OpPhi`
instruction. All types of pointers may be used as variable pointers.
Variable pointers to storage buffers and workgroup memory may even be
loaded from and stored to, as though they were ordinary variables. In
addition, this enables using an interior pointer to an array as though
it were an array pointer itself using the `OpPtrAccessChain`
instruction.
This is a rather large and involved change, mostly because this is
somewhat complicated with a lot of moving parts. It's a wonder
SPIRV-Cross's output is largely unchanged. Indeed, many of these changes
are to accomplish exactly that! Perhaps the largest source of changes
was the violation of the assumption that, when emitting types, the
pointer type didn't matter.
One of the test cases added by the change doesn't optimize very well;
the output of `spirv-opt` here is invalid SPIR-V. I need to file a bug
with SPIRV-Tools about this.
I wanted to test that variable pointers to images worked too, but I
couldn't figure out how to propagate the access qualifier properly--in
MSL, it's part of the type, so getting this right is important. I've
punted on that for now.
2018-12-03 08:06:33 +00:00
|
|
|
bool should_dereference(uint32_t id);
|
2019-07-23 17:14:13 +00:00
|
|
|
bool should_forward(uint32_t id) const;
|
|
|
|
bool should_suppress_usage_tracking(uint32_t id) const;
|
2016-05-05 07:33:18 +00:00
|
|
|
void emit_mix_op(uint32_t result_type, uint32_t id, uint32_t left, uint32_t right, uint32_t lerp);
|
2019-03-21 14:26:46 +00:00
|
|
|
void emit_nminmax_op(uint32_t result_type, uint32_t id, uint32_t op0, uint32_t op1, GLSLstd450 op);
|
2023-01-19 16:00:20 +00:00
|
|
|
void emit_emulated_ahyper_op(uint32_t result_type, uint32_t result_id, uint32_t op0, GLSLstd450 op);
|
2016-10-03 13:54:02 +00:00
|
|
|
bool to_trivial_mix_op(const SPIRType &type, std::string &op, uint32_t left, uint32_t right, uint32_t lerp);
|
2016-05-05 07:33:18 +00: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);
|
2021-04-22 11:54:43 +00:00
|
|
|
void emit_atomic_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
|
|
|
void emit_atomic_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2, const char *op);
|
2019-03-27 10:53:47 +00:00
|
|
|
|
|
|
|
void emit_unary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op,
|
|
|
|
SPIRType::BaseType input_type, SPIRType::BaseType expected_result_type);
|
2016-05-10 21:39:41 +00: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);
|
2020-01-09 11:01:54 +00:00
|
|
|
void emit_binary_func_op_cast_clustered(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
|
|
|
|
const char *op, SPIRType::BaseType input_type);
|
2019-04-02 09:19:03 +00:00
|
|
|
void emit_trinary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
|
|
|
const char *op, SPIRType::BaseType input_type);
|
2019-08-28 12:25:26 +00:00
|
|
|
void emit_trinary_func_op_bitextract(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
|
|
|
|
uint32_t op2, const char *op, SPIRType::BaseType expected_result_type,
|
|
|
|
SPIRType::BaseType input_type0, SPIRType::BaseType input_type1,
|
2019-08-26 09:01:14 +00:00
|
|
|
SPIRType::BaseType input_type2);
|
2019-08-28 12:25:26 +00:00
|
|
|
void emit_bitfield_insert_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
|
|
|
uint32_t op3, const char *op, SPIRType::BaseType offset_count_type);
|
2019-03-27 10:53:47 +00:00
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
void emit_unary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op);
|
2017-03-24 14:00:48 +00:00
|
|
|
void emit_unrolled_unary_op(uint32_t result_type, uint32_t result_id, uint32_t operand, const char *op);
|
2016-05-05 07:33:18 +00:00
|
|
|
void emit_binary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
2019-10-14 14:08:39 +00:00
|
|
|
void emit_unrolled_binary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op,
|
|
|
|
bool negate, SPIRType::BaseType expected_type);
|
2016-05-10 21:39:41 +00:00
|
|
|
void emit_binary_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op,
|
2022-10-31 12:05:56 +00:00
|
|
|
SPIRType::BaseType input_type, bool skip_cast_if_equal_type, bool implicit_integer_promotion);
|
2016-05-10 21:39:41 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-04-21 21:27:33 +00:00
|
|
|
virtual bool emit_complex_bitcast(uint32_t result_type, uint32_t id, uint32_t op0);
|
|
|
|
|
2018-06-25 07:48:17 +00:00
|
|
|
std::string to_ternary_expression(const SPIRType &result_type, uint32_t select, uint32_t true_value,
|
|
|
|
uint32_t false_value);
|
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
void emit_unary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op);
|
2022-10-31 12:05:56 +00:00
|
|
|
void emit_unary_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op);
|
2019-07-23 17:14:13 +00:00
|
|
|
bool expression_is_forwarded(uint32_t id) const;
|
|
|
|
bool expression_suppresses_usage_tracking(uint32_t id) const;
|
2020-06-29 10:20:35 +00:00
|
|
|
bool expression_read_implies_multiple_reads(uint32_t id) const;
|
2016-05-05 07:33:18 +00:00
|
|
|
SPIRExpression &emit_op(uint32_t result_type, uint32_t result_id, const std::string &rhs, bool forward_rhs,
|
2016-12-05 09:22:54 +00:00
|
|
|
bool suppress_usage_tracking = false);
|
2019-01-17 09:30:13 +00:00
|
|
|
|
2019-10-25 14:41:02 +00:00
|
|
|
void access_chain_internal_append_index(std::string &expr, uint32_t base, const SPIRType *type,
|
2019-10-28 11:55:14 +00:00
|
|
|
AccessChainFlags flags, bool &access_chain_is_arrayed, uint32_t index);
|
2019-10-22 15:06:16 +00:00
|
|
|
|
|
|
|
std::string access_chain_internal(uint32_t base, const uint32_t *indices, uint32_t count, AccessChainFlags flags,
|
|
|
|
AccessChainMeta *meta);
|
2019-01-17 09:30:13 +00:00
|
|
|
|
2021-04-19 09:46:30 +00:00
|
|
|
spv::StorageClass get_expression_effective_storage_class(uint32_t ptr);
|
2021-04-14 13:10:02 +00:00
|
|
|
virtual bool access_chain_needs_stage_io_builtin_translation(uint32_t base);
|
|
|
|
|
2022-07-01 20:10:41 +00:00
|
|
|
virtual void check_physical_type_cast(std::string &expr, const SPIRType *type, uint32_t physical_type);
|
2020-07-01 11:02:11 +00:00
|
|
|
virtual void prepare_access_chain_for_scalar_access(std::string &expr, const SPIRType &type,
|
|
|
|
spv::StorageClass storage, bool &is_packed);
|
|
|
|
|
2017-01-20 16:33:59 +00:00
|
|
|
std::string access_chain(uint32_t base, const uint32_t *indices, uint32_t count, const SPIRType &target_type,
|
MSL: Support SPV_KHR_variable_pointers.
This allows shaders to declare and use pointer-type variables. Pointers
may be loaded and stored, be the result of an `OpSelect`, be passed to
and returned from functions, and even be passed as inputs to the `OpPhi`
instruction. All types of pointers may be used as variable pointers.
Variable pointers to storage buffers and workgroup memory may even be
loaded from and stored to, as though they were ordinary variables. In
addition, this enables using an interior pointer to an array as though
it were an array pointer itself using the `OpPtrAccessChain`
instruction.
This is a rather large and involved change, mostly because this is
somewhat complicated with a lot of moving parts. It's a wonder
SPIRV-Cross's output is largely unchanged. Indeed, many of these changes
are to accomplish exactly that! Perhaps the largest source of changes
was the violation of the assumption that, when emitting types, the
pointer type didn't matter.
One of the test cases added by the change doesn't optimize very well;
the output of `spirv-opt` here is invalid SPIR-V. I need to file a bug
with SPIRV-Tools about this.
I wanted to test that variable pointers to images worked too, but I
couldn't figure out how to propagate the access qualifier properly--in
MSL, it's part of the type, so getting this right is important. I've
punted on that for now.
2018-12-03 08:06:33 +00:00
|
|
|
AccessChainMeta *meta = nullptr, bool ptr_chain = false);
|
2017-01-20 16:33:59 +00:00
|
|
|
|
|
|
|
std::string flattened_access_chain(uint32_t base, const uint32_t *indices, uint32_t count,
|
2017-01-24 15:42:19 +00:00
|
|
|
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
2020-01-08 12:05:56 +00:00
|
|
|
uint32_t array_stride, bool need_transpose);
|
2017-01-20 16:33:59 +00: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 08:21:22 +00:00
|
|
|
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
|
|
|
bool need_transpose);
|
2017-01-24 15:42:19 +00: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 13:36:30 +00:00
|
|
|
std::pair<std::string, uint32_t> flattened_access_chain_offset(const SPIRType &basetype, const uint32_t *indices,
|
2017-01-20 16:33:59 +00:00
|
|
|
uint32_t count, uint32_t offset,
|
2017-08-28 07:01:03 +00:00
|
|
|
uint32_t word_stride, bool *need_transpose = nullptr,
|
MSL: Support SPV_KHR_variable_pointers.
This allows shaders to declare and use pointer-type variables. Pointers
may be loaded and stored, be the result of an `OpSelect`, be passed to
and returned from functions, and even be passed as inputs to the `OpPhi`
instruction. All types of pointers may be used as variable pointers.
Variable pointers to storage buffers and workgroup memory may even be
loaded from and stored to, as though they were ordinary variables. In
addition, this enables using an interior pointer to an array as though
it were an array pointer itself using the `OpPtrAccessChain`
instruction.
This is a rather large and involved change, mostly because this is
somewhat complicated with a lot of moving parts. It's a wonder
SPIRV-Cross's output is largely unchanged. Indeed, many of these changes
are to accomplish exactly that! Perhaps the largest source of changes
was the violation of the assumption that, when emitting types, the
pointer type didn't matter.
One of the test cases added by the change doesn't optimize very well;
the output of `spirv-opt` here is invalid SPIR-V. I need to file a bug
with SPIRV-Tools about this.
I wanted to test that variable pointers to images worked too, but I
couldn't figure out how to propagate the access qualifier properly--in
MSL, it's part of the type, so getting this right is important. I've
punted on that for now.
2018-12-03 08:06:33 +00:00
|
|
|
uint32_t *matrix_stride = nullptr,
|
2020-01-08 12:05:56 +00:00
|
|
|
uint32_t *array_stride = nullptr,
|
MSL: Support SPV_KHR_variable_pointers.
This allows shaders to declare and use pointer-type variables. Pointers
may be loaded and stored, be the result of an `OpSelect`, be passed to
and returned from functions, and even be passed as inputs to the `OpPhi`
instruction. All types of pointers may be used as variable pointers.
Variable pointers to storage buffers and workgroup memory may even be
loaded from and stored to, as though they were ordinary variables. In
addition, this enables using an interior pointer to an array as though
it were an array pointer itself using the `OpPtrAccessChain`
instruction.
This is a rather large and involved change, mostly because this is
somewhat complicated with a lot of moving parts. It's a wonder
SPIRV-Cross's output is largely unchanged. Indeed, many of these changes
are to accomplish exactly that! Perhaps the largest source of changes
was the violation of the assumption that, when emitting types, the
pointer type didn't matter.
One of the test cases added by the change doesn't optimize very well;
the output of `spirv-opt` here is invalid SPIR-V. I need to file a bug
with SPIRV-Tools about this.
I wanted to test that variable pointers to images worked too, but I
couldn't figure out how to propagate the access qualifier properly--in
MSL, it's part of the type, so getting this right is important. I've
punted on that for now.
2018-12-03 08:06:33 +00:00
|
|
|
bool ptr_chain = false);
|
2016-05-05 07:33:18 +00:00
|
|
|
|
|
|
|
const char *index_to_swizzle(uint32_t index);
|
2017-10-24 07:23:29 +00:00
|
|
|
std::string remap_swizzle(const SPIRType &result_type, uint32_t input_components, const std::string &expr);
|
2016-05-05 07:33:18 +00:00
|
|
|
std::string declare_temporary(uint32_t type, uint32_t id);
|
2019-04-09 09:50:45 +00:00
|
|
|
void emit_uninitialized_temporary(uint32_t type, uint32_t id);
|
|
|
|
SPIRExpression &emit_uninitialized_temporary_expression(uint32_t type, uint32_t id);
|
2019-04-02 09:19:03 +00:00
|
|
|
void append_global_func_args(const SPIRFunction &func, uint32_t index, SmallVector<std::string> &arglist);
|
2021-04-22 11:54:43 +00:00
|
|
|
std::string to_non_uniform_aware_expression(uint32_t id);
|
2019-01-04 12:19:50 +00:00
|
|
|
std::string to_expression(uint32_t id, bool register_expression_read = true);
|
2022-01-17 16:33:57 +00:00
|
|
|
std::string to_composite_constructor_expression(uint32_t id, bool block_like_type);
|
2019-07-10 09:19:33 +00:00
|
|
|
std::string to_rerolled_array_expression(const std::string &expr, const SPIRType &type);
|
2019-01-04 12:19:50 +00:00
|
|
|
std::string to_enclosed_expression(uint32_t id, bool register_expression_read = true);
|
2019-01-17 09:06:23 +00:00
|
|
|
std::string to_unpacked_expression(uint32_t id, bool register_expression_read = true);
|
2019-07-23 09:36:54 +00:00
|
|
|
std::string to_unpacked_row_major_matrix_expression(uint32_t id);
|
2019-01-17 09:06:23 +00:00
|
|
|
std::string to_enclosed_unpacked_expression(uint32_t id, bool register_expression_read = true);
|
2019-09-23 22:05:04 +00:00
|
|
|
std::string to_dereferenced_expression(uint32_t id, bool register_expression_read = true);
|
2019-01-17 09:06:23 +00:00
|
|
|
std::string to_pointer_expression(uint32_t id, bool register_expression_read = true);
|
|
|
|
std::string to_enclosed_pointer_expression(uint32_t id, bool register_expression_read = true);
|
2018-05-25 08:56:27 +00:00
|
|
|
std::string to_extract_component_expression(uint32_t id, uint32_t index);
|
2021-01-22 11:17:05 +00:00
|
|
|
std::string to_extract_constant_composite_expression(uint32_t result_type, const SPIRConstant &c,
|
|
|
|
const uint32_t *chain, uint32_t length);
|
2017-05-22 14:52:25 +00:00
|
|
|
std::string enclose_expression(const std::string &expr);
|
2019-04-24 12:12:50 +00:00
|
|
|
std::string dereference_expression(const SPIRType &expression_type, const std::string &expr);
|
MSL: Support SPV_KHR_variable_pointers.
This allows shaders to declare and use pointer-type variables. Pointers
may be loaded and stored, be the result of an `OpSelect`, be passed to
and returned from functions, and even be passed as inputs to the `OpPhi`
instruction. All types of pointers may be used as variable pointers.
Variable pointers to storage buffers and workgroup memory may even be
loaded from and stored to, as though they were ordinary variables. In
addition, this enables using an interior pointer to an array as though
it were an array pointer itself using the `OpPtrAccessChain`
instruction.
This is a rather large and involved change, mostly because this is
somewhat complicated with a lot of moving parts. It's a wonder
SPIRV-Cross's output is largely unchanged. Indeed, many of these changes
are to accomplish exactly that! Perhaps the largest source of changes
was the violation of the assumption that, when emitting types, the
pointer type didn't matter.
One of the test cases added by the change doesn't optimize very well;
the output of `spirv-opt` here is invalid SPIR-V. I need to file a bug
with SPIRV-Tools about this.
I wanted to test that variable pointers to images worked too, but I
couldn't figure out how to propagate the access qualifier properly--in
MSL, it's part of the type, so getting this right is important. I've
punted on that for now.
2018-12-03 08:06:33 +00:00
|
|
|
std::string address_of_expression(const std::string &expr);
|
2016-12-06 22:03:35 +00:00
|
|
|
void strip_enclosed_expression(std::string &expr);
|
2016-05-05 07:33:18 +00:00
|
|
|
std::string to_member_name(const SPIRType &type, uint32_t index);
|
2022-11-21 12:40:27 +00:00
|
|
|
virtual std::string to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain_is_resolved);
|
2020-07-03 11:12:05 +00:00
|
|
|
std::string to_multi_member_reference(const SPIRType &type, const SmallVector<uint32_t> &indices);
|
2016-05-05 07:33:18 +00:00
|
|
|
std::string type_to_glsl_constructor(const SPIRType &type);
|
|
|
|
std::string argument_decl(const SPIRFunction::Parameter &arg);
|
2017-11-06 02:34:42 +00:00
|
|
|
virtual std::string to_qualifiers_glsl(uint32_t id);
|
2022-09-02 14:31:04 +00:00
|
|
|
void fixup_io_block_patch_primitive_qualifiers(const SPIRVariable &var);
|
2021-01-05 11:50:36 +00:00
|
|
|
void emit_output_variable_initializer(const SPIRVariable &var);
|
2021-05-07 10:28:08 +00:00
|
|
|
std::string to_precision_qualifiers_glsl(uint32_t id);
|
2017-02-24 10:15:34 +00:00
|
|
|
virtual const char *to_storage_qualifiers_glsl(const SPIRVariable &var);
|
2021-05-07 10:28:08 +00:00
|
|
|
std::string flags_to_qualifiers_glsl(const SPIRType &type, const Bitset &flags);
|
2018-06-19 15:14:31 +00:00
|
|
|
const char *format_to_glsl(spv::ImageFormat format);
|
2017-03-07 15:18:43 +00:00
|
|
|
virtual std::string layout_for_member(const SPIRType &type, uint32_t index);
|
2018-03-12 12:09:25 +00:00
|
|
|
virtual std::string to_interpolation_qualifiers(const Bitset &flags);
|
2016-05-05 07:33:18 +00:00
|
|
|
std::string layout_for_variable(const SPIRVariable &variable);
|
2019-09-05 10:43:40 +00:00
|
|
|
std::string to_combined_image_sampler(VariableID image_id, VariableID samp_id);
|
2017-05-07 10:36:14 +00:00
|
|
|
virtual bool skip_argument(uint32_t id) const;
|
2021-04-19 09:46:30 +00:00
|
|
|
virtual void emit_array_copy(const std::string &lhs, uint32_t lhs_id, uint32_t rhs_id,
|
|
|
|
spv::StorageClass lhs_storage, spv::StorageClass rhs_storage);
|
2018-06-25 08:33:13 +00:00
|
|
|
virtual void emit_block_hints(const SPIRBlock &block);
|
2018-07-05 13:29:49 +00:00
|
|
|
virtual std::string to_initializer_expression(const SPIRVariable &var);
|
2020-03-26 10:21:23 +00:00
|
|
|
virtual std::string to_zero_initialized_expression(uint32_t type_id);
|
|
|
|
bool type_can_zero_initialize(const SPIRType &type) const;
|
2016-05-05 07:33:18 +00:00
|
|
|
|
2019-11-06 10:20:57 +00:00
|
|
|
bool buffer_is_packing_standard(const SPIRType &type, BufferPackingStandard packing,
|
|
|
|
uint32_t *failed_index = nullptr, uint32_t start_offset = 0,
|
2018-07-16 22:10:12 +00:00
|
|
|
uint32_t end_offset = ~(0u));
|
2019-05-28 10:21:08 +00:00
|
|
|
std::string buffer_to_packing_standard(const SPIRType &type, bool support_std430_without_scalar_layout);
|
2019-04-24 12:12:50 +00:00
|
|
|
|
2017-10-10 08:12:27 +00:00
|
|
|
uint32_t type_to_packed_base_size(const SPIRType &type, BufferPackingStandard packing);
|
2018-03-12 12:09:25 +00:00
|
|
|
uint32_t type_to_packed_alignment(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing);
|
|
|
|
uint32_t type_to_packed_array_stride(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing);
|
|
|
|
uint32_t type_to_packed_size(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing);
|
2021-04-20 11:03:58 +00:00
|
|
|
uint32_t type_to_location_count(const SPIRType &type) const;
|
2016-05-05 07:33:18 +00:00
|
|
|
|
2016-05-10 21:39:41 +00:00
|
|
|
std::string bitcast_glsl(const SPIRType &result_type, uint32_t arg);
|
2017-03-24 13:13:59 +00:00
|
|
|
virtual std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type);
|
2017-09-19 14:08:25 +00:00
|
|
|
|
|
|
|
std::string bitcast_expression(SPIRType::BaseType target_type, uint32_t arg);
|
2017-09-19 14:09:19 +00:00
|
|
|
std::string bitcast_expression(const SPIRType &target_type, SPIRType::BaseType expr_type, const std::string &expr);
|
2017-09-19 14:08:25 +00:00
|
|
|
|
2018-01-22 08:52:57 +00:00
|
|
|
std::string build_composite_combiner(uint32_t result_type, const uint32_t *elems, uint32_t length);
|
2016-05-05 07:33:18 +00: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 02:34:42 +00:00
|
|
|
virtual void replace_illegal_names();
|
2020-01-16 09:28:54 +00:00
|
|
|
void replace_illegal_names(const std::unordered_set<std::string> &keywords);
|
2018-04-17 15:43:10 +00:00
|
|
|
virtual void emit_entry_point_declarations();
|
2016-08-12 22:14:52 +00:00
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
void replace_fragment_output(SPIRVariable &var);
|
|
|
|
void replace_fragment_outputs();
|
2020-11-07 11:43:53 +00:00
|
|
|
std::string legacy_tex_op(const std::string &op, const SPIRType &imgtype, uint32_t id);
|
2016-05-05 07:33:18 +00:00
|
|
|
|
2022-04-29 11:49:02 +00:00
|
|
|
void forward_relaxed_precision(uint32_t dst_id, const uint32_t *args, uint32_t length);
|
|
|
|
void analyze_precision_requirements(uint32_t type_id, uint32_t dst_id, uint32_t *args, uint32_t length);
|
|
|
|
Options::Precision analyze_expression_precision(const uint32_t *args, uint32_t length) const;
|
|
|
|
|
2016-05-05 07:33:18 +00:00
|
|
|
uint32_t indent = 0;
|
|
|
|
|
|
|
|
std::unordered_set<uint32_t> emitted_functions;
|
2019-09-23 22:05:04 +00:00
|
|
|
|
2019-09-18 18:03:54 +00:00
|
|
|
// Ensure that we declare phi-variable copies even if the original declaration isn't deferred
|
2019-08-14 15:04:58 +00:00
|
|
|
std::unordered_set<uint32_t> flushed_phi_variables;
|
2016-05-05 07:33:18 +00:00
|
|
|
|
2016-12-07 05:02:15 +00:00
|
|
|
std::unordered_set<uint32_t> flattened_buffer_blocks;
|
2020-07-03 11:12:05 +00:00
|
|
|
std::unordered_map<uint32_t, bool> flattened_structs;
|
|
|
|
|
2020-10-08 10:14:52 +00:00
|
|
|
ShaderSubgroupSupportHelper shader_subgroup_supporter;
|
|
|
|
|
2020-07-03 11:12:05 +00:00
|
|
|
std::string load_flattened_struct(const std::string &basename, const SPIRType &type);
|
|
|
|
std::string to_flattened_struct_member(const std::string &basename, const SPIRType &type, uint32_t index);
|
|
|
|
void store_flattened_struct(uint32_t lhs_id, uint32_t value);
|
|
|
|
void store_flattened_struct(const std::string &basename, uint32_t rhs, const SPIRType &type,
|
|
|
|
const SmallVector<uint32_t> &indices);
|
|
|
|
std::string to_flattened_access_chain_expression(uint32_t id);
|
2016-12-07 05:02:15 +00:00
|
|
|
|
2016-05-05 07:33:18 +00: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);
|
|
|
|
|
2019-04-02 09:19:03 +00:00
|
|
|
SmallVector<std::string> forced_extensions;
|
|
|
|
SmallVector<std::string> header_lines;
|
2016-05-05 07:33:18 +00:00
|
|
|
|
2019-03-21 14:26:46 +00:00
|
|
|
// Used when expressions emit extra opcodes with their own unique IDs,
|
|
|
|
// and we need to reuse the IDs across recompilation loops.
|
|
|
|
// Currently used by NMin/Max/Clamp implementations.
|
|
|
|
std::unordered_map<uint32_t, uint32_t> extra_sub_expressions;
|
|
|
|
|
2020-10-14 13:51:49 +00:00
|
|
|
SmallVector<TypeID> workaround_ubo_load_overload_types;
|
|
|
|
void request_workaround_wrapper_overload(TypeID id);
|
|
|
|
void rewrite_load_for_wrapped_row_major(std::string &expr, TypeID loaded_type, ID ptr);
|
|
|
|
|
2019-04-09 10:46:23 +00:00
|
|
|
uint32_t statement_count = 0;
|
2016-05-05 07:33:18 +00:00
|
|
|
|
|
|
|
inline bool is_legacy() const
|
|
|
|
{
|
|
|
|
return (options.es && options.version < 300) || (!options.es && options.version < 130);
|
|
|
|
}
|
|
|
|
|
2016-09-17 12:33:16 +00:00
|
|
|
inline bool is_legacy_es() const
|
|
|
|
{
|
2016-09-17 13:56:23 +00:00
|
|
|
return options.es && options.version < 300;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool is_legacy_desktop() const
|
|
|
|
{
|
|
|
|
return !options.es && options.version < 130;
|
2016-09-17 12:33:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 19:21:27 +00:00
|
|
|
enum Polyfill : uint32_t
|
|
|
|
{
|
|
|
|
PolyfillTranspose2x2 = 1 << 0,
|
|
|
|
PolyfillTranspose3x3 = 1 << 1,
|
|
|
|
PolyfillTranspose4x4 = 1 << 2,
|
|
|
|
PolyfillDeterminant2x2 = 1 << 3,
|
|
|
|
PolyfillDeterminant3x3 = 1 << 4,
|
|
|
|
PolyfillDeterminant4x4 = 1 << 5,
|
|
|
|
PolyfillMatrixInverse2x2 = 1 << 6,
|
|
|
|
PolyfillMatrixInverse3x3 = 1 << 7,
|
|
|
|
PolyfillMatrixInverse4x4 = 1 << 8,
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t required_polyfills = 0;
|
|
|
|
uint32_t required_polyfills_relaxed = 0;
|
|
|
|
void require_polyfill(Polyfill polyfill, bool relaxed);
|
|
|
|
|
2021-01-08 10:37:29 +00:00
|
|
|
bool ray_tracing_is_khr = false;
|
2022-05-27 11:27:48 +00:00
|
|
|
bool barycentric_is_nv = false;
|
2021-01-08 10:37:29 +00:00
|
|
|
void ray_tracing_khr_fixup_locations();
|
2020-11-05 16:09:33 +00:00
|
|
|
|
2016-05-05 07:33:18 +00: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();
|
2018-03-12 16:34:54 +00:00
|
|
|
void register_control_dependent_expression(uint32_t expr);
|
2016-05-05 07:33:18 +00:00
|
|
|
|
|
|
|
// GL_EXT_shader_pixel_local_storage support.
|
2019-04-09 10:46:23 +00:00
|
|
|
std::vector<PlsRemap> pls_inputs;
|
|
|
|
std::vector<PlsRemap> pls_outputs;
|
2016-05-05 07:33:18 +00:00
|
|
|
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 10:25:09 +00:00
|
|
|
|
2020-03-19 13:20:37 +00:00
|
|
|
// GL_EXT_shader_framebuffer_fetch support.
|
|
|
|
std::vector<std::pair<uint32_t, uint32_t>> subpass_to_framebuffer_fetch_attachment;
|
2021-05-21 12:21:13 +00:00
|
|
|
std::vector<std::pair<uint32_t, bool>> inout_color_attachments;
|
|
|
|
bool location_is_framebuffer_fetch(uint32_t location) const;
|
|
|
|
bool location_is_non_coherent_framebuffer_fetch(uint32_t location) const;
|
2020-03-19 13:20:37 +00:00
|
|
|
bool subpass_input_is_framebuffer_fetch(uint32_t id) const;
|
|
|
|
void emit_inout_fragment_outputs_copy_to_subpass_inputs();
|
|
|
|
const SPIRVariable *find_subpass_input_by_attachment_index(uint32_t index) const;
|
|
|
|
const SPIRVariable *find_color_output_by_location(uint32_t location) const;
|
|
|
|
|
2019-01-04 11:15:43 +00:00
|
|
|
// A variant which takes two sets of name. The secondary is only used to verify there are no collisions,
|
|
|
|
// but the set is not updated when we have found a new name.
|
|
|
|
// Used primarily when adding block interface names.
|
|
|
|
void add_variable(std::unordered_set<std::string> &variables_primary,
|
2019-01-07 09:01:28 +00:00
|
|
|
const std::unordered_set<std::string> &variables_secondary, std::string &name);
|
2019-01-04 11:15:43 +00:00
|
|
|
|
2016-07-06 09:04:06 +00:00
|
|
|
void check_function_call_constraints(const uint32_t *args, uint32_t length);
|
2016-07-12 12:33:04 +00:00
|
|
|
void handle_invalid_expression(uint32_t id);
|
2022-02-16 11:12:58 +00:00
|
|
|
void force_temporary_and_recompile(uint32_t id);
|
2016-07-27 08:59:00 +00:00
|
|
|
void find_static_extensions();
|
2016-12-15 16:14:47 +00:00
|
|
|
|
2022-04-29 11:49:02 +00:00
|
|
|
uint32_t consume_temporary_in_precision_context(uint32_t type_id, uint32_t id, Options::Precision precision);
|
|
|
|
std::unordered_map<uint32_t, uint32_t> temporary_to_mirror_precision_alias;
|
2022-05-18 10:26:20 +00:00
|
|
|
std::unordered_set<uint32_t> composite_insert_overwritten;
|
|
|
|
std::unordered_set<uint32_t> block_composite_insert_overwrite;
|
2022-04-29 11:49:02 +00:00
|
|
|
|
2016-12-15 16:14:47 +00:00
|
|
|
std::string emit_for_loop_initializers(const SPIRBlock &block);
|
2018-08-06 10:52:22 +00:00
|
|
|
void emit_while_loop_initializers(const SPIRBlock &block);
|
2018-01-16 09:27:58 +00:00
|
|
|
bool for_loop_initializers_are_same_type(const SPIRBlock &block);
|
2018-05-04 08:35:32 +00:00
|
|
|
bool optimize_read_modify_write(const SPIRType &type, const std::string &lhs, const std::string &rhs);
|
2017-01-05 17:16:33 +00:00
|
|
|
void fixup_image_load_store_access();
|
2017-03-24 09:03:11 +00:00
|
|
|
|
|
|
|
bool type_is_empty(const SPIRType &type);
|
2017-04-01 14:08:19 +00:00
|
|
|
|
2018-04-17 12:16:27 +00:00
|
|
|
bool can_use_io_location(spv::StorageClass storage, bool block);
|
2018-01-09 11:07:07 +00:00
|
|
|
const Instruction *get_next_instruction_in_block(const Instruction &instr);
|
2018-01-09 11:41:13 +00:00
|
|
|
static uint32_t mask_relevant_memory_semantics(uint32_t semantics);
|
2017-10-19 12:17:18 +00:00
|
|
|
|
2018-03-06 14:32:26 +00:00
|
|
|
std::string convert_half_to_string(const SPIRConstant &value, uint32_t col, uint32_t row);
|
2018-02-23 12:06:20 +00:00
|
|
|
std::string convert_float_to_string(const SPIRConstant &value, uint32_t col, uint32_t row);
|
|
|
|
std::string convert_double_to_string(const SPIRConstant &value, uint32_t col, uint32_t row);
|
|
|
|
|
2018-09-27 11:36:38 +00:00
|
|
|
std::string convert_separate_image_to_expression(uint32_t id);
|
2018-04-30 09:18:18 +00:00
|
|
|
|
2018-06-22 09:30:13 +00:00
|
|
|
// Builtins in GLSL are always specific signedness, but the SPIR-V can declare them
|
|
|
|
// as either unsigned or signed.
|
2020-10-14 20:04:03 +00:00
|
|
|
// Sometimes we will need to automatically perform casts on load and store to make this work.
|
2021-10-25 08:55:11 +00:00
|
|
|
virtual void cast_to_variable_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type);
|
|
|
|
virtual void cast_from_variable_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type);
|
2019-03-21 10:50:53 +00:00
|
|
|
void unroll_array_from_complex_load(uint32_t target_id, uint32_t source_id, std::string &expr);
|
2021-03-08 10:51:51 +00:00
|
|
|
bool unroll_array_to_complex_store(uint32_t target_id, uint32_t source_id);
|
2021-04-22 11:54:43 +00:00
|
|
|
void convert_non_uniform_expression(std::string &expr, uint32_t ptr_id);
|
2018-06-22 09:30:13 +00:00
|
|
|
|
2018-11-22 10:55:57 +00:00
|
|
|
void handle_store_to_invariant_variable(uint32_t store_id, uint32_t value_id);
|
|
|
|
void disallow_forwarding_in_expression_chain(const SPIRExpression &expr);
|
|
|
|
|
2019-01-07 09:01:00 +00:00
|
|
|
bool expression_is_constant_null(uint32_t id) const;
|
2020-06-18 10:46:39 +00:00
|
|
|
bool expression_is_non_value_type_array(uint32_t ptr);
|
2019-01-17 11:21:16 +00:00
|
|
|
virtual void emit_store_statement(uint32_t lhs_expression, uint32_t rhs_expression);
|
2019-01-07 09:01:00 +00:00
|
|
|
|
2019-01-30 13:49:55 +00:00
|
|
|
uint32_t get_integer_width_for_instruction(const Instruction &instr) const;
|
2019-03-27 10:53:47 +00:00
|
|
|
uint32_t get_integer_width_for_glsl_instruction(GLSLstd450 op, const uint32_t *arguments, uint32_t length) const;
|
2019-01-30 13:49:55 +00:00
|
|
|
|
2019-02-06 09:38:18 +00:00
|
|
|
bool variable_is_lut(const SPIRVariable &var) const;
|
|
|
|
|
2019-02-28 10:26:26 +00:00
|
|
|
char current_locale_radix_character = '.';
|
|
|
|
|
2019-05-23 12:54:04 +00:00
|
|
|
void fixup_type_alias();
|
|
|
|
void reorder_type_alias();
|
2022-03-10 14:38:57 +00:00
|
|
|
void fixup_anonymous_struct_names();
|
|
|
|
void fixup_anonymous_struct_names(std::unordered_set<uint32_t> &visited, const SPIRType &type);
|
2019-05-23 12:54:04 +00:00
|
|
|
|
2020-01-07 13:05:55 +00:00
|
|
|
static const char *vector_swizzle(int vecsize, int index);
|
|
|
|
|
2021-03-25 17:08:49 +00:00
|
|
|
bool is_stage_output_location_masked(uint32_t location, uint32_t component) const;
|
|
|
|
bool is_stage_output_builtin_masked(spv::BuiltIn builtin) const;
|
2021-04-06 12:12:24 +00:00
|
|
|
bool is_stage_output_variable_masked(const SPIRVariable &var) const;
|
2021-04-06 12:43:34 +00:00
|
|
|
bool is_stage_output_block_member_masked(const SPIRVariable &var, uint32_t index, bool strip_array) const;
|
2022-10-10 22:16:45 +00:00
|
|
|
bool is_per_primitive_variable(const SPIRVariable &var) const;
|
2021-04-06 12:43:34 +00:00
|
|
|
uint32_t get_accumulated_member_location(const SPIRVariable &var, uint32_t mbr_idx, bool strip_array) const;
|
|
|
|
uint32_t get_declared_member_location(const SPIRVariable &var, uint32_t mbr_idx, bool strip_array) const;
|
2021-03-25 17:08:49 +00:00
|
|
|
std::unordered_set<LocationComponentPair, InternalHasher> masked_output_locations;
|
|
|
|
std::unordered_set<uint32_t> masked_output_builtins;
|
|
|
|
|
2017-04-01 14:08:19 +00:00
|
|
|
private:
|
2019-02-28 10:26:26 +00:00
|
|
|
void init();
|
2022-10-26 20:31:10 +00:00
|
|
|
|
|
|
|
SmallVector<ConstantID> get_composite_constant_ids(ConstantID const_id);
|
|
|
|
void fill_composite_constant(SPIRConstant &constant, TypeID type_id, const SmallVector<ConstantID> &initializers);
|
|
|
|
void set_composite_constant(ConstantID const_id, TypeID type_id, const SmallVector<ConstantID> &initializers);
|
|
|
|
TypeID get_composite_member_type(TypeID type_id, uint32_t member_idx);
|
|
|
|
std::unordered_map<uint32_t, SmallVector<ConstantID>> const_composite_insert_ids;
|
2016-05-05 07:33:18 +00:00
|
|
|
};
|
2019-04-02 09:19:03 +00:00
|
|
|
} // namespace SPIRV_CROSS_NAMESPACE
|
2016-03-02 17:09:16 +00:00
|
|
|
|
|
|
|
#endif
|