Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0010] Allow casting to uint64_t #134

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions proposals/0010-vk-buffer-ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
```

Expand All @@ -105,10 +106,10 @@ This new type will have the following operations
vk::BufferPointer<DstType, DstAlign> only if SrcType is a type derived from
DstType. vk::reinterpret_pointer_cast<T, A> 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<T,A>(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:

Expand All @@ -120,8 +121,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
s-perron marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -191,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
}
Expand Down