1656
1656
< span id ="1656 "> 1656</ span >
1657
1657
< span id ="1657 "> 1657</ span >
1658
1658
< span id ="1658 "> 1658</ span >
1659
- < span id ="1659 "> 1659</ span >
1660
- < span id ="1660 "> 1660</ span >
1661
- < span id ="1661 "> 1661</ span >
1662
- < span id ="1662 "> 1662</ span >
1663
- < span id ="1663 "> 1663</ span >
1664
- < span id ="1664 "> 1664</ span >
1665
- < span id ="1665 "> 1665</ span >
1666
- < span id ="1666 "> 1666</ span >
1667
1659
</ pre > < pre class ="rust "> < code > < span class ="kw "> use </ span > < span class ="kw "> super</ span > ::conv;
1668
1660
1669
1661
< span class ="kw "> use </ span > ash::{extensions::khr, vk};
2008
2000
}
2009
2001
}
2010
2002
2011
- < span class ="kw "> fn </ span > to_wgpu(< span class ="kw-2 "> &</ span > < span class ="self "> self</ span > , caps: < span class ="kw-2 "> &</ span > PhysicalDeviceCapabilities) -> (wgt::Features, wgt::DownlevelFlags) {
2003
+ < span class ="kw "> fn </ span > to_wgpu(
2004
+ < span class ="kw-2 "> &</ span > < span class ="self "> self</ span > ,
2005
+ instance: < span class ="kw-2 "> &</ span > ash::Instance,
2006
+ phd: vk::PhysicalDevice,
2007
+ caps: < span class ="kw-2 "> &</ span > PhysicalDeviceCapabilities,
2008
+ ) -> (wgt::Features, wgt::DownlevelFlags) {
2012
2009
< span class ="kw "> use </ span > < span class ="kw "> crate</ span > ::auxil::db;
2013
2010
< span class ="kw "> use </ span > wgt::{DownlevelFlags < span class ="kw "> as </ span > Df, Features < span class ="kw "> as </ span > F};
2014
2011
< span class ="kw "> let </ span > < span class ="kw-2 "> mut </ span > features = F::empty()
2198
2195
2199
2196
features.set(
2200
2197
F::TEXTURE_FORMAT_16BIT_NORM,
2201
- is_format_16bit_norm_supported(caps ),
2198
+ is_format_16bit_norm_supported(instance, phd ),
2202
2199
);
2203
2200
2204
2201
< span class ="kw "> if let </ span > < span class ="prelude-val "> Some</ span > (< span class ="kw-2 "> ref </ span > astc_hdr) = < span class ="self "> self</ span > .astc_hdr {
2219
2216
2220
2217
features.set(
2221
2218
F::DEPTH32FLOAT_STENCIL8,
2222
- caps.supports_format(
2219
+ supports_format(
2220
+ instance,
2221
+ phd,
2223
2222
vk::Format::D32_SFLOAT_S8_UINT,
2224
2223
vk::ImageTiling::OPTIMAL,
2225
2224
vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT,
2228
2227
2229
2228
features.set(
2230
2229
F::DEPTH24UNORM_STENCIL8,
2231
- caps.supports_format(
2230
+ supports_format(
2231
+ instance,
2232
+ phd,
2232
2233
vk::Format::D24_UNORM_S8_UINT,
2233
2234
vk::ImageTiling::OPTIMAL,
2234
2235
vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT,
2255
2256
properties: vk::PhysicalDeviceProperties,
2256
2257
vulkan_1_2: < span class ="prelude-ty "> Option</ span > <vk::PhysicalDeviceVulkan12Properties>,
2257
2258
descriptor_indexing: < span class ="prelude-ty "> Option</ span > <vk::PhysicalDeviceDescriptorIndexingPropertiesEXT>,
2258
- formats: Vec<vk::FormatProperties>,
2259
2259
}
2260
2260
2261
2261
< span class ="comment "> // This is safe because the structs have `p_next: *mut c_void`, which we null out/never read.
2273
2273
.any(|ep| < span class ="kw "> unsafe </ span > { CStr::from_ptr(ep.extension_name.as_ptr()) } == extension)
2274
2274
}
2275
2275
2276
- < span class ="kw "> fn </ span > supports_format(
2277
- < span class ="kw-2 "> &</ span > < span class ="self "> self</ span > ,
2278
- format: vk::Format,
2279
- tiling: vk::ImageTiling,
2280
- features: vk::FormatFeatureFlags,
2281
- ) -> bool {
2282
- < span class ="self "> self</ span > .formats
2283
- .get(format.as_raw() < span class ="kw "> as </ span > usize)
2284
- .map(|properties| < span class ="kw "> match </ span > tiling {
2285
- vk::ImageTiling::LINEAR => properties.linear_tiling_features.contains(features),
2286
- vk::ImageTiling::OPTIMAL => properties.optimal_tiling_features.contains(features),
2287
- < span class ="kw "> _ </ span > => < span class ="bool-val "> false</ span > ,
2288
- })
2289
- .unwrap()
2290
- }
2291
-
2292
2276
< span class ="doccomment "> /// Map `requested_features` to the list of Vulkan extension strings required to create the logical device.
2293
2277
</ span > < span class ="kw "> fn </ span > get_required_extensions(< span class ="kw-2 "> &</ span > < span class ="self "> self</ span > , requested_features: wgt::Features) -> Vec<< span class ="kw-2 "> &</ span > < span class ="lifetime "> 'static </ span > CStr> {
2294
2278
< span class ="kw "> let </ span > < span class ="kw-2 "> mut </ span > extensions = Vec::new();
2534
2518
} < span class ="kw "> else </ span > {
2535
2519
< span class ="kw "> unsafe </ span > { < span class ="self "> self</ span > .raw.get_physical_device_properties(phd) }
2536
2520
};
2537
- capabilities.formats = query_format_properties(< span class ="kw-2 "> &</ span > < span class ="self "> self</ span > .raw, phd);
2538
2521
2539
2522
capabilities
2540
2523
};
2662
2645
backend: wgt::Backend::Vulkan,
2663
2646
};
2664
2647
2665
- < span class ="kw "> let </ span > (available_features, downlevel_flags) = phd_features.to_wgpu(< span class ="kw-2 "> &</ span > phd_capabilities);
2648
+ < span class ="kw "> let </ span > (available_features, downlevel_flags) =
2649
+ phd_features.to_wgpu(< span class ="kw-2 "> &</ span > < span class ="self "> self</ span > .shared.raw, phd, < span class ="kw-2 "> &</ span > phd_capabilities);
2666
2650
< span class ="kw "> let </ span > < span class ="kw-2 "> mut </ span > workarounds = < span class ="kw "> super</ span > ::Workarounds::empty();
2667
2651
{
2668
2652
< span class ="comment "> // see https://github.com/gfx-rs/gfx/issues/1930
2965
2949
}
2966
2950
};
2967
2951
2968
- < span class ="macro "> log::info!</ span > (< span class ="string "> "Private capabilities: {:?}"</ span > , < span class ="self "> self</ span > .private_caps);
2969
2952
< span class ="kw "> let </ span > raw_queue = {
2970
2953
< span class ="macro "> profiling::scope!</ span > (< span class ="string "> "vkGetDeviceQueue"</ span > );
2971
2954
raw_device.get_device_queue(family_index, queue_index)
3115
3098
3116
3099
< span class ="kw "> let </ span > vk_format = < span class ="self "> self</ span > .private_caps.map_texture_format(format);
3117
3100
< span class ="kw "> let </ span > properties = < span class ="self "> self
3118
- </ span > .phd_capabilities
3119
- .formats
3120
- .get(vk_format.as_raw() < span class ="kw "> as </ span > usize);
3121
- < span class ="kw "> let </ span > properties = < span class ="kw "> match </ span > properties {
3122
- < span class ="prelude-val "> Some</ span > (p) => p,
3123
- < span class ="prelude-val "> None </ span > => < span class ="kw "> return </ span > Tfc::empty(),
3124
- };
3101
+ </ span > .instance
3102
+ .raw
3103
+ .get_physical_device_format_properties(< span class ="self "> self</ span > .raw, vk_format);
3125
3104
< span class ="kw "> let </ span > features = properties.optimal_tiling_features;
3126
3105
3127
3106
< span class ="kw "> let </ span > < span class ="kw-2 "> mut </ span > flags = Tfc::empty();
3293
3272
}
3294
3273
}
3295
3274
3296
- < span class ="doccomment "> /// Querys properties of all known image formats. The raw value of `vk::Format` corresponds
3297
- /// to the index of the returned Vec.
3298
- </ span > < span class ="kw "> fn </ span > query_format_properties(
3299
- instance: < span class ="kw-2 "> &</ span > ash::Instance,
3300
- physical_device: vk::PhysicalDevice,
3301
- ) -> Vec<vk::FormatProperties> {
3302
- < span class ="comment "> // vk::Format::UNDEFINED
3303
- </ span > < span class ="kw "> const </ span > FORMAT_MIN: i32 = < span class ="number "> 0</ span > ;
3304
-
3305
- < span class ="comment "> // vk::Format::ASTC_12X12_SRGB_BLOCK
3306
- </ span > < span class ="kw "> const </ span > FORMAT_MAX: i32 = < span class ="number "> 184</ span > ;
3307
-
3308
- < span class ="macro "> debug_assert_eq!</ span > (FORMAT_MAX, vk::Format::ASTC_12X12_SRGB_BLOCK.as_raw());
3309
-
3310
- (FORMAT_MIN..(FORMAT_MAX + < span class ="number "> 1</ span > ))
3311
- .map(|raw| {
3312
- < span class ="kw "> let </ span > image_format = vk::Format::from_raw(raw);
3313
- < span class ="kw "> unsafe </ span > { instance.get_physical_device_format_properties(physical_device, image_format) }
3314
- })
3315
- .collect::<Vec<< span class ="kw "> _</ span > >>()
3316
- }
3317
-
3318
- < span class ="kw "> fn </ span > is_format_16bit_norm_supported(caps: < span class ="kw-2 "> &</ span > PhysicalDeviceCapabilities) -> bool {
3275
+ < span class ="kw "> fn </ span > is_format_16bit_norm_supported(instance: < span class ="kw-2 "> &</ span > ash::Instance, phd: vk::PhysicalDevice) -> bool {
3319
3276
< span class ="kw "> let </ span > tiling = vk::ImageTiling::OPTIMAL;
3320
3277
< span class ="kw "> let </ span > features = vk::FormatFeatureFlags::SAMPLED_IMAGE
3321
3278
| vk::FormatFeatureFlags::STORAGE_IMAGE
3322
3279
| vk::FormatFeatureFlags::TRANSFER_SRC
3323
3280
| vk::FormatFeatureFlags::TRANSFER_DST;
3324
- < span class ="kw "> let </ span > r16unorm = caps.supports_format(vk::Format::R16_UNORM, tiling, features);
3325
- < span class ="kw "> let </ span > r16snorm = caps.supports_format(vk::Format::R16_SNORM, tiling, features);
3326
- < span class ="kw "> let </ span > rg16unorm = caps.supports_format(vk::Format::R16G16_UNORM, tiling, features);
3327
- < span class ="kw "> let </ span > rg16snorm = caps.supports_format(vk::Format::R16G16_SNORM, tiling, features);
3328
- < span class ="kw "> let </ span > rgba16unorm = caps.supports_format(vk::Format::R16G16B16A16_UNORM, tiling, features);
3329
- < span class ="kw "> let </ span > rgba16snorm = caps.supports_format(vk::Format::R16G16B16A16_SNORM, tiling, features);
3281
+ < span class ="kw "> let </ span > r16unorm = supports_format(instance, phd, vk::Format::R16_UNORM, tiling, features);
3282
+ < span class ="kw "> let </ span > r16snorm = supports_format(instance, phd, vk::Format::R16_SNORM, tiling, features);
3283
+ < span class ="kw "> let </ span > rg16unorm = supports_format(instance, phd, vk::Format::R16G16_UNORM, tiling, features);
3284
+ < span class ="kw "> let </ span > rg16snorm = supports_format(instance, phd, vk::Format::R16G16_SNORM, tiling, features);
3285
+ < span class ="kw "> let </ span > rgba16unorm = supports_format(
3286
+ instance,
3287
+ phd,
3288
+ vk::Format::R16G16B16A16_UNORM,
3289
+ tiling,
3290
+ features,
3291
+ );
3292
+ < span class ="kw "> let </ span > rgba16snorm = supports_format(
3293
+ instance,
3294
+ phd,
3295
+ vk::Format::R16G16B16A16_SNORM,
3296
+ tiling,
3297
+ features,
3298
+ );
3330
3299
3331
3300
r16unorm && r16snorm && rg16unorm && rg16snorm && rgba16unorm && rgba16snorm
3332
3301
}
3302
+
3303
+ < span class ="kw "> fn </ span > supports_format(
3304
+ instance: < span class ="kw-2 "> &</ span > ash::Instance,
3305
+ phd: vk::PhysicalDevice,
3306
+ format: vk::Format,
3307
+ tiling: vk::ImageTiling,
3308
+ features: vk::FormatFeatureFlags,
3309
+ ) -> bool {
3310
+ < span class ="kw "> let </ span > properties = < span class ="kw "> unsafe </ span > { instance.get_physical_device_format_properties(phd, format) };
3311
+ < span class ="kw "> match </ span > tiling {
3312
+ vk::ImageTiling::LINEAR => properties.linear_tiling_features.contains(features),
3313
+ vk::ImageTiling::OPTIMAL => properties.optimal_tiling_features.contains(features),
3314
+ < span class ="kw "> _ </ span > => < span class ="bool-val "> false</ span > ,
3315
+ }
3316
+ }
3333
3317
</ code > </ pre > </ div >
3334
3318
</ section > </ div > </ main > < div id ="rustdoc-vars " data-root-path ="../../../ " data-current-crate ="wgpu_hal " data-themes ="ayu,dark,light " data-resource-suffix ="" data-rustdoc-version ="1.65.0-nightly (e1b28cd2f 2022-08-19) " > </ div > </ body > </ html >
0 commit comments