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 capability attribute #529

Closed
wants to merge 4 commits into from
Closed

Add capability attribute #529

wants to merge 4 commits into from

Conversation

XAMPPRocky
Copy link
Member

@XAMPPRocky XAMPPRocky commented Mar 23, 2021

This PR adds the #[spirv(capabilities)] attribute, which accepts a list of capabilities on an entrypoint function and emits those capabilities.

To Do

  • Documentation
  • Ensure you can only use #[spirv(capabilities)] with entry point functions.

@XAMPPRocky XAMPPRocky requested a review from eddyb March 23, 2021 11:54
@dragostis
Copy link

Just out of curiosity, could capabilities be detected at compile time and would that be desirable?

tests/src/main.rs Outdated Show resolved Hide resolved
@XAMPPRocky
Copy link
Member Author

XAMPPRocky commented Mar 23, 2021

Just out of curiosity, could capabilities be detected at compile time and would that be desirable?

@dragostis In theory, I believe so, I believe you probably could visit each instruction, see what capabilities it requires, and construct a set of a capabilities to emit at the end.

However whether that's desirable is another part, because as I understand, these capabilities affect platform availability, meaning that some platforms don't have certain capabilities. So unintentionally enabling them can be a frustrating experience as your code will compile successfully to SPIR-V, but will fail when that SPIR-V is compiled on the target platform.

@khyperia
Copy link
Contributor

khyperia commented Mar 23, 2021

@dragostis In theory, I believe so, I believe you probably could visit each instruction, see what capabilities it requires, and construct a set of a capabilities to emit at the end.

FWIW we kind of do that right now, and we're moving away from that.

let mut set = HashSet::new();
for inst in module.all_inst_iter() {
set.extend(inst.class.capabilities);

(that file should also go away with this PR, along with this

builder.capability(Capability::Int8);
builder.capability(Capability::Int16);
builder.capability(Capability::Int64);
builder.capability(Capability::Float64);
)

@XAMPPRocky
Copy link
Member Author

@khyperia Removing capability_computation is fine, however removing the defaults in builder_spirv.rs prevents glam from being compiled.

  error: f64 without OpCapability Float64
     --> /Users/erin.power/.rustup/toolchains/nightly-2021-03-21-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/num/f64.rs:640:5
      |
  640 |     pub fn recip(self) -> f64 {
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^

  error: aborting due to previous error

  error: could not compile `glam`

@khyperia
Copy link
Contributor

@khyperia Removing capability_computation is fine, however removing the defaults in builder_spirv.rs prevents glam from being compiled.

Yes, those systems in the compiler will need to be updated to the new capability computation system, in this case, my comment

perhaps functions using u64 are automatically declared with needs_capability = Int64 implicitly, to avoid needing to modify libraries

in #42.

(Don't remove capability_computation without removing the defaults in builder_spirv.rs, the two complement each other, and unexpected capabilities will arise if you remove one without the other)

@XAMPPRocky XAMPPRocky changed the title Add capabilities attribute Add capability attribute Mar 24, 2021
@XAMPPRocky XAMPPRocky requested a review from eddyb March 24, 2021 08:17
@XAMPPRocky XAMPPRocky marked this pull request as ready for review March 24, 2021 08:17
@XAMPPRocky XAMPPRocky requested a review from khyperia as a code owner March 24, 2021 08:17
@XAMPPRocky
Copy link
Member Author

(Don't remove capability_computation without removing the defaults in builder_spirv.rs, the two complement each other, and unexpected capabilities will arise if you remove one without the other)

Okay, well I think we should make removing those a separate PR, as they aren't incompatible with the new attribute, and it keeps both PRs smaller and easier to test.

@khyperia
Copy link
Contributor

Okay, well I think we should make removing those a separate PR, as they aren't incompatible with the new attribute, and it keeps both PRs smaller and easier to test.

Sorry, I guess I was confused by the scope of this PR

@XAMPPRocky
Copy link
Member Author

Sorry, I guess I was confused by the scope of this PR

No worries, I don't think there was a explicit scope when I opened, and this discussion helped clarified it. 😄

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.

I think multiple.rs and invalid-target.rs need to be updated with this. not_entry_point.rs can probably also be folded into invalid-target.rs?

.filter_map(|i| {
CAPABILITIES
.iter()
.find(|x| Symbol::intern(x.0) == i.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be cached and put in a HashMap, similar to how const BUILTINS/Symbols::attributes is done - interning is relatively expensive, especially in a O(n) find loop. The array should probably also be defined alongside the other large chunks of data, to consolidate them into something more manageable.

@khyperia
Copy link
Contributor

Going with #555 instead of attributes, so closing this

@khyperia khyperia reopened this Apr 30, 2021
@khyperia khyperia closed this Apr 30, 2021
@khyperia
Copy link
Contributor

rip, race condition on closing it, hit the button literally the moment github flipped it to "reopen", haha

@XAMPPRocky XAMPPRocky deleted the capabilities branch April 30, 2021 07:35
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.

4 participants