amber
amber copied to clipboard
Ray Tracing support in Amber
Add support for ray tracing in Amber scripts. New syntax should include:
- new shader types
- geometries declaration (triangles, AABBs)
- bottom level acceleration structures declaration
- top level acceleration structures with declaration including
- instances
- transformations
- flags
- pipeline extension
- shader group declarations
- shader binding tables declarations
- run command extension to execute ray tracing pipeline
Syntax changes proposed at https://github.com/archimedus/amber/blob/main/docs/amber_script.md
Example CTS: https://gerrit.khronos.org/c/vk-gl-cts/+/12867
Awesome, thanks a lot for putting this together. Reading through the MD file a few questions/comments.
Listing things as I read through the doc, some of these refer to prior points I make (and some are potential modifications of those points).
-
I think we should make
BLASandTLASmore descriptive as names. Suggest something likeACCELERATION_STRUCTURE BOTTOM_LEVELandACCELERATION_STRUCTURE TOP_LEVEL. They're longer (we could drop the_LEVEL). But, they make it a lot clearer for someone that my not have as much ray tracing knowledge what they are. -
SBTis very short, maybeSHADER_BIND_TABLEto be more descriptive? -
I think
AABBis fine, it's a pretty common acronym so I think having it as the shortened form doesn't hurt anything -
BLAS_INSTANCE USE. Could this just beBOTTOM_LEVEL {name}? Is that too short? or even just something likeATTACHwhich would be similar to how things are attached to a pipeline? -
For the
TRIANGLEgeometry, do we need theVERTEXkeyword? Could we just have:TRIANGLE x0 y0 z0 x1 y1 z1 x2 y2 z2? -
Similar for
AABBgeometry as it looks like you end up withAABBtwice? -
For
GEOMETRYwe allow multiple triangles and aabbs, so possibly pluralize the namesGEOMETRY TRIANGLESandGEOMETRY AABBS? -
Or, maybe for both
GEOMETRY TRIANGLEandGEOMETRY AABBit would be better to do something like:
GEOMETRY TRIANGLES
TRIANGLE x0 y0 z0 x1 y1 z1 x2 y2 z2
TRIANGLE x0 y0 z0 ...
END
GEOMETRY AABBS
AABB x0 y0 z0 x1 y1 z1
AABB ...
END
I think I like that better, thoughts?
-
The flags with the optional
ENDfeels a bit weird. Could we change it to just be a comma separated list, remove the ability to spread over multiple lines? (Or does that become too long because you often want to specify multiples of them?) Or, comma separated but allow line breaks, so no END needed, if there is no comma then then the list ends? -
I don't understand what goes in
transform.12 space separated values, are those numbers, strings flags? Is this a 3x4 matrix transform? -
For the
SHADER_GROUPit says the ordering is essential. Is that the order of theSHADER_GROUPcommands in the Amberscript, or the order of the shaders listed in the shader group command (likeany_hit,closest_hit, etc). If it's the order in the Amber file is there something we can do to remove that restriction and fix the order up afterwards? LikeSHADER_GROUP GENERATION {name} {ray_generation_shader_name},SHADER_GROUP MISS {name} {miss_shader_name}and then I can put those in whatever order and we always reorder them to be raygen, miss, call, others after parsing the script? -
What does the
group_countmean onSBT? Does that mean that thegroup_name_1shader group will be attached to the binding table that many times? -
Reading the note on shader bind tables needed, could we do something like have named shader bind table entries. So, combined with point 11 above we end up with something like:
SHADER_GROUP MISS miss1 my_miss_shader
SHADER_GROUP MISS miss2 another_miss_shader
SHADER_GROUP RAYGEN gen my_gen_shader
SHADER_GROUP CALL call my_call_shader
SHADER_GROUP HIT hit1 my_any_hit my_closest_hit my_intersection
SHADER_GROUP HIT hit2 any_hit2 closest_hit2 intersection2
SHADER_BIND_GROUP MISS miss_group
USE miss1
USE miss2 MULTIPLE 3
END
SHADER_BIND_GROUP HIT hit_group
USE hit1
USE hit2
END
SHADER_BIND_GROUP CALL call_group
USE call
END
SHADER_BIND_GROUP RAYGEN ray_group
USE gen
END
We can then validate that the shader_bind_group types match up to the shader_group types what we defined above?
-
I think for
BINDwe should make the type required. So,BIND ACCELERATION_STRUCTURE TOP_LEVEL {name} DESCRIPTOR_SET _id_ BINDING _id_or something like that -
Not a huge fan of using
NULLin theRUNcommand, what about using named params:
RUN {pipeline_name} RAYGEN {ray_gen_sbt_name} MISS {miss_sbt_name} HIT {hit_sbt_name} [CALL {call_sbt_name}]? _x_ _y_ _z_
- After typing
ACCELERATION_STRUCTUREa bunch, maybeACCEL_STRUCTURE?
For the GEOMETRY TRIANGLES should we take something more complex then just vertex values? It seems like it actually takes a vertex and index buffer of a given stride, so, should we be able to attach a BUFFER?
For 13 above, after watching more of the rt video, I don't think it's necessarily the best way. Maybe something like the following would be better?
SHADER_BIND_GROUP gen generation_group
RAYGEN my_gen_shader
END
SHADER_BIND_GROUP miss_group1
MISS my_miss_shader
END
SHADER_BIND_GROUP miss_group2
MISS another_miss_shader
END
SHADER_BIND_GROUP sphere_group
ANY_HIT my_any_hit
CLOSEST_HIT my_closest_hit
INTERSECTION intersection2
END
SHADER_BIND_GROUP triangle_group
CLOSEST_HIT closest_hit2
END
SHADER_BIND_TABLE bind_table
generation_group
sphere_group
triangle_group
miss_group1
miss_group2
END
The bind group can contain either a MISS, a RAYGEN or (ANY_HIT?, CLOSEST_HIT, INTERSECTION?). I don't have the group_count as it maybe better to just be explicit here and duplicate the names into the bind_table?
- OK: ACCELERATION_STRUCTURE BOTTOM_LEVEL and ACCELERATION_STRUCTURE TOP_LEVEL
- I would use exact Vulkan spec name (i.e. bindING): SHADER_BINDING_TABLE
- agree
- "BLAS_INSTANCE USE. Could this just be BOTTOM_LEVEL {name}" This is heavily confusing. We include into Top Level Acceleration Structure not a Bottom Level Acceleration Structure itself, but a reference to it (that is like Vulkan specs says about it) but also names it instance. Ideal name would be BOTTOM_LEVEL_INSTANCE_REFERENCE, but I understand it is too long. May be BOTTOM_LEVEL_INSTANCE?
- will remove VERTEX
- will remove AABB
- plural is reasonable.
- I propose following:
GEOMETRY TRIANGLES
x0 y0 z0 x1 y1 z1 x2 y2 z2
xn yn zn ...
END
GEOMETRY AABBS
x0a y0a z0a x0b y0b z0b x1a y1a z1a x1b y1b z1b
xna yna zna xnb ynb znb ...
END
- Will force flags to be one-liner.
- yes, 3*4 matrix. I will update doc
- This ordering requirement was introduced due to vkGetRayTracingShaderGroupHandlesKHR. This function queries pipeline for a list of shader group and have two parameters: firstGroup and groupCount. We probably can remove group ordering and query shader groups one-by-one. Also no reason to specify shader type: it can be deduced from shader name.
- "What does the group_count mean on SBT" This is a number of consecutive groups function vkGetRayTracingShaderGroupHandlesKHR will return. group_count is parameter groupCount to that function.
- "SHADER_GROUP MISS miss1 my_miss_shader" What for MISS here? The type is easily deduced from shader name my_miss_shader "SHADER_BIND_GROUP MISS miss_group" Actually here we declare/define Shader Binding Table, thus I would stay with name SHADER_BINDING_TABLE. Assigning a type to shader binding table does not seem reasonable: actually SBT can contain various shader group handles. I intentionally limited shader mixing group types in amber (for now), due to start address cannot be any, it should be aligned according to VkPhysicalDeviceRayTracingPipelinePropertiesKHR::shaderGroupBaseAlignment, that depends on driver implementation. If we would like to put all groups into single SBT we need to make some padding, that is variable, that might overcomplicate support implementation in amber. "MULTIPLE 3" Should be COUNT 3, though we can skip this for now.
- "I think for BIND we should make the type required." I doubt it. I agree we can go as "BIND ACCELERATION_STRUCTURE tlas1": no reason for TOP_LEVEL as BLAS is not allowed to be bound as descriptor set.
- Good point
- ACCELERATION_STRUCTURE is ok for me: I don't much like reducing names by cutting them due to cutting is ambigous.
For the GEOMETRY TRIANGLES should we take something more complex then just vertex values? It seems like it actually takes a vertex and index buffer of a given stride, so, should we be able to attach a BUFFER?
Yes, though this is complicated subject. You are right that this is just a buffer with vertices or indices and in Vulkan RT it is more advanced: several types are allowed for both vertices and indices. Vertices formats are implementation dependent. I would leave this for future. Indexing vertices does not seem natural for scripting languages, but giving names to vertices will complicate approach.
PIPELINE ...
SHADER_GROUP generation_group
my_gen_shader
END
SHADER_GROUP miss_group1
my_miss_shader
END
SHADER_GROUP miss_group2
another_miss_shader
END
SHADER_GROUP sphere_group
my_any_hit
my_closest_hit
intersection2
END
SHADER_GROUP triangle_group
closest_hit2
END
SHADER_BINDING_TABLE bind_table
generation_group
sphere_group
triangle_group
miss_group1
miss_group2
END
END
Syntax updated https://github.com/google/amber/commit/d4a407943094bff32cc498addbfae394bfbf5ad6
Also link to example CTS implementation added into head.
The changes to the doc look good to me. One note, you can't assume that you'll be able to determine the type of a thing from the name. So SHADER_GROUP MISS miss1 my_miss_shader could also be SHADER_GROUP MISS some_random_name and you won't know it's a miss shader without MISS in there.
the type of a thing from the name.
Yes I was incorrect, I meant that it is deduced from shader types included into group, not shader group name.
I merged fixes found by @nhaehnle.
I think we have enough for initial RT support, thus I created PR for this issue https://github.com/google/amber/pull/1035
Should we close this now and file followup issues for anything new to be added?
I think we can go with part 2 within this issue that is in https://github.com/google/amber/pull/1039 Edit: We have https://github.com/google/amber/issues/1038 for it, thus closing this one.