Skip to content

Commit 38626eb

Browse files
llvm-beanzhekota
andauthored
[Lang] Update and restructure cbuffer spec (#684)
This change pulls the cbuffer section into the Declarations chapter instead of the Resources chapter since it defines a declaration type, and updates the grammar and specification language based on the updates to proposal 37. The updated language avoids nesting of cbuffers and namepaces in cbuffers to simplify semantic validation. The updated langauge also adds additional language around storage durations which is referenced in the updated specification language. Resolves #671 --------- Co-authored-by: Helena Kotas <hekotas@microsoft.com>
1 parent d9ceba8 commit 38626eb

3 files changed

Lines changed: 107 additions & 65 deletions

File tree

specs/language/basic.tex

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,44 @@
124124

125125
\Sec{Name Lookup}{Basic.Lookup}
126126

127+
\Sec{Storage Duration}{Basic.Storage}
128+
129+
\p The storage duration of an object is the portion of the program's execution
130+
time during which the object exists in memory. An object may have one of the
131+
following storage durations:
132+
\begin{itemize}
133+
\item \textit{static storage duration}
134+
\item \textit{automatic storage duration}
135+
\item \textit{program storage duration}
136+
\item \textit{groupshared storage duration}
137+
\end{itemize}
138+
139+
\Sub{Static Storage Duration}{Basic.Storage.Static}
140+
141+
\p An object whose name is declared with the \texttt{static} storage specifier
142+
has \textit{static storage duration}. Such an object is created when the thread
143+
begins execution and destroyed when the thread ends execution.
144+
145+
\Sub{Automatic Storage Duration}{Basic.Storage.Auto}
146+
147+
\p An object whose name is declared in a block (including function parameters)
148+
without the \texttt{static} storage specifier has \textit{automatic storage
149+
duration}. Such an object is created when the block in which it is declared is
150+
entered and destroyed when the block is exited.
151+
152+
\Sub{Program Storage Duration}{Basic.Storage.Program}
153+
154+
\p An object whose name is declared in a global, namespace, or cbuffer scope
155+
without the \texttt{static} storage specifier has \textit{program storage
156+
duration}. Such an object is created when the program begins execution and
157+
destroyed when the program ends execution.
158+
159+
\Sub{Groupshared Storage Duration}{Basic.Storage.Groupshared}
160+
161+
\p An object whose name is declared with the \texttt{groupshared} storage
162+
specifier has \textit{groupshared storage duration}. Such an object is created
163+
when the thread group begins execution and destroyed when the thread group ends.
164+
127165
\Sec{Program and linkage}{Basic.Linkage}
128166

129167
\p A translation unit (\ref{Lex.Translation}) is comprised of a sequence of

specs/language/declarations.tex

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,38 @@
33
\p Declarations generally specify how names are to be interpreted. Declarations have the form
44
\begin{grammar}
55
\define{declaration-seq}\br
6-
\textit{declaration}\br
7-
\textit{declaration-seq declaration}
6+
declaration\br
7+
declaration-seq declaration\br
88

99
\define{declaration}\br
10-
\textit{name-declaration}\br
11-
\textit{special-declaration}\br
12-
\textit{empty-declaration}
10+
name-declaration\br
11+
special-declaration\br
1312

1413
\define{name-declaration}\br
15-
\textit{variable-declaration}\br
16-
\textit{function-declaration}\br
17-
\textit{namespace-declaration}\br
18-
\textit{record-declaration}\br
19-
\textit{template-declaration}\br
20-
\textit{type-alias-declaration}\br
21-
...
22-
14+
block-declaration\br
15+
function-definition\br
16+
template-declaration\br
17+
namespace-definition\br
18+
empty-declaration\br
19+
attribute-declaration\br
20+
cbuffer-declaration\br
21+
2322
\define{special-declaration}\br
24-
\textit{export-declaration-group}\br
25-
\textit{cbuffer-declaration-group}\br
26-
...
23+
export-declaration-group\br
24+
cbuffer-member-declaration\br
25+
26+
\define{block-declaration}\br
27+
simple-declaration\br
28+
namespace-alias-definition\br
29+
using-declaration\br
30+
using-directive\br
31+
static\_assert-declaration\br
32+
alias-declaration\br
33+
opaque-enum-declaration\br
34+
35+
\define{empty-declaration}\br
36+
\terminal{;}
2737

28-
\define{empty-declaration} \terminal{;}
29-
3038
\end{grammar}
3139

3240
\Sec{Specifiers}{Decl.Spec}
@@ -146,3 +154,41 @@
146154
\p Functions with \textit{external linkage} can also be declared with an \texttt{export} specifier (\ref{Decl.Spec.Fct}).
147155

148156
\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}).
157+
158+
\Sec{Constant Buffer Declarations}{Decl.cbuffer}
159+
160+
\begin{grammar}
161+
\define{cbuffer-declaration}\br
162+
\terminal{cbuffer} name \opt{resource-binding} \terminal{\{}
163+
\opt{cbuffer-member-seq} \terminal {\}}\br
164+
165+
\define{cbuffer-member-seq}\br
166+
cbuffer-member-declaration\br
167+
cbuffer-member-seq cbuffer-member-declaration\br
168+
169+
\define{cbuffer-member-declaration}\br
170+
block-declaration\br
171+
function-definition\br
172+
template-declaration\br
173+
empty-declaration
174+
\end{grammar}
175+
176+
\p A \textit{cbuffer declaration} is declared with the \texttt{cbuffer} keyword.
177+
The name of the cbuffer declaration does not declare a name, and cannot be
178+
referenced from within the translation unit, nor is it required to be unique.
179+
Each cbuffer declaration refers to a unique constant buffer resource
180+
(\ref{Resources.cnbuf}).
181+
182+
\p The cbuffer declaration itself does not declare a declaration scope.
183+
Declarations within a cbuffer declaration that declare names, declare their names
184+
in the scope containing the cbuffer declaration. A cbuffer declaration may not
185+
contain a \textit{namespace-declaration} or \textit{cbuffer-declaration}.
186+
\footnote{These declarations were previously allowed in HLSL reference compilers
187+
but are not supported in this specification.}
188+
189+
\p Variable declarations with program storage duration
190+
(\ref{Basic.Storage.Program}) in the cbuffer declaration are called
191+
\textit{shader constants}. Shader constants are implicitly \texttt{const} and
192+
cannot be modified in program code.\footnote{A future version of this
193+
specification will likely disallow variable declarations with storage durations
194+
other than program storage duration in cbuffer declarations.}

specs/language/resources.tex

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -665,59 +665,17 @@
665665

666666
\Sec{Constant Buffers}{Resources.cnbuf}
667667

668-
Constant buffers represent resources that contain read-only constant data in a
669-
well-defined memory layout.
670-
671-
\Sub{Constant Buffer Declaration Block}{Resources.cnbuf.cb}
672-
673-
\p A constant buffer can be declared using the \texttt{cbuffer} specifier.
674-
675-
\begin{grammar}
676-
\define{cbuffer-declaration-group}\br
677-
\terminal{cbuffer} name \opt{resource-binding} \terminal{\{}
678-
\opt{cbuffer-declaration-seq} \terminal {\}}
679-
680-
\define{cbuffer-declaration-seq}\br
681-
\textit{cbuffer-declaration}\br
682-
\textit{cbuffer-declaration-seq cbuffer-declaration}
683-
684-
\define{cbuffer-declaration}\br
685-
\textit{variable-declaration}\br
686-
\textit{empty-declaration}
687-
\end{grammar}
688-
689-
\p The name of the \texttt{cbuffer} declaration group cannot be referenced from within the translation unit and is not required to be unique.
690-
691-
\p Variable declarations in the \texttt{cbuffer} declaration group are called \textit{shader constants}.
692-
693-
\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.
694-
695-
\p Variable declarations in the \texttt{cbuffer} declaration group cannot have \texttt{groupshared} or \texttt{static} variable modifiers.
696-
697-
\p Other declarations in the \texttt{cbuffer} declaration group such as
698-
\textit{namespace-declaration}, \textit{record-declaration} or
699-
\textit{function-declaration} are not allowed.
700-
701-
\p Nesting of \texttt{cbuffer} declaration groups is not allowed.
702-
703-
\p For example:
704-
705-
\begin{HLSL}
706-
cbuffer MyConstants {
707-
float4 CameraPos;
708-
};
709-
710-
float4 getCameraPosition() {
711-
return CameraPos;
712-
}
713-
\end{HLSL}
668+
\p Constant buffers represent resources that contain read-only constant data in a
669+
well-defined memory layout. A constant buffer is declared either as a
670+
cbuffer-declaration (\ref{Decl.cbuffer}) or as a declaration of Constant Buffer
671+
Class type (\ref{Resources.cnbuf.cbclass}).
714672

715673
\Sub{Constant Buffer Class}{Resources.cnbuf.cbclass}
716674

717675
\p Another way of declaring constant buffers is by using the
718676
\texttt{ConstantBuffer<T>} resource class.
719677

720-
\p The template parameter \texttt{T} must be a class type (\ref{Classes}).
678+
\p The template parameter \texttt{T} must be a class type (\ref{Classes}).
721679

722680
\begin{HLSL}
723681
template <typename T>

0 commit comments

Comments
 (0)