From 04182c24ecd9db68d03ee591a9fecde38401fed1 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Wed, 2 Oct 2024 16:16:10 -0700 Subject: [PATCH] [naga spv-out] Make `write_block` and its types private. Make `naga::back::spv::BlockContext::write_block` private to `naga::back::spv::block`. Introduce a new `pub(super)` function, `write_function_body`, for `Writer::write_function` to call. Make `BlockExit` private to `naga::back::spv::block`. Move `LoopContext` from `naga::back::spv` into `naga::back::spv::block`, and make it private. --- naga/src/back/spv/block.rs | 29 +++++++++++++++++++++++++---- naga/src/back/spv/mod.rs | 6 ------ naga/src/back/spv/writer.rs | 10 ++-------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/naga/src/back/spv/block.rs b/naga/src/back/spv/block.rs index 97db1cb54..4076fc5a8 100644 --- a/naga/src/back/spv/block.rs +++ b/naga/src/back/spv/block.rs @@ -4,8 +4,7 @@ Implementations for `BlockContext` methods. use super::{ helpers, index::BoundsCheckResult, make_local, selection::Selection, Block, BlockContext, - Dimension, Error, Instruction, LocalType, LookupType, LoopContext, ResultMember, Writer, - WriterFlags, + Dimension, Error, Instruction, LocalType, LookupType, ResultMember, Writer, WriterFlags, }; use crate::{arena::Handle, proc::TypeResolution, Statement}; use spirv::Word; @@ -39,7 +38,7 @@ enum ExpressionPointer { } /// The termination statement to be added to the end of the block -pub enum BlockExit { +enum BlockExit { /// Generates an OpReturn (void return) Return, /// Generates an OpBranch to the specified block @@ -60,6 +59,12 @@ pub enum BlockExit { }, } +#[derive(Clone, Copy, Default)] +struct LoopContext { + continuing_id: Option, + break_id: Option, +} + #[derive(Debug)] pub(crate) struct DebugInfoInner<'a> { pub source_code: &'a str, @@ -2060,7 +2065,7 @@ impl<'w> BlockContext<'w> { } } - pub(super) fn write_block( + fn write_block( &mut self, label_id: Word, naga_block: &crate::Block, @@ -2721,4 +2726,20 @@ impl<'w> BlockContext<'w> { self.function.consume(block, termination); Ok(()) } + + pub(super) fn write_function_body( + &mut self, + entry_id: Word, + debug_info: Option<&DebugInfoInner>, + ) -> Result<(), Error> { + self.write_block( + entry_id, + &self.ir_function.body, + super::block::BlockExit::Return, + LoopContext::default(), + debug_info, + )?; + + Ok(()) + } } diff --git a/naga/src/back/spv/mod.rs b/naga/src/back/spv/mod.rs index 764d06c90..e6397017c 100644 --- a/naga/src/back/spv/mod.rs +++ b/naga/src/back/spv/mod.rs @@ -665,12 +665,6 @@ impl BlockContext<'_> { } } -#[derive(Clone, Copy, Default)] -struct LoopContext { - continuing_id: Option, - break_id: Option, -} - pub struct Writer { physical_layout: PhysicalLayout, logical_layout: LogicalLayout, diff --git a/naga/src/back/spv/writer.rs b/naga/src/back/spv/writer.rs index 7f41caf29..14f1fc002 100644 --- a/naga/src/back/spv/writer.rs +++ b/naga/src/back/spv/writer.rs @@ -3,7 +3,7 @@ use super::{ helpers::{contains_builtin, global_needs_wrapper, map_storage_class}, make_local, Block, BlockContext, CachedConstant, CachedExpressions, DebugInfo, EntryPointContext, Error, Function, FunctionArgument, GlobalVariable, IdGenerator, Instruction, - LocalType, LocalVariable, LogicalLayout, LookupFunctionType, LookupType, LoopContext, Options, + LocalType, LocalVariable, LogicalLayout, LookupFunctionType, LookupType, Options, PhysicalLayout, PipelineOptions, ResultMember, Writer, WriterFlags, BITS_PER_BYTE, }; use crate::{ @@ -756,13 +756,7 @@ impl Writer { next_id }; - context.write_block( - main_id, - &ir_function.body, - super::block::BlockExit::Return, - LoopContext::default(), - debug_info.as_ref(), - )?; + context.write_function_body(main_id, debug_info.as_ref())?; // Consume the `BlockContext`, ending its borrows and letting the // `Writer` steal back its cached expression table and temp_list.