Skip to content

Implement Buffer Device Address for Rendering Device Vulkan and DirectX12 - #100062

Merged
akien-mga merged 1 commit into
godotengine:masterfrom
thimenesup:rd_buffer_address
Jan 14, 2025
Merged

akien-mga merged 1 commit into
godotengine:masterfrom
thimenesup:rd_buffer_address

Conversation

@thimenesup

Copy link
Copy Markdown
Contributor

This is an extremely useful feature that is supported on many GPUs which may be worthwhile to have it since the changes are minimally invasive, and allows for a lot of flexibility, specially for compute shaders and a requirement for ray tracing.

Tested to work on Windows 10 with Vulkan driver.
On DirectX12 the SPIR-V to NIR shader compiler doesn't have implemented this extension (yet?), so remains untested.
Test project used available here

Do note that it only has been implemented for storage buffers, to not change function signatures, but it could be implemented for the other buffer types, either by adding another default parameter, or breaking compatibility and using bitwise flags.

@thimenesup
thimenesup requested a review from a team as a code owner December 5, 2024 17:49
@DarioSamo

DarioSamo commented Dec 5, 2024 •

Copy link
Copy Markdown
Contributor

Both you and #99119 are trying to implement this as buffer device address is required for RT as well. You might want to coordinate how to support this particular feature as both implementations seem to be a bit different. CC @Fahien

Comment thread servers/rendering/rendering_device.cpp Outdated
@thimenesup

Copy link
Copy Markdown
Contributor Author

From what I have seen the implementations are fairly similar, albeit with some small differences, mine loads the extension either from core 1.2 or the KHR version which has a wider support compared to the EXT used in the other branch (sourced from the gpuinfo database), and also flags index and vertex buffers by default, which likely won't play nicely on devices where its not supported.

I think the buffer device address feature its worthwhile on its own and should be merged beforehand, then the other ray tracing branch could be rebased from it.

Went ahead an added it as optional functionality to index, vertex and uniform buffers while preserving compatibility, and updated the documentation.
Also implemented it for Metal to ensure compilation, but its an API I haven't really used, so I don't know for sure if its 100% correct.

@Fahien

Fahien commented Dec 6, 2024

Copy link
Copy Markdown
Contributor

@thimenesup: I think the buffer device address feature its worthwhile on its own and should be merged beforehand, then the other ray tracing branch could be rebased from it.

I agree.

@DarioSamo

Copy link
Copy Markdown
Contributor

I think the buffer device address feature its worthwhile on its own and should be merged beforehand, then the other ray tracing branch could be rebased from it.

I believe so as well, it's easier to integrate it piece-meal like this. I just wanted to make sure you were both in agreement as it'll break the RT branch as soon as it's merged. I have no qualms with integrating the feature as I know how necessary it is for advanced rendering.

@thimenesup
thimenesup force-pushed the rd_buffer_address branch 2 times, most recently from e8b36c3 to 0326684 Compare December 9, 2024 19:09
@RandomShaper

Copy link
Copy Markdown
Member

Looks good, but there are compatibility breakages.

@thimenesup

Copy link
Copy Markdown
Contributor Author

Added the GDExtension compatiblity methods and rebased with the current master again to fix merge conflicts.

Comment thread core/extension/gdextension_compat_hashes.cpp Outdated
@Fahien

Fahien commented Dec 20, 2024

Copy link
Copy Markdown
Contributor

Do we need something like this in _initialize_device()?

	VkPhysicalDeviceBufferDeviceAddressFeaturesKHR device_address_features = {};
	if (buffer_device_address_support) {
		device_address_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_KHR;
		device_address_features.pNext = create_info_next;
		device_address_features.bufferDeviceAddress = buffer_device_address_support;
		create_info_next = &device_address_features;
	}

@thimenesup

Copy link
Copy Markdown
Contributor Author

I think it might be needed for the devices that aren't initializing core Vulkan 1.2 but a prior version instead.

@stuartcarnie stuartcarnie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've left a couple of notes for Metal. Your implementation is correct, so I suggest you add a property to the MetalFeatures structure, that is set on initialisation, so you can return the correct value for the SUPPORTS_BUFFER_ADDRESS feature.

Comment on lines 3959 to 4039

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be true, but I would like to implement it by adding a new boolean property on the MetalFeatures struct:

struct API_AVAILABLE(macos(11.0), ios(14.0)) MetalFeatures {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this be addressed in this PR?

Comment thread drivers/metal/rendering_device_driver_metal.mm Outdated
@DarioSamo

Copy link
Copy Markdown
Contributor

I'd like to push for this to be merged, but it seems there's some compatibility breakage that must be addressed. I'll give it a thorough review soon.

@DarioSamo DarioSamo left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So far this looks excellent to me, but I've noticed there's some inconsistency when it comes to choosing these terms:

  • Device Address (buffer_get_device_address)
  • Shader Address (enable_shader_address)
  • Shader Device Address (STORAGE_BUFFER_USAGE_SHADER_DEVICE_ADDRESS)
  • Buffer Address (SUPPORTS_BUFFER_ADDRESS)

If we can settle on one consistent terminlogy (device address sounds like the best one to me), and fix the conflicts on the API change, I think this is good to go.

buffer_get_device_address()
enable_device_address
STORAGE_BUFFER_USAGE_DEVICE_ADDRESS
SUPPORTS_BUFFER_DEVICE_ADDRESS

@thimenesup
thimenesup force-pushed the rd_buffer_address branch 2 times, most recently from b4c8a18 to b5f7359 Compare January 10, 2025 19:53
@DarioSamo

Copy link
Copy Markdown
Contributor

Approved, thank you very much for your work!

Comment thread misc/extension_api_validation/4.3-stable.expected Outdated
Comment thread servers/rendering/rendering_device.h Outdated
Comment thread servers/rendering/rendering_device.compat.inc Outdated
Comment thread doc/classes/RenderingDevice.xml Outdated
@clayjohn clayjohn modified the milestones: 4.x, 4.4 Jan 14, 2025
@clayjohn

Copy link
Copy Markdown
Member

Updated with the changes requested by ATS. Should be ready to merge now

@akien-mga
akien-mga merged commit 89999b9 into godotengine:master Jan 14, 2025
@akien-mga

Copy link
Copy Markdown
Member

Thanks!

darksylinc added a commit to darksylinc/godot that referenced this pull request Feb 11, 2025
PR godotengine#100062 introduced BUFFER_USAGE_DEVICE_ADDRESS_BIT.

However it did so by adding a boolean to uniform_buffer_create(), called
"bool p_enable_device_address".

This makes maintaining backwards compatibility harder because I am
working on another feature that would require introducing yet another
bit flag.

This would save us the need to add fallback routines when the feature I
am working on makes it to Godot 4.5.

Even if my feature doesn't make it to 4.5 either, this PR makes the
routine more future-proof.

This PR also moves STORAGE_BUFFER_USAGE_DEVICE_ADDRESS into
BUFFER_CREATION_DEVICE_ADDRESS_BIT, since it's an option available to
both storage and uniforms.

This PR also moves the boolean use_as_storage into
BUFFER_CREATION_AS_STORAGE.
rddi-8 pushed a commit to rddi-8/godot-custom-features that referenced this pull request Mar 2, 2025
PR godotengine#100062 introduced BUFFER_USAGE_DEVICE_ADDRESS_BIT.

However it did so by adding a boolean to uniform_buffer_create(), called
"bool p_enable_device_address".

This makes maintaining backwards compatibility harder because I am
working on another feature that would require introducing yet another
bit flag.

This would save us the need to add fallback routines when the feature I
am working on makes it to Godot 4.5.

Even if my feature doesn't make it to 4.5 either, this PR makes the
routine more future-proof.

This PR also moves STORAGE_BUFFER_USAGE_DEVICE_ADDRESS into
BUFFER_CREATION_DEVICE_ADDRESS_BIT, since it's an option available to
both storage and uniforms.

This PR also moves the boolean use_as_storage into
BUFFER_CREATION_AS_STORAGE.
leandro-benedet-garcia pushed a commit to leandro-benedet-garcia/godot that referenced this pull request Apr 19, 2025
PR godotengine#100062 introduced BUFFER_USAGE_DEVICE_ADDRESS_BIT.

However it did so by adding a boolean to uniform_buffer_create(), called
"bool p_enable_device_address".

This makes maintaining backwards compatibility harder because I am
working on another feature that would require introducing yet another
bit flag.

This would save us the need to add fallback routines when the feature I
am working on makes it to Godot 4.5.

Even if my feature doesn't make it to 4.5 either, this PR makes the
routine more future-proof.

This PR also moves STORAGE_BUFFER_USAGE_DEVICE_ADDRESS into
BUFFER_CREATION_DEVICE_ADDRESS_BIT, since it's an option available to
both storage and uniforms.

This PR also moves the boolean use_as_storage into
BUFFER_CREATION_AS_STORAGE.
@thimenesup
thimenesup deleted the rd_buffer_address branch June 29, 2025 19:28
BendyLand pushed a commit to BendyLand/voltaire that referenced this pull request Aug 2, 2026
Implement Buffer Device Address for Rendering Device Vulkan and DirectX12
BendyLand pushed a commit to BendyLand/voltaire that referenced this pull request Aug 2, 2026
PR godotengine#100062 introduced BUFFER_USAGE_DEVICE_ADDRESS_BIT.

However it did so by adding a boolean to uniform_buffer_create(), called
"bool p_enable_device_address".

This makes maintaining backwards compatibility harder because I am
working on another feature that would require introducing yet another
bit flag.

This would save us the need to add fallback routines when the feature I
am working on makes it to Godot 4.5.

Even if my feature doesn't make it to 4.5 either, this PR makes the
routine more future-proof.

This PR also moves STORAGE_BUFFER_USAGE_DEVICE_ADDRESS into
BUFFER_CREATION_DEVICE_ADDRESS_BIT, since it's an option available to
both storage and uniforms.

This PR also moves the boolean use_as_storage into
BUFFER_CREATION_AS_STORAGE.
BendyLand pushed a commit to BendyLand/voltaire that referenced this pull request Aug 2, 2026
Implement Buffer Device Address for Rendering Device Vulkan and DirectX12
BendyLand pushed a commit to BendyLand/voltaire that referenced this pull request Aug 2, 2026
PR godotengine#100062 introduced BUFFER_USAGE_DEVICE_ADDRESS_BIT.

However it did so by adding a boolean to uniform_buffer_create(), called
"bool p_enable_device_address".

This makes maintaining backwards compatibility harder because I am
working on another feature that would require introducing yet another
bit flag.

This would save us the need to add fallback routines when the feature I
am working on makes it to Godot 4.5.

Even if my feature doesn't make it to 4.5 either, this PR makes the
routine more future-proof.

This PR also moves STORAGE_BUFFER_USAGE_DEVICE_ADDRESS into
BUFFER_CREATION_DEVICE_ADDRESS_BIT, since it's an option available to
both storage and uniforms.

This PR also moves the boolean use_as_storage into
BUFFER_CREATION_AS_STORAGE.
wangshucheng pushed a commit to wangshucheng/godot that referenced this pull request Aug 27, 2026
Implement Buffer Device Address for Rendering Device Vulkan and DirectX12
wangshucheng pushed a commit to wangshucheng/godot that referenced this pull request Aug 27, 2026
PR godotengine#100062 introduced BUFFER_USAGE_DEVICE_ADDRESS_BIT.

However it did so by adding a boolean to uniform_buffer_create(), called
"bool p_enable_device_address".

This makes maintaining backwards compatibility harder because I am
working on another feature that would require introducing yet another
bit flag.

This would save us the need to add fallback routines when the feature I
am working on makes it to Godot 4.5.

Even if my feature doesn't make it to 4.5 either, this PR makes the
routine more future-proof.

This PR also moves STORAGE_BUFFER_USAGE_DEVICE_ADDRESS into
BUFFER_CREATION_DEVICE_ADDRESS_BIT, since it's an option available to
both storage and uniforms.

This PR also moves the boolean use_as_storage into
BUFFER_CREATION_AS_STORAGE.
Shane-Gadsby pushed a commit to Shane-Gadsby/godotwebgpu that referenced this pull request Sep 21, 2026
Implement Buffer Device Address for Rendering Device Vulkan and DirectX12
Shane-Gadsby pushed a commit to Shane-Gadsby/godotwebgpu that referenced this pull request Sep 21, 2026
PR godotengine#100062 introduced BUFFER_USAGE_DEVICE_ADDRESS_BIT.

However it did so by adding a boolean to uniform_buffer_create(), called
"bool p_enable_device_address".

This makes maintaining backwards compatibility harder because I am
working on another feature that would require introducing yet another
bit flag.

This would save us the need to add fallback routines when the feature I
am working on makes it to Godot 4.5.

Even if my feature doesn't make it to 4.5 either, this PR makes the
routine more future-proof.

This PR also moves STORAGE_BUFFER_USAGE_DEVICE_ADDRESS into
BUFFER_CREATION_DEVICE_ADDRESS_BIT, since it's an option available to
both storage and uniforms.

This PR also moves the boolean use_as_storage into
BUFFER_CREATION_AS_STORAGE.
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.

10 participants