From e83cb694ab8bf3aaaaf79c35dabc8679585ee48f Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Fri, 1 Dec 2023 13:51:16 -0500 Subject: [PATCH 1/3] [0010] Allow casting to uint64_t We have decided to allow casting to uint64_t. It will make create more opportunities for developers to make mistakes, but they do not have to use it. The implementation cost does not seem too high. Fixes https://github.com/microsoft/hlsl-specs/issues/93 --- proposals/0010-vk-buffer-ref.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/proposals/0010-vk-buffer-ref.md b/proposals/0010-vk-buffer-ref.md index 34991f22..26ace9a9 100644 --- a/proposals/0010-vk-buffer-ref.md +++ b/proposals/0010-vk-buffer-ref.md @@ -109,6 +109,8 @@ This new type will have the following operations syntax vk::BufferPointer(u). * A buffer pointer can be cast to a bool. If so, it returns FALSE if the pointer is null, TRUE otherwise. +* A buffer pointer can be cast to a uint64_t. The cast will return the 64-bit + address that the pointer points to. Note the operations that are not allowed: @@ -120,8 +122,12 @@ Note the operations that are not allowed: * The comparison operators == and != are not supported for buffer pointers. Most of these restrictions are there for safety. They minimize the possibility -of getting an invalid pointer. If the Get() method is used on a null or invalid -pointer, the behaviour is undefined. +of getting an invalid pointer. If a buffer pointer is cast to and from a +uint64_t, then it is the responsibility of the user to make sure that a valid +pointer is generated, and that aliasing rules are followed. + +If the Get() method is used on a null or invalid pointer, the behaviour is +undefined. When used as a member in a buffer, vk::BufferPointer can be used to pass physical buffer addresses into a shader, and address and access buffer space From dbb3af4383fc920e954a702ae5733b590fce659b Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Wed, 6 Dec 2023 09:19:03 -0500 Subject: [PATCH 2/3] Remove cast to bool As Greg suggested, the cast to bool is no longer needed if we can cast to an int, so we removed it. This commit also adds the uint64_t cast to the pseudo class definition for BufferPointers. --- proposals/0010-vk-buffer-ref.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/proposals/0010-vk-buffer-ref.md b/proposals/0010-vk-buffer-ref.md index 26ace9a9..77252ee3 100644 --- a/proposals/0010-vk-buffer-ref.md +++ b/proposals/0010-vk-buffer-ref.md @@ -86,6 +86,7 @@ class vk::BufferPointer { vk::BufferPointer& operator=(const vk::BufferPointer&); vk::BufferPointer(const uint64_t); S& Get() const; + operator uint64_t() const; } ``` @@ -105,10 +106,8 @@ This new type will have the following operations vk::BufferPointer only if SrcType is a type derived from DstType. vk::reinterpret_pointer_cast allows casting for all other BufferPointer types. For both casts, DstAlign <= SrcAlign must be true. -* A buffer pointer can be constructed from a uint64_t u using the constructor +* A buffer pointer can be constructed from a uint64_t using the constructor syntax vk::BufferPointer(u). -* A buffer pointer can be cast to a bool. If so, it returns FALSE if the - pointer is null, TRUE otherwise. * A buffer pointer can be cast to a uint64_t. The cast will return the 64-bit address that the pointer points to. From f1668ee32994b8d47f8a371e4a61c85ee6042991 Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Thu, 7 Dec 2023 14:07:41 -0500 Subject: [PATCH 3/3] Fix linked list example after rebaseing. --- proposals/0010-vk-buffer-ref.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/0010-vk-buffer-ref.md b/proposals/0010-vk-buffer-ref.md index 77252ee3..9c083c3e 100644 --- a/proposals/0010-vk-buffer-ref.md +++ b/proposals/0010-vk-buffer-ref.md @@ -196,7 +196,7 @@ float4 MainPs(void) : SV_Target0 { block_p g_p(g_PushConstants.root); g_p = g_p.Get().next; - if (!(bool)g_p) // Null pointer test + if ((uint64_t)g_pi == 0) // Null pointer test return float4(0.0,0.0,0.0,0.0); return g_p.Get().x }