Organize render surface sorting key for optimizing API performance.
This commit is contained in:
@ -844,7 +844,7 @@ void RenderForwardClustered::_fill_instance_data(RenderListType p_render_list, i
|
||||
|
||||
RenderElementInfo &element_info = rl->element_info[p_offset + i];
|
||||
|
||||
element_info.value = uint32_t((surface->sort.sort_key2 & 0x0FFF00000000) >> 32u);
|
||||
element_info.value = uint32_t(surface->sort.sort_key1 & 0xFFF);
|
||||
|
||||
if (cant_repeat) {
|
||||
prev_surface = nullptr;
|
||||
@ -4075,7 +4075,8 @@ void RenderForwardClustered::_geometry_instance_add_surface_with_material(Geomet
|
||||
sdcache->sort.sort_key2 = 0;
|
||||
|
||||
sdcache->sort.surface_index = p_surface;
|
||||
sdcache->sort.material_id = p_material_id;
|
||||
sdcache->sort.material_id_hi = (p_material_id & 0xFF000000) >> 24;
|
||||
sdcache->sort.material_id_lo = (p_material_id & 0x00FFFFFF);
|
||||
sdcache->sort.shader_id = p_shader_id;
|
||||
sdcache->sort.geometry_id = p_mesh.get_local_index(); //only meshes can repeat anyway
|
||||
sdcache->sort.uses_forward_gi = ginstance->can_sdfgi;
|
||||
|
||||
@ -498,17 +498,23 @@ private:
|
||||
uint64_t sort_key2;
|
||||
};
|
||||
struct {
|
||||
uint64_t geometry_id : 32;
|
||||
uint64_t material_id : 32;
|
||||
|
||||
uint64_t shader_id : 32;
|
||||
// Needs to be grouped together to be used in RenderElementInfo, as the value is masked directly.
|
||||
uint64_t lod_index : 8;
|
||||
uint64_t uses_softshadow : 1;
|
||||
uint64_t uses_projector : 1;
|
||||
uint64_t uses_forward_gi : 1;
|
||||
uint64_t uses_lightmap : 1;
|
||||
|
||||
// Sorted based on optimal order for respecting priority and reducing the amount of rebinding of shaders, materials,
|
||||
// and geometry. This current order was found to be the most optimal in large projects. If you wish to measure
|
||||
// differences, refer to RenderingDeviceGraph and the methods available to print statistics for draw lists.
|
||||
uint64_t depth_layer : 4;
|
||||
uint64_t surface_index : 8;
|
||||
uint64_t geometry_id : 32;
|
||||
uint64_t material_id_hi : 8;
|
||||
|
||||
uint64_t material_id_lo : 24;
|
||||
uint64_t shader_id : 32;
|
||||
uint64_t priority : 8;
|
||||
};
|
||||
} sort;
|
||||
|
||||
@ -1981,7 +1981,7 @@ void RenderForwardMobile::_fill_instance_data(RenderListType p_render_list, uint
|
||||
RenderElementInfo &element_info = rl->element_info[p_offset + i];
|
||||
|
||||
// Sets lod_index and uses_lightmap at once.
|
||||
element_info.value = uint32_t((surface->sort.sort_key2 & 0x01FF00000000) >> 32u);
|
||||
element_info.value = uint32_t(surface->sort.sort_key1 & 0x1FF);
|
||||
}
|
||||
|
||||
if (p_update_buffer) {
|
||||
@ -2764,7 +2764,8 @@ void RenderForwardMobile::_geometry_instance_add_surface_with_material(GeometryI
|
||||
sdcache->sort.sort_key2 = 0;
|
||||
|
||||
sdcache->sort.surface_index = p_surface;
|
||||
sdcache->sort.material_id = p_material_id;
|
||||
sdcache->sort.material_id_hi = (p_material_id & 0xFF000000) >> 24;
|
||||
sdcache->sort.material_id_lo = (p_material_id & 0x00FFFFFF);
|
||||
sdcache->sort.shader_id = p_shader_id;
|
||||
sdcache->sort.geometry_id = p_mesh.get_local_index();
|
||||
sdcache->sort.priority = p_material->priority;
|
||||
|
||||
@ -478,15 +478,21 @@ protected:
|
||||
uint64_t sort_key2;
|
||||
};
|
||||
struct {
|
||||
uint64_t geometry_id : 32;
|
||||
uint64_t material_id : 32;
|
||||
|
||||
uint64_t shader_id : 32;
|
||||
// Needs to be grouped together to be used in RenderElementInfo, as the value is masked directly.
|
||||
uint64_t lod_index : 8;
|
||||
uint64_t uses_lightmap : 1;
|
||||
uint64_t pad : 3;
|
||||
|
||||
// Sorted based on optimal order for respecting priority and reducing the amount of rebinding of shaders, materials,
|
||||
// and geometry. This current order was found to be the most optimal in large projects. If you wish to measure
|
||||
// differences, refer to RenderingDeviceGraph and the methods available to print statistics for draw lists.
|
||||
uint64_t depth_layer : 4;
|
||||
uint64_t surface_index : 8;
|
||||
uint64_t geometry_id : 32;
|
||||
uint64_t material_id_hi : 8;
|
||||
|
||||
uint64_t material_id_lo : 24;
|
||||
uint64_t shader_id : 32;
|
||||
uint64_t priority : 8;
|
||||
};
|
||||
} sort;
|
||||
|
||||
Reference in New Issue
Block a user