X Tutup
Skip to content

Fix D3D12 rendering device driver returning pointers to internal types for get_resource_native_handle instead of proper D3D12 primitives#111658

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
brycehutchings:bryceh_d3d12_native_handle_fixes
Oct 16, 2025
Merged

Fix D3D12 rendering device driver returning pointers to internal types for get_resource_native_handle instead of proper D3D12 primitives#111658
Repiteo merged 1 commit intogodotengine:masterfrom
brycehutchings:bryceh_d3d12_native_handle_fixes

Conversation

@brycehutchings
Copy link
Contributor

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:

  • When querying for DRIVER_RESOURCE_COMMAND_QUEUE, a pointer to an internal structure (CommandQueueInfo *) rather than the ID3D12CommandQueue * pointer was being returned.
  • When querying for DRIVER_RESOURCE_TEXTURE, a pointer to an internal structure was being returned ((uint64_t)tex_info->main_texture is a TextureInfo *). Instead, this should be returning the ID3D12Resource * 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 of texture_get_native_handle in rendering_device_d3d12.cpp - Split RenderingDevice into API-agnostic and RenderingDeviceDriver parts #83452).

@brycehutchings brycehutchings requested a review from a team as a code owner October 14, 2025 22:32
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting!

@brycehutchings brycehutchings force-pushed the bryceh_d3d12_native_handle_fixes branch from 00a18c7 to 1f7e7de Compare October 15, 2025 17:35
@brycehutchings brycehutchings requested a review from a team as a code owner October 15, 2025 17:35
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me

@Repiteo Repiteo merged commit 2edad68 into godotengine:master Oct 16, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 16, 2025

Thanks!

@akien-mga akien-mga changed the title Fix D3D12 rendering device driver returning pointers to internal types for get_resource_native_handle instead of proper D3D12 primitives Fix D3D12 rendering device driver returning pointers to internal types for get_resource_native_handle instead of proper D3D12 primitives Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup