Fix D3D12 rendering device driver returning pointers to internal types for get_resource_native_handle instead of proper D3D12 primitives#111658
Conversation
clayjohn
left a comment
There was a problem hiding this comment.
This PR should also update the respective documentation for DRIVER_RESOURCE_COMMAND_QUEUE and DRIVER_RESOURCE_TEXTURE
Overall this make sense to me since it never makes sense for us to return an internal pointer out of the RD API
| case DRIVER_RESOURCE_TEXTURE: { | ||
| const TextureInfo *tex_info = (const TextureInfo *)p_driver_id.id; | ||
| return (uint64_t)tex_info->main_texture; | ||
| return (uint64_t)tex_info->resource; |
There was a problem hiding this comment.
This might need to be tex_info->main_texture->resource Otherwise it is returning the handle to the texture slice, not to the texture itself
There was a problem hiding this comment.
Good point, and this matches the pattern of other parts of the code. I've fixed that now, thanks.
As an aside, it looks like in practice these are always the same resource because D3D12 doesn't have an object that maps cleanly to VkImageView (Metal also returns the same object for both DRIVER_RESOURCE_TEXTURE and DRIVER_RESOURCE_TEXTURE_VIEW).
…e_get_native_handle/get_driver_resource
00a18c7 to
1f7e7de
Compare
|
Thanks! |
get_resource_native_handle instead of proper D3D12 primitives
I am working on a project to display texture resources in Godot that are shared from another process. To do this I require interop with the underlying rendering primitives (e.g. ID3D12Device/VkLogicalDevice, ID3D12CommandQueue/VkQueue, ID3D12Resource/VkImage). I found with D3D12 that the wrong memory addresses were being returned by RenderingDevice::get_driver_resource in two cases:
DRIVER_RESOURCE_COMMAND_QUEUE, a pointer to an internal structure (CommandQueueInfo *) rather than theID3D12CommandQueue *pointer was being returned.DRIVER_RESOURCE_TEXTURE, a pointer to an internal structure was being returned ((uint64_t)tex_info->main_textureis aTextureInfo *). Instead, this should be returning theID3D12Resource *pointer. In fact, looking back in the history, I can see that this is what was done before a big refactor to avoid code duplication between D3D12 and VK (See the old definition oftexture_get_native_handlein rendering_device_d3d12.cpp - SplitRenderingDeviceinto API-agnostic andRenderingDeviceDriverparts #83452).