-
-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Vulkan raytracing plumbing #99119
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
Vulkan raytracing plumbing #99119
Conversation
|
Commits needs to be squashed (see https://docs.godotengine.org/en/latest/contributing/workflow/pr_workflow.html). |
d5f4b02 to
4ff001d
Compare
|
I had a very brief look and it looks pretty good to me, although I'd hold off on making changes that add a new rendering method. Are you planning on sticking to only supporting the hit shader workflow or would you also like to add ray query support as well? If you'd like to test your rendering without adding a new rendering method, keep in mind you can also use GDScript to drive the renderer and it should be pretty sufficient to test it out. This is also a simple way you can provide us with a demo project to test it out. |
|
i see that you started on a renderer too on that repo, i think your renderer could be tested/based on the godot ideas https://gist.github.com/reduz/c5769d0e705d8ab7ac187d63be0099b5 |
3eea43f to
2e1d952
Compare
2e1d952 to
61a9d1c
Compare
b456ef5 to
a784c7d
Compare
Just focusing on the hit shader for now.
There you go: https://github.com/Fahien/godot-raytracing-gdscript-demo |
de229f2 to
2474b4d
Compare
|
This is very cool to see! Last night I took a look at how hard it might be adding metal support and while it's definitely out of my wheelhouse here's a commit to at least get it building on macos + a new method to guard user code from invoking raytracing when it isn't supported (also includes some precommit changes) a-johnston@a220083 ed: I have some (probably very misguided and) incomplete changes on https://github.com/a-johnston/godot/tree/raytracing-metal but giving up where it is. Currently it blows up for |
|
What follows from my side as well is that I'll test the PR locally, as I was told by somebody else that there were problems that'd make it crash the GPU when used. I'll report back if I find any issues. |
|
RenderingShaderContainerD3D12 has a build error with DEV_ASSERT(!reflection_data.is_compute); // Could be supported if needed, but it's pointless as of now.Updating it to the proper pipeline type fixes it. |
|
RenderingShaderContainer::reflect_spirv does not set the pipeline type. diff --git a/servers/rendering/rendering_shader_container.cpp b/servers/rendering/rendering_shader_container.cpp
index 3609e52c10..296d9e41d6 100644
--- a/servers/rendering/rendering_shader_container.cpp
+++ b/servers/rendering/rendering_shader_container.cpp
@@ -242,12 +242,38 @@ Error RenderingShaderContainer::reflect_spirv(const String &p_shader_name, Span<
LocalVector<ReflectShaderStage> &r_refl = r_shader.shader_stages;
r_refl.resize(spirv_size);
+ bool pipeline_type_detected = false;
for (uint32_t i = 0; i < spirv_size; i++) {
RDC::ShaderStage stage = p_spirv[i].shader_stage;
RDC::ShaderStage stage_flag = (RDC::ShaderStage)(1 << stage);
r_refl[i].shader_stage = stage;
r_refl[i]._spirv_data = p_spirv[i].spirv;
+ if (!pipeline_type_detected) {
+ switch (stage) {
+ case RDC::SHADER_STAGE_VERTEX:
+ case RDC::SHADER_STAGE_FRAGMENT:
+ case RDC::SHADER_STAGE_TESSELATION_CONTROL:
+ case RDC::SHADER_STAGE_TESSELATION_EVALUATION:
+ r_shader.pipeline_type = RDC::PIPELINE_TYPE_RASTERIZATION;
+ break;
+ case RDC::SHADER_STAGE_COMPUTE:
+ r_shader.pipeline_type = RDC::PIPELINE_TYPE_COMPUTE;
+ break;
+ case RDC::SHADER_STAGE_RAYGEN:
+ case RDC::SHADER_STAGE_ANY_HIT:
+ case RDC::SHADER_STAGE_CLOSEST_HIT:
+ case RDC::SHADER_STAGE_MISS:
+ case RDC::SHADER_STAGE_INTERSECTION:
+ r_shader.pipeline_type = RDC::PIPELINE_TYPE_RAYTRACING;
+ break;
+ default:
+ DEV_ASSERT(false && "Unknown shader stage.");
+ }
+
+ pipeline_type_detected = true;
+ }
+
const Vector<uint64_t> &dynamic_buffers = p_spirv[i].dynamic_buffers;
if (stage == RDC::SHADER_STAGE_COMPUTE) { |
|
With those changes, the gdscript demo runs! |
30b3e97 to
350317e
Compare
DarioSamo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I have any further changes to request. Thanks a lot to @Fahien for the work and refactoring it along the way!
This is a fairly low risk merge as it only adds functions to RenderingDevice that will not be currently used by any of Godot's renderers yet. Users can fire up code in gdscript to use it if they wish, but they must check for the device to explicitly support the feature first. On top of that, only Vulkan is implemented and D3D12/Metal implementations will remain pending to do after this is merged.
I consider those to be out of the scope of this PR, and having it be part of the codebase before those are developed will help establish a base on top of which others can reliably build on.
85f23dd to
da81105
Compare
da81105 to
5701522
Compare
Thank you for testing this! It should be fixed now. |
fc7cef6 to
06a74eb
Compare
Calinou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally on Windows + NVIDIA, it works as expected. Code looks good to me.
Note that if you run the test project on OpenGL, you get this error on this line:
if rd.has_feature(RenderingDevice.SUPPORTS_RAYTRACING_PIPELINE):
Cannot call method 'has_feature' on a null value.
I suppose a null check avoids the issue. This is not an issue with the PR, but I'm noting it nonetheless in case someone is copying this code for their own project.
06a74eb to
84e285e
Compare
|
@Fahien Anything else you'd want adjusted on this PR, or is it good to merge as-is? |
It's good to go, thanks! :) |
- Vulkan implementations in `RenderingDeviceDriverVulkan`. - Raytracing instruction list in `RenderingDeviceGraph`. - Functions to create acceleration structures and raytracing pipelines in `RenderingDevice`. - Raygen, Miss, and ClosestHit shader stages support. - GDScript bindings. - Update classes documentation. - Unimplemented placeholders for Metal and D3D12. - Build acceleration structure command. - Expose a shader preprocessor define. - Align build scratch address. - Create STB after creating the pipeline. - Separate acceleration structure barriers. - Use transforms in TLAS instances. - AnyHit and Intersection stages. - Optionally set acceleration structure build input buffer usage. - Introduce instances buffer. - Move scratch buffers to RenderingDevice. - Rename AccelerationStructureGeometryBits. - Use regular buffer creation and free routines for scratch buffer. - Store trackers in acceleration structures. - Bump Shader SPIR-V version to 1.4 - Add Position attribute location in blas_create. - Encapsulate MoltenVK check in preprocessor macro. - Split SUPPORTS_RAYTRACING for pipeline and query.
84e285e to
27e4f24
Compare
|
Thanks! |


Here's a bunch of code adding some Vulkan raytracing stuff to the rendering device:
RenderingDeviceDriverVulkanRenderingDeviceGraphRenderingDeviceThere's more in the fahien/raytracing-test branch, with code handling raygen, miss, and closest-hit shaders, but it's a hack on top of the forward clustered renderer, and it needs some "guided" refactoring.
Here's a sample which uses GDScript to drive the renderer: raytracing-gdscript-demo
I hope this changes would look useful to jump-start raytracing support.
Relevant for godotengine/godot-proposals#5162