gprt-org / GPRT

MIT License
22 stars 6 forks source link

More Type-Safe SBT Value Assignment #56

Closed natevm closed 1 year ago

natevm commented 1 year ago

In this PR, we change the mechanism involved in setting shader binding table record data to be more type safe.

Before this change, GPRT users were required to provide a list of declarations in the SBT record for each program handle and geometry type made. This has several disadvantages:

Therefore, this PR does away with declaration lists, and instead exposes a gprtProgramGetPointer API, where the returned pointer belongs to a struct matching the SBT record type.

By working with this pointer directly, the compiler can catch incorrect types during compilation time. Further, many IDEs can intelligently provide a list of all available fields in the SBT record.

In the GPRT backend, we now copy the entire SBT record template into the SBT at once, rather than field by field. This greatly simplifies the SBT construction process and opens the door to a device side construction, which would be required for device-side instance creation.

For additional type safety, this PR also introduces GPRTTypeOf, where the T is the SBT record type. This allows users to avoid casting void pointers to the SBT record type. This also applies to buffers:

float* tmp = (float*) GPRTBufferGetPointer(buffer);

becomes

float* tmp = GPRTBufferGetPointer(buffer)