Advertisement

Why is D3D12_CPU_DESCRIPTOR_HANDLE a struct?

Started by July 27, 2018 12:28 PM
4 comments, last by AndreyVK_D3D 6 years, 6 months ago

In DX12 API, we have this definition:


typedef struct D3D12_CPU_DESCRIPTOR_HANDLE
{
  SIZE_T ptr;
} D3D12_CPU_DESCRIPTOR_HANDLE;

As the title says, what is the reason for it to be a struct? Is there any reason apart from being type safe? In my engine, I store size_t handles for my graphics types instead of this, because I am not including dx12 headers in the rest of the code base. I go out of my way to convert my size_t handles to D3D12_CPU_DESCRIPTOR_HANDLE like this:


typedef size_t wiCPUHandle; // My own handle type

inline D3D12_CPU_DESCRIPTOR_HANDLE ToNativeHandle(wiCPUHandle handle)
{
	D3D12_CPU_DESCRIPTOR_HANDLE native;
	native.ptr = handle;
	return native;
}

And this function gets copied before every native API call to retrieve the native handle from my handle type. Doesn't seem like a very nice solution, maybe I am not realizing something obvious? In Vulkan, they simply typedef the handles to pointer type or uint64.

Don't have a definitive answer, but does it really make a difference in your use case ? Its seems that even in the Vulkan case you would still need to do some translation since you have your own version of object handles.

Advertisement

It's definitely not a huge difference, but in the Vulkan wrapper, I can just cast instead of using that function. It just got me wondering why is it like this. 

Instead of 
D3D12_CPU_DESCRIPTOR_HANDLE h = ToNativeHandle(handle);
You can probably just write:
D3D12_CPU_DESCRIPTOR_HANDLE h = {handle};

You can use te following code:


inline D3D12_CPU_DESCRIPTOR_HANDLE ToNativeHandle(wiCPUHandle handle)
{
	return reinterpret_cast<const D3D12_CPU_DESCRIPTOR_HANDLE &>(handle);
}

?

 

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

This topic is closed to new replies.

Advertisement