Skip to content

Initial implementation Ray Tracing support in Amber#1035

Merged
dj2 merged 3 commits intogoogle:mainfrom
archimedus:amberrt_rebased
May 22, 2024
Merged

Initial implementation Ray Tracing support in Amber#1035
dj2 merged 3 commits intogoogle:mainfrom
archimedus:amberrt_rebased

Conversation

@archimedus
Copy link
Contributor

Ray Tracing support in Amber #1033

@google-cla
Copy link

google-cla bot commented Apr 4, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@dj2 dj2 left a comment

Choose a reason for hiding this comment

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

I'm not quite done the review yet, I'm about half way through engine_vulkan and then have the following files to do. Wanted to send this out as I have to leave for the day and am off until Tuesday of next week. I'll finish the review when I'm back on Tuesday.

@dj2
Copy link
Collaborator

dj2 commented Apr 11, 2024 via email

@ben-clayton
Copy link
Contributor

You can download clang-format as part of the LLVM binaries at https://github.com/llvm/llvm-project/releases/tag/llvmorg-17.0.1

Copy link

@jasilvanus jasilvanus left a comment

Choose a reason for hiding this comment

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

My questions are regarding the planned final script format. I'm aware this is in an initial state as of now.

How can max payload and hit attribute sizes be specified?

Are pipeline libraries (planned to be) supported?

Comment on lines +564 to +583
```groovy
# Four possible shader group definitions
SHADER_GROUP {group_name_1} {ray_generation_shader_name}
SHADER_GROUP {group_name_2} {miss_shader_name}
SHADER_GROUP {group_name_3} {call_shader_name}
SHADER_GROUP {group_name_4} {any_hit_shader_name} {closest_hit_shader_name} {intersection_shader_name}
```

Each group name must be unique within a pipeline. The same shader can be used within one or more
shader groups. The shader group order is important, further commands as shader code might refer
them directly. With the shader groups defined, they are then added into shader binding tables:

```groovy
# Create shader binding tables and set shader groups into it
SHADER_BINDING_TABLE {sbt_name}
{group_name_1}
[ | {group_name_n}]
END
```

Choose a reason for hiding this comment

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

How are non-existing/null shaders (e.g. null AHS) specified here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How can max payload and hit attribute sizes be specified?

I am not sure what do you mean. These values are fully inside shader interfaces and do not need any regulation through scripting language.

Are pipeline libraries (planned to be) supported?

Not sure yet.

How are non-existing/null shaders (e.g. null AHS) specified here?

I should update documentation to:

SHADER_GROUP {group_name_4} [any_hit_shader_name] [closest_hit_shader_name] [intersection_shader_name]

i.e. you can skip unused shaders, actually code does not enforce shader order two only things checked: (1) is that code does not mix general shaders with hit shaders; (2) there are no two same types within group (i.e. group does not include two+ intersection shaders or two+ anyhit shaders or two+ closesthit shaders).

@jasilvanus
Copy link

jasilvanus commented Apr 17, 2024

How can max payload and hit attribute sizes be specified?

I am not sure what do you mean. These values are fully inside shader interfaces and do not need any regulation through scripting language.

I was referring to https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkRayTracingPipelineInterfaceCreateInfoKHR.html but that might only be relevant when using libraries.

Or is there an alternate shader-level mechanism to specify the max payload and hit attribute size of other shaders in the pipeline, say when early-compiling an Intersection shader that doesn't know the payload types it will be used with?

Are pipeline libraries (planned to be) supported?

Not sure yet.

Supporting libraries would be very helpful. It doesn't have to be in the initial version, but we should have an idea how it should look like so we don't have to break back-compat when introducing it.

How are non-existing/null shaders (e.g. null AHS) specified here?

I should update documentation to:

SHADER_GROUP {group_name_4} [any_hit_shader_name] [closest_hit_shader_name] [intersection_shader_name]

i.e. you can skip unused shaders, actually code does not enforce shader order two only things checked: (1) is that code does not mix general shaders with hit shaders; (2) there are no two same types within group (i.e. group does not include two+ intersection shaders or two+ anyhit shaders or two+ closesthit shaders).

I see, sounds good. We should mention though that the order doesn't matter, and that shader types are automatically derived.

@archimedus
Copy link
Contributor Author

archimedus commented Apr 22, 2024

For raytracing libraries (probably it can be later extended for graphics, though I am interested in RT only here) I think following syntax should cover subject:

PIPELINE ... [RAY_PAYLOAD_SIZE <integer>] [RAY_HIT_ATTRIBUTE_SIZE <integer>]
LIBRARY
USE_LIBRARY <name1> [<name2> [...]]
...
END

The first line should declare library.
The second line should be used in final pipeline or another library using this one.
I think this should cover raytracing pipeline libraries.

What do you think?

@jasilvanus
Copy link

Thanks! I'm not sure whether the formatting is as-intended, why start one line with PIPELINE and then have a second line starting with LIBRARY? Maybe its best to give a small full example.

The keywords RAY_PAYLOAD_SIZE and RAY_HIT_ATTRIBUTE_SIZE maybe should have a MAX_ prefix?

@archimedus
Copy link
Contributor Author

Thanks! I'm not sure whether the formatting is as-intended, why start one line with PIPELINE and then have a second line starting with LIBRARY? Maybe its best to give a small full example.

Well, indentation is lost. It should be like this:

PIPELINE ... [MAX_RAY_PAYLOAD_SIZE <integer>] [MAX_RAY_HIT_ATTRIBUTE_SIZE <integer>]
    LIBRARY
    USE_LIBRARY <name1> [<name2> [...]]
...
END

The keywords RAY_PAYLOAD_SIZE and RAY_HIT_ATTRIBUTE_SIZE maybe should have a MAX_ prefix?

Will add MAX_

LIBRARY is a flag here to mark that we need to have VK_PIPELINE_CREATE_LIBRARY_BIT_KHR flag.
USE_LIBRARY is a list of VkPipelines we need to add into VkRayTracingPipelineCreateInfoKHR::pLibraryInfo

I was thinking about something like this (I hope it is feasible):

PIPELINE raytracing lib_a
  LIBRARY
  SHADER_GROUP g1 raygen1
  SHADER_BINDING_TABLE sbt1
    g1
  END
END

PIPELINE raytracing lib_b
  LIBRARY
  SHADER_GROUP g2 miss1
  SHADER_BINDING_TABLE sbt2
    g2
  END
END

PIPELINE raytracing lib_c
  LIBRARY
  SHADER_GROUP g3 anyhit1 closesthit1 intersection1
  SHADER_BINDING_TABLE sbt3
    g3
  END
END

PIPELINE raytracing my_rtpipeline
  USE_LIBRARY lib_a lib_b lib_c
END

RUN my_rtpipeline RAYGEN sbt1 MISS sbt2 HIT sbt3 1920 1080 1

@jasilvanus
Copy link

Thanks, the syntax looks good to me.

@dj2
Copy link
Collaborator

dj2 commented Apr 23, 2024

Are there other pipeline flags we may want to set? Having it FLAGS LIBRARY may make more sense in that case.

@archimedus
Copy link
Contributor Author

Are there other pipeline flags we may want to set? Having it FLAGS LIBRARY may make more sense in that case.

Well VkPipelineCreateFlagBits have a bunch of flags, not sure which of these are supposed to be exposed.

I agree that FLAGS LIBRARY looks like a good point.

@archimedus
Copy link
Contributor Author

@dj2

I accepted CLA, but it seems github added you as a co-author, thus it requires you to accept the CLA.

@dj2
Copy link
Collaborator

dj2 commented May 7, 2024

Fixed, needed to associate the email github picked with my account. Is this ready for me to do another round of reviews?

@archimedus
Copy link
Contributor Author

Thanks.

Yes, I think it is ready for review.

The library support I think I should add as next pull request.

@archimedus
Copy link
Contributor Author

kokoro:run

@archimedus
Copy link
Contributor Author

Rebased.

@dj2 dj2 added the kokoro:run label May 13, 2024
@archimedus archimedus force-pushed the amberrt_rebased branch 2 times, most recently from a09783f to b68334c Compare May 14, 2024 10:04
@dj2 dj2 added the kokoro:run label May 14, 2024
@archimedus
Copy link
Contributor Author

@dj2

Test cases executed: 183
  Successes:  74
  Failures:   72
  Suppressed: 37

Is that expected or something was broken by this PR?

@dj2
Copy link
Collaborator

dj2 commented May 14, 2024

They all passed with the DeviceProperties CL, and with my fixup CL. So, it seems like something in this PR is causing the failures.

@archimedus
Copy link
Contributor Author

I will investigate

@archimedus
Copy link
Contributor Author

@dj2
I think it is ready to be merged

Copy link
Collaborator

@dj2 dj2 left a comment

Choose a reason for hiding this comment

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

This looks pretty close, I think the only outstanding was the last use of shared_ptr which I think could be a unique_ptr.


private:
std::string name_;
std::vector<std::shared_ptr<Geometry>> geometry_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

std::vector<std::unique_ptr<Geometry>> should work fine. It also makes the ownership clear.

@dj2 dj2 merged commit 32ca240 into google:main May 22, 2024
@dj2
Copy link
Collaborator

dj2 commented May 22, 2024

Merged. Thank you very much for the design, implementation, and patience as we worked through the bot issues. Very much appreciate the contribution.

@archimedus archimedus deleted the amberrt_rebased branch May 23, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants