| 1 |
use alloc::{string::String, sync::Arc, vec::Vec}; |
| 2 |
use core::ptr; |
| 3 |
use std::thread; |
| 4 |
|
| 5 |
use parking_lot::Mutex; |
| 6 |
use windows::{ |
| 7 |
core::Interface as _, |
| 8 |
Win32::{ |
| 9 |
Graphics::{Direct3D, Direct3D12, Dxgi}, |
| 10 |
UI::WindowsAndMessaging, |
| 11 |
}, |
| 12 |
}; |
| 13 |
|
| 14 |
use super::D3D12Lib; |
| 15 |
use crate::{ |
| 16 |
auxil::{ |
| 17 |
self, |
| 18 |
dxgi::{factory::DxgiAdapter, result::HResult}, |
| 19 |
}, |
| 20 |
dx12::{shader_compilation, SurfaceTarget}, |
| 21 |
}; |
| 22 |
|
| 23 |
impl Drop for super::Adapter { |
| 24 |
fn drop(&mut self) { |
| 25 |
// Debug tracking alive objects |
| 26 |
if !thread::panicking() |
| 27 |
&& self |
| 28 |
.private_caps |
| 29 |
.instance_flags |
| 30 |
.contains(wgt::InstanceFlags::VALIDATION) |
| 31 |
{ |
| 32 |
unsafe { |
| 33 |
self.report_live_objects(); |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
impl super::Adapter { |
| 40 |
pub unsafe fn report_live_objects(&self) { |
| 41 |
if let Ok(debug_device) = self.raw.cast::<Direct3D12::ID3D12DebugDevice>() { |
| 42 |
unsafe { |
| 43 |
debug_device.ReportLiveDeviceObjects( |
| 44 |
Direct3D12::D3D12_RLDO_SUMMARY | Direct3D12::D3D12_RLDO_IGNORE_INTERNAL, |
| 45 |
) |
| 46 |
} |
| 47 |
.unwrap() |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
pub fn raw_adapter(&self) -> &DxgiAdapter { |
| 52 |
&self.raw |
| 53 |
} |
| 54 |
|
| 55 |
pub(super) fn expose( |
| 56 |
adapter: DxgiAdapter, |
| 57 |
library: &Arc<D3D12Lib>, |
| 58 |
instance_flags: wgt::InstanceFlags, |
| 59 |
memory_budget_thresholds: wgt::MemoryBudgetThresholds, |
| 60 |
dxc_container: Option<Arc<shader_compilation::DxcContainer>>, |
| 61 |
) -> Option<crate::ExposedAdapter<super::Api>> { |
| 62 |
// Create the device so that we can get the capabilities. |
| 63 |
let device = { |
| 64 |
profiling::scope!("ID3D12Device::create_device"); |
| 65 |
library |
| 66 |
.create_device(&adapter, Direct3D::D3D_FEATURE_LEVEL_11_0) |
| 67 |
.ok()?? |
| 68 |
}; |
| 69 |
|
| 70 |
profiling::scope!("feature queries"); |
| 71 |
|
| 72 |
// Detect the highest supported feature level. |
| 73 |
let d3d_feature_level = [ |
| 74 |
Direct3D::D3D_FEATURE_LEVEL_12_1, |
| 75 |
Direct3D::D3D_FEATURE_LEVEL_12_0, |
| 76 |
Direct3D::D3D_FEATURE_LEVEL_11_1, |
| 77 |
Direct3D::D3D_FEATURE_LEVEL_11_0, |
| 78 |
]; |
| 79 |
let mut device_levels = Direct3D12::D3D12_FEATURE_DATA_FEATURE_LEVELS { |
| 80 |
NumFeatureLevels: d3d_feature_level.len() as u32, |
| 81 |
pFeatureLevelsRequested: d3d_feature_level.as_ptr().cast(), |
| 82 |
MaxSupportedFeatureLevel: Default::default(), |
| 83 |
}; |
| 84 |
unsafe { |
| 85 |
device.CheckFeatureSupport( |
| 86 |
Direct3D12::D3D12_FEATURE_FEATURE_LEVELS, |
| 87 |
<*mut _>::cast(&mut device_levels), |
| 88 |
size_of_val(&device_levels) as u32, |
| 89 |
) |
| 90 |
} |
| 91 |
.unwrap(); |
| 92 |
let max_feature_level = device_levels.MaxSupportedFeatureLevel; |
| 93 |
|
| 94 |
// We have found a possible adapter. |
| 95 |
// Acquire the device information. |
| 96 |
let desc = unsafe { adapter.GetDesc2() }.unwrap(); |
| 97 |
|
| 98 |
let device_name = auxil::dxgi::conv::map_adapter_name(desc.Description); |
| 99 |
|
| 100 |
let mut features_architecture = Direct3D12::D3D12_FEATURE_DATA_ARCHITECTURE::default(); |
| 101 |
|
| 102 |
unsafe { |
| 103 |
device.CheckFeatureSupport( |
| 104 |
Direct3D12::D3D12_FEATURE_ARCHITECTURE, |
| 105 |
<*mut _>::cast(&mut features_architecture), |
| 106 |
size_of_val(&features_architecture) as u32, |
| 107 |
) |
| 108 |
} |
| 109 |
.unwrap(); |
| 110 |
|
| 111 |
let mut workarounds = super::Workarounds::default(); |
| 112 |
|
| 113 |
let info = wgt::AdapterInfo { |
| 114 |
backend: wgt::Backend::Dx12, |
| 115 |
name: device_name, |
| 116 |
vendor: desc.VendorId, |
| 117 |
device: desc.DeviceId, |
| 118 |
device_type: if Dxgi::DXGI_ADAPTER_FLAG(desc.Flags as i32) |
| 119 |
.contains(Dxgi::DXGI_ADAPTER_FLAG_SOFTWARE) |
| 120 |
{ |
| 121 |
workarounds.avoid_cpu_descriptor_overwrites = true; |
| 122 |
wgt::DeviceType::Cpu |
| 123 |
} else if features_architecture.UMA.as_bool() { |
| 124 |
wgt::DeviceType::IntegratedGpu |
| 125 |
} else { |
| 126 |
wgt::DeviceType::DiscreteGpu |
| 127 |
}, |
| 128 |
driver: { |
| 129 |
if let Ok(i) = unsafe { adapter.CheckInterfaceSupport(&Dxgi::IDXGIDevice::IID) } { |
| 130 |
const MASK: i64 = 0xFFFF; |
| 131 |
format!( |
| 132 |
"{}.{}.{}.{}", |
| 133 |
i >> 48, |
| 134 |
(i >> 32) & MASK, |
| 135 |
(i >> 16) & MASK, |
| 136 |
i & MASK |
| 137 |
) |
| 138 |
} else { |
| 139 |
String::new() |
| 140 |
} |
| 141 |
}, |
| 142 |
driver_info: String::new(), |
| 143 |
}; |
| 144 |
|
| 145 |
let mut options = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS::default(); |
| 146 |
unsafe { |
| 147 |
device.CheckFeatureSupport( |
| 148 |
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS, |
| 149 |
<*mut _>::cast(&mut options), |
| 150 |
size_of_val(&options) as u32, |
| 151 |
) |
| 152 |
} |
| 153 |
.unwrap(); |
| 154 |
|
| 155 |
if options.ResourceBindingTier.0 < Direct3D12::D3D12_RESOURCE_BINDING_TIER_2.0 { |
| 156 |
// We require Tier 2 or higher for the ability to make samplers bindless in all cases. |
| 157 |
return None; |
| 158 |
} |
| 159 |
|
| 160 |
let _depth_bounds_test_supported = { |
| 161 |
let mut features2 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS2::default(); |
| 162 |
unsafe { |
| 163 |
device.CheckFeatureSupport( |
| 164 |
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS2, |
| 165 |
<*mut _>::cast(&mut features2), |
| 166 |
size_of_val(&features2) as u32, |
| 167 |
) |
| 168 |
} |
| 169 |
.is_ok() |
| 170 |
&& features2.DepthBoundsTestSupported.as_bool() |
| 171 |
}; |
| 172 |
|
| 173 |
let casting_fully_typed_format_supported = { |
| 174 |
let mut features3 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS3::default(); |
| 175 |
unsafe { |
| 176 |
device.CheckFeatureSupport( |
| 177 |
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS3, |
| 178 |
<*mut _>::cast(&mut features3), |
| 179 |
size_of_val(&features3) as u32, |
| 180 |
) |
| 181 |
} |
| 182 |
.is_ok() |
| 183 |
&& features3.CastingFullyTypedFormatSupported.as_bool() |
| 184 |
}; |
| 185 |
|
| 186 |
let heap_create_not_zeroed = { |
| 187 |
// For D3D12_HEAP_FLAG_CREATE_NOT_ZEROED we just need to |
| 188 |
// make sure that options7 can be queried. See also: |
| 189 |
// https://devblogs.microsoft.com/directx/coming-to-directx-12-more-control-over-memory-allocation/ |
| 190 |
let mut features7 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS7::default(); |
| 191 |
unsafe { |
| 192 |
device.CheckFeatureSupport( |
| 193 |
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS7, |
| 194 |
<*mut _>::cast(&mut features7), |
| 195 |
size_of_val(&features7) as u32, |
| 196 |
) |
| 197 |
} |
| 198 |
.is_ok() |
| 199 |
}; |
| 200 |
|
| 201 |
let mut max_sampler_descriptor_heap_size = |
| 202 |
Direct3D12::D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE; |
| 203 |
{ |
| 204 |
let mut features19 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS19::default(); |
| 205 |
let res = unsafe { |
| 206 |
device.CheckFeatureSupport( |
| 207 |
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS19, |
| 208 |
<*mut _>::cast(&mut features19), |
| 209 |
size_of_val(&features19) as u32, |
| 210 |
) |
| 211 |
}; |
| 212 |
|
| 213 |
// Sometimes on Windows 11 23H2, the function returns success, even though the runtime |
| 214 |
// does not know about `Options19`. This can cause this number to be 0 as the structure isn't written to. |
| 215 |
// This value is nonsense and creating zero-sized sampler heaps can cause drivers to explode. |
| 216 |
// As as we're guaranteed 2048 anyway, we make sure this value is not under 2048. |
| 217 |
// |
| 218 |
// https://github.com/gfx-rs/wgpu/issues/7053 |
| 219 |
let is_ok = res.is_ok(); |
| 220 |
let is_above_minimum = features19.MaxSamplerDescriptorHeapSize |
| 221 |
> Direct3D12::D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE; |
| 222 |
if is_ok && is_above_minimum { |
| 223 |
max_sampler_descriptor_heap_size = features19.MaxSamplerDescriptorHeapSize; |
| 224 |
} |
| 225 |
}; |
| 226 |
|
| 227 |
let shader_model = if let Some(ref dxc_container) = dxc_container { |
| 228 |
let max_shader_model = match dxc_container.max_shader_model { |
| 229 |
wgt::DxcShaderModel::V6_0 => Direct3D12::D3D_SHADER_MODEL_6_0, |
| 230 |
wgt::DxcShaderModel::V6_1 => Direct3D12::D3D_SHADER_MODEL_6_1, |
| 231 |
wgt::DxcShaderModel::V6_2 => Direct3D12::D3D_SHADER_MODEL_6_2, |
| 232 |
wgt::DxcShaderModel::V6_3 => Direct3D12::D3D_SHADER_MODEL_6_3, |
| 233 |
wgt::DxcShaderModel::V6_4 => Direct3D12::D3D_SHADER_MODEL_6_4, |
| 234 |
wgt::DxcShaderModel::V6_5 => Direct3D12::D3D_SHADER_MODEL_6_5, |
| 235 |
wgt::DxcShaderModel::V6_6 => Direct3D12::D3D_SHADER_MODEL_6_6, |
| 236 |
wgt::DxcShaderModel::V6_7 => Direct3D12::D3D_SHADER_MODEL_6_7, |
| 237 |
}; |
| 238 |
|
| 239 |
let mut versions = [ |
| 240 |
Direct3D12::D3D_SHADER_MODEL_6_7, |
| 241 |
Direct3D12::D3D_SHADER_MODEL_6_6, |
| 242 |
Direct3D12::D3D_SHADER_MODEL_6_5, |
| 243 |
Direct3D12::D3D_SHADER_MODEL_6_4, |
| 244 |
Direct3D12::D3D_SHADER_MODEL_6_3, |
| 245 |
Direct3D12::D3D_SHADER_MODEL_6_2, |
| 246 |
Direct3D12::D3D_SHADER_MODEL_6_1, |
| 247 |
Direct3D12::D3D_SHADER_MODEL_6_0, |
| 248 |
] |
| 249 |
.iter() |
| 250 |
.filter(|shader_model| shader_model.0 <= max_shader_model.0); |
| 251 |
|
| 252 |
let highest_shader_model = loop { |
| 253 |
if let Some(&sm) = versions.next() { |
| 254 |
let mut sm = Direct3D12::D3D12_FEATURE_DATA_SHADER_MODEL { |
| 255 |
HighestShaderModel: sm, |
| 256 |
}; |
| 257 |
if unsafe { |
| 258 |
device.CheckFeatureSupport( |
| 259 |
Direct3D12::D3D12_FEATURE_SHADER_MODEL, |
| 260 |
<*mut _>::cast(&mut sm), |
| 261 |
size_of_val(&sm) as u32, |
| 262 |
) |
| 263 |
} |
| 264 |
.is_ok() |
| 265 |
{ |
| 266 |
break sm.HighestShaderModel; |
| 267 |
} |
| 268 |
} else { |
| 269 |
break Direct3D12::D3D_SHADER_MODEL_5_1; |
| 270 |
} |
| 271 |
}; |
| 272 |
|
| 273 |
match highest_shader_model { |
| 274 |
Direct3D12::D3D_SHADER_MODEL_5_1 => return None, // don't expose this adapter if it doesn't support DXIL |
| 275 |
Direct3D12::D3D_SHADER_MODEL_6_0 => naga::back::hlsl::ShaderModel::V6_0, |
| 276 |
Direct3D12::D3D_SHADER_MODEL_6_1 => naga::back::hlsl::ShaderModel::V6_1, |
| 277 |
Direct3D12::D3D_SHADER_MODEL_6_2 => naga::back::hlsl::ShaderModel::V6_2, |
| 278 |
Direct3D12::D3D_SHADER_MODEL_6_3 => naga::back::hlsl::ShaderModel::V6_3, |
| 279 |
Direct3D12::D3D_SHADER_MODEL_6_4 => naga::back::hlsl::ShaderModel::V6_4, |
| 280 |
Direct3D12::D3D_SHADER_MODEL_6_5 => naga::back::hlsl::ShaderModel::V6_5, |
| 281 |
Direct3D12::D3D_SHADER_MODEL_6_6 => naga::back::hlsl::ShaderModel::V6_6, |
| 282 |
Direct3D12::D3D_SHADER_MODEL_6_7 => naga::back::hlsl::ShaderModel::V6_7, |
| 283 |
_ => unreachable!(), |
| 284 |
} |
| 285 |
} else { |
| 286 |
naga::back::hlsl::ShaderModel::V5_1 |
| 287 |
}; |
| 288 |
let private_caps = super::PrivateCapabilities { |
| 289 |
instance_flags, |
| 290 |
heterogeneous_resource_heaps: options.ResourceHeapTier |
| 291 |
!= Direct3D12::D3D12_RESOURCE_HEAP_TIER_1, |
| 292 |
memory_architecture: if features_architecture.UMA.as_bool() { |
| 293 |
super::MemoryArchitecture::Unified { |
| 294 |
cache_coherent: features_architecture.CacheCoherentUMA.as_bool(), |
| 295 |
} |
| 296 |
} else { |
| 297 |
super::MemoryArchitecture::NonUnified |
| 298 |
}, |
| 299 |
heap_create_not_zeroed, |
| 300 |
casting_fully_typed_format_supported, |
| 301 |
// See https://github.com/gfx-rs/wgpu/issues/3552 |
| 302 |
suballocation_supported: !info.name.contains("Iris(R) Xe"), |
| 303 |
shader_model, |
| 304 |
max_sampler_descriptor_heap_size, |
| 305 |
}; |
| 306 |
|
| 307 |
// Theoretically vram limited, but in practice 2^20 is the limit |
| 308 |
let tier3_practical_descriptor_limit = 1 << 20; |
| 309 |
|
| 310 |
let (full_heap_count, uav_count) = match options.ResourceBindingTier { |
| 311 |
Direct3D12::D3D12_RESOURCE_BINDING_TIER_1 => { |
| 312 |
let uav_count = match max_feature_level { |
| 313 |
Direct3D::D3D_FEATURE_LEVEL_11_0 => 8, |
| 314 |
_ => 64, |
| 315 |
}; |
| 316 |
|
| 317 |
( |
| 318 |
Direct3D12::D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1, |
| 319 |
uav_count, |
| 320 |
) |
| 321 |
} |
| 322 |
Direct3D12::D3D12_RESOURCE_BINDING_TIER_2 => ( |
| 323 |
Direct3D12::D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_2, |
| 324 |
64, |
| 325 |
), |
| 326 |
Direct3D12::D3D12_RESOURCE_BINDING_TIER_3 => ( |
| 327 |
tier3_practical_descriptor_limit, |
| 328 |
tier3_practical_descriptor_limit, |
| 329 |
), |
| 330 |
other => { |
| 331 |
log::warn!("Unknown resource binding tier {:?}", other); |
| 332 |
( |
| 333 |
Direct3D12::D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1, |
| 334 |
8, |
| 335 |
) |
| 336 |
} |
| 337 |
}; |
| 338 |
|
| 339 |
// these should always be available on d3d12 |
| 340 |
let mut features = wgt::Features::empty() |
| 341 |
| wgt::Features::DEPTH_CLIP_CONTROL |
| 342 |
| wgt::Features::DEPTH32FLOAT_STENCIL8 |
| 343 |
| wgt::Features::INDIRECT_FIRST_INSTANCE |
| 344 |
| wgt::Features::MAPPABLE_PRIMARY_BUFFERS |
| 345 |
| wgt::Features::MULTI_DRAW_INDIRECT |
| 346 |
| wgt::Features::MULTI_DRAW_INDIRECT_COUNT |
| 347 |
| wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER |
| 348 |
| wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO |
| 349 |
| wgt::Features::POLYGON_MODE_LINE |
| 350 |
| wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES |
| 351 |
| wgt::Features::TIMESTAMP_QUERY |
| 352 |
| wgt::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS |
| 353 |
| wgt::Features::TIMESTAMP_QUERY_INSIDE_PASSES |
| 354 |
| wgt::Features::TEXTURE_COMPRESSION_BC |
| 355 |
| wgt::Features::TEXTURE_COMPRESSION_BC_SLICED_3D |
| 356 |
| wgt::Features::CLEAR_TEXTURE |
| 357 |
| wgt::Features::TEXTURE_FORMAT_16BIT_NORM |
| 358 |
| wgt::Features::PUSH_CONSTANTS |
| 359 |
| wgt::Features::SHADER_PRIMITIVE_INDEX |
| 360 |
| wgt::Features::RG11B10UFLOAT_RENDERABLE |
| 361 |
| wgt::Features::DUAL_SOURCE_BLENDING |
| 362 |
| wgt::Features::TEXTURE_FORMAT_NV12 |
| 363 |
| wgt::Features::FLOAT32_FILTERABLE |
| 364 |
| wgt::Features::TEXTURE_ATOMIC; |
| 365 |
|
| 366 |
//TODO: in order to expose this, we need to run a compute shader |
| 367 |
// that extract the necessary statistics out of the D3D12 result. |
| 368 |
// Alternatively, we could allocate a buffer for the query set, |
| 369 |
// write the results there, and issue a bunch of copy commands. |
| 370 |
//| wgt::Features::PIPELINE_STATISTICS_QUERY |
| 371 |
|
| 372 |
if max_feature_level.0 >= Direct3D::D3D_FEATURE_LEVEL_11_1.0 { |
| 373 |
features |= wgt::Features::VERTEX_WRITABLE_STORAGE; |
| 374 |
} |
| 375 |
|
| 376 |
features.set( |
| 377 |
wgt::Features::CONSERVATIVE_RASTERIZATION, |
| 378 |
options.ConservativeRasterizationTier |
| 379 |
!= Direct3D12::D3D12_CONSERVATIVE_RASTERIZATION_TIER_NOT_SUPPORTED, |
| 380 |
); |
| 381 |
|
| 382 |
features.set( |
| 383 |
wgt::Features::TEXTURE_BINDING_ARRAY |
| 384 |
| wgt::Features::STORAGE_RESOURCE_BINDING_ARRAY |
| 385 |
| wgt::Features::STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING |
| 386 |
| wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING |
| 387 |
// See note below the table https://learn.microsoft.com/en-us/windows/win32/direct3d12/hardware-support |
| 388 |
| wgt::Features::PARTIALLY_BOUND_BINDING_ARRAY, |
| 389 |
shader_model >= naga::back::hlsl::ShaderModel::V5_1 |
| 390 |
&& options.ResourceBindingTier.0 >= Direct3D12::D3D12_RESOURCE_BINDING_TIER_3.0, |
| 391 |
); |
| 392 |
|
| 393 |
let bgra8unorm_storage_supported = { |
| 394 |
let mut bgra8unorm_info = Direct3D12::D3D12_FEATURE_DATA_FORMAT_SUPPORT { |
| 395 |
Format: Dxgi::Common::DXGI_FORMAT_B8G8R8A8_UNORM, |
| 396 |
..Default::default() |
| 397 |
}; |
| 398 |
let hr = unsafe { |
| 399 |
device.CheckFeatureSupport( |
| 400 |
Direct3D12::D3D12_FEATURE_FORMAT_SUPPORT, |
| 401 |
<*mut _>::cast(&mut bgra8unorm_info), |
| 402 |
size_of_val(&bgra8unorm_info) as u32, |
| 403 |
) |
| 404 |
}; |
| 405 |
hr.is_ok() |
| 406 |
&& bgra8unorm_info |
| 407 |
.Support2 |
| 408 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE) |
| 409 |
}; |
| 410 |
features.set( |
| 411 |
wgt::Features::BGRA8UNORM_STORAGE, |
| 412 |
bgra8unorm_storage_supported, |
| 413 |
); |
| 414 |
|
| 415 |
let mut features1 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS1::default(); |
| 416 |
let hr = unsafe { |
| 417 |
device.CheckFeatureSupport( |
| 418 |
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS1, |
| 419 |
<*mut _>::cast(&mut features1), |
| 420 |
size_of_val(&features1) as u32, |
| 421 |
) |
| 422 |
}; |
| 423 |
|
| 424 |
features.set( |
| 425 |
wgt::Features::SHADER_INT64, |
| 426 |
shader_model >= naga::back::hlsl::ShaderModel::V6_0 |
| 427 |
&& hr.is_ok() |
| 428 |
&& features1.Int64ShaderOps.as_bool(), |
| 429 |
); |
| 430 |
|
| 431 |
let float16_supported = { |
| 432 |
let mut features4 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS4::default(); |
| 433 |
let hr = unsafe { |
| 434 |
device.CheckFeatureSupport( |
| 435 |
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS4, // https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_feature#syntax |
| 436 |
ptr::from_mut(&mut features4).cast(), |
| 437 |
size_of::<Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS4>() as _, |
| 438 |
) |
| 439 |
}; |
| 440 |
hr.is_ok() && features4.Native16BitShaderOpsSupported.as_bool() |
| 441 |
}; |
| 442 |
|
| 443 |
features.set( |
| 444 |
wgt::Features::SHADER_F16, |
| 445 |
shader_model >= naga::back::hlsl::ShaderModel::V6_2 && float16_supported, |
| 446 |
); |
| 447 |
|
| 448 |
features.set( |
| 449 |
wgt::Features::TEXTURE_INT64_ATOMIC, |
| 450 |
shader_model >= naga::back::hlsl::ShaderModel::V6_6 |
| 451 |
&& hr.is_ok() |
| 452 |
&& features1.Int64ShaderOps.as_bool(), |
| 453 |
); |
| 454 |
|
| 455 |
features.set( |
| 456 |
wgt::Features::SUBGROUP, |
| 457 |
shader_model >= naga::back::hlsl::ShaderModel::V6_0 |
| 458 |
&& hr.is_ok() |
| 459 |
&& features1.WaveOps.as_bool(), |
| 460 |
); |
| 461 |
let mut features5 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS5::default(); |
| 462 |
let has_features5 = unsafe { |
| 463 |
device.CheckFeatureSupport( |
| 464 |
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS5, |
| 465 |
<*mut _>::cast(&mut features5), |
| 466 |
size_of_val(&features5) as u32, |
| 467 |
) |
| 468 |
} |
| 469 |
.is_ok(); |
| 470 |
|
| 471 |
// Since all features for raytracing pipeline (geometry index) and ray queries both come |
| 472 |
// from here, there is no point in adding an extra call here given that there will be no |
| 473 |
// feature using EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE if all these are not met. |
| 474 |
// Once ray tracing pipelines are supported they also will go here |
| 475 |
features.set( |
| 476 |
wgt::Features::EXPERIMENTAL_RAY_QUERY |
| 477 |
| wgt::Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE, |
| 478 |
features5.RaytracingTier == Direct3D12::D3D12_RAYTRACING_TIER_1_1 |
| 479 |
&& shader_model >= naga::back::hlsl::ShaderModel::V6_5 |
| 480 |
&& has_features5, |
| 481 |
); |
| 482 |
|
| 483 |
let atomic_int64_on_typed_resource_supported = { |
| 484 |
let mut features9 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS9::default(); |
| 485 |
unsafe { |
| 486 |
device.CheckFeatureSupport( |
| 487 |
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS9, |
| 488 |
<*mut _>::cast(&mut features9), |
| 489 |
size_of_val(&features9) as u32, |
| 490 |
) |
| 491 |
} |
| 492 |
.is_ok() |
| 493 |
&& features9.AtomicInt64OnGroupSharedSupported.as_bool() |
| 494 |
&& features9.AtomicInt64OnTypedResourceSupported.as_bool() |
| 495 |
}; |
| 496 |
features.set( |
| 497 |
wgt::Features::SHADER_INT64_ATOMIC_ALL_OPS | wgt::Features::SHADER_INT64_ATOMIC_MIN_MAX, |
| 498 |
atomic_int64_on_typed_resource_supported, |
| 499 |
); |
| 500 |
|
| 501 |
// TODO: Determine if IPresentationManager is supported |
| 502 |
let presentation_timer = auxil::dxgi::time::PresentationTimer::new_dxgi(); |
| 503 |
|
| 504 |
let base = wgt::Limits::default(); |
| 505 |
|
| 506 |
let downlevel = wgt::DownlevelCapabilities::default(); |
| 507 |
|
| 508 |
// See https://learn.microsoft.com/en-us/windows/win32/direct3d12/hardware-feature-levels#feature-level-support |
| 509 |
let max_color_attachments = 8; |
| 510 |
let max_color_attachment_bytes_per_sample = |
| 511 |
max_color_attachments * wgt::TextureFormat::MAX_TARGET_PIXEL_BYTE_COST; |
| 512 |
|
| 513 |
Some(crate::ExposedAdapter { |
| 514 |
adapter: super::Adapter { |
| 515 |
raw: adapter, |
| 516 |
device, |
| 517 |
library: Arc::clone(library), |
| 518 |
private_caps, |
| 519 |
presentation_timer, |
| 520 |
workarounds, |
| 521 |
memory_budget_thresholds, |
| 522 |
dxc_container, |
| 523 |
}, |
| 524 |
info, |
| 525 |
features, |
| 526 |
capabilities: crate::Capabilities { |
| 527 |
limits: wgt::Limits { |
| 528 |
max_texture_dimension_1d: Direct3D12::D3D12_REQ_TEXTURE1D_U_DIMENSION, |
| 529 |
max_texture_dimension_2d: Direct3D12::D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION |
| 530 |
.min(Direct3D12::D3D12_REQ_TEXTURECUBE_DIMENSION), |
| 531 |
max_texture_dimension_3d: Direct3D12::D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, |
| 532 |
max_texture_array_layers: Direct3D12::D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION, |
| 533 |
max_bind_groups: crate::MAX_BIND_GROUPS as u32, |
| 534 |
max_bindings_per_bind_group: 65535, |
| 535 |
// dynamic offsets take a root constant, so we expose the minimum here |
| 536 |
max_dynamic_uniform_buffers_per_pipeline_layout: base |
| 537 |
.max_dynamic_uniform_buffers_per_pipeline_layout, |
| 538 |
max_dynamic_storage_buffers_per_pipeline_layout: base |
| 539 |
.max_dynamic_storage_buffers_per_pipeline_layout, |
| 540 |
max_sampled_textures_per_shader_stage: match options.ResourceBindingTier { |
| 541 |
Direct3D12::D3D12_RESOURCE_BINDING_TIER_1 => 128, |
| 542 |
_ => full_heap_count, |
| 543 |
}, |
| 544 |
max_samplers_per_shader_stage: match options.ResourceBindingTier { |
| 545 |
Direct3D12::D3D12_RESOURCE_BINDING_TIER_1 => 16, |
| 546 |
_ => Direct3D12::D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE, |
| 547 |
}, |
| 548 |
// these both account towards `uav_count`, but we can't express the limit as as sum |
| 549 |
// of the two, so we divide it by 4 to account for the worst case scenario |
| 550 |
// (2 shader stages, with both using 16 storage textures and 16 storage buffers) |
| 551 |
max_storage_buffers_per_shader_stage: uav_count / 4, |
| 552 |
max_storage_textures_per_shader_stage: uav_count / 4, |
| 553 |
max_uniform_buffers_per_shader_stage: full_heap_count, |
| 554 |
max_binding_array_elements_per_shader_stage: full_heap_count, |
| 555 |
max_binding_array_sampler_elements_per_shader_stage: full_heap_count, |
| 556 |
max_uniform_buffer_binding_size: |
| 557 |
Direct3D12::D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 16, |
| 558 |
max_storage_buffer_binding_size: auxil::MAX_I32_BINDING_SIZE, |
| 559 |
max_vertex_buffers: Direct3D12::D3D12_VS_INPUT_REGISTER_COUNT |
| 560 |
.min(crate::MAX_VERTEX_BUFFERS as u32), |
| 561 |
max_vertex_attributes: Direct3D12::D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, |
| 562 |
max_vertex_buffer_array_stride: Direct3D12::D3D12_SO_BUFFER_MAX_STRIDE_IN_BYTES, |
| 563 |
min_subgroup_size: 4, // Not using `features1.WaveLaneCountMin` as it is unreliable |
| 564 |
max_subgroup_size: 128, |
| 565 |
// The push constants are part of the root signature which |
| 566 |
// has a limit of 64 DWORDS (256 bytes), but other resources |
| 567 |
// also share the root signature: |
| 568 |
// |
| 569 |
// - push constants consume a `DWORD` for each `4 bytes` of data |
| 570 |
// - If a bind group has buffers it will consume a `DWORD` |
| 571 |
// for the descriptor table |
| 572 |
// - If a bind group has samplers it will consume a `DWORD` |
| 573 |
// for the descriptor table |
| 574 |
// - Each dynamic uniform buffer will consume `2 DWORDs` for the |
| 575 |
// root descriptor |
| 576 |
// - Each dynamic storage buffer will consume `1 DWORD` for a |
| 577 |
// root constant representing the dynamic offset |
| 578 |
// - The special constants buffer count as constants |
| 579 |
// |
| 580 |
// Since we can't know beforehand all root signatures that |
| 581 |
// will be created, the max size to be used for push |
| 582 |
// constants needs to be set to a reasonable number instead. |
| 583 |
// |
| 584 |
// Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/root-signature-limits#memory-limits-and-costs |
| 585 |
max_push_constant_size: 128, |
| 586 |
min_uniform_buffer_offset_alignment: |
| 587 |
Direct3D12::D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT, |
| 588 |
min_storage_buffer_offset_alignment: 4, |
| 589 |
max_inter_stage_shader_components: base.max_inter_stage_shader_components, |
| 590 |
max_color_attachments, |
| 591 |
max_color_attachment_bytes_per_sample, |
| 592 |
max_compute_workgroup_storage_size: base.max_compute_workgroup_storage_size, //TODO? |
| 593 |
max_compute_invocations_per_workgroup: |
| 594 |
Direct3D12::D3D12_CS_4_X_THREAD_GROUP_MAX_THREADS_PER_GROUP, |
| 595 |
max_compute_workgroup_size_x: Direct3D12::D3D12_CS_THREAD_GROUP_MAX_X, |
| 596 |
max_compute_workgroup_size_y: Direct3D12::D3D12_CS_THREAD_GROUP_MAX_Y, |
| 597 |
max_compute_workgroup_size_z: Direct3D12::D3D12_CS_THREAD_GROUP_MAX_Z, |
| 598 |
max_compute_workgroups_per_dimension: |
| 599 |
Direct3D12::D3D12_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, |
| 600 |
// Dx12 does not expose a maximum buffer size in the API. |
| 601 |
// This limit is chosen to avoid potential issues with drivers should they internally |
| 602 |
// store buffer sizes using 32 bit ints (a situation we have already encountered with vulkan). |
| 603 |
max_buffer_size: i32::MAX as u64, |
| 604 |
max_non_sampler_bindings: 1_000_000, |
| 605 |
}, |
| 606 |
alignments: crate::Alignments { |
| 607 |
buffer_copy_offset: wgt::BufferSize::new( |
| 608 |
Direct3D12::D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT as u64, |
| 609 |
) |
| 610 |
.unwrap(), |
| 611 |
buffer_copy_pitch: wgt::BufferSize::new( |
| 612 |
Direct3D12::D3D12_TEXTURE_DATA_PITCH_ALIGNMENT as u64, |
| 613 |
) |
| 614 |
.unwrap(), |
| 615 |
// Direct3D correctly bounds-checks all array accesses: |
| 616 |
// https://microsoft.github.io/DirectX-Specs/d3d/archive/D3D11_3_FunctionalSpec.htm#18.6.8.2%20Device%20Memory%20Reads |
| 617 |
uniform_bounds_check_alignment: wgt::BufferSize::new(1).unwrap(), |
| 618 |
raw_tlas_instance_size: size_of::<Direct3D12::D3D12_RAYTRACING_INSTANCE_DESC>(), |
| 619 |
ray_tracing_scratch_buffer_alignment: |
| 620 |
Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BYTE_ALIGNMENT, |
| 621 |
}, |
| 622 |
downlevel, |
| 623 |
}, |
| 624 |
}) |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
impl crate::Adapter for super::Adapter { |
| 629 |
type A = super::Api; |
| 630 |
|
| 631 |
unsafe fn open( |
| 632 |
&self, |
| 633 |
features: wgt::Features, |
| 634 |
limits: &wgt::Limits, |
| 635 |
memory_hints: &wgt::MemoryHints, |
| 636 |
) -> Result<crate::OpenDevice<super::Api>, crate::DeviceError> { |
| 637 |
let queue: Direct3D12::ID3D12CommandQueue = { |
| 638 |
profiling::scope!("ID3D12Device::CreateCommandQueue"); |
| 639 |
unsafe { |
| 640 |
self.device |
| 641 |
.CreateCommandQueue(&Direct3D12::D3D12_COMMAND_QUEUE_DESC { |
| 642 |
Type: Direct3D12::D3D12_COMMAND_LIST_TYPE_DIRECT, |
| 643 |
Priority: Direct3D12::D3D12_COMMAND_QUEUE_PRIORITY_NORMAL.0, |
| 644 |
Flags: Direct3D12::D3D12_COMMAND_QUEUE_FLAG_NONE, |
| 645 |
NodeMask: 0, |
| 646 |
}) |
| 647 |
} |
| 648 |
.into_device_result("Queue creation")? |
| 649 |
}; |
| 650 |
|
| 651 |
let device = super::Device::new( |
| 652 |
self.raw.clone(), |
| 653 |
self.device.clone(), |
| 654 |
queue.clone(), |
| 655 |
features, |
| 656 |
limits, |
| 657 |
memory_hints, |
| 658 |
self.private_caps, |
| 659 |
&self.library, |
| 660 |
self.memory_budget_thresholds, |
| 661 |
self.dxc_container.clone(), |
| 662 |
)?; |
| 663 |
Ok(crate::OpenDevice { |
| 664 |
device, |
| 665 |
queue: super::Queue { |
| 666 |
raw: queue, |
| 667 |
temp_lists: Mutex::new(Vec::new()), |
| 668 |
}, |
| 669 |
}) |
| 670 |
} |
| 671 |
|
| 672 |
unsafe fn texture_format_capabilities( |
| 673 |
&self, |
| 674 |
format: wgt::TextureFormat, |
| 675 |
) -> crate::TextureFormatCapabilities { |
| 676 |
use crate::TextureFormatCapabilities as Tfc; |
| 677 |
|
| 678 |
let raw_format = match auxil::dxgi::conv::map_texture_format_failable(format) { |
| 679 |
Some(f) => f, |
| 680 |
None => return Tfc::empty(), |
| 681 |
}; |
| 682 |
let srv_uav_format = if format.is_combined_depth_stencil_format() { |
| 683 |
auxil::dxgi::conv::map_texture_format_for_srv_uav( |
| 684 |
format, |
| 685 |
// use the depth aspect here as opposed to stencil since it has more capabilities |
| 686 |
crate::FormatAspects::DEPTH, |
| 687 |
) |
| 688 |
} else { |
| 689 |
auxil::dxgi::conv::map_texture_format_for_srv_uav( |
| 690 |
format, |
| 691 |
crate::FormatAspects::from(format), |
| 692 |
) |
| 693 |
} |
| 694 |
.unwrap(); |
| 695 |
|
| 696 |
let mut data = Direct3D12::D3D12_FEATURE_DATA_FORMAT_SUPPORT { |
| 697 |
Format: raw_format, |
| 698 |
..Default::default() |
| 699 |
}; |
| 700 |
unsafe { |
| 701 |
self.device.CheckFeatureSupport( |
| 702 |
Direct3D12::D3D12_FEATURE_FORMAT_SUPPORT, |
| 703 |
<*mut _>::cast(&mut data), |
| 704 |
size_of_val(&data) as u32, |
| 705 |
) |
| 706 |
} |
| 707 |
.unwrap(); |
| 708 |
|
| 709 |
// Because we use a different format for SRV and UAV views of depth textures, we need to check |
| 710 |
// the features that use SRV/UAVs using the no-depth format. |
| 711 |
let mut data_srv_uav = Direct3D12::D3D12_FEATURE_DATA_FORMAT_SUPPORT { |
| 712 |
Format: srv_uav_format, |
| 713 |
Support1: Direct3D12::D3D12_FORMAT_SUPPORT1_NONE, |
| 714 |
Support2: Direct3D12::D3D12_FORMAT_SUPPORT2_NONE, |
| 715 |
}; |
| 716 |
if raw_format != srv_uav_format { |
| 717 |
// Only-recheck if we're using a different format |
| 718 |
unsafe { |
| 719 |
self.device.CheckFeatureSupport( |
| 720 |
Direct3D12::D3D12_FEATURE_FORMAT_SUPPORT, |
| 721 |
ptr::addr_of_mut!(data_srv_uav).cast(), |
| 722 |
size_of::<Direct3D12::D3D12_FEATURE_DATA_FORMAT_SUPPORT>() as u32, |
| 723 |
) |
| 724 |
} |
| 725 |
.unwrap(); |
| 726 |
} else { |
| 727 |
// Same format, just copy over. |
| 728 |
data_srv_uav = data; |
| 729 |
} |
| 730 |
|
| 731 |
let mut caps = Tfc::COPY_SRC | Tfc::COPY_DST; |
| 732 |
// Cannot use the contains() helper, and windows-rs doesn't provide a .intersect() helper |
| 733 |
let is_texture = (data.Support1 |
| 734 |
& (Direct3D12::D3D12_FORMAT_SUPPORT1_TEXTURE1D |
| 735 |
| Direct3D12::D3D12_FORMAT_SUPPORT1_TEXTURE2D |
| 736 |
| Direct3D12::D3D12_FORMAT_SUPPORT1_TEXTURE3D |
| 737 |
| Direct3D12::D3D12_FORMAT_SUPPORT1_TEXTURECUBE)) |
| 738 |
.0 |
| 739 |
!= 0; |
| 740 |
// SRVs use srv_uav_format |
| 741 |
caps.set( |
| 742 |
Tfc::SAMPLED, |
| 743 |
is_texture |
| 744 |
&& data_srv_uav |
| 745 |
.Support1 |
| 746 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT1_SHADER_LOAD), |
| 747 |
); |
| 748 |
caps.set( |
| 749 |
Tfc::SAMPLED_LINEAR, |
| 750 |
data_srv_uav |
| 751 |
.Support1 |
| 752 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE), |
| 753 |
); |
| 754 |
caps.set( |
| 755 |
Tfc::COLOR_ATTACHMENT, |
| 756 |
data.Support1 |
| 757 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT1_RENDER_TARGET), |
| 758 |
); |
| 759 |
caps.set( |
| 760 |
Tfc::COLOR_ATTACHMENT_BLEND, |
| 761 |
data.Support1 |
| 762 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT1_BLENDABLE), |
| 763 |
); |
| 764 |
caps.set( |
| 765 |
Tfc::DEPTH_STENCIL_ATTACHMENT, |
| 766 |
data.Support1 |
| 767 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT1_DEPTH_STENCIL), |
| 768 |
); |
| 769 |
// UAVs use srv_uav_format |
| 770 |
caps.set( |
| 771 |
Tfc::STORAGE_READ_ONLY, |
| 772 |
data_srv_uav |
| 773 |
.Support2 |
| 774 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT2_UAV_TYPED_LOAD), |
| 775 |
); |
| 776 |
caps.set( |
| 777 |
Tfc::STORAGE_ATOMIC, |
| 778 |
data_srv_uav |
| 779 |
.Support2 |
| 780 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT2_UAV_ATOMIC_UNSIGNED_MIN_OR_MAX), |
| 781 |
); |
| 782 |
caps.set( |
| 783 |
Tfc::STORAGE_WRITE_ONLY, |
| 784 |
data_srv_uav |
| 785 |
.Support2 |
| 786 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE), |
| 787 |
); |
| 788 |
caps.set( |
| 789 |
Tfc::STORAGE_READ_WRITE, |
| 790 |
caps.contains(Tfc::STORAGE_READ_ONLY | Tfc::STORAGE_WRITE_ONLY), |
| 791 |
); |
| 792 |
|
| 793 |
// We load via UAV/SRV so use srv_uav_format |
| 794 |
let no_msaa_load = caps.contains(Tfc::SAMPLED) |
| 795 |
&& !data_srv_uav |
| 796 |
.Support1 |
| 797 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT1_MULTISAMPLE_LOAD); |
| 798 |
|
| 799 |
let no_msaa_target = (data.Support1 |
| 800 |
& (Direct3D12::D3D12_FORMAT_SUPPORT1_RENDER_TARGET |
| 801 |
| Direct3D12::D3D12_FORMAT_SUPPORT1_DEPTH_STENCIL)) |
| 802 |
.0 |
| 803 |
!= 0 |
| 804 |
&& !data |
| 805 |
.Support1 |
| 806 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT1_MULTISAMPLE_RENDERTARGET); |
| 807 |
|
| 808 |
caps.set( |
| 809 |
Tfc::MULTISAMPLE_RESOLVE, |
| 810 |
data.Support1 |
| 811 |
.contains(Direct3D12::D3D12_FORMAT_SUPPORT1_MULTISAMPLE_RESOLVE), |
| 812 |
); |
| 813 |
|
| 814 |
let mut ms_levels = Direct3D12::D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS { |
| 815 |
Format: raw_format, |
| 816 |
SampleCount: 0, |
| 817 |
Flags: Direct3D12::D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE, |
| 818 |
NumQualityLevels: 0, |
| 819 |
}; |
| 820 |
|
| 821 |
let mut set_sample_count = |sc: u32, tfc: Tfc| { |
| 822 |
ms_levels.SampleCount = sc; |
| 823 |
|
| 824 |
if unsafe { |
| 825 |
self.device.CheckFeatureSupport( |
| 826 |
Direct3D12::D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, |
| 827 |
<*mut _>::cast(&mut ms_levels), |
| 828 |
size_of_val(&ms_levels) as u32, |
| 829 |
) |
| 830 |
} |
| 831 |
.is_ok() |
| 832 |
&& ms_levels.NumQualityLevels != 0 |
| 833 |
{ |
| 834 |
caps.set(tfc, !no_msaa_load && !no_msaa_target); |
| 835 |
} |
| 836 |
}; |
| 837 |
|
| 838 |
set_sample_count(2, Tfc::MULTISAMPLE_X2); |
| 839 |
set_sample_count(4, Tfc::MULTISAMPLE_X4); |
| 840 |
set_sample_count(8, Tfc::MULTISAMPLE_X8); |
| 841 |
set_sample_count(16, Tfc::MULTISAMPLE_X16); |
| 842 |
|
| 843 |
caps |
| 844 |
} |
| 845 |
|
| 846 |
unsafe fn surface_capabilities( |
| 847 |
&self, |
| 848 |
surface: &super::Surface, |
| 849 |
) -> Option<crate::SurfaceCapabilities> { |
| 850 |
let current_extent = { |
| 851 |
match surface.target { |
| 852 |
SurfaceTarget::WndHandle(wnd_handle) => { |
| 853 |
let mut rect = Default::default(); |
| 854 |
if unsafe { WindowsAndMessaging::GetClientRect(wnd_handle, &mut rect) }.is_ok() |
| 855 |
{ |
| 856 |
Some(wgt::Extent3d { |
| 857 |
width: (rect.right - rect.left) as u32, |
| 858 |
height: (rect.bottom - rect.top) as u32, |
| 859 |
depth_or_array_layers: 1, |
| 860 |
}) |
| 861 |
} else { |
| 862 |
log::warn!("Unable to get the window client rect"); |
| 863 |
None |
| 864 |
} |
| 865 |
} |
| 866 |
SurfaceTarget::Visual(_) |
| 867 |
| SurfaceTarget::SurfaceHandle(_) |
| 868 |
| SurfaceTarget::SwapChainPanel(_) => None, |
| 869 |
} |
| 870 |
}; |
| 871 |
|
| 872 |
let mut present_modes = vec![wgt::PresentMode::Mailbox, wgt::PresentMode::Fifo]; |
| 873 |
if surface.supports_allow_tearing { |
| 874 |
present_modes.push(wgt::PresentMode::Immediate); |
| 875 |
} |
| 876 |
|
| 877 |
Some(crate::SurfaceCapabilities { |
| 878 |
formats: vec![ |
| 879 |
wgt::TextureFormat::Bgra8UnormSrgb, |
| 880 |
wgt::TextureFormat::Bgra8Unorm, |
| 881 |
wgt::TextureFormat::Rgba8UnormSrgb, |
| 882 |
wgt::TextureFormat::Rgba8Unorm, |
| 883 |
wgt::TextureFormat::Rgb10a2Unorm, |
| 884 |
wgt::TextureFormat::Rgba16Float, |
| 885 |
], |
| 886 |
// See https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgidevice1-setmaximumframelatency |
| 887 |
maximum_frame_latency: 1..=16, |
| 888 |
current_extent, |
| 889 |
usage: wgt::TextureUses::COLOR_TARGET |
| 890 |
| wgt::TextureUses::COPY_SRC |
| 891 |
| wgt::TextureUses::COPY_DST, |
| 892 |
present_modes, |
| 893 |
composite_alpha_modes: match surface.target { |
| 894 |
SurfaceTarget::WndHandle(_) => vec![wgt::CompositeAlphaMode::Opaque], |
| 895 |
SurfaceTarget::Visual(_) |
| 896 |
| SurfaceTarget::SurfaceHandle(_) |
| 897 |
| SurfaceTarget::SwapChainPanel(_) => vec![ |
| 898 |
wgt::CompositeAlphaMode::Auto, |
| 899 |
wgt::CompositeAlphaMode::Inherit, |
| 900 |
wgt::CompositeAlphaMode::Opaque, |
| 901 |
wgt::CompositeAlphaMode::PostMultiplied, |
| 902 |
wgt::CompositeAlphaMode::PreMultiplied, |
| 903 |
], |
| 904 |
}, |
| 905 |
}) |
| 906 |
} |
| 907 |
|
| 908 |
unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp { |
| 909 |
wgt::PresentationTimestamp(self.presentation_timer.get_timestamp_ns()) |
| 910 |
} |
| 911 |
} |