Skip to content

Commit

Permalink
[rtx] refactor for updated le_resource_handle
Browse files Browse the repository at this point in the history
update rtx related elements to take advantage of specific, and type-safe
resources which are now used for rtx related commands: you can now
specify `le_tlas_resource_handle` and `le_blas_resource_handle` for
acceleration structure resources.
  • Loading branch information
tgfrerer committed May 27, 2021
1 parent 094e619 commit 14646ad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
11 changes: 7 additions & 4 deletions modules/le_backend_vk/le_backend_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3250,12 +3250,17 @@ static void frame_resources_set_debug_names( le_backend_vk_instance_o *instance,

static void backend_allocate_resources( le_backend_o *self, BackendFrameData &frame, le_renderpass_o **passes, size_t numRenderPasses ) {

static auto logger = LeLog( LOGGER_LABEL );
/*
- Frame is only ever allowed to reference frame-local resources.
- "Acquire" therefore means we create local copies of backend-wide resource handles.
*/

static auto logger = LeLog( LOGGER_LABEL );

#ifdef LE_FEATURE_RTX
static le_resource_handle LE_RTX_SCRATCH_BUFFER_HANDLE = LE_BUF_RESOURCE( "le_rtx_scratch_buffer_handle" ); // opaque handle for rtx scratch buffer
#endif

// -- first it is our holy duty to drop any binned resources which
// were condemned the last time this frame was active.
// It's possible that this was more than two frames ago,
Expand Down Expand Up @@ -5108,11 +5113,9 @@ static void backend_process_frame( le_backend_o *self, size_t frameIndex ) {

// fetch texture information based on texture id from command

assert( le_cmd->info.tlas_id.getResourceType() == LeResourceType::eRtxTlas );

auto found_resource = frame.availableResources.find( le_cmd->info.tlas_id );
if ( found_resource == frame.availableResources.end() ) {
logger.error( "Could not find acceleration structure: '%s'. Ignoring top level acceleration structure binding command.", le_cmd->info.tlas_id.debug_name );
logger.error( "Could not find acceleration structure: '%s'. Ignoring top level acceleration structure binding command.", le_cmd->info.tlas_id->data->debug_name );
break;
}

Expand Down
12 changes: 6 additions & 6 deletions modules/le_renderer/le_command_buffer_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ static void cbe_set_argument_image( le_command_buffer_encoder_o *self, le_img_re

// ----------------------------------------------------------------------

static void cbe_set_argument_tlas( le_command_buffer_encoder_o *self, le_resource_handle const tlasId, uint64_t argumentName, uint64_t arrayIndex ) {
static void cbe_set_argument_tlas( le_command_buffer_encoder_o *self, le_tlas_resource_handle const tlasId, uint64_t argumentName, uint64_t arrayIndex ) {

auto cmd = EMPLACE_CMD( le::CommandSetArgumentTlas );

Expand Down Expand Up @@ -841,9 +841,9 @@ static void cbe_set_push_constant_data( le_command_buffer_encoder_o *self, void
}
// ----------------------------------------------------------------------

static void cbe_build_rtx_blas( le_command_buffer_encoder_o * self,
le_resource_handle const *const p_blas_handles,
const uint32_t handles_count ) {
static void cbe_build_rtx_blas( le_command_buffer_encoder_o * self,
le_blas_resource_handle const *const p_blas_handles,
const uint32_t handles_count ) {

if ( handles_count == 0 || nullptr == p_blas_handles ) {
assert( p_blas_handles && handles_count > 0 && "must provide handles, and handles_count must be at least 1" );
Expand All @@ -868,9 +868,9 @@ static void cbe_build_rtx_blas( le_command_buffer_encoder_o * self,
// ----------------------------------------------------------------------

void cbe_build_rtx_tlas( le_command_buffer_encoder_o * self,
le_resource_handle const * tlas_handle,
le_tlas_resource_handle const * tlas_handle,
le_rtx_geometry_instance_t const *instances,
le_resource_handle const * blas_handles,
le_blas_resource_handle const * blas_handles,
uint32_t instances_count ) {

auto cmd = EMPLACE_CMD( le::CommandBuildRtxTlas );
Expand Down
8 changes: 4 additions & 4 deletions modules/le_renderer/le_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ struct le_renderer_api {
void ( *set_argument_texture )( le_command_buffer_encoder_o *self, le_texture_handle const textureId, uint64_t argumentName, uint64_t arrayIndex);
void ( *set_argument_image )( le_command_buffer_encoder_o *self, le_img_resource_handle const imageId, uint64_t argumentName, uint64_t arrayIndex);

void ( *set_argument_tlas )( le_command_buffer_encoder_o *self, le_resource_handle const tlasId, uint64_t argumentName, uint64_t arrayIndex);
void ( *set_argument_tlas )( le_command_buffer_encoder_o *self, le_tlas_resource_handle const tlasId, uint64_t argumentName, uint64_t arrayIndex);

void ( *build_rtx_blas )( le_command_buffer_encoder_o *self, le_resource_handle const* const blas_handles, const uint32_t handles_count);
void ( *build_rtx_blas )( le_command_buffer_encoder_o *self, le_blas_resource_handle const* const blas_handles, const uint32_t handles_count);
// one blas handle per rtx geometry instance
void ( *build_rtx_tlas )( le_command_buffer_encoder_o *self, le_resource_handle const* tlas_handle, le_rtx_geometry_instance_t const * instances, le_resource_handle const * blas_handles, uint32_t instances_count);
void ( *build_rtx_tlas )( le_command_buffer_encoder_o *self, le_tlas_resource_handle const* tlas_handle, le_rtx_geometry_instance_t const * instances, le_blas_resource_handle const * blas_handles, uint32_t instances_count);

le_shader_binding_table_o* ( *build_sbt )(le_command_buffer_encoder_o* self, le_rtxpso_handle pipeline);
void ( *sbt_set_ray_gen )(le_shader_binding_table_o* sbt, uint32_t ray_gen);
Expand Down Expand Up @@ -719,7 +719,7 @@ class Encoder {
return *this;
}

Encoder &setArgumentTlas( uint64_t const &argumentName, le_resource_handle const &tlasId, uint64_t const &arrayIndex = 0 ) {
Encoder &setArgumentTlas( uint64_t const &argumentName, le_tlas_resource_handle const &tlasId, uint64_t const &arrayIndex = 0 ) {
le_renderer::encoder_i.set_argument_tlas( self, tlasId, argumentName, arrayIndex );
return *this;
}
Expand Down
16 changes: 8 additions & 8 deletions modules/le_renderer/private/le_renderer_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1652,11 +1652,11 @@ struct CommandSetPushConstantData {
struct CommandBuildRtxTlas {
CommandHeader header = { { { CommandType::eBuildRtxTlas, sizeof( CommandBuildRtxTlas ) } } };
struct {
le_resource_handle tlas_handle;
uint32_t geometry_instances_count; // number of geometry instances for this tlas
uint32_t staging_buffer_offset; // offset into staging buffer for geometry instance data
le_resource_handle staging_buffer_id; // staging buffer which stores geometry instance data
void * staging_buffer_mapped_memory; // address of mapped area on staging buffer.
le_tlas_resource_handle tlas_handle;
uint32_t geometry_instances_count; // number of geometry instances for this tlas
uint32_t staging_buffer_offset; // offset into staging buffer for geometry instance data
le_buf_resource_handle staging_buffer_id; // staging buffer which stores geometry instance data
void * staging_buffer_mapped_memory; // address of mapped area on staging buffer.
} info;
};

Expand Down Expand Up @@ -1697,9 +1697,9 @@ struct CommandSetArgumentImage {
struct CommandSetArgumentTlas {
CommandHeader header = { { { CommandType::eSetArgumentTlas, sizeof( CommandSetArgumentTlas ) } } };
struct {
uint64_t argument_name_id; // const_char_hash id of argument name
le_resource_handle tlas_id; // top level acceleration structure resource id,
uint64_t array_index; // argument array index (default is 0)
uint64_t argument_name_id; // const_char_hash id of argument name
le_tlas_resource_handle tlas_id; // top level acceleration structure resource id,
uint64_t array_index; // argument array index (default is 0)
} info;
};

Expand Down
8 changes: 4 additions & 4 deletions modules/le_stage/le_stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ static uint32_t le_stage_create_mesh( le_stage_o *self, le_mesh_info const *info
char rtx_blas_resource_name[ 21 ]{};
snprintf( rtx_blas_resource_name, sizeof( rtx_blas_resource_name ), "blas_m%06lu_p%06lu", self->meshes.size(), mesh.primitives.size() );

primitive.rtx_blas_handle = LE_RESOURCE( rtx_blas_resource_name, LeResourceType::eRtxBlas );
primitive.rtx_blas_handle = le_renderer::renderer_i.produce_blas_resource_handle( rtx_blas_resource_name );
}

le_rtx_geometry_t geo{};
Expand Down Expand Up @@ -1578,7 +1578,7 @@ static void le_stage_update_render_module( le_stage_o *stage, le_render_module_o
// primitive describes geometry, and associated material.

using namespace le_renderer;
std::vector<le_resource_handle_t> blas_infos;
std::vector<le_blas_resource_handle> blas_infos;

// collect all handles over all meshes, primitives so that we may build them in a
// next step.
Expand Down Expand Up @@ -1620,7 +1620,7 @@ static void le_stage_update_render_module( le_stage_o *stage, le_render_module_o

// Collect instance data over all instances for the current scene.
std::vector<le_rtx_geometry_instance_t> instances;
std::vector<le_resource_handle_t> blas_handles;
std::vector<le_blas_resource_handle> blas_handles;

for ( auto const &n : stage->nodes ) {
if ( ( n->scene_bit_flags & ( 1 << scene_index ) ) && n->has_mesh ) {
Expand Down Expand Up @@ -2580,7 +2580,7 @@ static void le_stage_setup_pipelines( le_stage_o *stage ) {
snprintf( rtx_tlas_resource_name, sizeof( rtx_tlas_resource_name ), "tlas_%08u", i );

// -- Create top-level accelerator for this scene
stage->scenes[ i ].rtx_tlas_handle = LE_RESOURCE( rtx_tlas_resource_name, LeResourceType::eRtxTlas );
stage->scenes[ i ].rtx_tlas_handle = le_renderer::renderer_i.produce_tlas_resource_handle( rtx_tlas_resource_name );

LeBuildAccelerationStructureFlags tlas_flags =
{ LE_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR |
Expand Down

0 comments on commit 14646ad

Please sign in to comment.