forked from microsoft/hlsl-specs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.tex
245 lines (209 loc) · 12.1 KB
/
basic.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
\Ch{Basic Concepts}{Basic}
\begin{note}
\p HLSL inherits a significant portion of its language semantics from C and C++.
Some of this is a result of intentional adoption of syntax early in the development
of the language and some a side-effect of the Clang-based implementation of DXC.
\p This chapter includes a lot of definitions that are inherited from C and C++.
Some are identical to C or C++, others are slightly different. HLSL is neither
a subset nor a superset of C or C++, and cannot be simply described in terms
of C or C++. This specification includes all necessary definitions for clarity.
\end{note}
\Sec{Preamble}{Basic.preamble}
\p An \textit{entity} is a value, object, function, enumerator, type, class
member, bit-field, template, template specialization, namespace, or pack.
\p A \textit{name} is a use of an \textit{identifier} (\ref{Expr.Primary.ID}),
\textit{operator-function-id} (\ref{Overload.operator}),
\textit{conversion-function-id} (\ref{Classes.Conversions}),
or \textit{template-id} (\ref{Template}) that denotes any entity or
\textit{label} (\ref{Stmt.Label}).
\p Every name that denotes an entity is introduced by a \textit{declaration}.
Every name that denotes a label is introduced by a \textit{labeled statement}
(\ref{Stmt.Label})\footnote{HLSL does not have \texttt{goto}, and labeled
statements are only valid within \texttt{switch} statements.}.
\p A \textit{variable} is introduced by the declaration of a reference other
than a non-static data member of an object. The variable's name denotes the
reference or object.
\p Whenever a name is encountered it is necessary to determine if the name
denotes an entity that is a type or template. The process for determining if a
name refers to a type or template is called \textit{name lookup}.
\p Two names are the same name if:
\begin{itemize}
\item they are identifiers comprised of the same character sequence, or
\item they are operator-function-ids formed with the same operator, or
\item they are conversion-function-ids formed with the same type, or
\item they are template-ids that refer to the same class or function.
\end{itemize}
\p \begin{note}
This section matches \gls{isoCPP} section \textbf{[basic]} except for the
exclusion of \texttt{goto} and \textit{literal operators}.
\end{note}
\Sec{Declarations and definitions}{Basic.Decl}
\p A declaration (\ref{Decl}) may introduce one or more names into a translation
unit or redeclare names introduced by previous declarations. If a declaration
introduces names, it specifies the interpretation and attributes of these names.
A declaration may also have effects such as:
\begin{itemize}
\item verifying a static assertion (\ref{Decl}),
\item use of attributes (\ref{Decl}), and
\item controlling template instantiation (\ref{Template.Inst}).
\end{itemize}
\p A declaration is a \textit{definition} unless:
\begin{itemize}
\item it declares a function without specifying the function's body
(\ref{Decl.Function}),
\item it is a parameter declaration in a function declaration that does not
specify the function's body (\ref{Decl.Function}),
\item it is a global or namespace member declaration without the \texttt{static}
specifier\footnote{Global variable declarations are implicitly constant and
external in HLSL.},
\item it declares a static data member in a class definition,
\item it is a class name declaration,
\item it is a template parameter,
\item it is a \texttt{typedef} declaration (\ref{Decl}),
\item it is an \textit{alias-declaration} (\ref{Decl}),
\item it is a \textit{using-declaration} (\ref{Decl}),
\item it is a \textit{static\_assert-declaration} (\ref{Decl}),
\item it is an \textit{empty-declaration} (\ref{Decl}),
\item or a \textit{using-directive} (\ref{Decl}).
\end{itemize}
\p The two examples below are adapted from \gls{isoCPP} \textbf{[basic.def]}. All
but one of the following are definitions:
\begin{HLSL}
int f(int x) { return x+1; } // defines f and x
struct S {int a;int b;}; // defines S, S::a, and S::b
struct X { // defines X
int x; // defines non-static member x
static int y; // declares static data member y
};
int X::y = 1; // defines X::y
enum { up, down }; // defines up and down
namespace N { // defines N
int d; // declares N::d
static int i; // defines N::i
}
\end{HLSL}
\p All of the following are declarations:
\begin{HLSL}
int a; // declares a
const int c; // declares c
X anX; // declares anX
int f(int); // declares f
struct S; // declares S
typedef int Int; // declares Int
using N::d; // declares d
using Float = float; // declares Float
cbuffer CB { // does not declare CB
int z; // declares z
}
tbuffer TB { // does not declare TB
int w; // declares w
}
\end{HLSL}
\Sec{Types}{Basic.types}
\p The \textit{object representation} of an object of type \texttt{T} is the
sequence of \textit{N} bytes taken up by the object of type \texttt{T}, where
\textit{N} equals \texttt{sizeof(T)}\footnote{\texttt{sizeof(T)} returns the
size of the object as-if it's stored in device memory, and determining the size
if it's stored in another memory space is not possible.}. The \textit{object
representation} of an object may be different based on the \textit{memory space}
it is stored in (\ref{Intro.Memory.Spaces}).
\p The \textit{value representation} of an object is the set of bits that hold
the value of type \texttt{T}. Bits in the object representation that are not
part of the value representation are \textit{padding bits}.
\p An \textit{object type} is a type that is not a function type, not a
reference type, and not a void type.
\p A \textit{class type} is a data type declared with either the \texttt{class}
or \texttt{struct} keywords (\ref{Classes}). A class type \texttt{T} may be
declared as incomplete at one point in a translation unit via a \textit{forward
declaration}, and complete later with a full definition. The type \texttt{T} is
the same type throughout the translation unit.
\p There are special implementation-defined types such as \textit{handle types},
which fall into a category of \textit{standard intangible types}. Intangible
types are types that have no defined object representation or value
representation, as such the size is unknown at compile time.
% Note: The above definition is likely incomplete, and it is unclear if minimum
% precision types should be intangible.
\p A class type \texttt{T} is an \textit{intangible class type} if it contains
a base class or members of intangible class type, standard intangible type,
or arrays of such types. Standard intangible types and intangible class types
are collectively called \textit{intangible types}(\ref{Intangible}).
\p An object type is an \textit{incomplete type} if the compiler lacks
sufficient information to determine the size of an object of type \texttt{T},
and it is not an intangible type. It is a \textit{complete type} if the compiler
has sufficient information to determine the size of an object of type
\texttt{T}, or if the type is known to be an intangible type. An object may not
be defined to have an \textit{incomplete} type.
\p Arithmetic types (\ref{Basic.types.arithmetic}), enumeration types, and
\textit{cv-qualified} versions of these types are collectively called
\textit{scalar types}.
\p Vectors of scalar types declared with the built-in \texttt{vector<T,N>}
template are \textit{vector types}. Vector lengths must be between 1 and 4 (i.e.
\( 1 \leq N \leq 4 \) ).
\Sub{Arithmetic Types}{Basic.types.arithmetic}
\p There are three \textit{standard signed integer types}: \texttt{int16\_t},
\texttt{int32\_t}, and \texttt{int64\_t}. Each of the signed integer types is
explicitly named for the size in bits of the type's object representation. There
is also the type alias \texttt{int} which is an alias of \texttt{int32\_t}.
There is one \textit{minimum precision signed integer type}: \texttt{min16int}.
The minimum precision signed integer type is named for the required minimum
value representation size in bits. The object representation of
\texttt{min16int} is \texttt{int}. The standard signed integer types and minimum
precision signed integer type are collectively called \textit{signed integer
types}.
\p There are three \textit{standard unsigned integer types}: \texttt{uint16\_t},
\texttt{uint32\_t}, and \texttt{uint64\_t}. Each of the unsigned integer types
is explicitly named for the size in bits of the type's object representation.
There is also the type alias \texttt{uint} which is an alias of
\texttt{uint32\_t}. There is one \textit{minimum precision unsigned integer
type}: \texttt{min16uint}. The minimum precision unsigned integer type is named
for the required minimum value representation size in bits. The object
representation of \texttt{min16uint} is \texttt{uint}. The standard unsigned
integer types and minimum precision unsigned integer type are collectively
called \textit{unsigned integer types}.
\p The minimum precision signed integer types and minimum precision unsigned
integer types are collectively called \textit{minimum precision integer types}.
The standard signed integer types and standard unsigned integer types are
collectively called \textit{standard integer types}. The signed integer types
and unsigned integer types are collectively called \textit{integer types}.
Integer types inherit the object representation of integers defined in
\glsdesc{isoC23}\footnote{C23 adopts two's compliment as the object
representation for integer types.}. Integer types shall satisfy the constraints
defined in \glsdesc{isoCPP}, section \textbf{basic.fundamental}.
\p There are three \textit{standard floating point types}: \texttt{half},
\texttt{float}, and \texttt{double}. The \texttt{float} type is a 32-bit
floating point type. The \texttt{double} type is a 64-bit floating point type.
Both the \texttt{float} and \texttt{double} types have object representations as
defined in \gls{IEEE754}. The \texttt{half} type may be either 16-bit or 32-bit
as controlled by implementation defined compiler settings. If \texttt{half} is
32-bit it will have an object representation as defined in \gls{IEEE754},
otherwise it will have an object representation matching the \textbf{binary16}
format defined in \gls{IEEE754}\footnote{IEEE-754 only defines a binary encoding
for 16-bit floating point values, it does not fully specify the behavior of such
types.}. There is one \textit{minimum precision floating point type}:
\texttt{min16float}. The minimum precision floating point type is named for the
required minimum value representation size in bits. The object representation of
\texttt{min16float} is \texttt{float}\footnote{This means when stored to memory
objects of type \texttt{min16float} are stored as \textbf{binary32} as defined
in \gls{IEEE754}.}. The standard floating point types and minimum precision
floating point type are collectively called \textit{floating point types}.
\p Integer and floating point types are collectively called \textit{arithmetic
types}.
\p The \texttt{void} type is inherited from \gls{isoCPP}, which defines it as
having an empty set of values and being an incomplete type that can never be
completed. The \texttt{void} type is used to signify the return type of a
function that returns no value. Any expression can be explicitly converted to
\texttt{void}.
\Sec{Lvalues and rvalues}{Basic.lval}
\p Expressions are classified by the type(s) of values they produce. The valid
types of values produced by expressions are:
\begin{enumerate}
\item An \textit{lvalue} represents a function or object.
\item An \textit{rvalue} represents a temporary object.
\item An \textit{xvalue} (expiring value) represents an object near the end
of its lifetime.
\item A \textit{cxvalue} (casted expiring value) is an \textit{xvalue}
which, on expiration, assigns its value to a bound \textit{lvalue}.
\item A \textit{glvalue} is an \textit{lvalue}, \textit{xvalue}, or
\textit{cxvalue}.
\item A \textit{prvalue} is an \textit{rvalue} that is not an \textit{xvalue}.
\end{enumerate}