Skip to content

Commit

Permalink
texel pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
atlv24 committed Sep 23, 2024
1 parent f49858d commit d42372a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
57 changes: 57 additions & 0 deletions naga/src/back/spv/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,63 @@ struct Atomic {
value_id: Word,
}

struct TexelPointer {
/// The type id produced by the actual image access instruction.
type_id: Word,

/// The id of the image being accessed.
image_id: Word,
}

impl Access for TexelPointer {
type Output = Word;

/// Write an instruction to access a given texel of this image.
fn generate(
&self,
id_gen: &mut IdGenerator,
coordinates_id: Word,
level_id: Option<Word>,
sample_id: Option<Word>,
block: &mut Block,
) -> Word {
let texel_id = id_gen.next();
let mut instruction = Instruction::image_texel_pointer(
self.type_id,
texel_id,
self.image_id,
coordinates_id,
sample_id.unwrap(),
);

match (level_id, sample_id) {
(None, None) => {}
(Some(level_id), None) => {
instruction.add_operand(spirv::ImageOperands::LOD.bits());
instruction.add_operand(level_id);
}
(None, Some(sample_id)) => {
instruction.add_operand(spirv::ImageOperands::SAMPLE.bits());
instruction.add_operand(sample_id);
}
// There's no such thing as a multi-sampled mipmap.
(Some(_), Some(_)) => unreachable!(),
}

block.body.push(instruction);

texel_id
}

fn result_type(&self) -> Word {
self.type_id
}

fn out_of_bounds_value(&self, ctx: &mut BlockContext<'_>) -> Word {
ctx.writer.get_constant_null(self.type_id)
}
}

impl Access for Atomic {
/// Stores don't generate any value.
type Output = ();
Expand Down
16 changes: 16 additions & 0 deletions naga/src/back/spv/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,22 @@ impl super::Instruction {
instruction
}

pub(super) fn image_texel_pointer(
result_type_id: Word,
id: Word,
image: Word,
coordinates: Word,
sample: Word,
) -> Self {
let mut instruction = Self::new(Op::ImageTexelPointer);
instruction.add_operand(result_type_id);
instruction.add_operand(id);
instruction.add_operand(image);
instruction.add_operand(coordinates);
instruction.add_operand(sample);
instruction
}

pub(super) fn image_atomic(
image: Word,
coordinates: Word,
Expand Down

0 comments on commit d42372a

Please sign in to comment.