Skip to content

Commit

Permalink
Add cargo gpu show capabilities command
Browse files Browse the repository at this point in the history
  • Loading branch information
tombh committed Jan 10, 2025
1 parent f83fc96 commit cfdf4ed
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ log = "0.4"
relative-path = "1.9.3"
serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.132"
strum = { version = "0.26.3" }
strum_macros = "0.26.4"
toml = "0.8.19"
test-log = "0.2.16"

Expand Down
2 changes: 2 additions & 0 deletions crates/cargo-gpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ toml.workspace = true
chrono.workspace = true
http.workspace = true
crossterm.workspace = true
strum.workspace = true
strum_macros.workspace = true

[dev-dependencies]
test-log.workspace = true
Expand Down
238 changes: 238 additions & 0 deletions crates/cargo-gpu/src/capabilities.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
//! This is copied from `spirv::Capability` just because we need to add the `strum_macros::EnumIter` derive macro.
//! We could send a PR, but the repo doesn't seem to be very active.
/// All the options for the `cargo gpu build --capability` argument.
#[repr(u32)]
#[expect(
clippy::unseparated_literal_suffix,
reason = "The enum is copy-pasted from the `spirv` crate, so let's not over-complicate things"
)]
#[derive(Debug, strum_macros::EnumIter)]
pub enum Capability {
Matrix = 0u32,
Shader = 1u32,
Geometry = 2u32,
Tessellation = 3u32,
Addresses = 4u32,
Linkage = 5u32,
Kernel = 6u32,
Vector16 = 7u32,
Float16Buffer = 8u32,
Float16 = 9u32,
Float64 = 10u32,
Int64 = 11u32,
Int64Atomics = 12u32,
ImageBasic = 13u32,
ImageReadWrite = 14u32,
ImageMipmap = 15u32,
Pipes = 17u32,
Groups = 18u32,
DeviceEnqueue = 19u32,
LiteralSampler = 20u32,
AtomicStorage = 21u32,
Int16 = 22u32,
TessellationPointSize = 23u32,
GeometryPointSize = 24u32,
ImageGatherExtended = 25u32,
StorageImageMultisample = 27u32,
UniformBufferArrayDynamicIndexing = 28u32,
SampledImageArrayDynamicIndexing = 29u32,
StorageBufferArrayDynamicIndexing = 30u32,
StorageImageArrayDynamicIndexing = 31u32,
ClipDistance = 32u32,
CullDistance = 33u32,
ImageCubeArray = 34u32,
SampleRateShading = 35u32,
ImageRect = 36u32,
SampledRect = 37u32,
GenericPointer = 38u32,
Int8 = 39u32,
InputAttachment = 40u32,
SparseResidency = 41u32,
MinLod = 42u32,
Sampled1D = 43u32,
Image1D = 44u32,
SampledCubeArray = 45u32,
SampledBuffer = 46u32,
ImageBuffer = 47u32,
ImageMSArray = 48u32,
StorageImageExtendedFormats = 49u32,
ImageQuery = 50u32,
DerivativeControl = 51u32,
InterpolationFunction = 52u32,
TransformFeedback = 53u32,
GeometryStreams = 54u32,
StorageImageReadWithoutFormat = 55u32,
StorageImageWriteWithoutFormat = 56u32,
MultiViewport = 57u32,
SubgroupDispatch = 58u32,
NamedBarrier = 59u32,
PipeStorage = 60u32,
GroupNonUniform = 61u32,
GroupNonUniformVote = 62u32,
GroupNonUniformArithmetic = 63u32,
GroupNonUniformBallot = 64u32,
GroupNonUniformShuffle = 65u32,
GroupNonUniformShuffleRelative = 66u32,
GroupNonUniformClustered = 67u32,
GroupNonUniformQuad = 68u32,
ShaderLayer = 69u32,
ShaderViewportIndex = 70u32,
UniformDecoration = 71u32,
CoreBuiltinsARM = 4165u32,
TileImageColorReadAccessEXT = 4166u32,
TileImageDepthReadAccessEXT = 4167u32,
TileImageStencilReadAccessEXT = 4168u32,
FragmentShadingRateKHR = 4422u32,
SubgroupBallotKHR = 4423u32,
DrawParameters = 4427u32,
WorkgroupMemoryExplicitLayoutKHR = 4428u32,
WorkgroupMemoryExplicitLayout8BitAccessKHR = 4429u32,
WorkgroupMemoryExplicitLayout16BitAccessKHR = 4430u32,
SubgroupVoteKHR = 4431u32,
StorageBuffer16BitAccess = 4433u32,
UniformAndStorageBuffer16BitAccess = 4434u32,
StoragePushConstant16 = 4435u32,
StorageInputOutput16 = 4436u32,
DeviceGroup = 4437u32,
MultiView = 4439u32,
VariablePointersStorageBuffer = 4441u32,
VariablePointers = 4442u32,
AtomicStorageOps = 4445u32,
SampleMaskPostDepthCoverage = 4447u32,
StorageBuffer8BitAccess = 4448u32,
UniformAndStorageBuffer8BitAccess = 4449u32,
StoragePushConstant8 = 4450u32,
DenormPreserve = 4464u32,
DenormFlushToZero = 4465u32,
SignedZeroInfNanPreserve = 4466u32,
RoundingModeRTE = 4467u32,
RoundingModeRTZ = 4468u32,
RayQueryProvisionalKHR = 4471u32,
RayQueryKHR = 4472u32,
RayTraversalPrimitiveCullingKHR = 4478u32,
RayTracingKHR = 4479u32,
TextureSampleWeightedQCOM = 4484u32,
TextureBoxFilterQCOM = 4485u32,
TextureBlockMatchQCOM = 4486u32,
Float16ImageAMD = 5008u32,
ImageGatherBiasLodAMD = 5009u32,
FragmentMaskAMD = 5010u32,
StencilExportEXT = 5013u32,
ImageReadWriteLodAMD = 5015u32,
Int64ImageEXT = 5016u32,
ShaderClockKHR = 5055u32,
ShaderEnqueueAMDX = 5067u32,
SampleMaskOverrideCoverageNV = 5249u32,
GeometryShaderPassthroughNV = 5251u32,
ShaderViewportIndexLayerEXT = 5254u32,
ShaderViewportMaskNV = 5255u32,
ShaderStereoViewNV = 5259u32,
PerViewAttributesNV = 5260u32,
FragmentFullyCoveredEXT = 5265u32,
MeshShadingNV = 5266u32,
ImageFootprintNV = 5282u32,
MeshShadingEXT = 5283u32,
FragmentBarycentricKHR = 5284u32,
ComputeDerivativeGroupQuadsNV = 5288u32,
FragmentDensityEXT = 5291u32,
GroupNonUniformPartitionedNV = 5297u32,
ShaderNonUniform = 5301u32,
RuntimeDescriptorArray = 5302u32,
InputAttachmentArrayDynamicIndexing = 5303u32,
UniformTexelBufferArrayDynamicIndexing = 5304u32,
StorageTexelBufferArrayDynamicIndexing = 5305u32,
UniformBufferArrayNonUniformIndexing = 5306u32,
SampledImageArrayNonUniformIndexing = 5307u32,
StorageBufferArrayNonUniformIndexing = 5308u32,
StorageImageArrayNonUniformIndexing = 5309u32,
InputAttachmentArrayNonUniformIndexing = 5310u32,
UniformTexelBufferArrayNonUniformIndexing = 5311u32,
StorageTexelBufferArrayNonUniformIndexing = 5312u32,
RayTracingPositionFetchKHR = 5336u32,
RayTracingNV = 5340u32,
RayTracingMotionBlurNV = 5341u32,
VulkanMemoryModel = 5345u32,
VulkanMemoryModelDeviceScope = 5346u32,
PhysicalStorageBufferAddresses = 5347u32,
ComputeDerivativeGroupLinearNV = 5350u32,
RayTracingProvisionalKHR = 5353u32,
CooperativeMatrixNV = 5357u32,
FragmentShaderSampleInterlockEXT = 5363u32,
FragmentShaderShadingRateInterlockEXT = 5372u32,
ShaderSMBuiltinsNV = 5373u32,
FragmentShaderPixelInterlockEXT = 5378u32,
DemoteToHelperInvocation = 5379u32,
DisplacementMicromapNV = 5380u32,
RayTracingOpacityMicromapEXT = 5381u32,
ShaderInvocationReorderNV = 5383u32,
BindlessTextureNV = 5390u32,
RayQueryPositionFetchKHR = 5391u32,
RayTracingDisplacementMicromapNV = 5409u32,
SubgroupShuffleINTEL = 5568u32,
SubgroupBufferBlockIOINTEL = 5569u32,
SubgroupImageBlockIOINTEL = 5570u32,
SubgroupImageMediaBlockIOINTEL = 5579u32,
RoundToInfinityINTEL = 5582u32,
FloatingPointModeINTEL = 5583u32,
IntegerFunctions2INTEL = 5584u32,
FunctionPointersINTEL = 5603u32,
IndirectReferencesINTEL = 5604u32,
AsmINTEL = 5606u32,
AtomicFloat32MinMaxEXT = 5612u32,
AtomicFloat64MinMaxEXT = 5613u32,
AtomicFloat16MinMaxEXT = 5616u32,
VectorComputeINTEL = 5617u32,
VectorAnyINTEL = 5619u32,
ExpectAssumeKHR = 5629u32,
SubgroupAvcMotionEstimationINTEL = 5696u32,
SubgroupAvcMotionEstimationIntraINTEL = 5697u32,
SubgroupAvcMotionEstimationChromaINTEL = 5698u32,
VariableLengthArrayINTEL = 5817u32,
FunctionFloatControlINTEL = 5821u32,
FPGAMemoryAttributesINTEL = 5824u32,
FPFastMathModeINTEL = 5837u32,
ArbitraryPrecisionIntegersINTEL = 5844u32,
ArbitraryPrecisionFloatingPointINTEL = 5845u32,
UnstructuredLoopControlsINTEL = 5886u32,
FPGALoopControlsINTEL = 5888u32,
KernelAttributesINTEL = 5892u32,
FPGAKernelAttributesINTEL = 5897u32,
FPGAMemoryAccessesINTEL = 5898u32,
FPGAClusterAttributesINTEL = 5904u32,
LoopFuseINTEL = 5906u32,
FPGADSPControlINTEL = 5908u32,
MemoryAccessAliasingINTEL = 5910u32,
FPGAInvocationPipeliningAttributesINTEL = 5916u32,
FPGABufferLocationINTEL = 5920u32,
ArbitraryPrecisionFixedPointINTEL = 5922u32,
USMStorageClassesINTEL = 5935u32,
RuntimeAlignedAttributeINTEL = 5939u32,
IOPipesINTEL = 5943u32,
BlockingPipesINTEL = 5945u32,
FPGARegINTEL = 5948u32,
DotProductInputAll = 6016u32,
DotProductInput4x8Bit = 6017u32,
DotProductInput4x8BitPacked = 6018u32,
DotProduct = 6019u32,
RayCullMaskKHR = 6020u32,
CooperativeMatrixKHR = 6022u32,
BitInstructions = 6025u32,
GroupNonUniformRotateKHR = 6026u32,
AtomicFloat32AddEXT = 6033u32,
AtomicFloat64AddEXT = 6034u32,
LongConstantCompositeINTEL = 6089u32,
OptNoneINTEL = 6094u32,
AtomicFloat16AddEXT = 6095u32,
DebugInfoModuleINTEL = 6114u32,
BFloat16ConversionINTEL = 6115u32,
SplitBarrierINTEL = 6141u32,
GlobalVariableFPGADecorationsINTEL = 6146u32,
FPGAKernelAttributesv2INTEL = 6161u32,
GlobalVariableHostAccessINTEL = 6167u32,
FPMaxErrorINTEL = 6169u32,
FPGALatencyControlINTEL = 6171u32,
FPGAArgumentInterfacesINTEL = 6174u32,
GroupUniformArithmeticKHR = 6400u32,
CacheControlsINTEL = 6441u32,
}
1 change: 1 addition & 0 deletions crates/cargo-gpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use install::Install;
use show::Show;

mod build;
mod capabilities;
mod config;
mod install;
mod metadata;
Expand Down
14 changes: 14 additions & 0 deletions crates/cargo-gpu/src/show.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Display various information about `cargo gpu`, eg its cache directory.
use strum::IntoEnumIterator as _;

use crate::cache_dir;

/// Show the computed source of the spirv-std dependency.
Expand All @@ -19,6 +21,8 @@ pub enum Info {
SpirvSource(SpirvSourceDep),
/// The git commitsh of this cli tool.
Commitsh,
/// All the available SPIR-V capabilities that can be set with `--capability`
Capabilities,
}

/// `cargo gpu show`
Expand Down Expand Up @@ -53,6 +57,16 @@ impl Show {
Info::Commitsh => {
println!("{}", std::env!("GIT_HASH"));
}
Info::Capabilities => {
println!("All available options to the `cargo gpu build --capability` argument:");
#[expect(
clippy::use_debug,
reason = "It's easier to just use `Debug` formatting than implementing `Display`"
)]
for capability in crate::capabilities::Capability::iter() {
println!(" {capability:?}");
}
}
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/spirv-builder-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct BuildArgs {
pub debug: bool,

/// Enables the provided SPIR-V capabilities.
/// See: `impl core::str::FromStr for spirv_builder::Capability`
/// See: `cargo gpu show capabilities`
#[arg(long, value_parser=Self::spirv_capability)]
pub capability: Vec<spirv::Capability>,

Expand Down

0 comments on commit cfdf4ed

Please sign in to comment.