Skip to content
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

Add support for sampled images #320

Merged
merged 4 commits into from
Dec 4, 2020
Merged

Conversation

msiglreith
Copy link
Contributor

Implements #204 (comment)

Combined image samplers are allowed as resources and require a generic parameter indicating the underlying image type.
Therefore, no constructor ala let sampled_image = image.combine(sampler); for Image2d right now.

The way the internal spirv type of the underlying image is created feels a bit handwavy to be honest - ideally I would somehow directly check for all constraints (exactly an image type, possible some trait?).

Combined image samplers are allowed as resources and require a generic parameter indicating the underlying image type.
Copy link
Contributor

@khyperia khyperia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that was hecking quick, thanks so much! This looks super super good~

I would hit approve, but then mergify would merge it without letting you respond to my tiny lil nitpicks, so doing a comment.

// The spirv type of it will be generated by querying the type of the first generic.
if let TyKind::Adt(_, substs) = *ty.ty.kind() {
// TODO: enforce that the generic param is an image type?
let image_ty = substs.type_at(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think this might ICE if it's not a generic type (as in doesn't have a type parameter 0), but considering #[spirv(sampled_image)] is only intended to be used in spirv-std, that's probably okay.

@@ -440,6 +444,10 @@ impl fmt::Debug for SpirvTypePrinter<'_, '_> {
.field("access_qualifier", &access_qualifier)
.finish(),
SpirvType::Sampler => f.debug_struct("Sampler").field("id", &self.id).finish(),
SpirvType::SampledImage { image_type } => f
.debug_struct("SampledImage")
.field("image_type", &self.cx.debug_type(image_type))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this should have .field("id", &self.id) too (I've found including the id of self helps a lot when debugging type shenanigans)

} else {
cx.tcx
.sess
.err("#[spirv(sampled_image)] generic type must be an image");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think this might actually be a bug!()? I don't think it's possible to get a non-ADT here (see callsite of trans_image, where it's already matching on TyKind::Adt - I guess you could grab out the substs there and pass them into trans_image, if you'd like)

@khyperia
Copy link
Contributor

khyperia commented Dec 4, 2020

The way the internal spirv type of the underlying image is created feels a bit handwavy to be honest - ideally I would somehow directly check for all constraints (exactly an image type, possible some trait?).

yeah, haha, there's so much handwaviness right now that's very similar... we probably want to check that somehow eventually and produce a nice error (right now it'll fail spirv-val and produce its wacky message), but, considering the amount of similar handwaviness elsewhere, not really worth it to do that now.

@msiglreith
Copy link
Contributor Author

thanks for the quick and super helpful review!

Copy link
Contributor

@khyperia khyperia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants