2021-01-27 08:29:44 -08:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Matteo Bruni for CodeWeavers
|
|
|
|
* Copyright 2019-2020 Zebediah Figura for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VKD3D_SHADER_HLSL_H
|
|
|
|
#define __VKD3D_SHADER_HLSL_H
|
|
|
|
|
|
|
|
#include "vkd3d_shader_private.h"
|
|
|
|
#include "rbtree.h"
|
2021-08-19 16:44:27 -07:00
|
|
|
#include "vkd3d_d3dcommon.h"
|
2021-08-09 19:56:17 -07:00
|
|
|
#include "vkd3d_d3dx9shader.h"
|
2021-08-19 16:44:27 -07:00
|
|
|
#include "sm4.h"
|
2021-01-27 08:29:44 -08:00
|
|
|
|
|
|
|
/* The general IR structure is inspired by Mesa GLSL hir, even though the code
|
|
|
|
* ends up being quite different in practice. Anyway, here comes the relevant
|
|
|
|
* licensing information.
|
|
|
|
*
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define HLSL_SWIZZLE_X (0u)
|
|
|
|
#define HLSL_SWIZZLE_Y (1u)
|
|
|
|
#define HLSL_SWIZZLE_Z (2u)
|
|
|
|
#define HLSL_SWIZZLE_W (3u)
|
|
|
|
|
|
|
|
#define HLSL_SWIZZLE(x, y, z, w) \
|
|
|
|
(((HLSL_SWIZZLE_ ## x) << 0) \
|
|
|
|
| ((HLSL_SWIZZLE_ ## y) << 2) \
|
|
|
|
| ((HLSL_SWIZZLE_ ## z) << 4) \
|
|
|
|
| ((HLSL_SWIZZLE_ ## w) << 6))
|
|
|
|
|
|
|
|
enum hlsl_type_class
|
|
|
|
{
|
|
|
|
HLSL_CLASS_SCALAR,
|
|
|
|
HLSL_CLASS_VECTOR,
|
|
|
|
HLSL_CLASS_MATRIX,
|
|
|
|
HLSL_CLASS_LAST_NUMERIC = HLSL_CLASS_MATRIX,
|
|
|
|
HLSL_CLASS_STRUCT,
|
|
|
|
HLSL_CLASS_ARRAY,
|
|
|
|
HLSL_CLASS_OBJECT,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum hlsl_base_type
|
|
|
|
{
|
|
|
|
HLSL_TYPE_FLOAT,
|
|
|
|
HLSL_TYPE_HALF,
|
|
|
|
HLSL_TYPE_DOUBLE,
|
|
|
|
HLSL_TYPE_INT,
|
|
|
|
HLSL_TYPE_UINT,
|
|
|
|
HLSL_TYPE_BOOL,
|
|
|
|
HLSL_TYPE_LAST_SCALAR = HLSL_TYPE_BOOL,
|
|
|
|
HLSL_TYPE_SAMPLER,
|
|
|
|
HLSL_TYPE_TEXTURE,
|
2021-08-12 19:03:26 -07:00
|
|
|
HLSL_TYPE_UAV,
|
2021-01-27 08:29:44 -08:00
|
|
|
HLSL_TYPE_PIXELSHADER,
|
|
|
|
HLSL_TYPE_VERTEXSHADER,
|
|
|
|
HLSL_TYPE_STRING,
|
|
|
|
HLSL_TYPE_VOID,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum hlsl_sampler_dim
|
|
|
|
{
|
|
|
|
HLSL_SAMPLER_DIM_GENERIC,
|
|
|
|
HLSL_SAMPLER_DIM_1D,
|
|
|
|
HLSL_SAMPLER_DIM_2D,
|
|
|
|
HLSL_SAMPLER_DIM_3D,
|
|
|
|
HLSL_SAMPLER_DIM_CUBE,
|
2022-01-27 10:31:23 -08:00
|
|
|
HLSL_SAMPLER_DIM_LAST_SAMPLER = HLSL_SAMPLER_DIM_CUBE,
|
|
|
|
HLSL_SAMPLER_DIM_1DARRAY,
|
|
|
|
HLSL_SAMPLER_DIM_2DARRAY,
|
|
|
|
HLSL_SAMPLER_DIM_2DMS,
|
|
|
|
HLSL_SAMPLER_DIM_2DMSARRAY,
|
|
|
|
HLSL_SAMPLER_DIM_CUBEARRAY,
|
|
|
|
HLSL_SAMPLER_DIM_MAX = HLSL_SAMPLER_DIM_CUBEARRAY,
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum hlsl_matrix_majority
|
|
|
|
{
|
|
|
|
HLSL_COLUMN_MAJOR,
|
|
|
|
HLSL_ROW_MAJOR
|
|
|
|
};
|
|
|
|
|
2022-11-14 08:48:55 -08:00
|
|
|
/* An HLSL source-level data type, including anonymous structs and typedefs. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_type
|
|
|
|
{
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Item entry in hlsl_ctx->types. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct list entry;
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Item entry in hlsl_scope->types. hlsl_type->name is used as key (if not NULL). */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct rb_entry scope_entry;
|
2022-11-14 08:48:55 -08:00
|
|
|
|
2021-01-27 08:29:44 -08:00
|
|
|
enum hlsl_type_class type;
|
2022-11-14 08:48:55 -08:00
|
|
|
/* If type is <= HLSL_CLASS_LAST_NUMERIC, then base_type is <= HLSL_TYPE_LAST_SCALAR.
|
|
|
|
* If type is HLSL_CLASS_OBJECT, then base_type is > HLSL_TYPE_LAST_SCALAR.
|
|
|
|
* Otherwise, base_type is not used. */
|
2021-01-27 08:29:44 -08:00
|
|
|
enum hlsl_base_type base_type;
|
2022-11-14 08:48:55 -08:00
|
|
|
|
|
|
|
/* If base_type is HLSL_TYPE_SAMPLER, then sampler_dim is <= HLSL_SAMPLER_DIM_LAST_SAMPLER.
|
|
|
|
* If base_type is HLSL_TYPE_TEXTURE, then sampler_dim can have any value of the enum.
|
|
|
|
* If base_type is HLSL_TYPE_UAV, them sampler_dim must be one of HLSL_SAMPLER_DIM_1D,
|
|
|
|
* HLSL_SAMPLER_DIM_2D, HLSL_SAMPLER_DIM_3D, HLSL_SAMPLER_DIM_1DARRAY, or HLSL_SAMPLER_DIM_2DARRAY.
|
|
|
|
* Otherwise, sampler_dim is not used */
|
2021-01-27 08:29:44 -08:00
|
|
|
enum hlsl_sampler_dim sampler_dim;
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Name, in case the type is a named struct or a typedef. */
|
2021-01-27 08:29:44 -08:00
|
|
|
const char *name;
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Bitfield for storing type modifiers, subset of HLSL_TYPE_MODIFIERS_MASK.
|
|
|
|
* Modifiers that don't fall inside this mask are to be stored in the variable in
|
|
|
|
* hlsl_ir_var.modifiers, or in the struct field in hlsl_ir_field.modifiers. */
|
2021-01-27 08:29:44 -08:00
|
|
|
unsigned int modifiers;
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Size of the type values on each dimension. For non-numeric types, they are set for the
|
|
|
|
* convenience of the sm1/sm4 backends.
|
|
|
|
* If type is HLSL_CLASS_SCALAR, then both dimx = 1 and dimy = 1.
|
|
|
|
* If type is HLSL_CLASS_VECTOR, then dimx is the size of the vector, and dimy = 1.
|
|
|
|
* If type is HLSL_CLASS_MATRIX, then dimx is the number of columns, and dimy the number of rows.
|
|
|
|
* If type is HLSL_CLASS_ARRAY, then dimx and dimy have the same value as in the type of the array elements.
|
|
|
|
* If type is HLSL_CLASS_STRUCT, then dimx is the sum of (dimx * dimy) of every component, and dimy = 1.
|
|
|
|
* If type is HLSL_CLASS_OBJECT, dimx and dimy depend on the base_type:
|
|
|
|
* If base_type is HLSL_TYPE_SAMPLER, then both dimx = 1 and dimy = 1.
|
|
|
|
* If base_type is HLSL_TYPE_TEXTURE, then dimx = 4 and dimy = 1.
|
|
|
|
* If base_type is HLSL_TYPE_UAV, then dimx is the dimx of e.resource_format, and dimy = 1.
|
|
|
|
* Otherwise both dimx = 1 and dimy = 1. */
|
2021-01-27 08:29:44 -08:00
|
|
|
unsigned int dimx;
|
|
|
|
unsigned int dimy;
|
2022-11-14 08:48:55 -08:00
|
|
|
|
2021-01-27 08:29:44 -08:00
|
|
|
union
|
|
|
|
{
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Additional information if type is HLSL_CLASS_STRUCT. */
|
2022-07-14 18:23:43 -07:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct hlsl_struct_field *fields;
|
|
|
|
size_t field_count;
|
|
|
|
} record;
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Additional information if type is HLSL_CLASS_ARRAY. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct hlsl_type *type;
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Array lenght, or HLSL_ARRAY_ELEMENTS_COUNT_IMPLICIT if it is unknown yet while parsing. */
|
2021-01-27 08:29:44 -08:00
|
|
|
unsigned int elements_count;
|
|
|
|
} array;
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Format of the data contained within the type if the base_type is HLSL_TYPE_TEXTURE or
|
|
|
|
* HLSL_TYPE_UAV. */
|
2021-10-07 19:58:55 -07:00
|
|
|
struct hlsl_type *resource_format;
|
2021-01-27 08:29:44 -08:00
|
|
|
} e;
|
2021-04-15 17:03:46 -07:00
|
|
|
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Number of numeric register components used by one value of this type (4 components make 1
|
|
|
|
* register).
|
|
|
|
* If type is HLSL_CLASS_STRUCT or HLSL_CLASS_ARRAY, this value includes the reg_size of
|
|
|
|
* their elements and padding (which varies according to the backend).
|
|
|
|
* This value is 0 for types without numeric components, like objects. */
|
2021-04-15 17:03:46 -07:00
|
|
|
unsigned int reg_size;
|
2022-11-14 08:48:55 -08:00
|
|
|
/* Offset where the type's description starts in the output bytecode, in bytes. */
|
2021-07-08 19:13:19 -07:00
|
|
|
size_t bytecode_offset;
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
2021-04-27 10:14:19 -07:00
|
|
|
struct hlsl_semantic
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
uint32_t index;
|
|
|
|
};
|
|
|
|
|
2022-11-14 09:25:24 -08:00
|
|
|
/* A field within a struct type declaration, used in hlsl_type.e.fields. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_struct_field
|
|
|
|
{
|
2021-03-02 13:34:43 -08:00
|
|
|
struct vkd3d_shader_location loc;
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_type *type;
|
|
|
|
const char *name;
|
2021-04-27 10:14:19 -07:00
|
|
|
struct hlsl_semantic semantic;
|
2022-11-14 09:25:24 -08:00
|
|
|
|
|
|
|
/* Bitfield for storing modifiers that are not in HLSL_TYPE_MODIFIERS_MASK (these are stored in
|
|
|
|
* type->modifiers instead) and that also are specific to the field and not the whole variable.
|
|
|
|
* In particular, interpolation modifiers. */
|
2022-11-29 11:31:54 -08:00
|
|
|
unsigned int storage_modifiers;
|
2022-11-14 09:25:24 -08:00
|
|
|
/* Offset of the field within the type it belongs to, in numeric register components. */
|
2021-01-27 08:29:44 -08:00
|
|
|
unsigned int reg_offset;
|
2021-04-27 10:14:15 -07:00
|
|
|
|
2022-11-14 09:25:24 -08:00
|
|
|
/* Offset where the fields's name starts in the output bytecode, in bytes. */
|
2021-07-08 19:13:19 -07:00
|
|
|
size_t name_bytecode_offset;
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
2021-04-08 21:38:23 -07:00
|
|
|
struct hlsl_reg
|
|
|
|
{
|
|
|
|
uint32_t id;
|
|
|
|
unsigned int writemask;
|
|
|
|
bool allocated;
|
|
|
|
};
|
|
|
|
|
2022-11-14 17:46:17 -08:00
|
|
|
/* Types of instruction nodes for the IR.
|
|
|
|
* Each type of instruction node is associated to a struct with the same name in lower case.
|
|
|
|
* e.g. for HLSL_IR_CONSTANT there exists struct hlsl_ir_constant.
|
|
|
|
* Each one of these structs start with a struct hlsl_ir_node field, so pointers to values of these
|
|
|
|
* types can be casted seamlessly to (struct hlsl_ir_node *) and vice-versa. */
|
2021-01-27 08:29:44 -08:00
|
|
|
enum hlsl_ir_node_type
|
|
|
|
{
|
|
|
|
HLSL_IR_CONSTANT,
|
|
|
|
HLSL_IR_EXPR,
|
|
|
|
HLSL_IR_IF,
|
|
|
|
HLSL_IR_LOAD,
|
|
|
|
HLSL_IR_LOOP,
|
|
|
|
HLSL_IR_JUMP,
|
2021-10-07 19:58:57 -07:00
|
|
|
HLSL_IR_RESOURCE_LOAD,
|
2021-08-15 10:08:32 -07:00
|
|
|
HLSL_IR_RESOURCE_STORE,
|
2021-04-08 21:38:22 -07:00
|
|
|
HLSL_IR_STORE,
|
2021-01-27 08:29:44 -08:00
|
|
|
HLSL_IR_SWIZZLE,
|
|
|
|
};
|
|
|
|
|
2022-11-14 17:46:17 -08:00
|
|
|
/* Common data for every type of IR instruction node. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_ir_node
|
|
|
|
{
|
2022-11-14 17:46:17 -08:00
|
|
|
/* Item entry for storing the instruction in a list of instructions. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct list entry;
|
2022-11-14 17:46:17 -08:00
|
|
|
|
|
|
|
/* Type of node, which means that a pointer to this struct hlsl_ir_node can be casted to a
|
|
|
|
* pointer to the struct with the same name. */
|
2021-01-27 08:29:44 -08:00
|
|
|
enum hlsl_ir_node_type type;
|
2022-11-14 17:46:17 -08:00
|
|
|
/* HLSL data type of the node, when used by other nodes as a source (through an hlsl_src).
|
|
|
|
* HLSL_IR_CONSTANT, HLSL_IR_EXPR, HLSL_IR_LOAD, HLSL_IR_RESOURCE_LOAD, and HLSL_IR_SWIZZLE
|
|
|
|
* have a data type and can be used through an hlsl_src; other types of node don't. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_type *data_type;
|
|
|
|
|
2022-11-14 17:46:17 -08:00
|
|
|
/* List containing all the struct hlsl_src·s that point to this node; linked by the
|
|
|
|
* hlsl_src.entry fields. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct list uses;
|
|
|
|
|
2021-02-12 08:48:55 -08:00
|
|
|
struct vkd3d_shader_location loc;
|
2021-01-27 08:29:44 -08:00
|
|
|
|
|
|
|
/* Liveness ranges. "index" is the index of this instruction. Since this is
|
|
|
|
* essentially an SSA value, the earliest live point is the index. This is
|
|
|
|
* true even for loops, since currently we can't have a reference to a
|
|
|
|
* value generated in an earlier iteration of the loop. */
|
|
|
|
unsigned int index, last_read;
|
2022-11-14 17:46:17 -08:00
|
|
|
/* Temp. register allocated to store the result of this instruction (if any). */
|
2021-04-08 21:38:24 -07:00
|
|
|
struct hlsl_reg reg;
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
2021-10-15 14:54:10 -07:00
|
|
|
struct hlsl_block
|
|
|
|
{
|
|
|
|
struct list instrs;
|
|
|
|
};
|
|
|
|
|
2022-11-14 19:37:07 -08:00
|
|
|
/* A reference to an instruction node (struct hlsl_ir_node), usable as a field in other structs.
|
|
|
|
* struct hlsl_src is more powerful than a mere pointer to an hlsl_ir_node because it also
|
|
|
|
* contains a linked list item entry, which is used by the referenced instruction node to keep
|
|
|
|
* track of all the hlsl_src·s that reference it.
|
|
|
|
* This allows replacing any hlsl_ir_node with any other in all the places it is used, or checking
|
|
|
|
* that a node has no uses before it is removed. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_src
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node *node;
|
2022-11-14 19:37:07 -08:00
|
|
|
/* Item entry for node->uses. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct list entry;
|
|
|
|
};
|
|
|
|
|
2021-08-16 12:52:10 -07:00
|
|
|
struct hlsl_attribute
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
struct list instrs;
|
|
|
|
struct vkd3d_shader_location loc;
|
|
|
|
unsigned int args_count;
|
|
|
|
struct hlsl_src args[];
|
|
|
|
};
|
|
|
|
|
2021-01-27 08:29:44 -08:00
|
|
|
#define HLSL_STORAGE_EXTERN 0x00000001
|
|
|
|
#define HLSL_STORAGE_NOINTERPOLATION 0x00000002
|
|
|
|
#define HLSL_MODIFIER_PRECISE 0x00000004
|
|
|
|
#define HLSL_STORAGE_SHARED 0x00000008
|
|
|
|
#define HLSL_STORAGE_GROUPSHARED 0x00000010
|
|
|
|
#define HLSL_STORAGE_STATIC 0x00000020
|
|
|
|
#define HLSL_STORAGE_UNIFORM 0x00000040
|
2022-12-12 15:17:53 -08:00
|
|
|
#define HLSL_MODIFIER_VOLATILE 0x00000080
|
2021-01-27 08:29:44 -08:00
|
|
|
#define HLSL_MODIFIER_CONST 0x00000100
|
|
|
|
#define HLSL_MODIFIER_ROW_MAJOR 0x00000200
|
|
|
|
#define HLSL_MODIFIER_COLUMN_MAJOR 0x00000400
|
|
|
|
#define HLSL_STORAGE_IN 0x00000800
|
|
|
|
#define HLSL_STORAGE_OUT 0x00001000
|
|
|
|
|
2022-12-12 15:17:53 -08:00
|
|
|
#define HLSL_TYPE_MODIFIERS_MASK (HLSL_MODIFIER_PRECISE | HLSL_MODIFIER_VOLATILE | \
|
2021-01-27 08:29:44 -08:00
|
|
|
HLSL_MODIFIER_CONST | HLSL_MODIFIER_ROW_MAJOR | \
|
|
|
|
HLSL_MODIFIER_COLUMN_MAJOR)
|
|
|
|
|
|
|
|
#define HLSL_MODIFIERS_MAJORITY_MASK (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)
|
|
|
|
|
2022-08-08 15:11:03 -07:00
|
|
|
#define HLSL_ARRAY_ELEMENTS_COUNT_IMPLICIT 0
|
|
|
|
|
2021-02-02 14:11:14 -08:00
|
|
|
struct hlsl_reg_reservation
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
2021-05-31 19:41:13 -07:00
|
|
|
char type;
|
2021-06-21 21:37:07 -07:00
|
|
|
unsigned int index;
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_ir_var
|
|
|
|
{
|
|
|
|
struct hlsl_type *data_type;
|
2021-02-12 08:48:55 -08:00
|
|
|
struct vkd3d_shader_location loc;
|
2021-01-27 08:29:44 -08:00
|
|
|
const char *name;
|
2021-04-27 10:14:19 -07:00
|
|
|
struct hlsl_semantic semantic;
|
2022-11-14 12:14:03 -08:00
|
|
|
/* Buffer where the variable's value is stored, in case it is uniform. */
|
2021-06-21 21:37:10 -07:00
|
|
|
struct hlsl_buffer *buffer;
|
2022-11-14 12:14:03 -08:00
|
|
|
/* Bitfield for storage modifiers (type modifiers are stored in data_type->modifiers). */
|
2022-11-29 11:10:40 -08:00
|
|
|
unsigned int storage_modifiers;
|
2022-11-14 12:14:03 -08:00
|
|
|
/* Optional register to be used as a starting point for the variable allocation, specified
|
|
|
|
* by the user via the register(·) syntax. */
|
2021-05-31 19:41:14 -07:00
|
|
|
struct hlsl_reg_reservation reg_reservation;
|
2021-01-27 08:29:44 -08:00
|
|
|
|
2022-11-14 12:14:03 -08:00
|
|
|
/* Item entry in hlsl_scope.vars. Specifically hlsl_ctx.globals.vars if the variable is global. */
|
|
|
|
struct list scope_entry;
|
|
|
|
/* Item entry in hlsl_ir_function_decl.parameters, if the variable is a function parameter. */
|
|
|
|
struct list param_entry;
|
|
|
|
/* Item entry in hlsl_ctx.extern_vars, if the variable is extern. */
|
|
|
|
struct list extern_entry;
|
|
|
|
|
|
|
|
/* Indexes of the IR instructions where the variable is first written and last read (liveness
|
|
|
|
* range). The IR instructions are numerated starting from 2, because 0 means unused, and 1
|
|
|
|
* means function entry. */
|
2021-01-27 08:29:44 -08:00
|
|
|
unsigned int first_write, last_read;
|
2022-11-14 12:14:03 -08:00
|
|
|
/* Offset where the variable's value is stored within its buffer in numeric register components.
|
|
|
|
* This in case the variable is uniform. */
|
2021-06-23 21:57:35 -07:00
|
|
|
unsigned int buffer_offset;
|
2022-11-14 12:14:03 -08:00
|
|
|
/* Register to which the variable is allocated during its lifetime.
|
|
|
|
* In case that the variable spans multiple registers, this is set to the start of the register
|
|
|
|
* range.
|
|
|
|
* The register type is inferred from the data type and the storage of the variable.
|
|
|
|
* Builtin semantics don't use the field.
|
|
|
|
* In SM4, uniforms don't use the field because they are located using the buffer's hlsl_reg
|
|
|
|
* and the buffer_offset instead.
|
|
|
|
* If the variable is an input semantic copy, the register is 'v'.
|
|
|
|
* If the variable is an output semantic copy, the register is 'o'.
|
|
|
|
* Textures are stored on 's' registers in SM1, and 't' registers in SM4.
|
|
|
|
* Samplers are stored on 's' registers.
|
|
|
|
* UAVs are stored on 'u' registers. */
|
2021-04-08 21:38:23 -07:00
|
|
|
struct hlsl_reg reg;
|
2021-03-22 15:02:37 -07:00
|
|
|
|
2021-04-27 10:14:20 -07:00
|
|
|
uint32_t is_input_semantic : 1;
|
|
|
|
uint32_t is_output_semantic : 1;
|
2021-03-22 15:02:37 -07:00
|
|
|
uint32_t is_uniform : 1;
|
2021-04-15 17:03:46 -07:00
|
|
|
uint32_t is_param : 1;
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_ir_function
|
|
|
|
{
|
|
|
|
struct rb_entry entry;
|
|
|
|
const char *name;
|
|
|
|
struct rb_tree overloads;
|
2021-02-02 14:11:17 -08:00
|
|
|
bool intrinsic;
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_ir_function_decl
|
|
|
|
{
|
|
|
|
struct hlsl_type *return_type;
|
|
|
|
struct hlsl_ir_var *return_var;
|
2021-02-12 08:48:55 -08:00
|
|
|
struct vkd3d_shader_location loc;
|
2021-01-27 08:29:44 -08:00
|
|
|
struct rb_entry entry;
|
|
|
|
struct hlsl_ir_function *func;
|
|
|
|
struct list *parameters;
|
2021-10-15 14:54:10 -07:00
|
|
|
struct hlsl_block body;
|
2021-10-15 14:54:09 -07:00
|
|
|
bool has_body;
|
2021-08-16 12:52:10 -07:00
|
|
|
unsigned int attr_count;
|
|
|
|
const struct hlsl_attribute *const *attrs;
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_ir_if
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node node;
|
|
|
|
struct hlsl_src condition;
|
2021-10-15 14:54:10 -07:00
|
|
|
struct hlsl_block then_instrs;
|
|
|
|
struct hlsl_block else_instrs;
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_ir_loop
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node node;
|
|
|
|
/* loop condition is stored in the body (as "if (!condition) break;") */
|
2021-10-15 14:54:10 -07:00
|
|
|
struct hlsl_block body;
|
2021-01-27 08:29:44 -08:00
|
|
|
unsigned int next_index; /* liveness index of the end of the loop */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum hlsl_ir_expr_op
|
|
|
|
{
|
2021-08-12 17:36:13 -07:00
|
|
|
HLSL_OP1_ABS,
|
|
|
|
HLSL_OP1_BIT_NOT,
|
|
|
|
HLSL_OP1_CAST,
|
|
|
|
HLSL_OP1_COS,
|
|
|
|
HLSL_OP1_COS_REDUCED, /* Reduced range [-pi, pi] */
|
|
|
|
HLSL_OP1_DSX,
|
|
|
|
HLSL_OP1_DSY,
|
|
|
|
HLSL_OP1_EXP2,
|
2022-02-02 04:46:15 -08:00
|
|
|
HLSL_OP1_FLOOR,
|
2021-08-12 17:36:13 -07:00
|
|
|
HLSL_OP1_FRACT,
|
|
|
|
HLSL_OP1_LOG2,
|
|
|
|
HLSL_OP1_LOGIC_NOT,
|
|
|
|
HLSL_OP1_NEG,
|
|
|
|
HLSL_OP1_NRM,
|
|
|
|
HLSL_OP1_RCP,
|
2022-10-09 20:59:12 -07:00
|
|
|
HLSL_OP1_REINTERPRET,
|
2021-11-19 06:38:41 -08:00
|
|
|
HLSL_OP1_ROUND,
|
2021-08-12 17:36:13 -07:00
|
|
|
HLSL_OP1_RSQ,
|
|
|
|
HLSL_OP1_SAT,
|
|
|
|
HLSL_OP1_SIGN,
|
|
|
|
HLSL_OP1_SIN,
|
|
|
|
HLSL_OP1_SIN_REDUCED, /* Reduced range [-pi, pi] */
|
|
|
|
HLSL_OP1_SQRT,
|
|
|
|
|
|
|
|
HLSL_OP2_ADD,
|
|
|
|
HLSL_OP2_BIT_AND,
|
|
|
|
HLSL_OP2_BIT_OR,
|
|
|
|
HLSL_OP2_BIT_XOR,
|
|
|
|
HLSL_OP2_CRS,
|
|
|
|
HLSL_OP2_DIV,
|
|
|
|
HLSL_OP2_DOT,
|
|
|
|
HLSL_OP2_EQUAL,
|
|
|
|
HLSL_OP2_GEQUAL,
|
|
|
|
HLSL_OP2_LESS,
|
|
|
|
HLSL_OP2_LOGIC_AND,
|
|
|
|
HLSL_OP2_LOGIC_OR,
|
|
|
|
HLSL_OP2_LSHIFT,
|
|
|
|
HLSL_OP2_MAX,
|
|
|
|
HLSL_OP2_MIN,
|
|
|
|
HLSL_OP2_MOD,
|
|
|
|
HLSL_OP2_MUL,
|
|
|
|
HLSL_OP2_NEQUAL,
|
|
|
|
HLSL_OP2_RSHIFT,
|
|
|
|
|
|
|
|
HLSL_OP3_LERP,
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
2021-09-27 18:51:44 -07:00
|
|
|
#define HLSL_MAX_OPERANDS 3
|
|
|
|
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_ir_expr
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node node;
|
|
|
|
enum hlsl_ir_expr_op op;
|
2021-09-27 18:51:44 -07:00
|
|
|
struct hlsl_src operands[HLSL_MAX_OPERANDS];
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum hlsl_ir_jump_type
|
|
|
|
{
|
|
|
|
HLSL_IR_JUMP_BREAK,
|
|
|
|
HLSL_IR_JUMP_CONTINUE,
|
|
|
|
HLSL_IR_JUMP_DISCARD,
|
|
|
|
HLSL_IR_JUMP_RETURN,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_ir_jump
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node node;
|
|
|
|
enum hlsl_ir_jump_type type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_ir_swizzle
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node node;
|
|
|
|
struct hlsl_src val;
|
|
|
|
DWORD swizzle;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_deref
|
|
|
|
{
|
|
|
|
struct hlsl_ir_var *var;
|
2022-06-30 15:20:20 -07:00
|
|
|
|
|
|
|
unsigned int path_len;
|
|
|
|
struct hlsl_src *path;
|
|
|
|
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_src offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_ir_load
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node node;
|
|
|
|
struct hlsl_deref src;
|
|
|
|
};
|
|
|
|
|
2021-10-07 19:58:57 -07:00
|
|
|
enum hlsl_resource_load_type
|
|
|
|
{
|
|
|
|
HLSL_RESOURCE_LOAD,
|
2021-11-05 11:35:52 -07:00
|
|
|
HLSL_RESOURCE_SAMPLE,
|
2021-08-16 18:28:47 -07:00
|
|
|
HLSL_RESOURCE_SAMPLE_LOD,
|
2022-01-26 06:35:32 -08:00
|
|
|
HLSL_RESOURCE_GATHER_RED,
|
|
|
|
HLSL_RESOURCE_GATHER_GREEN,
|
|
|
|
HLSL_RESOURCE_GATHER_BLUE,
|
|
|
|
HLSL_RESOURCE_GATHER_ALPHA,
|
2021-10-07 19:58:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_ir_resource_load
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node node;
|
|
|
|
enum hlsl_resource_load_type load_type;
|
2021-11-05 11:35:52 -07:00
|
|
|
struct hlsl_deref resource, sampler;
|
2021-08-16 18:28:47 -07:00
|
|
|
struct hlsl_src coords, lod, texel_offset;
|
2021-10-07 19:58:57 -07:00
|
|
|
};
|
|
|
|
|
2021-08-15 10:08:32 -07:00
|
|
|
struct hlsl_ir_resource_store
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node node;
|
|
|
|
struct hlsl_deref resource;
|
|
|
|
struct hlsl_src coords, value;
|
|
|
|
};
|
|
|
|
|
2021-04-08 21:38:22 -07:00
|
|
|
struct hlsl_ir_store
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
|
|
|
struct hlsl_ir_node node;
|
|
|
|
struct hlsl_deref lhs;
|
|
|
|
struct hlsl_src rhs;
|
|
|
|
unsigned char writemask;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_ir_constant
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node node;
|
2021-09-20 14:40:10 -07:00
|
|
|
union hlsl_constant_value
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
2021-09-20 14:40:10 -07:00
|
|
|
uint32_t u;
|
|
|
|
int32_t i;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
} value[4];
|
2021-04-08 21:38:26 -07:00
|
|
|
struct hlsl_reg reg;
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_scope
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
struct list vars;
|
|
|
|
struct rb_tree types;
|
|
|
|
struct hlsl_scope *upper;
|
|
|
|
};
|
|
|
|
|
2021-04-08 21:38:25 -07:00
|
|
|
struct hlsl_profile_info
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
enum vkd3d_shader_type type;
|
|
|
|
unsigned int major_version;
|
|
|
|
unsigned int minor_version;
|
|
|
|
unsigned int major_level;
|
|
|
|
unsigned int minor_level;
|
|
|
|
bool software;
|
|
|
|
};
|
|
|
|
|
2021-04-27 10:14:17 -07:00
|
|
|
struct hlsl_vec4
|
|
|
|
{
|
|
|
|
float f[4];
|
|
|
|
};
|
|
|
|
|
2021-06-21 21:37:09 -07:00
|
|
|
enum hlsl_buffer_type
|
|
|
|
{
|
|
|
|
HLSL_BUFFER_CONSTANT,
|
|
|
|
HLSL_BUFFER_TEXTURE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hlsl_buffer
|
|
|
|
{
|
|
|
|
struct vkd3d_shader_location loc;
|
|
|
|
enum hlsl_buffer_type type;
|
|
|
|
const char *name;
|
|
|
|
struct hlsl_reg_reservation reservation;
|
|
|
|
struct list entry;
|
2021-06-23 21:57:35 -07:00
|
|
|
|
|
|
|
unsigned size, used_size;
|
|
|
|
struct hlsl_reg reg;
|
2021-06-21 21:37:09 -07:00
|
|
|
};
|
|
|
|
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_ctx
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
2021-04-08 21:38:25 -07:00
|
|
|
const struct hlsl_profile_info *profile;
|
|
|
|
|
2021-01-27 08:29:44 -08:00
|
|
|
const char **source_files;
|
|
|
|
unsigned int source_files_count;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Current location being read in the HLSL source, updated while parsing. */
|
2021-02-12 08:48:56 -08:00
|
|
|
struct vkd3d_shader_location location;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Stores the logging messages and logging configuration. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct vkd3d_shader_message_context *message_context;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Cache for temporary string allocations. */
|
2021-02-27 16:03:09 -08:00
|
|
|
struct vkd3d_string_buffer_cache string_buffers;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* A value from enum vkd3d_result with the current success/failure result of the whole
|
|
|
|
* compilation.
|
|
|
|
* It is initialized to VKD3D_OK and set to an error code in case a call to hlsl_fixme() or
|
|
|
|
* hlsl_error() is triggered, or in case of a memory allocation error.
|
|
|
|
* The value of this field is checked between compilation stages to stop execution in case of
|
|
|
|
* failure. */
|
2021-05-20 22:32:23 -07:00
|
|
|
int result;
|
2021-01-27 08:29:44 -08:00
|
|
|
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Pointer to an opaque data structure managed by FLEX (during lexing), that encapsulates the
|
|
|
|
* current state of the scanner. This pointer is required by all FLEX API functions when the
|
|
|
|
* scanner is declared as reentrant, which is the case. */
|
2021-02-04 14:33:53 -08:00
|
|
|
void *scanner;
|
|
|
|
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Pointer to the current scope; changes as the parser reads the code. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_scope *cur_scope;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Scope of global variables. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_scope *globals;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* List of all the scopes in the program; linked by the hlsl_scope.entry fields. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct list scopes;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* List of all the extern variables; linked by the hlsl_ir_var.extern_entry fields.
|
|
|
|
* This exists as a convenience because it is often necessary to iterate all extern variables
|
|
|
|
* and these can be declared in global scope, as function parameters, or as the function
|
|
|
|
* return value. */
|
2021-04-15 17:03:44 -07:00
|
|
|
struct list extern_vars;
|
2021-01-27 08:29:44 -08:00
|
|
|
|
2022-11-14 13:03:37 -08:00
|
|
|
/* List containing both the built-in HLSL buffers ($Globals and $Params) and the ones declared
|
|
|
|
* in the shader; linked by the hlsl_buffer.entry fields. */
|
2021-06-21 21:37:09 -07:00
|
|
|
struct list buffers;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Current buffer (changes as the parser reads the code), $Globals buffer, and $Params buffer,
|
|
|
|
* respectively. */
|
2021-07-08 19:13:18 -07:00
|
|
|
struct hlsl_buffer *cur_buffer, *globals_buffer, *params_buffer;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* List containing all created hlsl_types, except builtin_types; linked by the hlsl_type.entry
|
|
|
|
* fields. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct list types;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Tree map for the declared functions, using hlsl_ir_function.name as key.
|
|
|
|
* The functions are attached through the hlsl_ir_function.entry fields. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct rb_tree functions;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Pointer to the current function; changes as the parser reads the code. */
|
2021-01-27 08:29:44 -08:00
|
|
|
const struct hlsl_ir_function_decl *cur_function;
|
|
|
|
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Default matrix majority for matrix types. Can be set by a pragma within the HLSL source. */
|
2021-01-27 08:29:44 -08:00
|
|
|
enum hlsl_matrix_majority matrix_majority;
|
|
|
|
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Basic data types stored for convenience. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct hlsl_type *scalar[HLSL_TYPE_LAST_SCALAR + 1];
|
|
|
|
struct hlsl_type *vector[HLSL_TYPE_LAST_SCALAR + 1][4];
|
2022-11-14 13:03:37 -08:00
|
|
|
/* matrix[HLSL_TYPE_FLOAT][1][3] is a float4x2, i.e. dimx = 2, dimy = 4 */
|
2021-09-27 18:51:46 -07:00
|
|
|
struct hlsl_type *matrix[HLSL_TYPE_LAST_SCALAR + 1][4][4];
|
2022-01-27 10:31:23 -08:00
|
|
|
struct hlsl_type *sampler[HLSL_SAMPLER_DIM_LAST_SAMPLER + 1];
|
2021-01-27 08:29:44 -08:00
|
|
|
struct hlsl_type *Void;
|
|
|
|
} builtin_types;
|
|
|
|
|
2022-11-14 13:03:37 -08:00
|
|
|
/* List of the instruction nodes for initializing static variables; linked by the
|
|
|
|
* hlsl_ir_node.entry fields. */
|
2021-01-27 08:29:44 -08:00
|
|
|
struct list static_initializers;
|
2021-04-27 10:14:17 -07:00
|
|
|
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Dynamic array of constant values that appear in the shader, associated to the 'c' registers.
|
|
|
|
* Only used for SM1 profiles. */
|
2021-04-27 10:14:17 -07:00
|
|
|
struct hlsl_constant_defs
|
|
|
|
{
|
|
|
|
struct hlsl_vec4 *values;
|
|
|
|
size_t count, size;
|
|
|
|
} constant_defs;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Number of temp. registers required for the shader to run, i.e. the largest temp register
|
|
|
|
* index that will be used in the output bytecode (+1). */
|
2021-08-19 16:44:30 -07:00
|
|
|
uint32_t temp_count;
|
2021-09-27 18:51:42 -07:00
|
|
|
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Number of threads to be executed (on the X, Y, and Z dimensions) in a single thread group in
|
|
|
|
* compute shader profiles. It is set using the numthreads() attribute in the entry point. */
|
2021-08-16 15:29:34 -07:00
|
|
|
uint32_t thread_count[3];
|
|
|
|
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Whether the parser is inside an state block (effects' metadata) inside a variable declarition. */
|
2021-09-27 18:51:42 -07:00
|
|
|
uint32_t in_state_block : 1;
|
2022-11-14 13:03:37 -08:00
|
|
|
/* Whether the numthreads() attribute has been provided in the entry-point function. */
|
2021-08-16 15:29:34 -07:00
|
|
|
uint32_t found_numthreads : 1;
|
2021-01-27 08:29:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum hlsl_error_level
|
|
|
|
{
|
|
|
|
HLSL_LEVEL_ERROR = 0,
|
|
|
|
HLSL_LEVEL_WARNING,
|
|
|
|
HLSL_LEVEL_NOTE,
|
|
|
|
};
|
|
|
|
|
2022-09-26 16:20:22 -07:00
|
|
|
struct hlsl_resource_load_params
|
|
|
|
{
|
|
|
|
struct hlsl_type *format;
|
|
|
|
enum hlsl_resource_load_type type;
|
|
|
|
struct hlsl_deref resource, sampler;
|
|
|
|
struct hlsl_ir_node *coords, *lod, *texel_offset;
|
|
|
|
};
|
|
|
|
|
2021-02-02 14:11:14 -08:00
|
|
|
static inline struct hlsl_ir_constant *hlsl_ir_constant(const struct hlsl_ir_node *node)
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
|
|
|
assert(node->type == HLSL_IR_CONSTANT);
|
|
|
|
return CONTAINING_RECORD(node, struct hlsl_ir_constant, node);
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:11:14 -08:00
|
|
|
static inline struct hlsl_ir_expr *hlsl_ir_expr(const struct hlsl_ir_node *node)
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
|
|
|
assert(node->type == HLSL_IR_EXPR);
|
|
|
|
return CONTAINING_RECORD(node, struct hlsl_ir_expr, node);
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:11:14 -08:00
|
|
|
static inline struct hlsl_ir_if *hlsl_ir_if(const struct hlsl_ir_node *node)
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
|
|
|
assert(node->type == HLSL_IR_IF);
|
|
|
|
return CONTAINING_RECORD(node, struct hlsl_ir_if, node);
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:11:14 -08:00
|
|
|
static inline struct hlsl_ir_jump *hlsl_ir_jump(const struct hlsl_ir_node *node)
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
|
|
|
assert(node->type == HLSL_IR_JUMP);
|
|
|
|
return CONTAINING_RECORD(node, struct hlsl_ir_jump, node);
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:11:14 -08:00
|
|
|
static inline struct hlsl_ir_load *hlsl_ir_load(const struct hlsl_ir_node *node)
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
|
|
|
assert(node->type == HLSL_IR_LOAD);
|
|
|
|
return CONTAINING_RECORD(node, struct hlsl_ir_load, node);
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:11:14 -08:00
|
|
|
static inline struct hlsl_ir_loop *hlsl_ir_loop(const struct hlsl_ir_node *node)
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
|
|
|
assert(node->type == HLSL_IR_LOOP);
|
|
|
|
return CONTAINING_RECORD(node, struct hlsl_ir_loop, node);
|
|
|
|
}
|
|
|
|
|
2021-10-07 19:58:57 -07:00
|
|
|
static inline struct hlsl_ir_resource_load *hlsl_ir_resource_load(const struct hlsl_ir_node *node)
|
|
|
|
{
|
|
|
|
assert(node->type == HLSL_IR_RESOURCE_LOAD);
|
|
|
|
return CONTAINING_RECORD(node, struct hlsl_ir_resource_load, node);
|
|
|
|
}
|
|
|
|
|
2021-08-15 10:08:32 -07:00
|
|
|
static inline struct hlsl_ir_resource_store *hlsl_ir_resource_store(const struct hlsl_ir_node *node)
|
|
|
|
{
|
|
|
|
assert(node->type == HLSL_IR_RESOURCE_STORE);
|
|
|
|
return CONTAINING_RECORD(node, struct hlsl_ir_resource_store, node);
|
|
|
|
}
|
|
|
|
|
2021-04-08 21:38:22 -07:00
|
|
|
static inline struct hlsl_ir_store *hlsl_ir_store(const struct hlsl_ir_node *node)
|
|
|
|
{
|
|
|
|
assert(node->type == HLSL_IR_STORE);
|
|
|
|
return CONTAINING_RECORD(node, struct hlsl_ir_store, node);
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:11:14 -08:00
|
|
|
static inline struct hlsl_ir_swizzle *hlsl_ir_swizzle(const struct hlsl_ir_node *node)
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
|
|
|
assert(node->type == HLSL_IR_SWIZZLE);
|
|
|
|
return CONTAINING_RECORD(node, struct hlsl_ir_swizzle, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void hlsl_src_from_node(struct hlsl_src *src, struct hlsl_ir_node *node)
|
|
|
|
{
|
|
|
|
src->node = node;
|
|
|
|
if (node)
|
|
|
|
list_add_tail(&node->uses, &src->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void hlsl_src_remove(struct hlsl_src *src)
|
|
|
|
{
|
|
|
|
if (src->node)
|
|
|
|
list_remove(&src->entry);
|
|
|
|
src->node = NULL;
|
|
|
|
}
|
|
|
|
|
2021-05-20 22:32:20 -07:00
|
|
|
static inline void *hlsl_alloc(struct hlsl_ctx *ctx, size_t size)
|
|
|
|
{
|
|
|
|
void *ptr = vkd3d_calloc(1, size);
|
|
|
|
|
|
|
|
if (!ptr)
|
2021-05-20 22:32:23 -07:00
|
|
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
2021-05-20 22:32:20 -07:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2021-09-20 14:40:11 -07:00
|
|
|
static inline void *hlsl_realloc(struct hlsl_ctx *ctx, void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
void *ret = vkd3d_realloc(ptr, size);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-05-20 22:32:20 -07:00
|
|
|
static inline char *hlsl_strdup(struct hlsl_ctx *ctx, const char *string)
|
|
|
|
{
|
|
|
|
char *ptr = vkd3d_strdup(string);
|
|
|
|
|
|
|
|
if (!ptr)
|
2021-05-20 22:32:23 -07:00
|
|
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
2021-05-20 22:32:20 -07:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool hlsl_array_reserve(struct hlsl_ctx *ctx, void **elements,
|
|
|
|
size_t *capacity, size_t element_count, size_t element_size)
|
|
|
|
{
|
|
|
|
bool ret = vkd3d_array_reserve(elements, capacity, element_count, element_size);
|
|
|
|
|
|
|
|
if (!ret)
|
2021-05-20 22:32:23 -07:00
|
|
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
2021-05-20 22:32:20 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-05-20 22:32:21 -07:00
|
|
|
static inline struct vkd3d_string_buffer *hlsl_get_string_buffer(struct hlsl_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct vkd3d_string_buffer *ret = vkd3d_string_buffer_get(&ctx->string_buffers);
|
|
|
|
|
|
|
|
if (!ret)
|
2021-05-20 22:32:23 -07:00
|
|
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
2021-05-20 22:32:21 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void hlsl_release_string_buffer(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer)
|
|
|
|
{
|
|
|
|
vkd3d_string_buffer_release(&ctx->string_buffers, buffer);
|
|
|
|
}
|
|
|
|
|
2021-10-25 00:06:25 -07:00
|
|
|
static inline struct hlsl_type *hlsl_get_scalar_type(const struct hlsl_ctx *ctx, enum hlsl_base_type base_type)
|
|
|
|
{
|
|
|
|
return ctx->builtin_types.scalar[base_type];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct hlsl_type *hlsl_get_vector_type(const struct hlsl_ctx *ctx, enum hlsl_base_type base_type,
|
|
|
|
unsigned int dimx)
|
|
|
|
{
|
|
|
|
return ctx->builtin_types.vector[base_type][dimx - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct hlsl_type *hlsl_get_matrix_type(const struct hlsl_ctx *ctx, enum hlsl_base_type base_type,
|
|
|
|
unsigned int dimx, unsigned int dimy)
|
|
|
|
{
|
|
|
|
return ctx->builtin_types.matrix[base_type][dimx - 1][dimy - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct hlsl_type *hlsl_get_numeric_type(const struct hlsl_ctx *ctx, enum hlsl_type_class type,
|
|
|
|
enum hlsl_base_type base_type, unsigned int dimx, unsigned int dimy)
|
|
|
|
{
|
|
|
|
if (type == HLSL_CLASS_SCALAR)
|
|
|
|
return hlsl_get_scalar_type(ctx, base_type);
|
|
|
|
else if (type == HLSL_CLASS_VECTOR)
|
|
|
|
return hlsl_get_vector_type(ctx, base_type, dimx);
|
|
|
|
else
|
|
|
|
return hlsl_get_matrix_type(ctx, base_type, dimx, dimy);
|
|
|
|
}
|
|
|
|
|
2022-01-27 10:31:22 -08:00
|
|
|
static inline unsigned int hlsl_sampler_dim_count(enum hlsl_sampler_dim dim)
|
|
|
|
{
|
|
|
|
switch (dim)
|
|
|
|
{
|
|
|
|
case HLSL_SAMPLER_DIM_1D:
|
|
|
|
return 1;
|
2022-01-27 10:31:23 -08:00
|
|
|
case HLSL_SAMPLER_DIM_1DARRAY:
|
2022-01-27 10:31:22 -08:00
|
|
|
case HLSL_SAMPLER_DIM_2D:
|
2022-01-27 10:31:23 -08:00
|
|
|
case HLSL_SAMPLER_DIM_2DMS:
|
2022-01-27 10:31:22 -08:00
|
|
|
return 2;
|
2022-01-27 10:31:23 -08:00
|
|
|
case HLSL_SAMPLER_DIM_2DARRAY:
|
|
|
|
case HLSL_SAMPLER_DIM_2DMSARRAY:
|
2022-01-27 10:31:22 -08:00
|
|
|
case HLSL_SAMPLER_DIM_3D:
|
|
|
|
case HLSL_SAMPLER_DIM_CUBE:
|
|
|
|
return 3;
|
2022-01-27 10:31:23 -08:00
|
|
|
case HLSL_SAMPLER_DIM_CUBEARRAY:
|
|
|
|
return 4;
|
2022-01-27 10:31:22 -08:00
|
|
|
default:
|
2022-08-31 04:25:24 -07:00
|
|
|
vkd3d_unreachable();
|
2022-01-27 10:31:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-13 07:03:24 -07:00
|
|
|
const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op);
|
2021-08-08 23:11:49 -07:00
|
|
|
const char *debug_hlsl_type(struct hlsl_ctx *ctx, const struct hlsl_type *type);
|
|
|
|
const char *debug_hlsl_writemask(unsigned int writemask);
|
2021-12-01 08:14:50 -08:00
|
|
|
const char *debug_hlsl_swizzle(unsigned int swizzle, unsigned int count);
|
2021-02-12 12:38:50 -08:00
|
|
|
|
2021-08-08 23:11:49 -07:00
|
|
|
struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const struct hlsl_type *type);
|
|
|
|
struct vkd3d_string_buffer *hlsl_modifiers_to_string(struct hlsl_ctx *ctx, unsigned int modifiers);
|
|
|
|
const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type);
|
2021-02-02 14:11:14 -08:00
|
|
|
|
2021-08-08 23:11:49 -07:00
|
|
|
void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function_decl *decl, bool intrinsic);
|
|
|
|
bool hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local_var);
|
2021-02-02 14:11:14 -08:00
|
|
|
|
2021-08-08 23:11:49 -07:00
|
|
|
void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl *func);
|
2021-02-02 14:11:14 -08:00
|
|
|
|
2022-02-28 03:23:43 -08:00
|
|
|
int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func,
|
|
|
|
enum vkd3d_shader_target_type target_type, struct vkd3d_shader_code *out);
|
2021-03-02 13:34:46 -08:00
|
|
|
|
2022-09-26 16:19:54 -07:00
|
|
|
bool hlsl_copy_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, const struct hlsl_deref *other);
|
2022-06-30 15:20:20 -07:00
|
|
|
void hlsl_cleanup_deref(struct hlsl_deref *deref);
|
|
|
|
|
2022-02-10 19:48:18 -08:00
|
|
|
void hlsl_replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new);
|
|
|
|
|
2021-08-16 12:52:10 -07:00
|
|
|
void hlsl_free_attribute(struct hlsl_attribute *attr);
|
2021-08-08 23:11:49 -07:00
|
|
|
void hlsl_free_instr(struct hlsl_ir_node *node);
|
|
|
|
void hlsl_free_instr_list(struct list *list);
|
|
|
|
void hlsl_free_type(struct hlsl_type *type);
|
|
|
|
void hlsl_free_var(struct hlsl_ir_var *decl);
|
2021-02-02 14:11:14 -08:00
|
|
|
|
2021-08-08 23:11:49 -07:00
|
|
|
bool hlsl_get_function(struct hlsl_ctx *ctx, const char *name);
|
|
|
|
struct hlsl_ir_function_decl *hlsl_get_func_decl(struct hlsl_ctx *ctx, const char *name);
|
|
|
|
struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, bool recursive);
|
|
|
|
struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name);
|
2021-02-02 14:11:14 -08:00
|
|
|
|
2022-08-16 09:33:51 -07:00
|
|
|
struct hlsl_type *hlsl_get_element_type_from_path_index(struct hlsl_ctx *ctx, const struct hlsl_type *type,
|
2022-06-30 10:16:37 -07:00
|
|
|
struct hlsl_ir_node *idx);
|
|
|
|
|
2021-08-08 23:11:49 -07:00
|
|
|
struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type, unsigned int array_size);
|
2021-05-20 22:32:20 -07:00
|
|
|
struct hlsl_ir_node *hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1,
|
2021-08-08 23:11:49 -07:00
|
|
|
struct hlsl_ir_node *arg2);
|
2022-09-26 16:54:03 -07:00
|
|
|
struct hlsl_ir_constant *hlsl_new_bool_constant(struct hlsl_ctx *ctx, bool b, const struct vkd3d_shader_location *loc);
|
2021-06-21 21:37:09 -07:00
|
|
|
struct hlsl_buffer *hlsl_new_buffer(struct hlsl_ctx *ctx, enum hlsl_buffer_type type, const char *name,
|
2021-08-08 23:11:49 -07:00
|
|
|
const struct hlsl_reg_reservation *reservation, struct vkd3d_shader_location loc);
|
2021-05-20 22:32:20 -07:00
|
|
|
struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type,
|
2021-10-07 19:58:57 -07:00
|
|
|
const struct vkd3d_shader_location *loc);
|
2022-04-05 03:33:11 -07:00
|
|
|
struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type,
|
|
|
|
const struct vkd3d_shader_location *loc);
|
2021-08-08 23:11:49 -07:00
|
|
|
struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ctx *ctx, struct hlsl_ir_node *node);
|
2022-09-26 17:00:09 -07:00
|
|
|
struct hlsl_ir_node *hlsl_new_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op,
|
|
|
|
struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS],
|
|
|
|
struct hlsl_type *data_type, const struct vkd3d_shader_location *loc);
|
2022-09-26 16:50:04 -07:00
|
|
|
struct hlsl_ir_constant *hlsl_new_float_constant(struct hlsl_ctx *ctx,
|
|
|
|
float f, const struct vkd3d_shader_location *loc);
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hlsl_type *return_type,
|
2021-08-16 12:52:10 -07:00
|
|
|
struct list *parameters, const struct hlsl_semantic *semantic, const struct vkd3d_shader_location *loc);
|
2021-08-08 23:11:49 -07:00
|
|
|
struct hlsl_ir_if *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *condition, struct vkd3d_shader_location loc);
|
2021-12-01 08:15:00 -08:00
|
|
|
struct hlsl_ir_constant *hlsl_new_int_constant(struct hlsl_ctx *ctx, int n,
|
2022-04-05 03:33:10 -07:00
|
|
|
const struct vkd3d_shader_location *loc);
|
2021-08-08 23:11:49 -07:00
|
|
|
struct hlsl_ir_jump *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type type, struct vkd3d_shader_location loc);
|
2022-06-30 15:20:20 -07:00
|
|
|
|
|
|
|
void hlsl_init_simple_deref_from_var(struct hlsl_deref *deref, struct hlsl_ir_var *var);
|
|
|
|
|
|
|
|
struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var,
|
|
|
|
struct vkd3d_shader_location loc);
|
|
|
|
struct hlsl_ir_load *hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
|
|
|
|
struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc);
|
|
|
|
struct hlsl_ir_load *hlsl_new_load_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
|
|
|
const struct hlsl_deref *deref, unsigned int comp, const struct vkd3d_shader_location *loc);
|
|
|
|
|
|
|
|
struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs);
|
2022-07-13 13:56:21 -07:00
|
|
|
struct hlsl_ir_store *hlsl_new_store_index(struct hlsl_ctx *ctx, const struct hlsl_deref *lhs,
|
|
|
|
struct hlsl_ir_node *idx, struct hlsl_ir_node *rhs, unsigned int writemask, const struct vkd3d_shader_location *loc);
|
2022-07-14 12:11:51 -07:00
|
|
|
struct hlsl_ir_store *hlsl_new_store_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
|
|
|
const struct hlsl_deref *lhs, unsigned int comp, struct hlsl_ir_node *rhs);
|
2022-06-30 15:20:20 -07:00
|
|
|
|
|
|
|
struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_location loc);
|
2022-09-26 16:20:22 -07:00
|
|
|
struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx,
|
|
|
|
const struct hlsl_resource_load_params *params, const struct vkd3d_shader_location *loc);
|
2021-08-15 10:08:32 -07:00
|
|
|
struct hlsl_ir_resource_store *hlsl_new_resource_store(struct hlsl_ctx *ctx, const struct hlsl_deref *resource,
|
|
|
|
struct hlsl_ir_node *coords, struct hlsl_ir_node *value, const struct vkd3d_shader_location *loc);
|
2022-07-14 18:23:43 -07:00
|
|
|
struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name,
|
|
|
|
struct hlsl_struct_field *fields, size_t field_count);
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components,
|
2021-12-01 08:14:58 -08:00
|
|
|
struct hlsl_ir_node *val, const struct vkd3d_shader_location *loc);
|
2022-09-26 15:51:36 -07:00
|
|
|
struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *template,
|
|
|
|
struct hlsl_type *type, const struct vkd3d_shader_location *loc);
|
2021-10-07 19:58:55 -07:00
|
|
|
struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format);
|
2021-08-12 19:03:26 -07:00
|
|
|
struct hlsl_type *hlsl_new_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format);
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n,
|
2022-04-05 03:33:10 -07:00
|
|
|
const struct vkd3d_shader_location *loc);
|
2021-05-20 22:32:20 -07:00
|
|
|
struct hlsl_ir_node *hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg,
|
2021-08-08 23:11:49 -07:00
|
|
|
struct vkd3d_shader_location loc);
|
2021-05-20 22:32:20 -07:00
|
|
|
struct hlsl_ir_var *hlsl_new_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type,
|
2021-04-27 10:14:19 -07:00
|
|
|
const struct vkd3d_shader_location loc, const struct hlsl_semantic *semantic, unsigned int modifiers,
|
2021-08-08 23:11:49 -07:00
|
|
|
const struct hlsl_reg_reservation *reg_reservation);
|
2021-02-02 14:11:14 -08:00
|
|
|
|
2021-12-01 08:14:57 -08:00
|
|
|
void hlsl_error(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc,
|
2021-08-08 23:11:49 -07:00
|
|
|
enum vkd3d_shader_error error, const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5);
|
2021-12-01 08:14:57 -08:00
|
|
|
void hlsl_fixme(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc,
|
2021-08-13 07:03:24 -07:00
|
|
|
const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4);
|
2021-12-01 08:14:57 -08:00
|
|
|
void hlsl_warning(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc,
|
2021-08-08 23:11:49 -07:00
|
|
|
enum vkd3d_shader_error error, const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5);
|
2021-12-01 08:14:57 -08:00
|
|
|
void hlsl_note(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc,
|
2021-08-08 23:11:49 -07:00
|
|
|
enum vkd3d_shader_log_level level, const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5);
|
2021-02-02 14:11:14 -08:00
|
|
|
|
2021-08-08 23:11:49 -07:00
|
|
|
void hlsl_push_scope(struct hlsl_ctx *ctx);
|
|
|
|
void hlsl_pop_scope(struct hlsl_ctx *ctx);
|
2021-02-02 14:11:14 -08:00
|
|
|
|
2021-08-08 23:11:49 -07:00
|
|
|
bool hlsl_scope_add_type(struct hlsl_scope *scope, struct hlsl_type *type);
|
2021-02-04 14:33:50 -08:00
|
|
|
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old,
|
2021-08-08 23:11:49 -07:00
|
|
|
unsigned int default_majority, unsigned int modifiers);
|
2022-06-30 15:20:20 -07:00
|
|
|
unsigned int hlsl_type_component_count(const struct hlsl_type *type);
|
2022-03-17 13:58:35 -07:00
|
|
|
unsigned int hlsl_type_get_array_element_reg_size(const struct hlsl_type *type);
|
2022-06-30 15:20:20 -07:00
|
|
|
struct hlsl_type *hlsl_type_get_component_type(struct hlsl_ctx *ctx, struct hlsl_type *type,
|
|
|
|
unsigned int index);
|
2022-06-30 10:16:37 -07:00
|
|
|
bool hlsl_type_is_row_major(const struct hlsl_type *type);
|
2022-06-30 13:25:12 -07:00
|
|
|
unsigned int hlsl_type_minor_size(const struct hlsl_type *type);
|
|
|
|
unsigned int hlsl_type_major_size(const struct hlsl_type *type);
|
2022-07-20 14:42:13 -07:00
|
|
|
unsigned int hlsl_type_element_count(const struct hlsl_type *type);
|
2021-08-08 23:11:49 -07:00
|
|
|
unsigned int hlsl_type_get_sm4_offset(const struct hlsl_type *type, unsigned int offset);
|
|
|
|
bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2);
|
2021-01-27 08:29:44 -08:00
|
|
|
|
2021-08-09 19:56:17 -07:00
|
|
|
unsigned int hlsl_combine_swizzles(unsigned int first, unsigned int second, unsigned int dim);
|
|
|
|
unsigned int hlsl_combine_writemasks(unsigned int first, unsigned int second);
|
|
|
|
unsigned int hlsl_map_swizzle(unsigned int swizzle, unsigned int writemask);
|
|
|
|
unsigned int hlsl_swizzle_from_writemask(unsigned int writemask);
|
|
|
|
|
2021-08-15 10:08:32 -07:00
|
|
|
struct hlsl_type *hlsl_deref_get_type(struct hlsl_ctx *ctx, const struct hlsl_deref *deref);
|
2022-07-20 12:37:07 -07:00
|
|
|
bool hlsl_component_index_range_from_deref(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
|
|
|
|
unsigned int *start, unsigned int *count);
|
2022-02-24 06:06:15 -08:00
|
|
|
bool hlsl_offset_from_deref(struct hlsl_ctx *ctx, const struct hlsl_deref *deref, unsigned int *offset);
|
2021-11-17 00:47:26 -08:00
|
|
|
unsigned int hlsl_offset_from_deref_safe(struct hlsl_ctx *ctx, const struct hlsl_deref *deref);
|
2022-03-10 07:14:05 -08:00
|
|
|
struct hlsl_reg hlsl_reg_from_deref(struct hlsl_ctx *ctx, const struct hlsl_deref *deref);
|
2021-08-09 19:56:17 -07:00
|
|
|
|
2022-06-27 08:22:38 -07:00
|
|
|
bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
|
|
|
|
bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context);
|
2022-02-10 19:48:19 -08:00
|
|
|
|
2021-08-09 19:56:17 -07:00
|
|
|
bool hlsl_sm1_register_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semantic *semantic,
|
|
|
|
bool output, D3DSHADER_PARAM_REGISTER_TYPE *type, unsigned int *reg);
|
|
|
|
bool hlsl_sm1_usage_from_semantic(const struct hlsl_semantic *semantic, D3DDECLUSAGE *usage, uint32_t *usage_idx);
|
|
|
|
int hlsl_sm1_write(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, struct vkd3d_shader_code *out);
|
|
|
|
|
2021-08-19 16:44:27 -07:00
|
|
|
bool hlsl_sm4_usage_from_semantic(struct hlsl_ctx *ctx,
|
|
|
|
const struct hlsl_semantic *semantic, bool output, D3D_NAME *usage);
|
|
|
|
bool hlsl_sm4_register_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semantic *semantic,
|
2021-11-15 10:40:04 -08:00
|
|
|
bool output, enum vkd3d_sm4_register_type *type, enum vkd3d_sm4_swizzle_type *swizzle_type, bool *has_idx);
|
2021-08-17 10:38:57 -07:00
|
|
|
int hlsl_sm4_write(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, struct vkd3d_shader_code *out);
|
|
|
|
|
2021-08-08 23:11:49 -07:00
|
|
|
int hlsl_lexer_compile(struct hlsl_ctx *ctx, const struct vkd3d_shader_code *hlsl);
|
2021-01-27 08:29:44 -08:00
|
|
|
|
|
|
|
#endif
|