mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 15:31:03 +01:00
Add draw_id builtin (#8883)
This commit is contained in:
1 parent
7c74c1d606
commit
7609ed99e5
26 files changed
+358
-12
No files matched your search
@@ -67,6 +67,7 @@ By @cwfitzgerald in [#8999](https://github.com/gfx-rs/wgpu/pull/8999).
|
||||
- `ir::Block::is_empty`
|
||||
- `ir::Block::len`
|
||||
- Changed passthrough shaders to not require an entry point parameter, so that the same shader module may be used in multiple entry points. Also added support for metallib passthrough. By @inner-daemons in #8886.
|
||||
- Added support for `@builtin(draw_index)` to the vulkan backend. By @inner-daemons in #8883.
|
||||
- Added support for `insert_debug_marker`, `push_debug_group` and `pop_debug_group` on WebGPU. By @evilpie in [#9017](https://github.com/gfx-rs/wgpu/pull/9017).
|
||||
- Added support for `enable primitive_index` and `@builtin(primitive_index)` with support on all platforms. By @inner-daemons in #8879.
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ pub(in crate::back::glsl) const fn glsl_built_in(
|
||||
}
|
||||
Bi::PointSize => "gl_PointSize",
|
||||
Bi::VertexIndex => "uint(gl_VertexID)",
|
||||
Bi::DrawID => "gl_DrawID",
|
||||
Bi::DrawIndex => "gl_DrawID",
|
||||
// fragment
|
||||
Bi::FragDepth => "gl_FragDepth",
|
||||
Bi::PointCoord => "gl_PointCoord",
|
||||
|
||||
@@ -624,7 +624,7 @@ impl<W> Writer<'_, W> {
|
||||
self.features.request(Features::SAMPLE_VARIABLES)
|
||||
}
|
||||
crate::BuiltIn::ViewIndex => self.features.request(Features::MULTI_VIEW),
|
||||
crate::BuiltIn::InstanceIndex | crate::BuiltIn::DrawID => {
|
||||
crate::BuiltIn::InstanceIndex | crate::BuiltIn::DrawIndex => {
|
||||
self.features.request(Features::INSTANCE_INDEX)
|
||||
}
|
||||
crate::BuiltIn::Barycentric { .. } => {
|
||||
|
||||
@@ -182,7 +182,7 @@ impl crate::BuiltIn {
|
||||
Self::BaseInstance | Self::BaseVertex | Self::WorkGroupSize => {
|
||||
return Err(Error::Unimplemented(format!("builtin {self:?}")))
|
||||
}
|
||||
Self::PointSize | Self::PointCoord | Self::DrawID => {
|
||||
Self::PointSize | Self::PointCoord | Self::DrawIndex => {
|
||||
return Err(Error::Custom(format!("Unsupported builtin {self:?}")))
|
||||
}
|
||||
Self::CullPrimitive => "SV_CullPrimitive",
|
||||
|
||||
@@ -713,7 +713,7 @@ impl ResolvedBinding {
|
||||
Bi::SubgroupId => "simdgroup_index_in_threadgroup",
|
||||
Bi::SubgroupSize => "threads_per_simdgroup",
|
||||
Bi::SubgroupInvocationId => "thread_index_in_simdgroup",
|
||||
Bi::CullDistance | Bi::DrawID => {
|
||||
Bi::CullDistance | Bi::DrawIndex => {
|
||||
return Err(Error::UnsupportedBuiltIn(built_in))
|
||||
}
|
||||
Bi::CullPrimitive => "primitive_culled",
|
||||
|
||||
@@ -3077,7 +3077,14 @@ impl Writer {
|
||||
Bi::InstanceIndex => BuiltIn::InstanceIndex,
|
||||
Bi::PointSize => BuiltIn::PointSize,
|
||||
Bi::VertexIndex => BuiltIn::VertexIndex,
|
||||
Bi::DrawID => BuiltIn::DrawIndex,
|
||||
Bi::DrawIndex => {
|
||||
self.use_extension("SPV_KHR_shader_draw_parameters");
|
||||
self.require_any(
|
||||
"`draw_index built-in",
|
||||
&[spirv::Capability::DrawParameters],
|
||||
)?;
|
||||
BuiltIn::DrawIndex
|
||||
}
|
||||
// fragment
|
||||
Bi::FragDepth => BuiltIn::FragDepth,
|
||||
Bi::PointCoord => BuiltIn::PointCoord,
|
||||
|
||||
@@ -286,6 +286,7 @@ impl<W: Write> Writer<W> {
|
||||
mesh_shaders: bool,
|
||||
primitive_index: bool,
|
||||
cooperative_matrix: bool,
|
||||
draw_index: bool,
|
||||
}
|
||||
let mut needed = RequiredEnabled::default();
|
||||
|
||||
@@ -308,6 +309,7 @@ impl<W: Write> Writer<W> {
|
||||
} => {
|
||||
needed.mesh_shaders = true;
|
||||
}
|
||||
crate::Binding::BuiltIn(crate::BuiltIn::DrawIndex) => needed.draw_index = true,
|
||||
crate::Binding::BuiltIn(
|
||||
crate::BuiltIn::MeshTaskSize
|
||||
| crate::BuiltIn::CullPrimitive
|
||||
@@ -387,6 +389,10 @@ impl<W: Write> Writer<W> {
|
||||
writeln!(self.out, "enable wgpu_mesh_shader;")?;
|
||||
any_written = true;
|
||||
}
|
||||
if needed.draw_index {
|
||||
writeln!(self.out, "enable draw_index;")?;
|
||||
any_written = true;
|
||||
}
|
||||
if needed.primitive_index {
|
||||
writeln!(self.out, "enable primitive_index;")?;
|
||||
any_written = true;
|
||||
|
||||
@@ -169,6 +169,7 @@ impl TryToWgsl for crate::BuiltIn {
|
||||
Bi::FragDepth => "frag_depth",
|
||||
Bi::FrontFacing => "front_facing",
|
||||
Bi::PrimitiveIndex => "primitive_index",
|
||||
Bi::DrawIndex => "draw_index",
|
||||
Bi::Barycentric { perspective: true } => "barycentric",
|
||||
Bi::Barycentric { perspective: false } => "barycentric_no_perspective",
|
||||
Bi::SampleIndex => "sample_index",
|
||||
@@ -198,7 +199,6 @@ impl TryToWgsl for crate::BuiltIn {
|
||||
| Bi::BaseVertex
|
||||
| Bi::CullDistance
|
||||
| Bi::PointSize
|
||||
| Bi::DrawID
|
||||
| Bi::PointCoord
|
||||
| Bi::WorkGroupSize
|
||||
| Bi::RayInvocationId
|
||||
|
||||
@@ -207,7 +207,7 @@ impl Frontend {
|
||||
"gl_VertexIndex" => BuiltIn::VertexIndex,
|
||||
"gl_SampleID" => BuiltIn::SampleIndex,
|
||||
"gl_LocalInvocationIndex" => BuiltIn::LocalInvocationIndex,
|
||||
"gl_DrawID" => BuiltIn::DrawID,
|
||||
"gl_DrawID" => BuiltIn::DrawIndex,
|
||||
_ => return Ok(None),
|
||||
};
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ pub(super) fn map_builtin(word: spirv::Word, invariant: bool) -> Result<crate::B
|
||||
Some(Bi::InstanceIndex) => crate::BuiltIn::InstanceIndex,
|
||||
Some(Bi::PointSize) => crate::BuiltIn::PointSize,
|
||||
Some(Bi::VertexIndex) => crate::BuiltIn::VertexIndex,
|
||||
Some(Bi::DrawIndex) => crate::BuiltIn::DrawID,
|
||||
Some(Bi::DrawIndex) => crate::BuiltIn::DrawIndex,
|
||||
// fragment
|
||||
Some(Bi::FragDepth) => crate::BuiltIn::FragDepth,
|
||||
Some(Bi::PointCoord) => crate::BuiltIn::PointCoord,
|
||||
|
||||
@@ -104,6 +104,7 @@ pub fn map_built_in(
|
||||
"front_facing" => crate::BuiltIn::FrontFacing,
|
||||
"frag_depth" => crate::BuiltIn::FragDepth,
|
||||
"primitive_index" => crate::BuiltIn::PrimitiveIndex,
|
||||
"draw_index" => crate::BuiltIn::DrawIndex,
|
||||
"barycentric" => crate::BuiltIn::Barycentric { perspective: true },
|
||||
"barycentric_no_perspective" => crate::BuiltIn::Barycentric { perspective: false },
|
||||
"sample_index" => crate::BuiltIn::SampleIndex,
|
||||
@@ -154,6 +155,14 @@ pub fn map_built_in(
|
||||
crate::BuiltIn::PrimitiveIndex => {
|
||||
enable_extensions.require(ImplementedEnableExtension::PrimitiveIndex, span)?
|
||||
}
|
||||
crate::BuiltIn::DrawIndex => {
|
||||
if !enable_extensions.contains(ImplementedEnableExtension::DrawIndex) {
|
||||
return Err(Box::new(Error::EnableExtensionNotEnabled {
|
||||
span,
|
||||
kind: ImplementedEnableExtension::DrawIndex.into(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
crate::BuiltIn::CullPrimitive
|
||||
| crate::BuiltIn::PointIndex
|
||||
| crate::BuiltIn::LineIndices
|
||||
|
||||
@@ -19,6 +19,7 @@ pub(crate) struct EnableExtensions {
|
||||
f16: bool,
|
||||
clip_distances: bool,
|
||||
wgpu_cooperative_matrix: bool,
|
||||
draw_index: bool,
|
||||
primitive_index: bool,
|
||||
}
|
||||
|
||||
@@ -33,6 +34,7 @@ impl EnableExtensions {
|
||||
dual_source_blending: false,
|
||||
clip_distances: false,
|
||||
wgpu_cooperative_matrix: false,
|
||||
draw_index: false,
|
||||
primitive_index: false,
|
||||
}
|
||||
}
|
||||
@@ -52,6 +54,7 @@ impl EnableExtensions {
|
||||
ImplementedEnableExtension::F16 => &mut self.f16,
|
||||
ImplementedEnableExtension::ClipDistances => &mut self.clip_distances,
|
||||
ImplementedEnableExtension::WgpuCooperativeMatrix => &mut self.wgpu_cooperative_matrix,
|
||||
ImplementedEnableExtension::DrawIndex => &mut self.draw_index,
|
||||
ImplementedEnableExtension::PrimitiveIndex => &mut self.primitive_index,
|
||||
};
|
||||
*field = true;
|
||||
@@ -70,6 +73,7 @@ impl EnableExtensions {
|
||||
ImplementedEnableExtension::F16 => self.f16,
|
||||
ImplementedEnableExtension::ClipDistances => self.clip_distances,
|
||||
ImplementedEnableExtension::WgpuCooperativeMatrix => self.wgpu_cooperative_matrix,
|
||||
ImplementedEnableExtension::DrawIndex => self.draw_index,
|
||||
ImplementedEnableExtension::PrimitiveIndex => self.primitive_index,
|
||||
}
|
||||
}
|
||||
@@ -122,6 +126,7 @@ impl EnableExtension {
|
||||
const COOPERATIVE_MATRIX: &'static str = "wgpu_cooperative_matrix";
|
||||
const SUBGROUPS: &'static str = "subgroups";
|
||||
const PRIMITIVE_INDEX: &'static str = "primitive_index";
|
||||
const DRAW_INDEX: &'static str = "draw_index";
|
||||
|
||||
/// Convert from a sentinel word in WGSL into its associated [`EnableExtension`], if possible.
|
||||
pub(crate) fn from_ident(word: &str, span: Span) -> Result<'_, Self> {
|
||||
@@ -143,6 +148,7 @@ impl EnableExtension {
|
||||
Self::Implemented(ImplementedEnableExtension::WgpuCooperativeMatrix)
|
||||
}
|
||||
Self::SUBGROUPS => Self::Unimplemented(UnimplementedEnableExtension::Subgroups),
|
||||
Self::DRAW_INDEX => Self::Implemented(ImplementedEnableExtension::DrawIndex),
|
||||
Self::PRIMITIVE_INDEX => Self::Implemented(ImplementedEnableExtension::PrimitiveIndex),
|
||||
_ => return Err(Box::new(Error::UnknownEnableExtension(span, word))),
|
||||
})
|
||||
@@ -161,6 +167,7 @@ impl EnableExtension {
|
||||
ImplementedEnableExtension::DualSourceBlending => Self::DUAL_SOURCE_BLENDING,
|
||||
ImplementedEnableExtension::F16 => Self::F16,
|
||||
ImplementedEnableExtension::ClipDistances => Self::CLIP_DISTANCES,
|
||||
ImplementedEnableExtension::DrawIndex => Self::DRAW_INDEX,
|
||||
ImplementedEnableExtension::PrimitiveIndex => Self::PRIMITIVE_INDEX,
|
||||
ImplementedEnableExtension::WgpuRayTracingPipeline => Self::RAY_TRACING_PIPELINE,
|
||||
},
|
||||
@@ -203,6 +210,8 @@ pub enum ImplementedEnableExtension {
|
||||
WgpuRayTracingPipeline,
|
||||
/// Enables the `wgpu_cooperative_matrix` extension, native only.
|
||||
WgpuCooperativeMatrix,
|
||||
/// Enables the `draw_index` builtin. Not currently part of the WGSL spec but probably will be at some point.
|
||||
DrawIndex,
|
||||
/// Enables the `@builtin(primitive_index)` attribute in WGSL.
|
||||
///
|
||||
/// In the WGSL standard, this corresponds to [`enable primitive-index;`].
|
||||
@@ -222,6 +231,7 @@ impl ImplementedEnableExtension {
|
||||
Self::WgpuRayQueryVertexReturn,
|
||||
Self::WgpuRayTracingPipeline,
|
||||
Self::WgpuCooperativeMatrix,
|
||||
Self::DrawIndex,
|
||||
Self::PrimitiveIndex,
|
||||
];
|
||||
|
||||
@@ -242,6 +252,7 @@ impl ImplementedEnableExtension {
|
||||
Self::WgpuRayQueryVertexReturn => C::RAY_HIT_VERTEX_POSITION,
|
||||
Self::WgpuCooperativeMatrix => C::COOPERATIVE_MATRIX,
|
||||
Self::WgpuRayTracingPipeline => C::RAY_TRACING_PIPELINE,
|
||||
Self::DrawIndex => C::DRAW_INDEX,
|
||||
Self::PrimitiveIndex => C::PRIMITIVE_INDEX,
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -421,7 +421,7 @@ pub enum BuiltIn {
|
||||
/// Read in vertex shaders
|
||||
VertexIndex,
|
||||
/// Read in vertex & task shaders, or mesh shaders in pipelines without task shaders
|
||||
DrawID,
|
||||
DrawIndex,
|
||||
|
||||
/// Written in fragment shaders
|
||||
FragDepth,
|
||||
|
||||
@@ -254,6 +254,7 @@ impl VaryingContext<'_> {
|
||||
| Bi::SubgroupId
|
||||
| Bi::SubgroupSize
|
||||
| Bi::SubgroupInvocationId => Capabilities::SUBGROUP,
|
||||
Bi::DrawIndex => Capabilities::DRAW_INDEX,
|
||||
_ => Capabilities::empty(),
|
||||
};
|
||||
if !self.capabilities.contains(required) {
|
||||
@@ -278,7 +279,7 @@ impl VaryingContext<'_> {
|
||||
&& !self.output,
|
||||
*ty_inner == Ti::Scalar(crate::Scalar::U32),
|
||||
),
|
||||
Bi::DrawID => (
|
||||
Bi::DrawIndex => (
|
||||
// Always allowed in task/vertex stage. Allowed in mesh stage if there is no task stage in the pipeline.
|
||||
(self.stage == St::Vertex
|
||||
|| self.stage == St::Task
|
||||
|
||||
@@ -207,6 +207,8 @@ bitflags::bitflags! {
|
||||
const PER_VERTEX = 1 << 37;
|
||||
/// Support for ray generation, any hit, closest hit, and miss shaders.
|
||||
const RAY_TRACING_PIPELINE = 1 << 38;
|
||||
/// Support for draw index builtin
|
||||
const DRAW_INDEX = 1 << 39;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
capabilities = "DRAW_INDEX"
|
||||
targets = "SPIRV | WGSL"
|
||||
|
||||
[spv]
|
||||
version = [1, 4]
|
||||
capabilities = ["DrawParameters"]
|
||||
@@ -0,0 +1,10 @@
|
||||
enable draw_index;
|
||||
|
||||
struct Input {
|
||||
@builtin(draw_index) draw_index: u32,
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn vertex(input: Input) -> @builtin(position) vec4<f32> {
|
||||
return vec4<f32>(f32(input.draw_index), 1.0, 1.0, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
; SPIR-V
|
||||
; Version: 1.4
|
||||
; Generator: rspirv
|
||||
; Bound: 21
|
||||
OpCapability Shader
|
||||
OpCapability DrawParameters
|
||||
OpExtension "SPV_KHR_shader_draw_parameters"
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Vertex %14 "vertex" %9 %12
|
||||
OpMemberDecorate %4 0 Offset 0
|
||||
OpDecorate %9 BuiltIn DrawIndex
|
||||
OpDecorate %12 BuiltIn Position
|
||||
%2 = OpTypeVoid
|
||||
%3 = OpTypeInt 32 0
|
||||
%4 = OpTypeStruct %3
|
||||
%6 = OpTypeFloat 32
|
||||
%5 = OpTypeVector %6 4
|
||||
%10 = OpTypePointer Input %3
|
||||
%9 = OpVariable %10 Input
|
||||
%13 = OpTypePointer Output %5
|
||||
%12 = OpVariable %13 Output
|
||||
%15 = OpTypeFunction %2
|
||||
%16 = OpConstant %6 1
|
||||
%14 = OpFunction %2 None %15
|
||||
%7 = OpLabel
|
||||
%11 = OpLoad %3 %9
|
||||
%8 = OpCompositeConstruct %4 %11
|
||||
OpBranch %17
|
||||
%17 = OpLabel
|
||||
%18 = OpCompositeExtract %3 %8 0
|
||||
%19 = OpConvertUToF %6 %18
|
||||
%20 = OpCompositeConstruct %5 %19 %16 %16 %16
|
||||
OpStore %12 %20
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,10 @@
|
||||
enable draw_index;
|
||||
|
||||
struct Input {
|
||||
@builtin(draw_index) draw_index: u32,
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn vertex(input: Input) -> @builtin(position) vec4<f32> {
|
||||
return vec4<f32>(f32(input.draw_index), 1f, 1f, 1f);
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
use wgpu::{
|
||||
Backends, ColorTargetState, ColorWrites, Features, FragmentState, Limits,
|
||||
MeshPipelineDescriptor, MeshState, RenderPipelineDescriptor, ShaderModuleDescriptor, TaskState,
|
||||
TextureFormat, VertexState,
|
||||
};
|
||||
use wgpu_test::{
|
||||
gpu_test, FailureCase, GpuTestConfiguration, GpuTestInitializer, TestParameters, TestingContext,
|
||||
};
|
||||
|
||||
pub fn all_tests(tests: &mut Vec<GpuTestInitializer>) {
|
||||
tests.push(DRAW_INDEX);
|
||||
tests.push(DRAW_INDEX_MESH_NO_TASK);
|
||||
tests.push(DRAW_INDEX_MESH_TASK);
|
||||
tests.push(DRAW_INDEX_TASK_NO_MESH);
|
||||
}
|
||||
|
||||
async fn test(ctx: TestingContext) {
|
||||
const CODE: &str = "\
|
||||
enable draw_index;
|
||||
|
||||
struct Input {
|
||||
@builtin(draw_index) draw_index: u32,
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn vertex(input: Input) -> @builtin(position) vec4<f32> {
|
||||
return vec4<f32>(f32(input.draw_index), 1.0, 1.0, 1.0);
|
||||
}
|
||||
@fragment
|
||||
fn fragment() -> @location(0) vec4<f32> {
|
||||
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
";
|
||||
let module = ctx.device.create_shader_module(ShaderModuleDescriptor {
|
||||
label: None,
|
||||
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(CODE)),
|
||||
});
|
||||
let _pipeline = ctx
|
||||
.device
|
||||
.create_render_pipeline(&RenderPipelineDescriptor {
|
||||
label: None,
|
||||
layout: None,
|
||||
vertex: VertexState {
|
||||
module: &module,
|
||||
entry_point: Some("vertex"),
|
||||
compilation_options: Default::default(),
|
||||
buffers: &[],
|
||||
},
|
||||
primitive: Default::default(),
|
||||
depth_stencil: None,
|
||||
multisample: Default::default(),
|
||||
fragment: Some(FragmentState {
|
||||
module: &module,
|
||||
entry_point: Some("fragment"),
|
||||
compilation_options: Default::default(),
|
||||
targets: &[Some(ColorTargetState {
|
||||
format: TextureFormat::Rgba8Unorm,
|
||||
blend: None,
|
||||
write_mask: ColorWrites::all(),
|
||||
})],
|
||||
}),
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
});
|
||||
}
|
||||
|
||||
#[gpu_test]
|
||||
static DRAW_INDEX: GpuTestConfiguration = GpuTestConfiguration::new()
|
||||
.parameters(TestParameters::default().features(Features::SHADER_DRAW_INDEX))
|
||||
.run_async(test);
|
||||
|
||||
async fn test_mesh(ctx: TestingContext, use_task: bool, mesh_uses_draw_id: bool) {
|
||||
const CODE: &str = "\
|
||||
enable draw_index;
|
||||
enable wgpu_mesh_shader;
|
||||
|
||||
struct VertexOutput {
|
||||
@builtin(position) position: vec4<f32>,
|
||||
}
|
||||
struct PrimitiveOutput {
|
||||
@builtin(triangle_indices) indices: vec3<u32>,
|
||||
}
|
||||
struct MeshOutput {
|
||||
@builtin(vertices) vertices: array<VertexOutput, 3>,
|
||||
@builtin(vertex_count) vertex_count: u32,
|
||||
@builtin(primitives) primitives: array<PrimitiveOutput, 3>,
|
||||
@builtin(primitive_count) primitive_count: u32,
|
||||
}
|
||||
var<workgroup> mesh_output: MeshOutput;
|
||||
struct TaskPayload { value: u32 }
|
||||
var<task_payload> payload: TaskPayload;
|
||||
|
||||
@task
|
||||
@payload(payload)
|
||||
@workgroup_size(1)
|
||||
fn task(@builtin(draw_index) id: u32) -> @builtin(mesh_task_size) vec3<u32> {
|
||||
return vec3<u32>(1, 1, 1);
|
||||
}
|
||||
|
||||
@mesh(mesh_output)
|
||||
@payload(payload)
|
||||
@workgroup_size(1)
|
||||
fn mesh_ts(MESH_DRAW_INDEX1) {
|
||||
mesh_output.vertex_count = 0;
|
||||
mesh_output.primitive_count = 0;
|
||||
}
|
||||
|
||||
@mesh(mesh_output)
|
||||
@workgroup_size(1)
|
||||
fn mesh_no_ts(MESH_DRAW_INDEX2) {
|
||||
mesh_output.vertex_count = 0;
|
||||
mesh_output.primitive_count = 0;
|
||||
}
|
||||
@fragment
|
||||
fn fragment() -> @location(0) vec4<f32> {
|
||||
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
";
|
||||
|
||||
let used_code = CODE
|
||||
.replace(
|
||||
"MESH_DRAW_INDEX2",
|
||||
if mesh_uses_draw_id {
|
||||
"@builtin(draw_index) id: u32"
|
||||
} else {
|
||||
""
|
||||
},
|
||||
)
|
||||
.replace(
|
||||
"MESH_DRAW_INDEX1",
|
||||
if mesh_uses_draw_id && use_task {
|
||||
"@builtin(draw_index) id: u32"
|
||||
} else {
|
||||
""
|
||||
},
|
||||
);
|
||||
let module = ctx.device.create_shader_module(ShaderModuleDescriptor {
|
||||
label: None,
|
||||
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Owned(used_code)),
|
||||
});
|
||||
let _ = ctx.device.create_mesh_pipeline(&MeshPipelineDescriptor {
|
||||
label: None,
|
||||
layout: None,
|
||||
task: use_task.then_some(TaskState {
|
||||
module: &module,
|
||||
entry_point: None,
|
||||
compilation_options: Default::default(),
|
||||
}),
|
||||
mesh: MeshState {
|
||||
module: &module,
|
||||
entry_point: Some(if use_task { "mesh_ts" } else { "mesh_no_ts" }),
|
||||
compilation_options: Default::default(),
|
||||
},
|
||||
primitive: Default::default(),
|
||||
depth_stencil: None,
|
||||
multisample: Default::default(),
|
||||
fragment: Some(FragmentState {
|
||||
module: &module,
|
||||
entry_point: None,
|
||||
compilation_options: Default::default(),
|
||||
targets: &[Some(ColorTargetState {
|
||||
format: TextureFormat::Rgba8Unorm,
|
||||
blend: None,
|
||||
write_mask: ColorWrites::all(),
|
||||
})],
|
||||
}),
|
||||
multiview: None,
|
||||
cache: None,
|
||||
});
|
||||
}
|
||||
|
||||
fn mesh_params() -> TestParameters {
|
||||
// TODO: when support for mesh shaders in naga on dx12/metal lands enable those backends
|
||||
TestParameters::default()
|
||||
.features(Features::SHADER_DRAW_INDEX | Features::EXPERIMENTAL_MESH_SHADER)
|
||||
.skip(FailureCase::backend(Backends::DX12 | Backends::METAL))
|
||||
.limits(Limits::defaults().using_recommended_minimum_mesh_shader_values())
|
||||
}
|
||||
|
||||
#[gpu_test]
|
||||
static DRAW_INDEX_TASK_NO_MESH: GpuTestConfiguration = GpuTestConfiguration::new()
|
||||
.parameters(mesh_params())
|
||||
.run_async(async |ctx| test_mesh(ctx, true, false).await);
|
||||
|
||||
#[gpu_test]
|
||||
static DRAW_INDEX_MESH_NO_TASK: GpuTestConfiguration = GpuTestConfiguration::new()
|
||||
.parameters(mesh_params())
|
||||
.run_async(async |ctx| test_mesh(ctx, false, true).await);
|
||||
|
||||
#[gpu_test]
|
||||
static DRAW_INDEX_MESH_TASK: GpuTestConfiguration = GpuTestConfiguration::new()
|
||||
.parameters(mesh_params().expect_fail(FailureCase::always()))
|
||||
.run_async(async |ctx| test_mesh(ctx, true, true).await);
|
||||
@@ -25,6 +25,7 @@ mod compute_pass_ownership;
|
||||
mod create_surface_error;
|
||||
mod device;
|
||||
mod dispatch_workgroups_indirect;
|
||||
mod draw_index;
|
||||
mod draw_indirect;
|
||||
mod dual_source_blending;
|
||||
mod encoder;
|
||||
@@ -94,6 +95,7 @@ fn all_tests() -> Vec<wgpu_test::GpuTestInitializer> {
|
||||
compute_pass_ownership::all_tests(&mut tests);
|
||||
device::all_tests(&mut tests);
|
||||
dispatch_workgroups_indirect::all_tests(&mut tests);
|
||||
draw_index::all_tests(&mut tests);
|
||||
draw_indirect::all_tests(&mut tests);
|
||||
dual_source_blending::all_tests(&mut tests);
|
||||
encoder::all_tests(&mut tests);
|
||||
|
||||
@@ -538,6 +538,10 @@ pub fn features_to_naga_capabilities(
|
||||
Caps::PER_VERTEX,
|
||||
features.intersects(wgt::Features::SHADER_PER_VERTEX),
|
||||
);
|
||||
caps.set(
|
||||
Caps::DRAW_INDEX,
|
||||
features.intersects(wgt::Features::SHADER_DRAW_INDEX),
|
||||
);
|
||||
|
||||
caps
|
||||
}
|
||||
|
||||
@@ -1513,7 +1513,7 @@ impl Interface {
|
||||
Varying::BuiltIn(naga::BuiltIn::PrimitiveIndex) => {
|
||||
this_stage_primitive_index = true;
|
||||
}
|
||||
Varying::BuiltIn(naga::BuiltIn::DrawID) => {
|
||||
Varying::BuiltIn(naga::BuiltIn::DrawIndex) => {
|
||||
has_draw_id = true;
|
||||
}
|
||||
Varying::BuiltIn(_) => {}
|
||||
|
||||
@@ -75,7 +75,7 @@ impl MaxFragmentShaderInputDeduction {
|
||||
| BuiltIn::InstanceIndex
|
||||
| BuiltIn::PointSize
|
||||
| BuiltIn::VertexIndex
|
||||
| BuiltIn::DrawID
|
||||
| BuiltIn::DrawIndex
|
||||
| BuiltIn::FragDepth
|
||||
| BuiltIn::GlobalInvocationId
|
||||
| BuiltIn::LocalInvocationId
|
||||
|
||||
@@ -141,6 +141,8 @@ pub struct PhysicalDeviceFeatures {
|
||||
|
||||
/// Features provided by `VK_KHR_vulkan_memory_model`, promoted to Vulkan 1.2
|
||||
vulkan_memory_model: Option<vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR<'static>>,
|
||||
|
||||
shader_draw_parameters: Option<vk::PhysicalDeviceShaderDrawParametersFeatures<'static>>,
|
||||
}
|
||||
|
||||
impl PhysicalDeviceFeatures {
|
||||
@@ -226,6 +228,9 @@ impl PhysicalDeviceFeatures {
|
||||
if let Some(ref mut feature) = self.vulkan_memory_model {
|
||||
info = info.push_next(feature);
|
||||
}
|
||||
if let Some(ref mut feature) = self.shader_draw_parameters {
|
||||
info = info.push_next(feature);
|
||||
}
|
||||
info
|
||||
}
|
||||
|
||||
@@ -606,6 +611,14 @@ impl PhysicalDeviceFeatures {
|
||||
} else {
|
||||
None
|
||||
},
|
||||
shader_draw_parameters: if device_api_version >= vk::API_VERSION_1_1 {
|
||||
Some(
|
||||
vk::PhysicalDeviceShaderDrawParametersFeatures::default()
|
||||
.shader_draw_parameters(true),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1006,6 +1019,13 @@ impl PhysicalDeviceFeatures {
|
||||
!caps.cooperative_matrix_properties.is_empty(),
|
||||
);
|
||||
|
||||
features.set(
|
||||
F::SHADER_DRAW_INDEX,
|
||||
self.shader_draw_parameters
|
||||
.is_some_and(|a| a.shader_draw_parameters != 0)
|
||||
|| caps.supports_extension(c"VK_KHR_shader_draw_parameters"),
|
||||
);
|
||||
|
||||
(features, dl_flags)
|
||||
}
|
||||
}
|
||||
@@ -1147,6 +1167,10 @@ impl PhysicalDeviceProperties {
|
||||
// we require that one already.
|
||||
extensions.push(khr::_16bit_storage::NAME);
|
||||
}
|
||||
|
||||
if requested_features.contains(wgt::Features::SHADER_DRAW_INDEX) {
|
||||
extensions.push(khr::shader_draw_parameters::NAME);
|
||||
}
|
||||
}
|
||||
|
||||
if self.device_api_version < vk::API_VERSION_1_2 {
|
||||
@@ -1829,6 +1853,13 @@ impl super::InstanceShared {
|
||||
features2 = features2.push_next(next);
|
||||
}
|
||||
|
||||
if capabilities.device_api_version >= vk::API_VERSION_1_1 {
|
||||
let next = features
|
||||
.shader_draw_parameters
|
||||
.insert(vk::PhysicalDeviceShaderDrawParametersFeatures::default());
|
||||
features2 = features2.push_next(next);
|
||||
}
|
||||
|
||||
unsafe { get_device_properties.get_physical_device_features2(phd, &mut features2) };
|
||||
features2.features
|
||||
} else {
|
||||
@@ -2358,6 +2389,10 @@ impl super::Adapter {
|
||||
capabilities.push(spv::Capability::FragmentBarycentricKHR);
|
||||
}
|
||||
|
||||
if features.contains(wgt::Features::SHADER_DRAW_INDEX) {
|
||||
capabilities.push(spv::Capability::DrawParameters);
|
||||
}
|
||||
|
||||
let mut flags = spv::WriterFlags::empty();
|
||||
flags.set(
|
||||
spv::WriterFlags::DEBUG,
|
||||
|
||||
@@ -1284,6 +1284,19 @@ bitflags_array! {
|
||||
///
|
||||
/// This is a native only feature.
|
||||
const SHADER_PER_VERTEX = 1 << 58;
|
||||
|
||||
/// Enables shader `draw_index` builtin.
|
||||
///
|
||||
/// Supported platforms:
|
||||
/// - GLES
|
||||
/// - Vulkan
|
||||
///
|
||||
/// Potential platforms:
|
||||
/// - DX12
|
||||
/// - Metal
|
||||
///
|
||||
/// This is a native only feature.
|
||||
const SHADER_DRAW_INDEX = 1 << 59;
|
||||
}
|
||||
|
||||
/// Features that are not guaranteed to be supported.
|
||||
|
||||
Reference in new issue
Block a user