2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +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
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// 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.
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-02-22 20:25:50 +00:00
|
|
|
#ifndef SPIRV_TOOLS_LIBSPIRV_H_
|
2016-02-17 19:44:00 +00:00
|
|
|
#define SPIRV_TOOLS_LIBSPIRV_H_
|
2015-05-22 17:26:19 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2016-03-01 15:17:18 +00:00
|
|
|
#else
|
|
|
|
#include <stdbool.h>
|
2015-05-22 17:26:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2018-02-02 22:37:14 +00:00
|
|
|
#if defined(SPIRV_TOOLS_SHAREDLIB)
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#if defined(SPIRV_TOOLS_IMPLEMENTATION)
|
|
|
|
#define SPIRV_TOOLS_EXPORT __declspec(dllexport)
|
|
|
|
#else
|
|
|
|
#define SPIRV_TOOLS_EXPORT __declspec(dllimport)
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if defined(SPIRV_TOOLS_IMPLEMENTATION)
|
|
|
|
#define SPIRV_TOOLS_EXPORT __attribute__((visibility("default")))
|
|
|
|
#else
|
|
|
|
#define SPIRV_TOOLS_EXPORT
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define SPIRV_TOOLS_EXPORT
|
|
|
|
#endif
|
|
|
|
|
2015-05-22 17:26:19 +00:00
|
|
|
// Helpers
|
|
|
|
|
2015-08-14 17:57:02 +00:00
|
|
|
#define SPV_BIT(shift) (1 << (shift))
|
2015-05-22 17:26:19 +00:00
|
|
|
|
|
|
|
#define SPV_FORCE_16_BIT_ENUM(name) _##name = 0x7fff
|
|
|
|
#define SPV_FORCE_32_BIT_ENUM(name) _##name = 0x7fffffff
|
|
|
|
|
|
|
|
// Enumerations
|
|
|
|
|
|
|
|
typedef enum spv_result_t {
|
|
|
|
SPV_SUCCESS = 0,
|
|
|
|
SPV_UNSUPPORTED = 1,
|
|
|
|
SPV_END_OF_STREAM = 2,
|
|
|
|
SPV_WARNING = 3,
|
2015-08-27 17:38:39 +00:00
|
|
|
SPV_FAILED_MATCH = 4,
|
2016-02-22 20:25:50 +00:00
|
|
|
SPV_REQUESTED_TERMINATION = 5, // Success, but signals early termination.
|
2015-05-22 17:26:19 +00:00
|
|
|
SPV_ERROR_INTERNAL = -1,
|
|
|
|
SPV_ERROR_OUT_OF_MEMORY = -2,
|
|
|
|
SPV_ERROR_INVALID_POINTER = -3,
|
|
|
|
SPV_ERROR_INVALID_BINARY = -4,
|
|
|
|
SPV_ERROR_INVALID_TEXT = -5,
|
|
|
|
SPV_ERROR_INVALID_TABLE = -6,
|
|
|
|
SPV_ERROR_INVALID_VALUE = -7,
|
|
|
|
SPV_ERROR_INVALID_DIAGNOSTIC = -8,
|
|
|
|
SPV_ERROR_INVALID_LOOKUP = -9,
|
|
|
|
SPV_ERROR_INVALID_ID = -10,
|
2015-12-14 13:21:08 +00:00
|
|
|
SPV_ERROR_INVALID_CFG = -11,
|
2015-12-15 19:50:05 +00:00
|
|
|
SPV_ERROR_INVALID_LAYOUT = -12,
|
2016-01-23 19:14:32 +00:00
|
|
|
SPV_ERROR_INVALID_CAPABILITY = -13,
|
2016-11-04 22:31:21 +00:00
|
|
|
SPV_ERROR_INVALID_DATA = -14, // Indicates data rules validation failure.
|
2017-03-10 20:58:15 +00:00
|
|
|
SPV_ERROR_MISSING_EXTENSION = -15,
|
2018-03-14 17:06:18 +00:00
|
|
|
SPV_ERROR_WRONG_VERSION = -16, // Indicates wrong SPIR-V version
|
2015-05-22 17:26:19 +00:00
|
|
|
SPV_FORCE_32_BIT_ENUM(spv_result_t)
|
|
|
|
} spv_result_t;
|
|
|
|
|
2016-09-16 20:12:04 +00:00
|
|
|
// Severity levels of messages communicated to the consumer.
|
|
|
|
typedef enum spv_message_level_t {
|
|
|
|
SPV_MSG_FATAL, // Unrecoverable error due to environment.
|
|
|
|
// Will exit the program immediately. E.g.,
|
|
|
|
// out of memory.
|
|
|
|
SPV_MSG_INTERNAL_ERROR, // Unrecoverable error due to SPIRV-Tools
|
|
|
|
// internals.
|
|
|
|
// Will exit the program immediately. E.g.,
|
|
|
|
// unimplemented feature.
|
|
|
|
SPV_MSG_ERROR, // Normal error due to user input.
|
2017-03-16 19:19:51 +00:00
|
|
|
SPV_MSG_WARNING, // Warning information.
|
2016-09-16 20:12:04 +00:00
|
|
|
SPV_MSG_INFO, // General information.
|
|
|
|
SPV_MSG_DEBUG, // Debug information.
|
|
|
|
} spv_message_level_t;
|
|
|
|
|
2015-05-22 17:26:19 +00:00
|
|
|
typedef enum spv_endianness_t {
|
|
|
|
SPV_ENDIANNESS_LITTLE,
|
|
|
|
SPV_ENDIANNESS_BIG,
|
|
|
|
SPV_FORCE_32_BIT_ENUM(spv_endianness_t)
|
|
|
|
} spv_endianness_t;
|
|
|
|
|
Use opcode operand definitions from SPIR-V specification generator.
The assembler and disassembler now use a dynamically adjusted
sequence of expected operand types. (Internally, it is a deque,
for readability.) Both parsers repeatedly pull an expected operand
type from the left of this pattern list, and try to match the next
input token against it.
The expected pattern is adjusted during the parse to accommodate:
- an extended instruction's expected operands, depending on the
extended instruction's index.
- when an operand itself has operands
- to handle sequences of zero or more operands, or pairs of
operands. These are expanded lazily during the parse.
Adds spv::OperandClass from the SPIR-V specification generator.
Modifies spv_operand_desc_t:
- adds hasResult, hasType, and operandClass array to the opcode
description type.
- "wordCount" is replaced with "numTypes", which counts the number
of entries in operandTypes. And each of those describes a
*logical* operand, including the type id for the instruction,
and the result id for the instruction. A logical operand could be
variable-width, such as a literal string.
Adds opcode.inc, an automatically-generated table of operation
descriptions, with one line to describe each core instruction.
Externally, we have modified the SPIR-V spec doc generator to
emit this file.
(We have hacked this copy to use the old semantics for OpLine.)
Inside the assembler, parsing an operand may fail with new
error code SPV_FAIL_MATCH. For an optional operand, this is not
fatal, but should trigger backtracking at a higher level.
The spvTextIsStartOfNewInst checks the case of the third letter
of what might be an opcode. So now, "OpenCL" does not look like
an opcode name.
In assembly, the EntryPoint name field is mandatory, but can be
an empty string.
Adjust tests for changes to:
- OpSampedImage
- OpTypeSampler
2015-08-27 17:03:52 +00:00
|
|
|
// The kinds of operands that an instruction may have.
|
|
|
|
//
|
2015-10-30 20:06:15 +00:00
|
|
|
// Some operand types are "concrete". The binary parser uses a concrete
|
|
|
|
// operand type to describe an operand of a parsed instruction.
|
|
|
|
//
|
|
|
|
// The assembler uses all operand types. In addition to determining what
|
|
|
|
// kind of value an operand may be, non-concrete operand types capture the
|
|
|
|
// fact that an operand might be optional (may be absent, or present exactly
|
2015-11-13 16:00:10 +00:00
|
|
|
// once), or might occur zero or more times.
|
Use opcode operand definitions from SPIR-V specification generator.
The assembler and disassembler now use a dynamically adjusted
sequence of expected operand types. (Internally, it is a deque,
for readability.) Both parsers repeatedly pull an expected operand
type from the left of this pattern list, and try to match the next
input token against it.
The expected pattern is adjusted during the parse to accommodate:
- an extended instruction's expected operands, depending on the
extended instruction's index.
- when an operand itself has operands
- to handle sequences of zero or more operands, or pairs of
operands. These are expanded lazily during the parse.
Adds spv::OperandClass from the SPIR-V specification generator.
Modifies spv_operand_desc_t:
- adds hasResult, hasType, and operandClass array to the opcode
description type.
- "wordCount" is replaced with "numTypes", which counts the number
of entries in operandTypes. And each of those describes a
*logical* operand, including the type id for the instruction,
and the result id for the instruction. A logical operand could be
variable-width, such as a literal string.
Adds opcode.inc, an automatically-generated table of operation
descriptions, with one line to describe each core instruction.
Externally, we have modified the SPIR-V spec doc generator to
emit this file.
(We have hacked this copy to use the old semantics for OpLine.)
Inside the assembler, parsing an operand may fail with new
error code SPV_FAIL_MATCH. For an optional operand, this is not
fatal, but should trigger backtracking at a higher level.
The spvTextIsStartOfNewInst checks the case of the third letter
of what might be an opcode. So now, "OpenCL" does not look like
an opcode name.
In assembly, the EntryPoint name field is mandatory, but can be
an empty string.
Adjust tests for changes to:
- OpSampedImage
- OpTypeSampler
2015-08-27 17:03:52 +00:00
|
|
|
//
|
|
|
|
// Sometimes we also need to be able to express the fact that an operand
|
|
|
|
// is a member of an optional tuple of values. In that case the first member
|
|
|
|
// would be optional, and the subsequent members would be required.
|
2015-05-22 17:26:19 +00:00
|
|
|
typedef enum spv_operand_type_t {
|
2015-11-04 22:38:17 +00:00
|
|
|
// A sentinel value.
|
Use opcode operand definitions from SPIR-V specification generator.
The assembler and disassembler now use a dynamically adjusted
sequence of expected operand types. (Internally, it is a deque,
for readability.) Both parsers repeatedly pull an expected operand
type from the left of this pattern list, and try to match the next
input token against it.
The expected pattern is adjusted during the parse to accommodate:
- an extended instruction's expected operands, depending on the
extended instruction's index.
- when an operand itself has operands
- to handle sequences of zero or more operands, or pairs of
operands. These are expanded lazily during the parse.
Adds spv::OperandClass from the SPIR-V specification generator.
Modifies spv_operand_desc_t:
- adds hasResult, hasType, and operandClass array to the opcode
description type.
- "wordCount" is replaced with "numTypes", which counts the number
of entries in operandTypes. And each of those describes a
*logical* operand, including the type id for the instruction,
and the result id for the instruction. A logical operand could be
variable-width, such as a literal string.
Adds opcode.inc, an automatically-generated table of operation
descriptions, with one line to describe each core instruction.
Externally, we have modified the SPIR-V spec doc generator to
emit this file.
(We have hacked this copy to use the old semantics for OpLine.)
Inside the assembler, parsing an operand may fail with new
error code SPV_FAIL_MATCH. For an optional operand, this is not
fatal, but should trigger backtracking at a higher level.
The spvTextIsStartOfNewInst checks the case of the third letter
of what might be an opcode. So now, "OpenCL" does not look like
an opcode name.
In assembly, the EntryPoint name field is mandatory, but can be
an empty string.
Adjust tests for changes to:
- OpSampedImage
- OpTypeSampler
2015-08-27 17:03:52 +00:00
|
|
|
SPV_OPERAND_TYPE_NONE = 0,
|
2015-10-30 20:06:15 +00:00
|
|
|
|
|
|
|
// Set 1: Operands that are IDs.
|
2017-12-03 19:26:16 +00:00
|
|
|
SPV_OPERAND_TYPE_ID,
|
2015-09-29 15:28:34 +00:00
|
|
|
SPV_OPERAND_TYPE_TYPE_ID,
|
2015-05-22 17:26:19 +00:00
|
|
|
SPV_OPERAND_TYPE_RESULT_ID,
|
2015-10-30 20:06:15 +00:00
|
|
|
SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID, // SPIR-V Sec 3.25
|
|
|
|
SPV_OPERAND_TYPE_SCOPE_ID, // SPIR-V Sec 3.27
|
|
|
|
|
|
|
|
// Set 2: Operands that are literal numbers.
|
|
|
|
SPV_OPERAND_TYPE_LITERAL_INTEGER, // Always unsigned 32-bits.
|
|
|
|
// The Instruction argument to OpExtInst. It's an unsigned 32-bit literal
|
|
|
|
// number indicating which instruction to use from an extended instruction
|
|
|
|
// set.
|
|
|
|
SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER,
|
2015-11-11 06:56:49 +00:00
|
|
|
// The Opcode argument to OpSpecConstantOp. It determines the operation
|
|
|
|
// to be performed on constant operands to compute a specialization constant
|
|
|
|
// result.
|
|
|
|
SPV_OPERAND_TYPE_SPEC_CONSTANT_OP_NUMBER,
|
2015-11-04 22:38:17 +00:00
|
|
|
// A literal number whose format and size are determined by a previous operand
|
|
|
|
// in the same instruction. It's a signed integer, an unsigned integer, or a
|
|
|
|
// floating point number. It also has a specified bit width. The width
|
|
|
|
// may be larger than 32, which would require such a typed literal value to
|
|
|
|
// occupy multiple SPIR-V words.
|
|
|
|
SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER,
|
2015-10-30 20:06:15 +00:00
|
|
|
|
|
|
|
// Set 3: The literal string operand type.
|
2015-05-22 17:26:19 +00:00
|
|
|
SPV_OPERAND_TYPE_LITERAL_STRING,
|
2015-10-30 20:06:15 +00:00
|
|
|
|
|
|
|
// Set 4: Operands that are a single word enumerated value.
|
|
|
|
SPV_OPERAND_TYPE_SOURCE_LANGUAGE, // SPIR-V Sec 3.2
|
|
|
|
SPV_OPERAND_TYPE_EXECUTION_MODEL, // SPIR-V Sec 3.3
|
|
|
|
SPV_OPERAND_TYPE_ADDRESSING_MODEL, // SPIR-V Sec 3.4
|
|
|
|
SPV_OPERAND_TYPE_MEMORY_MODEL, // SPIR-V Sec 3.5
|
|
|
|
SPV_OPERAND_TYPE_EXECUTION_MODE, // SPIR-V Sec 3.6
|
|
|
|
SPV_OPERAND_TYPE_STORAGE_CLASS, // SPIR-V Sec 3.7
|
|
|
|
SPV_OPERAND_TYPE_DIMENSIONALITY, // SPIR-V Sec 3.8
|
|
|
|
SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE, // SPIR-V Sec 3.9
|
|
|
|
SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE, // SPIR-V Sec 3.10
|
|
|
|
SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT, // SPIR-V Sec 3.11
|
|
|
|
SPV_OPERAND_TYPE_IMAGE_CHANNEL_ORDER, // SPIR-V Sec 3.12
|
|
|
|
SPV_OPERAND_TYPE_IMAGE_CHANNEL_DATA_TYPE, // SPIR-V Sec 3.13
|
|
|
|
SPV_OPERAND_TYPE_FP_ROUNDING_MODE, // SPIR-V Sec 3.16
|
|
|
|
SPV_OPERAND_TYPE_LINKAGE_TYPE, // SPIR-V Sec 3.17
|
|
|
|
SPV_OPERAND_TYPE_ACCESS_QUALIFIER, // SPIR-V Sec 3.18
|
|
|
|
SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE, // SPIR-V Sec 3.19
|
|
|
|
SPV_OPERAND_TYPE_DECORATION, // SPIR-V Sec 3.20
|
|
|
|
SPV_OPERAND_TYPE_BUILT_IN, // SPIR-V Sec 3.21
|
|
|
|
SPV_OPERAND_TYPE_GROUP_OPERATION, // SPIR-V Sec 3.28
|
|
|
|
SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS, // SPIR-V Sec 3.29
|
|
|
|
SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO, // SPIR-V Sec 3.30
|
|
|
|
SPV_OPERAND_TYPE_CAPABILITY, // SPIR-V Sec 3.31
|
|
|
|
|
2017-12-03 19:26:16 +00:00
|
|
|
// Set 5: Operands that are a single word bitmask.
|
|
|
|
// Sometimes a set bit indicates the instruction requires still more operands.
|
|
|
|
SPV_OPERAND_TYPE_IMAGE, // SPIR-V Sec 3.14
|
|
|
|
SPV_OPERAND_TYPE_FP_FAST_MATH_MODE, // SPIR-V Sec 3.15
|
|
|
|
SPV_OPERAND_TYPE_SELECTION_CONTROL, // SPIR-V Sec 3.22
|
|
|
|
SPV_OPERAND_TYPE_LOOP_CONTROL, // SPIR-V Sec 3.23
|
|
|
|
SPV_OPERAND_TYPE_FUNCTION_CONTROL, // SPIR-V Sec 3.24
|
|
|
|
SPV_OPERAND_TYPE_MEMORY_ACCESS, // SPIR-V Sec 3.26
|
2015-10-30 20:06:15 +00:00
|
|
|
|
2015-11-11 06:56:49 +00:00
|
|
|
// The remaining operand types are only used internally by the assembler.
|
|
|
|
// There are two categories:
|
|
|
|
// Optional : expands to 0 or 1 operand, like ? in regular expressions.
|
|
|
|
// Variable : expands to 0, 1 or many operands or pairs of operands.
|
|
|
|
// This is similar to * in regular expressions.
|
2015-11-04 22:38:17 +00:00
|
|
|
|
|
|
|
// Macros for defining bounds on optional and variable operand types.
|
|
|
|
// Any variable operand type is also optional.
|
|
|
|
#define FIRST_OPTIONAL(ENUM) ENUM, SPV_OPERAND_TYPE_FIRST_OPTIONAL_TYPE = ENUM
|
|
|
|
#define FIRST_VARIABLE(ENUM) ENUM, SPV_OPERAND_TYPE_FIRST_VARIABLE_TYPE = ENUM
|
|
|
|
#define LAST_VARIABLE(ENUM) \
|
|
|
|
ENUM, SPV_OPERAND_TYPE_LAST_VARIABLE_TYPE = ENUM, \
|
|
|
|
SPV_OPERAND_TYPE_LAST_OPTIONAL_TYPE = ENUM
|
2015-05-22 17:26:19 +00:00
|
|
|
|
Use opcode operand definitions from SPIR-V specification generator.
The assembler and disassembler now use a dynamically adjusted
sequence of expected operand types. (Internally, it is a deque,
for readability.) Both parsers repeatedly pull an expected operand
type from the left of this pattern list, and try to match the next
input token against it.
The expected pattern is adjusted during the parse to accommodate:
- an extended instruction's expected operands, depending on the
extended instruction's index.
- when an operand itself has operands
- to handle sequences of zero or more operands, or pairs of
operands. These are expanded lazily during the parse.
Adds spv::OperandClass from the SPIR-V specification generator.
Modifies spv_operand_desc_t:
- adds hasResult, hasType, and operandClass array to the opcode
description type.
- "wordCount" is replaced with "numTypes", which counts the number
of entries in operandTypes. And each of those describes a
*logical* operand, including the type id for the instruction,
and the result id for the instruction. A logical operand could be
variable-width, such as a literal string.
Adds opcode.inc, an automatically-generated table of operation
descriptions, with one line to describe each core instruction.
Externally, we have modified the SPIR-V spec doc generator to
emit this file.
(We have hacked this copy to use the old semantics for OpLine.)
Inside the assembler, parsing an operand may fail with new
error code SPV_FAIL_MATCH. For an optional operand, this is not
fatal, but should trigger backtracking at a higher level.
The spvTextIsStartOfNewInst checks the case of the third letter
of what might be an opcode. So now, "OpenCL" does not look like
an opcode name.
In assembly, the EntryPoint name field is mandatory, but can be
an empty string.
Adjust tests for changes to:
- OpSampedImage
- OpTypeSampler
2015-08-27 17:03:52 +00:00
|
|
|
// An optional operand represents zero or one logical operands.
|
|
|
|
// In an instruction definition, this may only appear at the end of the
|
|
|
|
// operand types.
|
2015-11-04 22:38:17 +00:00
|
|
|
FIRST_OPTIONAL(SPV_OPERAND_TYPE_OPTIONAL_ID),
|
|
|
|
// An optional image operand type.
|
|
|
|
SPV_OPERAND_TYPE_OPTIONAL_IMAGE,
|
|
|
|
// An optional memory access type.
|
|
|
|
SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS,
|
2015-10-14 21:02:39 +00:00
|
|
|
// An optional literal integer.
|
|
|
|
SPV_OPERAND_TYPE_OPTIONAL_LITERAL_INTEGER,
|
2015-11-04 22:38:17 +00:00
|
|
|
// An optional literal number, which may be either integer or floating point.
|
|
|
|
SPV_OPERAND_TYPE_OPTIONAL_LITERAL_NUMBER,
|
|
|
|
// Like SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER, but optional, and integral.
|
|
|
|
SPV_OPERAND_TYPE_OPTIONAL_TYPED_LITERAL_INTEGER,
|
Use opcode operand definitions from SPIR-V specification generator.
The assembler and disassembler now use a dynamically adjusted
sequence of expected operand types. (Internally, it is a deque,
for readability.) Both parsers repeatedly pull an expected operand
type from the left of this pattern list, and try to match the next
input token against it.
The expected pattern is adjusted during the parse to accommodate:
- an extended instruction's expected operands, depending on the
extended instruction's index.
- when an operand itself has operands
- to handle sequences of zero or more operands, or pairs of
operands. These are expanded lazily during the parse.
Adds spv::OperandClass from the SPIR-V specification generator.
Modifies spv_operand_desc_t:
- adds hasResult, hasType, and operandClass array to the opcode
description type.
- "wordCount" is replaced with "numTypes", which counts the number
of entries in operandTypes. And each of those describes a
*logical* operand, including the type id for the instruction,
and the result id for the instruction. A logical operand could be
variable-width, such as a literal string.
Adds opcode.inc, an automatically-generated table of operation
descriptions, with one line to describe each core instruction.
Externally, we have modified the SPIR-V spec doc generator to
emit this file.
(We have hacked this copy to use the old semantics for OpLine.)
Inside the assembler, parsing an operand may fail with new
error code SPV_FAIL_MATCH. For an optional operand, this is not
fatal, but should trigger backtracking at a higher level.
The spvTextIsStartOfNewInst checks the case of the third letter
of what might be an opcode. So now, "OpenCL" does not look like
an opcode name.
In assembly, the EntryPoint name field is mandatory, but can be
an empty string.
Adjust tests for changes to:
- OpSampedImage
- OpTypeSampler
2015-08-27 17:03:52 +00:00
|
|
|
// An optional literal string.
|
|
|
|
SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING,
|
2016-02-15 18:50:00 +00:00
|
|
|
// An optional access qualifier
|
|
|
|
SPV_OPERAND_TYPE_OPTIONAL_ACCESS_QUALIFIER,
|
2015-11-04 22:38:17 +00:00
|
|
|
// An optional context-independent value, or CIV. CIVs are tokens that we can
|
|
|
|
// assemble regardless of where they occur -- literals, IDs, immediate
|
|
|
|
// integers, etc.
|
|
|
|
SPV_OPERAND_TYPE_OPTIONAL_CIV,
|
|
|
|
|
Use opcode operand definitions from SPIR-V specification generator.
The assembler and disassembler now use a dynamically adjusted
sequence of expected operand types. (Internally, it is a deque,
for readability.) Both parsers repeatedly pull an expected operand
type from the left of this pattern list, and try to match the next
input token against it.
The expected pattern is adjusted during the parse to accommodate:
- an extended instruction's expected operands, depending on the
extended instruction's index.
- when an operand itself has operands
- to handle sequences of zero or more operands, or pairs of
operands. These are expanded lazily during the parse.
Adds spv::OperandClass from the SPIR-V specification generator.
Modifies spv_operand_desc_t:
- adds hasResult, hasType, and operandClass array to the opcode
description type.
- "wordCount" is replaced with "numTypes", which counts the number
of entries in operandTypes. And each of those describes a
*logical* operand, including the type id for the instruction,
and the result id for the instruction. A logical operand could be
variable-width, such as a literal string.
Adds opcode.inc, an automatically-generated table of operation
descriptions, with one line to describe each core instruction.
Externally, we have modified the SPIR-V spec doc generator to
emit this file.
(We have hacked this copy to use the old semantics for OpLine.)
Inside the assembler, parsing an operand may fail with new
error code SPV_FAIL_MATCH. For an optional operand, this is not
fatal, but should trigger backtracking at a higher level.
The spvTextIsStartOfNewInst checks the case of the third letter
of what might be an opcode. So now, "OpenCL" does not look like
an opcode name.
In assembly, the EntryPoint name field is mandatory, but can be
an empty string.
Adjust tests for changes to:
- OpSampedImage
- OpTypeSampler
2015-08-27 17:03:52 +00:00
|
|
|
// A variable operand represents zero or more logical operands.
|
|
|
|
// In an instruction definition, this may only appear at the end of the
|
|
|
|
// operand types.
|
2015-11-04 22:38:17 +00:00
|
|
|
FIRST_VARIABLE(SPV_OPERAND_TYPE_VARIABLE_ID),
|
2015-10-14 21:02:39 +00:00
|
|
|
SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER,
|
2015-11-04 22:38:17 +00:00
|
|
|
// A sequence of zero or more pairs of (typed literal integer, Id).
|
|
|
|
// Expands to zero or more:
|
|
|
|
// (SPV_OPERAND_TYPE_TYPED_LITERAL_INTEGER, SPV_OPERAND_TYPE_ID)
|
|
|
|
// where the literal number must always be an integer of some sort.
|
2015-10-14 21:02:39 +00:00
|
|
|
SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER_ID,
|
|
|
|
// A sequence of zero or more pairs of (Id, Literal integer)
|
2016-03-29 18:49:05 +00:00
|
|
|
LAST_VARIABLE(SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL_INTEGER),
|
2015-10-15 19:22:06 +00:00
|
|
|
|
2017-12-03 17:30:08 +00:00
|
|
|
// The following are concrete enum types.
|
|
|
|
SPV_OPERAND_TYPE_DEBUG_INFO_FLAGS, // DebugInfo Sec 3.2. A mask.
|
|
|
|
SPV_OPERAND_TYPE_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING, // DebugInfo Sec 3.3
|
|
|
|
SPV_OPERAND_TYPE_DEBUG_COMPOSITE_TYPE, // DebugInfo Sec 3.4
|
|
|
|
SPV_OPERAND_TYPE_DEBUG_TYPE_QUALIFIER, // DebugInfo Sec 3.5
|
|
|
|
SPV_OPERAND_TYPE_DEBUG_OPERATION, // DebugInfo Sec 3.6
|
|
|
|
|
Use opcode operand definitions from SPIR-V specification generator.
The assembler and disassembler now use a dynamically adjusted
sequence of expected operand types. (Internally, it is a deque,
for readability.) Both parsers repeatedly pull an expected operand
type from the left of this pattern list, and try to match the next
input token against it.
The expected pattern is adjusted during the parse to accommodate:
- an extended instruction's expected operands, depending on the
extended instruction's index.
- when an operand itself has operands
- to handle sequences of zero or more operands, or pairs of
operands. These are expanded lazily during the parse.
Adds spv::OperandClass from the SPIR-V specification generator.
Modifies spv_operand_desc_t:
- adds hasResult, hasType, and operandClass array to the opcode
description type.
- "wordCount" is replaced with "numTypes", which counts the number
of entries in operandTypes. And each of those describes a
*logical* operand, including the type id for the instruction,
and the result id for the instruction. A logical operand could be
variable-width, such as a literal string.
Adds opcode.inc, an automatically-generated table of operation
descriptions, with one line to describe each core instruction.
Externally, we have modified the SPIR-V spec doc generator to
emit this file.
(We have hacked this copy to use the old semantics for OpLine.)
Inside the assembler, parsing an operand may fail with new
error code SPV_FAIL_MATCH. For an optional operand, this is not
fatal, but should trigger backtracking at a higher level.
The spvTextIsStartOfNewInst checks the case of the third letter
of what might be an opcode. So now, "OpenCL" does not look like
an opcode name.
In assembly, the EntryPoint name field is mandatory, but can be
an empty string.
Adjust tests for changes to:
- OpSampedImage
- OpTypeSampler
2015-08-27 17:03:52 +00:00
|
|
|
// This is a sentinel value, and does not represent an operand type.
|
|
|
|
// It should come last.
|
|
|
|
SPV_OPERAND_TYPE_NUM_OPERAND_TYPES,
|
|
|
|
|
2015-05-22 17:26:19 +00:00
|
|
|
SPV_FORCE_32_BIT_ENUM(spv_operand_type_t)
|
|
|
|
} spv_operand_type_t;
|
|
|
|
|
|
|
|
typedef enum spv_ext_inst_type_t {
|
2015-11-09 23:55:42 +00:00
|
|
|
SPV_EXT_INST_TYPE_NONE = 0,
|
2015-05-22 17:26:19 +00:00
|
|
|
SPV_EXT_INST_TYPE_GLSL_STD_450,
|
2015-10-14 21:02:11 +00:00
|
|
|
SPV_EXT_INST_TYPE_OPENCL_STD,
|
2017-06-21 07:58:00 +00:00
|
|
|
SPV_EXT_INST_TYPE_SPV_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER,
|
|
|
|
SPV_EXT_INST_TYPE_SPV_AMD_SHADER_TRINARY_MINMAX,
|
2017-03-21 16:43:26 +00:00
|
|
|
SPV_EXT_INST_TYPE_SPV_AMD_GCN_SHADER,
|
2017-06-21 07:58:00 +00:00
|
|
|
SPV_EXT_INST_TYPE_SPV_AMD_SHADER_BALLOT,
|
2017-12-03 17:30:08 +00:00
|
|
|
SPV_EXT_INST_TYPE_DEBUGINFO,
|
2015-05-22 17:26:19 +00:00
|
|
|
|
|
|
|
SPV_FORCE_32_BIT_ENUM(spv_ext_inst_type_t)
|
|
|
|
} spv_ext_inst_type_t;
|
|
|
|
|
2015-11-11 21:59:31 +00:00
|
|
|
// This determines at a high level the kind of a binary-encoded literal
|
|
|
|
// number, but not the bit width.
|
|
|
|
// In principle, these could probably be folded into new entries in
|
|
|
|
// spv_operand_type_t. But then we'd have some special case differences
|
|
|
|
// between the assembler and disassembler.
|
|
|
|
typedef enum spv_number_kind_t {
|
|
|
|
SPV_NUMBER_NONE = 0, // The default for value initialization.
|
|
|
|
SPV_NUMBER_UNSIGNED_INT,
|
|
|
|
SPV_NUMBER_SIGNED_INT,
|
|
|
|
SPV_NUMBER_FLOATING,
|
|
|
|
} spv_number_kind_t;
|
|
|
|
|
2017-04-11 23:46:15 +00:00
|
|
|
typedef enum spv_text_to_binary_options_t {
|
|
|
|
SPV_TEXT_TO_BINARY_OPTION_NONE = SPV_BIT(0),
|
|
|
|
// Numeric IDs in the binary will have the same values as in the source.
|
|
|
|
// Non-numeric IDs are allocated by filling in the gaps, starting with 1
|
|
|
|
// and going up.
|
|
|
|
SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS = SPV_BIT(1),
|
|
|
|
SPV_FORCE_32_BIT_ENUM(spv_text_to_binary_options_t)
|
|
|
|
} spv_text_to_binary_options_t;
|
|
|
|
|
2015-05-22 17:26:19 +00:00
|
|
|
typedef enum spv_binary_to_text_options_t {
|
|
|
|
SPV_BINARY_TO_TEXT_OPTION_NONE = SPV_BIT(0),
|
|
|
|
SPV_BINARY_TO_TEXT_OPTION_PRINT = SPV_BIT(1),
|
|
|
|
SPV_BINARY_TO_TEXT_OPTION_COLOR = SPV_BIT(2),
|
2015-11-12 18:53:27 +00:00
|
|
|
SPV_BINARY_TO_TEXT_OPTION_INDENT = SPV_BIT(3),
|
2016-01-18 20:29:15 +00:00
|
|
|
SPV_BINARY_TO_TEXT_OPTION_SHOW_BYTE_OFFSET = SPV_BIT(4),
|
2016-06-27 19:06:41 +00:00
|
|
|
// Do not output the module header as leading comments in the assembly.
|
|
|
|
SPV_BINARY_TO_TEXT_OPTION_NO_HEADER = SPV_BIT(5),
|
2016-07-08 18:29:52 +00:00
|
|
|
// Use friendly names where possible. The heuristic may expand over
|
|
|
|
// time, but will use common names for scalar types, and debug names from
|
|
|
|
// OpName instructions.
|
|
|
|
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES = SPV_BIT(6),
|
2015-05-22 17:26:19 +00:00
|
|
|
SPV_FORCE_32_BIT_ENUM(spv_binary_to_text_options_t)
|
|
|
|
} spv_binary_to_text_options_t;
|
|
|
|
|
|
|
|
// Structures
|
|
|
|
|
2015-11-11 21:59:31 +00:00
|
|
|
// Information about an operand parsed from a binary SPIR-V module.
|
|
|
|
// Note that the values are not included. You still need access to the binary
|
|
|
|
// to extract the values.
|
|
|
|
typedef struct spv_parsed_operand_t {
|
|
|
|
// Location of the operand, in words from the start of the instruction.
|
|
|
|
uint16_t offset;
|
|
|
|
// Number of words occupied by this operand.
|
|
|
|
uint16_t num_words;
|
|
|
|
// The "concrete" operand type. See the definition of spv_operand_type_t
|
|
|
|
// for details.
|
|
|
|
spv_operand_type_t type;
|
|
|
|
// If type is a literal number type, then number_kind says whether it's
|
|
|
|
// a signed integer, an unsigned integer, or a floating point number.
|
|
|
|
spv_number_kind_t number_kind;
|
|
|
|
// The number of bits for a literal number type.
|
|
|
|
uint32_t number_bit_width;
|
|
|
|
} spv_parsed_operand_t;
|
|
|
|
|
|
|
|
// An instruction parsed from a binary SPIR-V module.
|
|
|
|
typedef struct spv_parsed_instruction_t {
|
2015-11-20 19:21:10 +00:00
|
|
|
// An array of words for this instruction, in native endianness.
|
|
|
|
const uint32_t* words;
|
|
|
|
// The number of words in this instruction.
|
|
|
|
uint16_t num_words;
|
2016-03-31 21:26:31 +00:00
|
|
|
uint16_t opcode;
|
2015-11-11 21:59:31 +00:00
|
|
|
// The extended instruction type, if opcode is OpExtInst. Otherwise
|
|
|
|
// this is the "none" value.
|
|
|
|
spv_ext_inst_type_t ext_inst_type;
|
|
|
|
// The type id, or 0 if this instruction doesn't have one.
|
|
|
|
uint32_t type_id;
|
|
|
|
// The result id, or 0 if this instruction doesn't have one.
|
|
|
|
uint32_t result_id;
|
|
|
|
// The array of parsed operands.
|
|
|
|
const spv_parsed_operand_t* operands;
|
|
|
|
uint16_t num_operands;
|
|
|
|
} spv_parsed_instruction_t;
|
|
|
|
|
2015-11-11 17:40:25 +00:00
|
|
|
typedef struct spv_const_binary_t {
|
|
|
|
const uint32_t* code;
|
|
|
|
const size_t wordCount;
|
|
|
|
} spv_const_binary_t;
|
2015-05-22 17:26:19 +00:00
|
|
|
|
|
|
|
typedef struct spv_binary_t {
|
2015-11-11 16:05:07 +00:00
|
|
|
uint32_t* code;
|
|
|
|
size_t wordCount;
|
2015-05-22 17:26:19 +00:00
|
|
|
} spv_binary_t;
|
|
|
|
|
|
|
|
typedef struct spv_text_t {
|
2015-11-02 14:41:20 +00:00
|
|
|
const char* str;
|
2015-11-11 16:05:07 +00:00
|
|
|
size_t length;
|
2015-05-22 17:26:19 +00:00
|
|
|
} spv_text_t;
|
|
|
|
|
|
|
|
typedef struct spv_position_t {
|
2015-11-11 16:05:07 +00:00
|
|
|
size_t line;
|
|
|
|
size_t column;
|
|
|
|
size_t index;
|
2015-05-22 17:26:19 +00:00
|
|
|
} spv_position_t;
|
|
|
|
|
|
|
|
typedef struct spv_diagnostic_t {
|
|
|
|
spv_position_t position;
|
2015-11-02 14:41:20 +00:00
|
|
|
char* error;
|
2015-09-01 22:05:14 +00:00
|
|
|
bool isTextSource;
|
2015-05-22 17:26:19 +00:00
|
|
|
} spv_diagnostic_t;
|
|
|
|
|
2015-11-12 18:48:30 +00:00
|
|
|
// Opaque struct containing the context used to operate on a SPIR-V module.
|
2015-11-13 16:00:10 +00:00
|
|
|
// Its object is used by various translation API functions.
|
2016-03-01 15:17:18 +00:00
|
|
|
typedef struct spv_context_t spv_context_t;
|
2015-11-12 18:48:30 +00:00
|
|
|
|
2017-02-15 18:29:33 +00:00
|
|
|
typedef struct spv_validator_options_t spv_validator_options_t;
|
|
|
|
|
2015-05-22 17:26:19 +00:00
|
|
|
// Type Definitions
|
|
|
|
|
2015-11-11 16:05:07 +00:00
|
|
|
typedef spv_const_binary_t* spv_const_binary;
|
2015-11-02 14:41:20 +00:00
|
|
|
typedef spv_binary_t* spv_binary;
|
|
|
|
typedef spv_text_t* spv_text;
|
|
|
|
typedef spv_position_t* spv_position;
|
|
|
|
typedef spv_diagnostic_t* spv_diagnostic;
|
2015-11-12 18:48:30 +00:00
|
|
|
typedef const spv_context_t* spv_const_context;
|
|
|
|
typedef spv_context_t* spv_context;
|
2017-02-15 18:29:33 +00:00
|
|
|
typedef spv_validator_options_t* spv_validator_options;
|
|
|
|
typedef const spv_validator_options_t* spv_const_validator_options;
|
2015-05-22 17:26:19 +00:00
|
|
|
|
|
|
|
// Platform API
|
|
|
|
|
2016-04-22 00:50:11 +00:00
|
|
|
// Returns the SPIRV-Tools software version as a null-terminated string.
|
|
|
|
// The contents of the underlying storage is valid for the remainder of
|
|
|
|
// the process.
|
2018-03-23 20:17:52 +00:00
|
|
|
SPIRV_TOOLS_EXPORT const char* spvSoftwareVersionString(void);
|
2016-04-22 00:50:11 +00:00
|
|
|
// Returns a null-terminated string containing the name of the project,
|
|
|
|
// the software version string, and commit details.
|
|
|
|
// The contents of the underlying storage is valid for the remainder of
|
|
|
|
// the process.
|
2018-03-23 20:17:52 +00:00
|
|
|
SPIRV_TOOLS_EXPORT const char* spvSoftwareVersionDetailsString(void);
|
2016-04-22 00:50:11 +00:00
|
|
|
|
2016-03-31 16:16:51 +00:00
|
|
|
// Certain target environments impose additional restrictions on SPIR-V, so it's
|
|
|
|
// often necessary to specify which one applies. SPV_ENV_UNIVERSAL means
|
|
|
|
// environment-agnostic SPIR-V.
|
|
|
|
typedef enum {
|
2016-04-11 19:31:00 +00:00
|
|
|
SPV_ENV_UNIVERSAL_1_0, // SPIR-V 1.0 latest revision, no other restrictions.
|
|
|
|
SPV_ENV_VULKAN_1_0, // Vulkan 1.0 latest revision.
|
2016-04-19 02:25:35 +00:00
|
|
|
SPV_ENV_UNIVERSAL_1_1, // SPIR-V 1.1 latest revision, no other restrictions.
|
2017-11-29 23:49:23 +00:00
|
|
|
SPV_ENV_OPENCL_2_1, // OpenCL Full Profile 2.1 latest revision.
|
|
|
|
SPV_ENV_OPENCL_2_2, // OpenCL Full Profile 2.2 latest revision.
|
2016-09-02 22:06:18 +00:00
|
|
|
SPV_ENV_OPENGL_4_0, // OpenGL 4.0 plus GL_ARB_gl_spirv, latest revisions.
|
|
|
|
SPV_ENV_OPENGL_4_1, // OpenGL 4.1 plus GL_ARB_gl_spirv, latest revisions.
|
|
|
|
SPV_ENV_OPENGL_4_2, // OpenGL 4.2 plus GL_ARB_gl_spirv, latest revisions.
|
|
|
|
SPV_ENV_OPENGL_4_3, // OpenGL 4.3 plus GL_ARB_gl_spirv, latest revisions.
|
2016-08-05 22:19:30 +00:00
|
|
|
// There is no variant for OpenGL 4.4.
|
2017-03-14 16:43:41 +00:00
|
|
|
SPV_ENV_OPENGL_4_5, // OpenGL 4.5 plus GL_ARB_gl_spirv, latest revisions.
|
|
|
|
SPV_ENV_UNIVERSAL_1_2, // SPIR-V 1.2, latest revision, no other restrictions.
|
2017-11-29 23:49:23 +00:00
|
|
|
SPV_ENV_OPENCL_1_2, // OpenCL Full Profile 1.2 plus cl_khr_il_program,
|
|
|
|
// latest revision.
|
|
|
|
SPV_ENV_OPENCL_EMBEDDED_1_2, // OpenCL Embedded Profile 1.2 plus
|
|
|
|
// cl_khr_il_program, latest revision.
|
|
|
|
SPV_ENV_OPENCL_2_0, // OpenCL Full Profile 2.0 plus cl_khr_il_program,
|
|
|
|
// latest revision.
|
|
|
|
SPV_ENV_OPENCL_EMBEDDED_2_0, // OpenCL Embedded Profile 2.0 plus
|
|
|
|
// cl_khr_il_program, latest revision.
|
|
|
|
SPV_ENV_OPENCL_EMBEDDED_2_1, // OpenCL Embedded Profile 2.1 latest revision.
|
|
|
|
SPV_ENV_OPENCL_EMBEDDED_2_2, // OpenCL Embedded Profile 2.2 latest revision.
|
2018-02-09 19:29:02 +00:00
|
|
|
SPV_ENV_UNIVERSAL_1_3, // SPIR-V 1.3 latest revision, no other restrictions.
|
2018-04-06 18:15:27 +00:00
|
|
|
SPV_ENV_VULKAN_1_1, // Vulkan 1.1 latest revision.
|
2018-06-20 17:29:38 +00:00
|
|
|
SPV_ENV_WEBGPU_0, // Work in progress WebGPU 1.0.
|
2016-03-31 16:16:51 +00:00
|
|
|
} spv_target_env;
|
|
|
|
|
2017-02-15 18:29:33 +00:00
|
|
|
// SPIR-V Validator can be parameterized with the following Universal Limits.
|
|
|
|
typedef enum {
|
|
|
|
spv_validator_limit_max_struct_members,
|
|
|
|
spv_validator_limit_max_struct_depth,
|
|
|
|
spv_validator_limit_max_local_variables,
|
|
|
|
spv_validator_limit_max_global_variables,
|
|
|
|
spv_validator_limit_max_switch_branches,
|
|
|
|
spv_validator_limit_max_function_args,
|
|
|
|
spv_validator_limit_max_control_flow_nesting_depth,
|
|
|
|
spv_validator_limit_max_access_chain_indexes,
|
|
|
|
} spv_validator_limit;
|
|
|
|
|
2016-03-31 21:26:31 +00:00
|
|
|
// Returns a string describing the given SPIR-V target environment.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT const char* spvTargetEnvDescription(spv_target_env env);
|
2016-03-31 21:26:31 +00:00
|
|
|
|
2016-03-31 16:16:51 +00:00
|
|
|
// Creates a context object. Returns null if env is invalid.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_context spvContextCreate(spv_target_env env);
|
2015-11-12 18:48:30 +00:00
|
|
|
|
|
|
|
// Destroys the given context object.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT void spvContextDestroy(spv_context context);
|
2015-11-12 18:48:30 +00:00
|
|
|
|
2017-02-15 18:29:33 +00:00
|
|
|
// Creates a Validator options object with default options. Returns a valid
|
|
|
|
// options object. The object remains valid until it is passed into
|
|
|
|
// spvValidatorOptionsDestroy.
|
2018-03-23 20:17:52 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_validator_options spvValidatorOptionsCreate(void);
|
2017-02-15 18:29:33 +00:00
|
|
|
|
|
|
|
// Destroys the given Validator options object.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT void spvValidatorOptionsDestroy(
|
|
|
|
spv_validator_options options);
|
2017-02-15 18:29:33 +00:00
|
|
|
|
|
|
|
// Records the maximum Universal Limit that is considered valid in the given
|
|
|
|
// Validator options object. <options> argument must be a valid options object.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetUniversalLimit(
|
|
|
|
spv_validator_options options, spv_validator_limit limit_type,
|
|
|
|
uint32_t limit);
|
2017-02-15 18:29:33 +00:00
|
|
|
|
2017-10-24 19:13:13 +00:00
|
|
|
// Record whether or not the validator should relax the rules on types for
|
|
|
|
// stores to structs. When relaxed, it will allow a type mismatch as long as
|
|
|
|
// the types are structs with the same layout. Two structs have the same layout
|
|
|
|
// if
|
|
|
|
//
|
|
|
|
// 1) the members of the structs are either the same type or are structs with
|
|
|
|
// same layout, and
|
|
|
|
//
|
|
|
|
// 2) the decorations that affect the memory layout are identical for both
|
|
|
|
// types. Other decorations are not relevant.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxStoreStruct(
|
|
|
|
spv_validator_options options, bool val);
|
2017-10-24 19:13:13 +00:00
|
|
|
|
2018-01-07 15:50:01 +00:00
|
|
|
// Records whether or not the validator should relax the rules on pointer usage
|
|
|
|
// in logical addressing mode.
|
|
|
|
//
|
|
|
|
// When relaxed, it will allow the following usage cases of pointers:
|
|
|
|
// 1) OpVariable allocating an object whose type is a pointer type
|
|
|
|
// 2) OpReturnValue returning a pointer value
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxLogicalPointer(
|
|
|
|
spv_validator_options options, bool val);
|
2018-01-07 15:50:01 +00:00
|
|
|
|
2018-05-17 07:49:19 +00:00
|
|
|
// Records whether or not the validator should relax the rules on block layout.
|
|
|
|
//
|
2018-07-11 20:53:19 +00:00
|
|
|
// When relaxed, it will enable VK_KHR_relaxed_block_layout when validating
|
|
|
|
// standard uniform/storage block layout.
|
2018-05-17 07:49:19 +00:00
|
|
|
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxBlockLayout(
|
|
|
|
spv_validator_options options, bool val);
|
|
|
|
|
2018-07-11 20:53:19 +00:00
|
|
|
// Records whether or not the validator should skip validating standard
|
|
|
|
// uniform/storage block layout.
|
|
|
|
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetSkipBlockLayout(
|
|
|
|
spv_validator_options options, bool val);
|
|
|
|
|
2015-11-11 17:14:36 +00:00
|
|
|
// Encodes the given SPIR-V assembly text to its binary representation. The
|
|
|
|
// length parameter specifies the number of bytes for text. Encoded binary will
|
2016-09-02 22:06:18 +00:00
|
|
|
// be stored into *binary. Any error will be written into *diagnostic if
|
|
|
|
// diagnostic is non-null. The generated binary is independent of the context
|
|
|
|
// and may outlive it.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_result_t spvTextToBinary(const spv_const_context context,
|
|
|
|
const char* text,
|
|
|
|
const size_t length,
|
|
|
|
spv_binary* binary,
|
|
|
|
spv_diagnostic* diagnostic);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2017-04-11 23:46:15 +00:00
|
|
|
// Encodes the given SPIR-V assembly text to its binary representation. Same as
|
|
|
|
// spvTextToBinary but with options. The options parameter is a bit field of
|
|
|
|
// spv_text_to_binary_options_t.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_result_t spvTextToBinaryWithOptions(
|
|
|
|
const spv_const_context context, const char* text, const size_t length,
|
|
|
|
const uint32_t options, spv_binary* binary, spv_diagnostic* diagnostic);
|
2017-04-11 23:46:15 +00:00
|
|
|
|
2015-11-13 16:00:10 +00:00
|
|
|
// Frees an allocated text stream. This is a no-op if the text parameter
|
2015-11-11 17:14:36 +00:00
|
|
|
// is a null pointer.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT void spvTextDestroy(spv_text text);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-11-11 17:14:36 +00:00
|
|
|
// Decodes the given SPIR-V binary representation to its assembly text. The
|
|
|
|
// word_count parameter specifies the number of words for binary. The options
|
|
|
|
// parameter is a bit field of spv_binary_to_text_options_t. Decoded text will
|
2016-09-02 22:06:18 +00:00
|
|
|
// be stored into *text. Any error will be written into *diagnostic if
|
|
|
|
// diagnostic is non-null.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_result_t spvBinaryToText(const spv_const_context context,
|
|
|
|
const uint32_t* binary,
|
|
|
|
const size_t word_count,
|
|
|
|
const uint32_t options,
|
|
|
|
spv_text* text,
|
|
|
|
spv_diagnostic* diagnostic);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-11-11 17:14:36 +00:00
|
|
|
// Frees a binary stream from memory. This is a no-op if binary is a null
|
|
|
|
// pointer.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT void spvBinaryDestroy(spv_binary binary);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-04-04 19:55:05 +00:00
|
|
|
// Validates a SPIR-V binary for correctness. Any errors will be written into
|
2016-09-02 22:06:18 +00:00
|
|
|
// *diagnostic if diagnostic is non-null.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_result_t spvValidate(const spv_const_context context,
|
|
|
|
const spv_const_binary binary,
|
|
|
|
spv_diagnostic* diagnostic);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2017-02-15 18:29:33 +00:00
|
|
|
// Validates a SPIR-V binary for correctness. Uses the provided Validator
|
|
|
|
// options. Any errors will be written into *diagnostic if diagnostic is
|
|
|
|
// non-null.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_result_t spvValidateWithOptions(
|
|
|
|
const spv_const_context context, const spv_const_validator_options options,
|
|
|
|
const spv_const_binary binary, spv_diagnostic* diagnostic);
|
2017-02-15 18:29:33 +00:00
|
|
|
|
2016-09-15 21:32:44 +00:00
|
|
|
// Validates a raw SPIR-V binary for correctness. Any errors will be written
|
|
|
|
// into *diagnostic if diagnostic is non-null.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_result_t
|
|
|
|
spvValidateBinary(const spv_const_context context, const uint32_t* words,
|
|
|
|
const size_t num_words, spv_diagnostic* diagnostic);
|
2016-09-15 21:32:44 +00:00
|
|
|
|
2015-11-11 17:14:36 +00:00
|
|
|
// Creates a diagnostic object. The position parameter specifies the location in
|
|
|
|
// the text/binary stream. The message parameter, copied into the diagnostic
|
|
|
|
// object, contains the error message to display.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_diagnostic
|
|
|
|
spvDiagnosticCreate(const spv_position position, const char* message);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-01-11 17:28:19 +00:00
|
|
|
// Destroys a diagnostic object. This is a no-op if diagnostic is a null
|
|
|
|
// pointer.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT void spvDiagnosticDestroy(spv_diagnostic diagnostic);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-11-11 17:14:36 +00:00
|
|
|
// Prints the diagnostic to stderr.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_result_t
|
|
|
|
spvDiagnosticPrint(const spv_diagnostic diagnostic);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-11-11 21:59:31 +00:00
|
|
|
// The binary parser interface.
|
|
|
|
|
|
|
|
// A pointer to a function that accepts a parsed SPIR-V header.
|
|
|
|
// The integer arguments are the 32-bit words from the header, as specified
|
|
|
|
// in SPIR-V 1.0 Section 2.3 Table 1.
|
|
|
|
// The function should return SPV_SUCCESS if parsing should continue.
|
|
|
|
typedef spv_result_t (*spv_parsed_header_fn_t)(
|
|
|
|
void* user_data, spv_endianness_t endian, uint32_t magic, uint32_t version,
|
|
|
|
uint32_t generator, uint32_t id_bound, uint32_t reserved);
|
|
|
|
|
|
|
|
// A pointer to a function that accepts a parsed SPIR-V instruction.
|
|
|
|
// The parsed_instruction value is transient: it may be overwritten
|
2015-11-20 19:21:10 +00:00
|
|
|
// or released immediately after the function has returned. That also
|
|
|
|
// applies to the words array member of the parsed instruction. The
|
|
|
|
// function should return SPV_SUCCESS if and only if parsing should
|
|
|
|
// continue.
|
2015-11-11 21:59:31 +00:00
|
|
|
typedef spv_result_t (*spv_parsed_instruction_fn_t)(
|
|
|
|
void* user_data, const spv_parsed_instruction_t* parsed_instruction);
|
|
|
|
|
|
|
|
// Parses a SPIR-V binary, specified as counted sequence of 32-bit words.
|
2015-11-24 23:37:24 +00:00
|
|
|
// Parsing feedback is provided via two callbacks provided as function
|
|
|
|
// pointers. Each callback function pointer can be a null pointer, in
|
|
|
|
// which case it is never called. Otherwise, in a valid parse the
|
2015-11-11 21:59:31 +00:00
|
|
|
// parsed-header callback is called once, and then the parsed-instruction
|
|
|
|
// callback once for each instruction in the stream. The user_data parameter
|
|
|
|
// is supplied as context to the callbacks. Returns SPV_SUCCESS on successful
|
|
|
|
// parse where the callbacks always return SPV_SUCCESS. For an invalid parse,
|
2016-09-14 16:48:38 +00:00
|
|
|
// returns a status code other than SPV_SUCCESS, and if diagnostic is non-null
|
|
|
|
// also emits a diagnostic. If a callback returns anything other than
|
|
|
|
// SPV_SUCCESS, then that status code is returned, no further callbacks are
|
|
|
|
// issued, and no additional diagnostics are emitted.
|
2018-02-02 22:37:14 +00:00
|
|
|
SPIRV_TOOLS_EXPORT spv_result_t spvBinaryParse(
|
|
|
|
const spv_const_context context, void* user_data, const uint32_t* words,
|
|
|
|
const size_t num_words, spv_parsed_header_fn_t parse_header,
|
|
|
|
spv_parsed_instruction_fn_t parse_instruction, spv_diagnostic* diagnostic);
|
2015-11-11 21:59:31 +00:00
|
|
|
|
2015-05-22 17:26:19 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-17 19:44:00 +00:00
|
|
|
#endif // SPIRV_TOOLS_LIBSPIRV_H_
|