Skip to content

Commit 40b2d30

Browse files
authored
[dx12] Fix detection of Int64 features (#8667)
1 parent fd671d4 commit 40b2d30

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ By @cwfitzgerald in [#8609](https://github.com/gfx-rs/wgpu/pull/8609).
214214
#### DX12
215215

216216
- Align copies b/w textures and buffers via a single intermediate buffer per copy when `D3D12_FEATURE_DATA_D3D12_OPTIONS13.UnrestrictedBufferTextureCopyPitchSupported` is `false`. By @ErichDonGubler in [#7721](https://github.com/gfx-rs/wgpu/pull/7721).
217+
- Fix detection of Int64 Buffer/Texture atomic features. By @cwfitzgerald in [#8667](https://github.com/gfx-rs/wgpu/pull/8667).
217218

218219
#### Vulkan
219220

wgpu-hal/src/dx12/adapter.rs

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,6 @@ impl super::Adapter {
518518
shader_model >= naga::back::hlsl::ShaderModel::V6_2 && float16_supported,
519519
);
520520

521-
features.set(
522-
wgt::Features::TEXTURE_INT64_ATOMIC,
523-
shader_model >= naga::back::hlsl::ShaderModel::V6_6
524-
&& hr.is_ok()
525-
&& features1.Int64ShaderOps.as_bool(),
526-
);
527-
528521
features.set(
529522
wgt::Features::SUBGROUP,
530523
shader_model >= naga::back::hlsl::ShaderModel::V6_0
@@ -552,23 +545,62 @@ impl super::Adapter {
552545
supports_ray_tracing,
553546
);
554547

555-
let atomic_int64_on_typed_resource_supported = {
548+
// Check for Int64 atomic support on buffers. This is very convoluted, but is based on a conservative reading
549+
// of https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_Int64_and_Float_Atomics.html#integer-64-bit-capabilities.
550+
let atomic_int64_buffers;
551+
let atomic_int64_textures;
552+
{
556553
let mut features9 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS9::default();
557-
unsafe {
554+
let hr9 = unsafe {
558555
device.CheckFeatureSupport(
559556
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS9,
560557
<*mut _>::cast(&mut features9),
561558
size_of_val(&features9) as u32,
562559
)
563560
}
564-
.is_ok()
565-
&& features9.AtomicInt64OnGroupSharedSupported.as_bool()
561+
.is_ok();
562+
563+
let mut features11 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS11::default();
564+
let hr11 = unsafe {
565+
device.CheckFeatureSupport(
566+
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS11,
567+
<*mut _>::cast(&mut features11),
568+
size_of_val(&features11) as u32,
569+
)
570+
}
571+
.is_ok();
572+
573+
atomic_int64_buffers = hr9 && hr11 && hr.is_ok()
574+
// Int64 atomics show up in SM6.6.
575+
&& shader_model >= naga::back::hlsl::ShaderModel::V6_6
576+
// They require Int64 to be available in the shader at all.
577+
&& features1.Int64ShaderOps.as_bool()
578+
// As our RWByteAddressBuffers can exist on both descriptor heaps and
579+
// as root descriptors, we need to ensure that both cases are supported.
580+
// base SM6.6 only guarantees Int64 atomics on resources in root descriptors.
581+
&& features11.AtomicInt64OnDescriptorHeapResourceSupported.as_bool()
582+
// Our Int64 atomic caps currently require groupshared. This
583+
// prevents Intel or Qcomm from using Int64 currently.
584+
// https://github.com/gfx-rs/wgpu/issues/8666
585+
&& features9.AtomicInt64OnGroupSharedSupported.as_bool();
586+
587+
atomic_int64_textures = hr9 && hr11 && hr.is_ok()
588+
// Int64 atomics show up in SM6.6.
589+
&& shader_model >= naga::back::hlsl::ShaderModel::V6_6
590+
// They require Int64 to be available in the shader at all.
591+
&& features1.Int64ShaderOps.as_bool()
592+
// Textures are typed resources, so we need this flag.
566593
&& features9.AtomicInt64OnTypedResourceSupported.as_bool()
594+
// As textures can only exist in descriptor heaps, we require this.
595+
// However, all architectures that support atomics on typed resources
596+
// support this as well, so this is somewhat redundant.
597+
&& features11.AtomicInt64OnDescriptorHeapResourceSupported.as_bool();
567598
};
568599
features.set(
569600
wgt::Features::SHADER_INT64_ATOMIC_ALL_OPS | wgt::Features::SHADER_INT64_ATOMIC_MIN_MAX,
570-
atomic_int64_on_typed_resource_supported,
601+
atomic_int64_buffers,
571602
);
603+
features.set(wgt::Features::TEXTURE_INT64_ATOMIC, atomic_int64_textures);
572604
let mesh_shader_supported = {
573605
let mut features7 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS7::default();
574606
unsafe {

0 commit comments

Comments
 (0)