Skip to content

Commit

Permalink
FIX SPV??????????????????????????????????????????????????????????????…
Browse files Browse the repository at this point in the history
…?????????
  • Loading branch information
atlv24 committed Sep 28, 2024
1 parent 191fd44 commit bf53013
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
38 changes: 28 additions & 10 deletions naga/src/back/spv/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,19 +1198,36 @@ impl<'w> BlockContext<'w> {
value: Handle<crate::Expression>,
block: &mut Block,
) -> Result<(), Error> {
let image_id = self.get_handle_id(image);
let result_type_id = self.get_expression_type_id(&self.fun_info[value].ty);
let crate::TypeInner::Image {
dim,
class,
arrayed,
} = *self.fun_info[image].ty.inner_with(&self.ir_module.types)
else {
return Err(Error::Validation("Invalid image type"));
};
let local_type = LocalType::Image(super::LocalImageType::from_inner(dim, arrayed, class));
let image_id = self.get_type_id(LookupType::Local(local_type));
let image_ptr_id = self.gen_id();
block.body.push(Instruction::type_pointer(
image_ptr_id,
spirv::StorageClass::UniformConstant,
image_id,
));
let image_var_id = self.gen_id();
block.body.push(Instruction::variable(
image_ptr_id,
image_var_id,
spirv::StorageClass::UniformConstant,
None,
));

let scalar = match *self.fun_info[image].ty.inner_with(&self.ir_module.types) {
crate::TypeInner::Image {
class: crate::ImageClass::Storage { format, .. },
..
} => format.into(),
_ => return Err(Error::Validation("Invalid image type")),
let crate::ImageClass::Storage { format, .. } = class else {
return Err(Error::Validation("Invalid image class"));
};
let pointer_type_id = self.get_type_id(LookupType::Local(LocalType::Value {
vector_size: None,
scalar,
scalar: format.into(),
pointer_space: Some(spirv::StorageClass::Image),
}));
let pointer_id = self.gen_id();
Expand All @@ -1219,7 +1236,7 @@ impl<'w> BlockContext<'w> {
block.body.push(Instruction::image_texel_pointer(
pointer_type_id,
pointer_id,
image_id,
image_var_id,
coordinates.value_id,
sample_id,
));
Expand All @@ -1229,6 +1246,7 @@ impl<'w> BlockContext<'w> {
crate::AtomicFunction::Min => spirv::Op::AtomicUMin,
_ => return Err(Error::Validation("Invalid image atomic operation")),
};
let result_type_id = self.get_expression_type_id(&self.fun_info[value].ty);
let id = self.gen_id();
let space = crate::AddressSpace::Handle;
let (semantics, scope) = space.to_spirv_semantics_and_scope();
Expand Down
2 changes: 1 addition & 1 deletion naga/src/back/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl LocalImageType {
image_format: spirv::ImageFormat::Unknown,
},
crate::ImageClass::Storage { format, access: _ } => LocalImageType {
sampled_type: crate::Scalar::from(format),
sampled_type: format.into(),
dim,
flags: make_flags(false, ImageTypeFlags::empty()),
image_format: format.into(),
Expand Down
26 changes: 15 additions & 11 deletions naga/tests/out/spv/atomicTexture-int64.spvasm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.0
; Generator: rspirv
; Bound: 32
; Bound: 36
OpCapability Shader
OpCapability Int64ImageEXT
OpCapability Int64
Expand Down Expand Up @@ -30,21 +30,25 @@ OpDecorate %12 BuiltIn LocalInvocationId
%19 = OpConstantComposite %8 %18 %18
%20 = OpConstantNull %7
%21 = OpConstant %4 1
%23 = OpTypePointer Image %4
%26 = OpConstant %7 4
%27 = OpConstant %6 0
%28 = OpConstant %6 2
%29 = OpConstant %6 264
%25 = OpTypePointer Image %4
%28 = OpConstant %7 4
%29 = OpConstant %6 0
%30 = OpConstant %6 2
%31 = OpConstant %6 264
%23 = OpTypePointer UniformConstant %3
%32 = OpTypePointer UniformConstant %3
%15 = OpFunction %2 None %16
%11 = OpLabel
%14 = OpLoad %5 %12
%17 = OpLoad %3 %9
OpBranch %22
%22 = OpLabel
%24 = OpImageTexelPointer %23 %17 %19 %20
%25 = OpAtomicUMax %4 %24 %26 %27 %21
OpControlBarrier %28 %28 %29
%30 = OpImageTexelPointer %23 %17 %19 %20
%31 = OpAtomicUMin %4 %30 %26 %27 %21
%24 = OpVariable %23 UniformConstant
%26 = OpImageTexelPointer %25 %24 %19 %20
%27 = OpAtomicUMax %4 %26 %28 %29 %21
OpControlBarrier %30 %30 %31
%33 = OpVariable %32 UniformConstant
%34 = OpImageTexelPointer %25 %33 %19 %20
%35 = OpAtomicUMin %4 %34 %28 %29 %21
OpReturn
OpFunctionEnd

0 comments on commit bf53013

Please sign in to comment.