pub struct DrawGen { /* private fields */ }Expand description
The cull and draw-argument dispatches, and everything they need.
Implementations§
Source§impl DrawGen
impl DrawGen
Sourcepub const MAX_PASSES: u32 = 5
pub const MAX_PASSES: u32 = 5
The maximum number of passes add_passes adds to a
frame: the clear, the cull, and the route, prefix-sum and scatter passes.
A ceiling rather than an exact count: a frame that tests no instance
omits the cull and scatter passes and adds only the clear, route and
prefix-sum ones. This upper bound is what a caller sizing
PassTimers adds up — see
MAX_TIMED_PASSES.
Sourcepub const DISPATCHES: u32 = 5
pub const DISPATCHES: u32 = 5
How many dispatches add_passes records for a frame
that tests at least one instance: the clear, the cull, and the
draw-argument pass’s route, prefix sum and scatter.
One per pass of MAX_PASSES, which is the same
number: a frame that tests no instance records neither the cull’s nor
the scatter’s, since a dispatch of no workgroups is one Metal rejects.
Sourcepub const LATE_PASSES: u32 = 3
pub const LATE_PASSES: u32 = 3
Passes add_late_passes adds at most: the
second occlusion phase, the late scatter and the finish.
Sourcepub fn new(
device: &dyn Device,
uploads: &mut UploadBatch<'_>,
pipelines: &Arc<DrawGenPipelines>,
desc: &DrawGenDesc<'_>,
) -> Result<Self, HalError>
pub fn new( device: &dyn Device, uploads: &mut UploadBatch<'_>, pipelines: &Arc<DrawGenPipelines>, desc: &DrawGenDesc<'_>, ) -> Result<Self, HalError>
Builds every bind group per frame and every buffer between the passes,
against pipelines — the layouts and pipelines it dispatches, which it
keeps a reference to and does not build. One DrawGenPipelines serves
every generator a renderer makes.
uploads carries the one start-up copy this makes: the one that zeroes
the hysteresis state, described on group_state.
It is recorded, not submitted, so no frame may run these passes until
the caller has submitted that batch — waiting, with
UploadBatch::submit, or, with UploadBatch::submit_deferred, to
the queue the frames go to. A renderer building several of these
submits all of their copies in one submission.
§Errors
HalError from any seam call. A failure part-way through releases
everything already created, so a caller that gives up leaves nothing
behind — and abandons uploads, which by then
may hold a copy into a buffer that release destroyed.
§Panics
If instances is empty or bucket_meshes is: a ring with no buffers has
nothing to bind, and a table with no buckets generates no draws at all.
Also if desc asks for DrawMode::Occlusion and pipelines was built
without the occlusion phases.
Sourcepub const fn bucket_count(&self) -> u32
pub const fn bucket_count(&self) -> u32
Buckets in the table, which is how many indirect calls a caller records.
Sourcepub const fn visible_capacity(&self) -> u32
pub const fn visible_capacity(&self) -> u32
Instances the visible list holds, and so how many every bucket’s run
holds between them — see DrawGenDesc::instance_capacity.
Sourcepub const fn bucket_start_word(&self, bucket: u32) -> u32
pub const fn bucket_start_word(&self, bucket: u32) -> u32
Which word of DrawGen::runs holds where bucket bucket’s run starts
this frame, as the number mesh.slang’s DrawConstants::start_at
carries.
The word, not the start. The start is a per-frame number the
draw-argument pass writes into this word — an absolute word index into
the same buffer, never below runs_at — and the word is
fixed at build, which is what lets a constant block written once name it.
Past the survivors, their routes and the runs; see the module docs. A
reader copying either back multiplies by four.
The same for every generator a renderer builds from one bucket table and one capacity, which is what lets one set of constant blocks serve the camera, every shadow cull and every secondary view.
Sourcepub const fn region_start_word(&self, region: u32, bucket: u32) -> u32
pub const fn region_start_word(&self, region: u32, bucket: u32) -> u32
Which word holds where bucket bucket’s run of draw region region
starts this frame — bucket_start_word for a
region past 0, on its terms exactly.
draw_gen::DRAW_REGIONS regions of start words are laid out in every
generator whatever it allocates, so this is the same for every generator
one renderer builds.
Sourcepub const fn chunk_start_word(&self, region: u32, bucket: u32) -> u32
pub const fn chunk_start_word(&self, region: u32, bucket: u32) -> u32
Which word of DrawGen::runs holds where bucket bucket’s task
chunks start in draw region region this frame —
draw_gen::chunk_start_word, the number
ClusterDrawConstants::chunk_starts_at
carries. bucket may be bucket_count, the
region’s end.
The same for every generator one renderer builds, for
region_start_word’s reason.
Sourcepub const fn flat_args_offset(&self, region: u32, segment: u32) -> u64
pub const fn flat_args_offset(&self, region: u32, segment: u32) -> u64
Byte offset in DrawGen::counts of flat segment segment’s task
dispatch in draw region region — what a flat call’s
DrawIndirect::offset carries.
Behind every region this generator allocates, so it differs between
generators of one renderer; GeneratedDraws::flat_args_offset is
region 0’s first, handed to the pass that draws them.
Sourcepub const fn bucket_mesh_word(&self, bucket: u32) -> u32
pub const fn bucket_mesh_word(&self, bucket: u32) -> u32
Which word of DrawGen::runs holds bucket bucket’s mesh, as the
number mesh.slang’s DrawConstants::mesh_at carries — filled every
frame by the draw-argument pass from the bucket table.
The same for every generator one renderer builds, for
region_start_word’s reason.
Sourcepub const fn args_region_offset(&self, region: u32) -> u64
pub const fn args_region_offset(&self, region: u32) -> u64
How far region region’s argument structures sit behind region 0’s, in
bytes — what a draw of that region adds to
args_offset.
Sourcepub const fn counts_region_offset(&self, region: u32) -> u64
pub const fn counts_region_offset(&self, region: u32) -> u64
How far region region’s draw counts and dispatch extents sit behind
region 0’s, in bytes — what a draw of that region adds to
count_offset and
mesh_args_offset. A region is one count and
one extent structure per bucket, so its counts and its extents move
together.
Sourcepub const fn mode(&self) -> DrawMode
pub const fn mode(&self) -> DrawMode
What DrawGenDesc::mode built this generator for.
Sourcepub fn occlusion_layout(&self) -> Option<BindGroupLayoutHandle>
pub fn occlusion_layout(&self) -> Option<BindGroupLayoutHandle>
Set 1 of the occlusion cull’s layout — the farthest-depth pyramid’s
levels — which PyramidInputs::group is built against. None on a
generator not built for DrawMode::Occlusion.
Sourcepub fn frame_mode(&self, frame: usize) -> DrawMode
pub fn frame_mode(&self, frame: usize) -> DrawMode
The mode frame’s dispatches were parametrised for by the last
begin_frame_with on that slot.
§Panics
If frame is not a slot this was built with.
Sourcepub fn uses_occlusion_entry(&self, frame: usize) -> bool
pub fn uses_occlusion_entry(&self, frame: usize) -> bool
Whether frame dispatches cull.slang’s occlusion entry point — the two
phases, or the small-feature test alone — and so must be recorded with
add_occlusion_passes.
§Panics
If frame is not a slot this was built with.
Sourcepub const fn runs_at(&self) -> u32
pub const fn runs_at(&self) -> u32
The first word of the run region in DrawGen::runs — where bucket
zero’s run starts in every frame, and the floor of every other start.
Sourcepub const fn runs_size(&self) -> u64
pub const fn runs_size(&self) -> u64
Bytes of each frame’s DrawGen::runs buffer: the survivors, their
routes, one capacity of runs and a start word per bucket.
Sourcepub const fn args_offset(&self, bucket: u32) -> u64
pub const fn args_offset(&self, bucket: u32) -> u64
Byte offset of bucket bucket’s argument structure.
Sourcepub const fn count_offset(&self, bucket: u32) -> u64
pub const fn count_offset(&self, bucket: u32) -> u64
Byte offset of bucket bucket’s draw count, which is at the front of the
buffer DrawGen::counts hands back.
Sourcepub const fn mesh_args_offset(&self, bucket: u32) -> u64
pub const fn mesh_args_offset(&self, bucket: u32) -> u64
Byte offset of bucket bucket’s mesh-dispatch argument structure — what
DrawIndirect::offset carries in the
call that reads it.
Past the one draw count per bucket that shares the buffer, so this is never zero — see the module docs.
Sourcepub fn runs(&self, frame: usize) -> BufferHandle
pub fn runs(&self, frame: usize) -> BufferHandle
The buffer of per-bucket instance runs for frame, which the drawing
pass’s bind group names.
The same buffer DrawGen::visible hands back: bucket bucket’s run
starts at the word this frame wrote into word
bucket_start_word(bucket), past the
survivor list and its routes.
§Panics
If frame is not a slot this was built with.
Sourcepub fn cull_params(&self, frame: usize) -> BufferHandle
pub fn cull_params(&self, frame: usize) -> BufferHandle
frame’s cull parameters — the frustum DrawGen::begin_frame wrote.
§Panics
If frame is not a slot this was built with.
Sourcepub fn visible(&self, frame: usize) -> BufferHandle
pub fn visible(&self, frame: usize) -> BufferHandle
frame’s compacted visible list — cull.slang’s survivors, as indices
into the instance array, in no particular order, in the first
visible_capacity words of the buffer.
The same buffer DrawGen::runs hands back; the routes, the per-bucket
runs and their starts follow the survivors in it. See the module docs.
§Panics
If frame is not a slot this was built with.
Sourcepub fn visible_count(&self, frame: usize) -> BufferHandle
pub fn visible_count(&self, frame: usize) -> BufferHandle
frame’s culling statistics: surviving instances in
INSTANCE_SURVIVOR_WORD
and surviving clusters in
CLUSTER_SURVIVOR_WORD.
Topic 03 §3.6’s culling-stats readback is this buffer, on a delayed ring — the one readback the frame loop is allowed. Both counters live here rather than in a buffer each so that stays one copy per frame.
The instance count is the true one, which can exceed
DrawGen::visible_capacity — so it is also where a scene that outgrew
the list says so. The cluster count is what §3.5’s amplification stage
kept, and is zero on every path that has no amplification stage: the two
indirect tails, and a device with Features::MESH_SHADER and no
Features::TASK_SHADER.
§Panics
If frame is not a slot this was built with.
Sourcepub fn args(&self, frame: usize) -> BufferHandle
pub fn args(&self, frame: usize) -> BufferHandle
frame’s indirect arguments, draw_gen::DRAW_ARGS_SIZE bytes per
bucket. The same buffer GeneratedDraws::args names.
§Panics
If frame is not a slot this was built with.
Sourcepub fn counts(&self, frame: usize) -> BufferHandle
pub fn counts(&self, frame: usize) -> BufferHandle
frame’s per-bucket draw counts, in the first
bucket_count words of the buffer
GeneratedDraws::counts names.
§Panics
If frame is not a slot this was built with.
Sourcepub fn tables(&self) -> BufferHandle
pub fn tables(&self) -> BufferHandle
Every host-written table the draw-argument pass reads, in one buffer — the bucket table, the per-bucket cluster counts and topic 25’s three selection tables.
Shared by every frame, because all five are decided when a mesh becomes
resident. Exposed for the reason the per-frame buffers are: the cluster
counts are the only CPU-side half of an extent that is otherwise the
GPU’s, so a test with no GPU can still check the pass copied each
bucket’s own — table_offsets is where each
region starts.
Sourcepub const fn table_offsets(&self) -> TableOffsets
pub const fn table_offsets(&self) -> TableOffsets
Where each region of tables begins, in words.
Sourcepub fn mesh_args(&self, frame: usize) -> BufferHandle
pub fn mesh_args(&self, frame: usize) -> BufferHandle
frame’s per-bucket mesh-dispatch arguments, at
mesh_args_offset(bucket) in the buffer
GeneratedDraws::counts names — the thing a test reads back to see that
the extent the mesh path dispatched is the count culling produced rather
than the instance pool’s size.
The same buffer DrawGen::counts hands back. Not at offset zero:
the draw counts are in front of it.
§Panics
If frame is not a slot this was built with.
Sourcepub fn group_state(&self) -> BufferHandle
pub fn group_state(&self) -> BufferHandle
Topic 25’s hysteresis state, for a caller binding it into a mesh pipeline that reads it.
One buffer for every frame in flight, unlike everything else here that a
caller binds — see DrawGen::group_state’s field
docs, which is where that is argued.
Sourcepub const fn group_stride(&self) -> u32
pub const fn group_stride(&self) -> u32
The stride between two instances in that buffer, which is what
ClusterDrawConstants::group_stride has to carry for the amplification
stage to index it the same way this pass does.
Sourcepub fn begin_frame(
&self,
device: &dyn Device,
frame: usize,
frustum: &Frustum,
instance_count: u32,
camera_position: [f32; 3],
lod_params: [f32; 3],
) -> Result<(), HalError>
pub fn begin_frame( &self, device: &dyn Device, frame: usize, frustum: &Frustum, instance_count: u32, camera_position: [f32; 3], lod_params: [f32; 3], ) -> Result<(), HalError>
Writes frame’s cull parameters — this frame’s frustum, how much of the
instance array to test, and the camera topic 25’s uniform
cut selects a level from.
The three counters both dispatches add to are not zeroed here: that
is the clearing pass DrawGen::add_passes schedules, and the module
docs say why it has to be a dispatch inside the frame rather than a host
write before it.
Call once per frame, before DrawGen::add_passes, against the frame
slot the instance pool rotated to — the buffer written here is the one
that slot’s bind groups name.
instance_count is how many elements of the instance array the cull
dispatch tests, which is
InstancePool::slot_count
and not its live count: an array with a hole in it still has live
instances above the hole.
§Errors
HalError if the write failed.
§Panics
If frame is not a slot this was built with.
camera_position and lod_params are the two the drawing pass writes
into FrameUniforms — passed in
rather than re-derived here for the reason the frustum is: a pass that
selects detail against one camera while another draws is a difference
nothing in a frame can see.
Which is why the one caller allowed to break that is a deliberate
setting rather than an accident of what was in scope.
ForwardRenderer::set_frozen_selection_eye hands this a pinned eye
while the frame block keeps the live camera, so the cut a reviewer is
looking at is the one chosen for somewhere they are no longer standing —
which is the only vantage point a cut can be judged from.
Sourcepub fn begin_frame_with(
&self,
device: &dyn Device,
frame: usize,
frustum: &Frustum,
instance_count: u32,
selection: Selection,
cull: &FrameCull<'_>,
) -> Result<(), HalError>
pub fn begin_frame_with( &self, device: &dyn Device, frame: usize, frustum: &Frustum, instance_count: u32, selection: Selection, cull: &FrameCull<'_>, ) -> Result<(), HalError>
begin_frame, with what the cull does beyond the
frustum this frame.
The mode written here is what add_passes and
add_occlusion_passes check against, so a
frame whose passes disagree with the block its dispatches read is a panic
rather than a frame that scatters into regions nothing draws.
§Errors
HalError if a write failed.
§Panics
If frame is not a slot this was built with, or cull asks for a mode
this generator was not built for.
Sourcepub fn add_passes(
&self,
graph: &mut RenderGraph<'_>,
frame: usize,
instance_count: u32,
) -> GeneratedDraws
pub fn add_passes( &self, graph: &mut RenderGraph<'_>, frame: usize, instance_count: u32, ) -> GeneratedDraws
Adds the cull and draw-argument passes to graph and returns what the
caller’s render pass draws from.
The barriers between the three — including the transition into
ResourceState::IndirectArgument — are the graph’s, computed from the
accesses declared here and the ones the caller declares on the
GeneratedDraws ids.
§Panics
If frame is not a slot this was built with.
Sourcepub fn add_occlusion_passes(
&self,
graph: &mut RenderGraph<'_>,
frame: usize,
instance_count: u32,
pyramid: &PyramidInputs<'_>,
) -> GeneratedDraws
pub fn add_occlusion_passes( &self, graph: &mut RenderGraph<'_>, frame: usize, instance_count: u32, pyramid: &PyramidInputs<'_>, ) -> GeneratedDraws
add_passes for a frame
begin_frame_with began with
FrameCull::Occlusion: the cull is the first occlusion phase against
pyramid, which it reads before this frame’s reduction passes write it.
The draws it returns are the early ones — region
draw_gen::EARLY_REGION — until add_late_passes
has closed the frame; a frame whose occlusion is off and whose
small-feature test is on draws region 0 from here directly.
§Panics
If frame is not a slot this was built with, or was not begun with
FrameCull::Occlusion.
Sourcepub fn add_late_passes(
&self,
graph: &mut RenderGraph<'_>,
frame: usize,
instance_count: u32,
draws: &GeneratedDraws,
pyramid: &PyramidInputs<'_>,
)
pub fn add_late_passes( &self, graph: &mut RenderGraph<'_>, frame: usize, instance_count: u32, draws: &GeneratedDraws, pyramid: &PyramidInputs<'_>, )
The second occlusion phase and the late draw arguments, after this frame’s farthest-depth pyramid has been reduced from the early prepass.
Three passes: cull.slang’s lateMain tests every survivor the first
phase marked against pyramid, draw_gen.slang’s late scatter appends
the ones it rescued behind each bucket’s early run, and its finish writes
region draw_gen::LATE_REGION’s counts and region 0’s — the early and
late draws together, which is what the forward pass draws. A frame that
tests no instance records the finish alone, because region 0 still needs
its zeroes written.
§Panics
If frame is not a slot this was built with, or was not begun with
occlusion on.
Sourcepub fn destroy(self, device: &dyn Device)
pub fn destroy(self, device: &dyn Device)
Releases everything it owns, in dependency order, and gives back its
reference to the shared DrawGenPipelines — which this destroys only
if it was the last. The device must be idle.