diff --git a/specs/language/basic.tex b/specs/language/basic.tex index 1d9ac74c..469767a5 100644 --- a/specs/language/basic.tex +++ b/specs/language/basic.tex @@ -124,6 +124,44 @@ \Sec{Name Lookup}{Basic.Lookup} +\Sec{Storage Duration}{Basic.Storage} + +\p The storage duration of an object is the portion of the program's execution +time during which the object exists in memory. An object may have one of the +following storage durations: +\begin{itemize} +\item \textit{static storage duration} +\item \textit{automatic storage duration} +\item \textit{program storage duration} +\item \textit{groupshared storage duration} +\end{itemize} + +\Sub{Static Storage Duration}{Basic.Storage.Static} + +\p An object whose name is declared with the \texttt{static} storage specifier +has \textit{static storage duration}. Such an object is created when the thread +begins execution and destroyed when the thread ends execution. + +\Sub{Automatic Storage Duration}{Basic.Storage.Auto} + +\p An object whose name is declared in a block (including function parameters) +without the \texttt{static} storage specifier has \textit{automatic storage +duration}. Such an object is created when the block in which it is declared is +entered and destroyed when the block is exited. + +\Sub{Program Storage Duration}{Basic.Storage.Program} + +\p An object whose name is declared in a global, namespace, or cbuffer scope +without the \texttt{static} storage specifier has \textit{program storage +duration}. Such an object is created when the program begins execution and +destroyed when the program ends execution. + +\Sub{Groupshared Storage Duration}{Basic.Storage.Groupshared} + +\p An object whose name is declared with the \texttt{groupshared} storage +specifier has \textit{groupshared storage duration}. Such an object is created +when the thread group begins execution and destroyed when the thread group ends. + \Sec{Program and linkage}{Basic.Linkage} \p A translation unit (\ref{Lex.Translation}) is comprised of a sequence of diff --git a/specs/language/declarations.tex b/specs/language/declarations.tex index 342b6adc..a6a27cd5 100644 --- a/specs/language/declarations.tex +++ b/specs/language/declarations.tex @@ -3,30 +3,38 @@ \p Declarations generally specify how names are to be interpreted. Declarations have the form \begin{grammar} \define{declaration-seq}\br - \textit{declaration}\br - \textit{declaration-seq declaration} + declaration\br + declaration-seq declaration\br \define{declaration}\br - \textit{name-declaration}\br - \textit{special-declaration}\br - \textit{empty-declaration} + name-declaration\br + special-declaration\br \define{name-declaration}\br - \textit{variable-declaration}\br - \textit{function-declaration}\br - \textit{namespace-declaration}\br - \textit{record-declaration}\br - \textit{template-declaration}\br - \textit{type-alias-declaration}\br - ... - + block-declaration\br + function-definition\br + template-declaration\br + namespace-definition\br + empty-declaration\br + attribute-declaration\br + cbuffer-declaration\br + \define{special-declaration}\br - \textit{export-declaration-group}\br - \textit{cbuffer-declaration-group}\br - ... + export-declaration-group\br + cbuffer-member-declaration\br + + \define{block-declaration}\br + simple-declaration\br + namespace-alias-definition\br + using-declaration\br + using-directive\br + static\_assert-declaration\br + alias-declaration\br + opaque-enum-declaration\br + + \define{empty-declaration}\br + \terminal{;} - \define{empty-declaration} \terminal{;} - \end{grammar} \Sec{Specifiers}{Decl.Spec} @@ -146,3 +154,41 @@ \p Functions with \textit{external linkage} can also be declared with an \texttt{export} specifier (\ref{Decl.Spec.Fct}). \p If a function is part of an \textit{export-declaration-group} then all redeclarations of the same function must also be part on a \textit{export-declaration-group} or be declared with an \texttt{export} specifier (\ref{Decl.Spec.Fct}). + +\Sec{Constant Buffer Declarations}{Decl.cbuffer} + +\begin{grammar} + \define{cbuffer-declaration}\br + \terminal{cbuffer} name \opt{resource-binding} \terminal{\{} + \opt{cbuffer-member-seq} \terminal {\}}\br + + \define{cbuffer-member-seq}\br + cbuffer-member-declaration\br + cbuffer-member-seq cbuffer-member-declaration\br + + \define{cbuffer-member-declaration}\br + block-declaration\br + function-definition\br + template-declaration\br + empty-declaration +\end{grammar} + +\p A \textit{cbuffer declaration} is declared with the \texttt{cbuffer} keyword. +The name of the cbuffer declaration does not declare a name, and cannot be +referenced from within the translation unit, nor is it required to be unique. +Each cbuffer declaration refers to a unique constant buffer resource +(\ref{Resources.cnbuf}). + +\p Declarations within a cbuffer declaration that declare names, declare their +names in the scope containing the cbuffer declaration. The cbuffer declaration +itself does not declare a declaration scope. A cbuffer declaration may not +contain a \textit{namespace-declaration} or \textit{cbuffer-declaration}. +\footnote{These declarations were previously allowed in HLSL reference compilers +but are not supported in this specification.} + +\p Variable declarations with program storage duration +(\ref{Basic.Storage.Program}) in the cbuffer declaration are called +\textit{shader constants}. Shader constants are implicitly \texttt{const} and +cannot be modified in program code.\footnote{A future version of this +specification will likely disallow variable declarations with storage durations +other than program storage duration in cbuffer declarations.} diff --git a/specs/language/resources.tex b/specs/language/resources.tex index 4d80a30f..3b5ae237 100644 --- a/specs/language/resources.tex +++ b/specs/language/resources.tex @@ -665,59 +665,17 @@ \Sec{Constant Buffers}{Resources.cnbuf} -Constant buffers represent resources that contain read-only constant data in a -well-defined memory layout. - -\Sub{Constant Buffer Declaration Block}{Resources.cnbuf.cb} - -\p A constant buffer can be declared using the \texttt{cbuffer} specifier. - -\begin{grammar} - \define{cbuffer-declaration-group}\br - \terminal{cbuffer} name \opt{resource-binding} \terminal{\{} - \opt{cbuffer-declaration-seq} \terminal {\}} - - \define{cbuffer-declaration-seq}\br - \textit{cbuffer-declaration}\br - \textit{cbuffer-declaration-seq cbuffer-declaration} - - \define{cbuffer-declaration}\br - \textit{variable-declaration}\br - \textit{empty-declaration} -\end{grammar} - -\p The name of the \texttt{cbuffer} declaration group cannot be referenced from within the translation unit and is not required to be unique. - -\p Variable declarations in the \texttt{cbuffer} declaration group are called \textit{shader constants}. - -\p Shader constants can be referenced from anywhere in the translation unit after they are declared by directly using the declaration name. This implies that all shader constants declared in a translation unit must have unique names, even though they might be declared in different \texttt{cbuffer} declaration groups. - -\p Variable declarations in the \texttt{cbuffer} declaration group cannot have \texttt{groupshared} or \texttt{static} variable modifiers. - -\p Other declarations in the \texttt{cbuffer} declaration group such as -\textit{namespace-declaration}, \textit{record-declaration} or -\textit{function-declaration} are not allowed. - -\p Nesting of \texttt{cbuffer} declaration groups is not allowed. - -\p For example: - -\begin{HLSL} - cbuffer MyConstants { - float4 CameraPos; - }; - - float4 getCameraPosition() { - return CameraPos; - } -\end{HLSL} +\p Constant buffers represent resources that contain read-only constant data in a +well-defined memory layout. A constant buffer is declared either as a +cbuffer-declaration (\ref{Decl.cbuffer}) or as a declaration of Constant Buffer +Class type (\ref{Resources.cnbuf.cbclass}). \Sub{Constant Buffer Class}{Resources.cnbuf.cbclass} \p Another way of declaring constant buffers is by using the \texttt{ConstantBuffer} resource class. -\p The template parameter \texttt{T} must be a class type (\ref{Classes}). +\p The template parameter \texttt{T} must be a class type (\ref{Classes}). \begin{HLSL} template