-
Notifications
You must be signed in to change notification settings - Fork 115
support scalar pairs properly #640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Firestar99
wants to merge
1
commit into
main
Choose a base branch
from
scalar_pair
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,10 @@ use rspirv::spirv::{ | |
| BuiltIn, Decoration, Dim, ExecutionModel, FunctionControl, StorageClass, Word, | ||
| }; | ||
| use rustc_abi::FieldsShape; | ||
| use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods, MiscCodegenMethods as _}; | ||
| use rustc_codegen_ssa::traits::{ | ||
| BaseTypeCodegenMethods, BuilderMethods, ConstCodegenMethods, LayoutTypeCodegenMethods, | ||
| MiscCodegenMethods as _, | ||
| }; | ||
| use rustc_data_structures::fx::FxHashMap; | ||
| use rustc_errors::MultiSpan; | ||
| use rustc_hir as hir; | ||
|
|
@@ -87,22 +90,7 @@ impl<'tcx> CodegenCx<'tcx> { | |
| }; | ||
| for (arg_abi, hir_param) in fn_abi.args.iter().zip(hir_params) { | ||
| match arg_abi.mode { | ||
| PassMode::Direct(_) | PassMode::Ignore => {} | ||
| PassMode::Pair(..) => { | ||
| // FIXME(eddyb) implement `ScalarPair` `Input`s, or change | ||
| // the `FnAbi` readjustment to only use `PassMode::Pair` for | ||
| // pointers to `!Sized` types, but not other `ScalarPair`s. | ||
| if !matches!(arg_abi.layout.ty.kind(), ty::Ref(..)) { | ||
| self.tcx.dcx().span_err( | ||
| hir_param.ty_span, | ||
| format!( | ||
| "entry point parameter type not yet supported \ | ||
| (`{}` has `ScalarPair` ABI but is not a `&T`)", | ||
| arg_abi.layout.ty | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
| PassMode::Direct(_) | PassMode::Pair(..) | PassMode::Ignore => {} | ||
| _ => span_bug!( | ||
| hir_param.ty_span, | ||
| "query hooks should've made this `PassMode` impossible: {:#?}", | ||
|
|
@@ -517,14 +505,6 @@ impl<'tcx> CodegenCx<'tcx> { | |
| vs layout:\n{value_layout:#?}", | ||
| entry_arg_abi.layout.ty | ||
| ); | ||
| if is_pair && !is_unsized { | ||
| // If PassMode is Pair, then we need to fill in the second part of the pair with a | ||
| // value. We currently only do that with unsized types, so if a type is a pair for some | ||
| // other reason (e.g. a tuple), we bail. | ||
| self.tcx | ||
| .dcx() | ||
| .span_fatal(hir_param.ty_span, "pair type not supported yet") | ||
| } | ||
| // FIXME(eddyb) should this talk about "typed buffers" instead of "interface blocks"? | ||
| // FIXME(eddyb) should we talk about "descriptor indexing" or | ||
| // actually use more reasonable terms like "resource arrays"? | ||
|
|
@@ -647,8 +627,8 @@ impl<'tcx> CodegenCx<'tcx> { | |
| } | ||
| } | ||
|
|
||
| let value_len = if is_pair { | ||
| // We've already emitted an error, fill in a placeholder value | ||
| let value_len = if is_pair && is_unsized { | ||
| // For wide references (e.g., slices), the second component is a length. | ||
| Some(bx.undef(self.type_isize())) | ||
| } else { | ||
| None | ||
|
|
@@ -693,6 +673,34 @@ impl<'tcx> CodegenCx<'tcx> { | |
| call_args.push(value); | ||
| assert_eq!(value_len, None); | ||
| } | ||
| PassMode::Pair(..) => { | ||
| // Load both elements of the scalar pair from the input variable. | ||
| assert_eq!(storage_class, Ok(StorageClass::Input)); | ||
| let layout = entry_arg_abi.layout; | ||
| let (a, b) = match layout.backend_repr { | ||
| rustc_abi::BackendRepr::ScalarPair(a, b) => (a, b), | ||
| other => span_bug!( | ||
| hir_param.ty_span, | ||
| "ScalarPair expected for entry param, found {other:?}" | ||
| ), | ||
| }; | ||
| let b_offset = a | ||
| .primitive() | ||
| .size(self) | ||
| .align_to(b.primitive().align(self).abi); | ||
|
|
||
| let elem0_ty = self.scalar_pair_element_backend_type(layout, 0, false); | ||
| let elem1_ty = self.scalar_pair_element_backend_type(layout, 1, false); | ||
|
|
||
| let base_ptr = value_ptr.unwrap(); | ||
| let ptr1 = bx.inbounds_ptradd(base_ptr, self.const_usize(b_offset.bytes())); | ||
|
|
||
| let v0 = bx.load(elem0_ty, base_ptr, layout.align.abi); | ||
| let v1 = bx.load(elem1_ty, ptr1, layout.align.restrict_for_offset(b_offset)); | ||
|
Comment on lines
+687
to
+699
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be possible to replace this with a call to |
||
| call_args.push(v0); | ||
| call_args.push(v1); | ||
| assert_eq!(value_len, None); | ||
| } | ||
| _ => unreachable!(), | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // build-pass | ||
| // compile-flags: -C target-feature=+Int64 | ||
|
|
||
| use spirv_std::spirv; | ||
|
|
||
| #[spirv(fragment)] | ||
| pub fn main_future_proof( | ||
| #[spirv(flat)] input: (u64, u32), | ||
| out: &mut (u64, u32), | ||
| #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] buffer_in: &(u64, u32), | ||
| #[spirv(storage_buffer, descriptor_set = 1, binding = 0)] buffer_out: &mut (u64, u32), | ||
| ) { | ||
| *out = trans0(trans_ref(buffer_in)); | ||
| *buffer_out = trans1(input); | ||
| } | ||
|
|
||
| pub fn trans0(arg: (u64, u32)) -> (u64, u32) { | ||
| (arg.0 + 1, arg.1 - 1) | ||
| } | ||
|
|
||
| pub fn trans1((a, b): (u64, u32)) -> (u64, u32) { | ||
| (a * 2, b * 3) | ||
| } | ||
|
|
||
| pub fn trans_ref((a, b): &(u64, u32)) -> (u64, u32) { | ||
| (a - 1, b - 1) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason I don't like this has to do with it feeling misplaced, likely a consequence of the
split_fmt_argschanges from months ago, which I might eventually revisit (and shouldn't block this PR).