From a483c45cc4e51ce389dfe757f58bbd4a47ad9859 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Wed, 18 Sep 2024 13:52:17 -0500 Subject: [PATCH 1/9] [Lang] Revisit memory model This change cleans up some of the wording in the memory model and clearly defines the terms _byte_, _memory location_, _memory access_, and _memory operation_. These terms will be useful in writing the Classes chapter where the layout of objects needs to be defined. --- specs/language/introduction.tex | 59 +++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/specs/language/introduction.tex b/specs/language/introduction.tex index f4003938..dcad7afc 100644 --- a/specs/language/introduction.tex +++ b/specs/language/introduction.tex @@ -273,21 +273,52 @@ \Sec{\acrshort{hlsl} Memory Models}{Intro.Memory} -\p Memory accesses for \gls{sm} 5.0 and earlier operate on 128-bit slots aligned -on 128-bit boundaries. This optimized for the common case in early shaders where -data being processed on the GPU was usually 4-element vectors of 32-bit data -types. - -\p On modern hardware memory access restrictions are loosened, and reads of -32-bit multiples are supported starting with \gls{sm} 5.1 and reads of 16-bit -multiples are supported with \gls{sm} 6.0. \gls{sm} features are fully -documented in the \gls{dx} Specifications, and this document will not attempt to -elaborate further. +\p The fundamental storage unit in HLSL is a \textit{byte}, which is comprised +of 8 \textit{bits}. Each \textit{bit} stores a single value 0 or 1. Each byte +has a unique \textit{memory location}, alternatively called an \textit{address}. + +\p An object that is not of an intangible type will have an associated set of +memory locations containing one or more location. For a bit-field the location +will represent a maximal sequence of adjacent bit-fields all having nonzero +width. + +\p Each read or write to a memory location is called a \textit{memory access}. +Operations that perform memory accesses are called \textit{memory operation}. A +memory operation may operate on one or more memory locations. A memory operation +must not alter memory at a location not contained in the memory location set it +is operating on\footnote{Two subtle notes here: (1) A bit-field's memory location +includes adjacent bit-fields, so reads and writes to bit-fields are expected to +read and write adjacent memory if they're within the same set of locations, (2) +padding bits inside a structure are included in the memory location of the +structure. Reads and writes of uninitialized memory may be undefined, but a +write is allowed to stomp over padding.}. + +\p Two sets of memory locations, \texttt{A} and \texttt{B}, are said to +\textit{overlap} each other if some memory location in \texttt{A} is also in +\texttt{B} (\(A \cap B \neq \emptyset\)). Two objects are said to +\textit{alias}, if their memory locations overlap. \Sub{Memory Spaces}{Intro.Memory.Spaces} \p \acrshort{hlsl} programs manipulate data stored in four distinct memory -spaces: thread, threadgroup, device and constant. +spaces: thread, threadgroup, device and constant. Memory spaces are logical +abstractions over physical memory. Each memory space has a defined \textit{line +width}, which specifies the minimum readable and writable size, and a +\textit{minimum alignment}, which defines the smallest addressable increment of +the memory space. The two values need not be the same, although they may be. + +\begin{note} + \p Memory accesses for many resource types in \gls{dx} operate on 128-bit + slots aligned on 128-bit boundaries. In the terms of this specification it + would be said that those memory spaces have a 128-byte \textit{line width}, + and a 128-byte \textit{minimum alignment}. +\end{note} + +\p A memory location in any space may overlap with another memory location in +the same space. A memory location in thread or threadgroup memory may not +overlap with memory locations in any other memory spaces. It is implementation +defined if memory locations in other memory spaces alias with memory locations +in different spaces. \SubSub{Thread Memory}{Intro.Memory.Spaces.Thread} @@ -319,3 +350,9 @@ \gls{lane}s executing on the device. Constant memory is read-only, and an implementation can assume that constant memory is immutable and cannot change during execution. + +\SubSub{Constant Memory}{Intro.Memory.Spaces.Overlap} + +\p The \textbf{Thread} and \textbf{Thread Group} memory spacees may not overlap +with any other memory space. All addresses in either memory space are implied to +not alias any address in any other memory space. From 0040940bea6b561b8d1c4655f9eb44579e0ebbc0 Mon Sep 17 00:00:00 2001 From: Chris B Date: Wed, 18 Sep 2024 20:55:30 -0500 Subject: [PATCH 2/9] Update specs/language/introduction.tex Co-authored-by: Damyan Pepper --- specs/language/introduction.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/language/introduction.tex b/specs/language/introduction.tex index dcad7afc..550e42cc 100644 --- a/specs/language/introduction.tex +++ b/specs/language/introduction.tex @@ -283,7 +283,7 @@ width. \p Each read or write to a memory location is called a \textit{memory access}. -Operations that perform memory accesses are called \textit{memory operation}. A +Operations that perform memory accesses are called \textit{memory operations}. A memory operation may operate on one or more memory locations. A memory operation must not alter memory at a location not contained in the memory location set it is operating on\footnote{Two subtle notes here: (1) A bit-field's memory location From 1ce665798e010e703822ca1c4a4484446043c71a Mon Sep 17 00:00:00 2001 From: Chris B Date: Wed, 18 Sep 2024 20:55:52 -0500 Subject: [PATCH 3/9] Update specs/language/introduction.tex Co-authored-by: Damyan Pepper --- specs/language/introduction.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/language/introduction.tex b/specs/language/introduction.tex index 550e42cc..e780fc8d 100644 --- a/specs/language/introduction.tex +++ b/specs/language/introduction.tex @@ -285,7 +285,7 @@ \p Each read or write to a memory location is called a \textit{memory access}. Operations that perform memory accesses are called \textit{memory operations}. A memory operation may operate on one or more memory locations. A memory operation -must not alter memory at a location not contained in the memory location set it +must not alter memory at a location not contained in the set of memory locations it is operating on\footnote{Two subtle notes here: (1) A bit-field's memory location includes adjacent bit-fields, so reads and writes to bit-fields are expected to read and write adjacent memory if they're within the same set of locations, (2) From 809bbc5c7ffbc1dddde4d0386e0ecca610b04ded Mon Sep 17 00:00:00 2001 From: Chris B Date: Wed, 18 Sep 2024 20:56:27 -0500 Subject: [PATCH 4/9] Update specs/language/introduction.tex Co-authored-by: Damyan Pepper --- specs/language/introduction.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/language/introduction.tex b/specs/language/introduction.tex index e780fc8d..bce26ccd 100644 --- a/specs/language/introduction.tex +++ b/specs/language/introduction.tex @@ -353,6 +353,6 @@ \SubSub{Constant Memory}{Intro.Memory.Spaces.Overlap} -\p The \textbf{Thread} and \textbf{Thread Group} memory spacees may not overlap +\p The \textbf{Thread} and \textbf{Thread Group} memory spaces may not overlap with any other memory space. All addresses in either memory space are implied to not alias any address in any other memory space. From e66e423dcf1d49354afe4f155088bdae0a52995e Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Thu, 19 Sep 2024 18:15:40 -0500 Subject: [PATCH 5/9] bytes->bits --- specs/language/introduction.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/language/introduction.tex b/specs/language/introduction.tex index bce26ccd..929260a4 100644 --- a/specs/language/introduction.tex +++ b/specs/language/introduction.tex @@ -310,8 +310,8 @@ \begin{note} \p Memory accesses for many resource types in \gls{dx} operate on 128-bit slots aligned on 128-bit boundaries. In the terms of this specification it - would be said that those memory spaces have a 128-byte \textit{line width}, - and a 128-byte \textit{minimum alignment}. + would be said that those memory spaces have a 128-bit \textit{line width}, + and a 128-bit \textit{minimum alignment}. \end{note} \p A memory location in any space may overlap with another memory location in From 2398305497ceedb09e7c2cb499e93a6b65a12211 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Thu, 19 Sep 2024 18:19:29 -0500 Subject: [PATCH 6/9] Remove object terms, those should go in a separate section --- specs/language/introduction.tex | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/specs/language/introduction.tex b/specs/language/introduction.tex index 929260a4..2114fe4f 100644 --- a/specs/language/introduction.tex +++ b/specs/language/introduction.tex @@ -277,11 +277,6 @@ of 8 \textit{bits}. Each \textit{bit} stores a single value 0 or 1. Each byte has a unique \textit{memory location}, alternatively called an \textit{address}. -\p An object that is not of an intangible type will have an associated set of -memory locations containing one or more location. For a bit-field the location -will represent a maximal sequence of adjacent bit-fields all having nonzero -width. - \p Each read or write to a memory location is called a \textit{memory access}. Operations that perform memory accesses are called \textit{memory operations}. A memory operation may operate on one or more memory locations. A memory operation @@ -295,8 +290,7 @@ \p Two sets of memory locations, \texttt{A} and \texttt{B}, are said to \textit{overlap} each other if some memory location in \texttt{A} is also in -\texttt{B} (\(A \cap B \neq \emptyset\)). Two objects are said to -\textit{alias}, if their memory locations overlap. +\texttt{B} (\(A \cap B \neq \emptyset\)). \Sub{Memory Spaces}{Intro.Memory.Spaces} From d89823f0533a1db80fa38ca869da75acfcc1bd56 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Thu, 19 Sep 2024 18:26:53 -0500 Subject: [PATCH 7/9] Fix up the footnote based on feedback from @damyanp --- specs/language/introduction.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/language/introduction.tex b/specs/language/introduction.tex index 2114fe4f..188d4e6e 100644 --- a/specs/language/introduction.tex +++ b/specs/language/introduction.tex @@ -285,8 +285,8 @@ includes adjacent bit-fields, so reads and writes to bit-fields are expected to read and write adjacent memory if they're within the same set of locations, (2) padding bits inside a structure are included in the memory location of the -structure. Reads and writes of uninitialized memory may be undefined, but a -write is allowed to stomp over padding.}. +structure. Reads and writes of uninitialized memory is undefined, but a write is +allowed to stomp over padding.}. \p Two sets of memory locations, \texttt{A} and \texttt{B}, are said to \textit{overlap} each other if some memory location in \texttt{A} is also in From 5f062b839146da238e64817efbf5b7e46a342311 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Thu, 26 Sep 2024 18:57:11 -0500 Subject: [PATCH 8/9] Working on clarifying the spec language based on feedback. Thank you! --- specs/language/introduction.tex | 68 ++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/specs/language/introduction.tex b/specs/language/introduction.tex index 188d4e6e..93ca156b 100644 --- a/specs/language/introduction.tex +++ b/specs/language/introduction.tex @@ -275,18 +275,48 @@ \p The fundamental storage unit in HLSL is a \textit{byte}, which is comprised of 8 \textit{bits}. Each \textit{bit} stores a single value 0 or 1. Each byte -has a unique \textit{memory location}, alternatively called an \textit{address}. +has a unique \textit{address}. + +\p A \textit{memory location} is a range of bytes which can be identified by an +address and a length. A memory location represents either a scalar object, or a +sequence of adjacent bit-fields of non-zero size. \p Each read or write to a memory location is called a \textit{memory access}. Operations that perform memory accesses are called \textit{memory operations}. A memory operation may operate on one or more memory locations. A memory operation -must not alter memory at a location not contained in the set of memory locations it -is operating on\footnote{Two subtle notes here: (1) A bit-field's memory location -includes adjacent bit-fields, so reads and writes to bit-fields are expected to -read and write adjacent memory if they're within the same set of locations, (2) -padding bits inside a structure are included in the memory location of the -structure. Reads and writes of uninitialized memory is undefined, but a write is -allowed to stomp over padding.}. +must not alter memory at a location not contained in the set of memory locations +it is operating on. + +\begin{note} + The memory location of a bit-field may include adjacent bit-fields. For + example given the following declaration: + + \begin{HLSL} + struct ContainingBitfields { + uint A : 4; + uint B : 4; + uint : 0; + uint D : 4; + } + \end{HLSL} + + Members \texttt{A}, and \texttt{B} have the same memory locations comprised of + 4 bytes beginning at the start of the structure. The zero-sized anonymous + bit-field member causes a break in bit-field packing, so member \texttt{D} + occupies the next set of memory locations beginning at the 5th byte of the + structure and continuing for 4 bytes. For more description of bit-fields see + \ref{Classes.BitFields}. +\end{note} + +\p Padding bytes inside a structure are included in the memory location of the +structure, but are not included in the memory locations of the members inside +the structure. This means that element-wise operations like default copy +operations do not copy padding bytes. Because structure padding is +implementation defined, and reading or writing padding bytes is undefined +behavior, an implementation may generate writes that overwrite padding bytes. + +\p Reading from uninitialized memory is undefined. Writing uninitialized values +to memory is undefined. \p Two sets of memory locations, \texttt{A} and \texttt{B}, are said to \textit{overlap} each other if some memory location in \texttt{A} is also in @@ -308,11 +338,17 @@ and a 128-bit \textit{minimum alignment}. \end{note} -\p A memory location in any space may overlap with another memory location in -the same space. A memory location in thread or threadgroup memory may not -overlap with memory locations in any other memory spaces. It is implementation -defined if memory locations in other memory spaces alias with memory locations -in different spaces. +\p Each address has an associated memory space. Two addresses with the same +value but different memory spaces are considered different unique addresses. + +\p A memory location in any memory space may overlap with another memory +location in the same space. A memory location in thread or threadgroup memory +may not overlap with memory locations in any other memory spaces\footnote{The +physical memory regions for thread and threadgroup memory are required to be +distinct and non-overlapping with any other memory space.}. It is implementation +defined if memory locations in other memory spaces overlap with memory locations +in different spaces\footnote{An implementation may define device, constant or +additional extended memory spaces to share logical address ranges.}. \SubSub{Thread Memory}{Intro.Memory.Spaces.Thread} @@ -344,9 +380,3 @@ \gls{lane}s executing on the device. Constant memory is read-only, and an implementation can assume that constant memory is immutable and cannot change during execution. - -\SubSub{Constant Memory}{Intro.Memory.Spaces.Overlap} - -\p The \textbf{Thread} and \textbf{Thread Group} memory spaces may not overlap -with any other memory space. All addresses in either memory space are implied to -not alias any address in any other memory space. From 05166763d11947d1c036b9dc5b3d8a0e7e71755e Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Fri, 27 Sep 2024 08:18:05 -0500 Subject: [PATCH 9/9] Adding missing placeholder --- specs/language/placeholders.tex | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/language/placeholders.tex b/specs/language/placeholders.tex index bfadec67..9c020d62 100644 --- a/specs/language/placeholders.tex +++ b/specs/language/placeholders.tex @@ -7,6 +7,7 @@ \Ch{Classes}{Classes} \Sec{Static Members}{Classes.Static} \Sec{Conversions}{Classes.Conversions} +\Sec{Bit-fields}{Classes.BitFields} \Ch{Templates}{Template} \Sec{Template Instantiation}{Template.Inst} \Sec{Partial Ordering of Function Templates}{Template.Func.Order}