mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-25 00:41:07 +01:00
Implement shader barycentrics (#8320)
This commit is contained in:
34 files changed
+422
-4
No files matched your search
@@ -568,6 +568,23 @@ impl super::Adapter {
|
||||
wgt::Features::EXPERIMENTAL_MESH_SHADER,
|
||||
mesh_shader_supported,
|
||||
);
|
||||
let shader_barycentrics_supported = {
|
||||
let mut features3 = Direct3D12::D3D12_FEATURE_DATA_D3D12_OPTIONS3::default();
|
||||
unsafe {
|
||||
device.CheckFeatureSupport(
|
||||
Direct3D12::D3D12_FEATURE_D3D12_OPTIONS3,
|
||||
<*mut _>::cast(&mut features3),
|
||||
size_of_val(&features3) as u32,
|
||||
)
|
||||
}
|
||||
.is_ok()
|
||||
&& features3.BarycentricsSupported.as_bool()
|
||||
&& shader_model >= naga::back::hlsl::ShaderModel::V6_1
|
||||
};
|
||||
features.set(
|
||||
wgt::Features::SHADER_BARYCENTRICS,
|
||||
shader_barycentrics_supported,
|
||||
);
|
||||
|
||||
// TODO: Determine if IPresentationManager is supported
|
||||
let presentation_timer = auxil::dxgi::time::PresentationTimer::new_dxgi();
|
||||
|
||||
@@ -902,6 +902,7 @@ impl super::PrivateCapabilities {
|
||||
&& (device.supports_family(MTLGPUFamily::Apple7)
|
||||
|| device.supports_family(MTLGPUFamily::Mac2)),
|
||||
supports_shared_event: version.at_least((10, 14), (12, 0), os_is_mac),
|
||||
shader_barycentrics: device.supports_shader_barycentric_coordinates(),
|
||||
// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf#page=3
|
||||
supports_memoryless_storage: if family_check {
|
||||
device.supports_family(MTLGPUFamily::Apple2)
|
||||
@@ -1003,6 +1004,11 @@ impl super::PrivateCapabilities {
|
||||
|
||||
features.set(F::RG11B10UFLOAT_RENDERABLE, self.format_rg11b10_all);
|
||||
|
||||
features.set(
|
||||
F::SHADER_BARYCENTRICS,
|
||||
self.shader_barycentrics && self.msl_version >= MTLLanguageVersion::V2_2,
|
||||
);
|
||||
|
||||
if self.supports_simd_scoped_operations {
|
||||
features.insert(F::SUBGROUP | F::SUBGROUP_BARRIER);
|
||||
}
|
||||
|
||||
@@ -302,6 +302,7 @@ struct PrivateCapabilities {
|
||||
int64_atomics: bool,
|
||||
float_atomics: bool,
|
||||
supports_shared_event: bool,
|
||||
shader_barycentrics: bool,
|
||||
supports_memoryless_storage: bool,
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +128,9 @@ pub struct PhysicalDeviceFeatures {
|
||||
/// Features provided by `VK_KHR_shader_integer_dot_product`, promoted to Vulkan 1.3.
|
||||
shader_integer_dot_product:
|
||||
Option<vk::PhysicalDeviceShaderIntegerDotProductFeaturesKHR<'static>>,
|
||||
|
||||
/// Features provided by `VK_KHR_fragment_shader_barycentric`
|
||||
shader_barycentrics: Option<vk::PhysicalDeviceFragmentShaderBarycentricFeaturesKHR<'static>>,
|
||||
}
|
||||
|
||||
impl PhysicalDeviceFeatures {
|
||||
@@ -201,6 +204,9 @@ impl PhysicalDeviceFeatures {
|
||||
if let Some(ref mut feature) = self.shader_integer_dot_product {
|
||||
info = info.push_next(feature);
|
||||
}
|
||||
if let Some(ref mut feature) = self.shader_barycentrics {
|
||||
info = info.push_next(feature);
|
||||
}
|
||||
info
|
||||
}
|
||||
|
||||
@@ -535,6 +541,17 @@ impl PhysicalDeviceFeatures {
|
||||
} else {
|
||||
None
|
||||
},
|
||||
shader_barycentrics: if enabled_extensions
|
||||
.contains(&khr::fragment_shader_barycentric::NAME)
|
||||
{
|
||||
let needed = requested_features.intersects(wgt::Features::SHADER_BARYCENTRICS);
|
||||
Some(
|
||||
vk::PhysicalDeviceFragmentShaderBarycentricFeaturesKHR::default()
|
||||
.fragment_shader_barycentric(needed),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -669,6 +686,13 @@ impl PhysicalDeviceFeatures {
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(ref shader_barycentrics) = self.shader_barycentrics {
|
||||
features.set(
|
||||
F::SHADER_BARYCENTRICS,
|
||||
shader_barycentrics.fragment_shader_barycentric != 0,
|
||||
);
|
||||
}
|
||||
|
||||
//if caps.supports_extension(khr::sampler_mirror_clamp_to_edge::NAME) {
|
||||
//if caps.supports_extension(ext::sampler_filter_minmax::NAME) {
|
||||
features.set(
|
||||
@@ -1184,6 +1208,11 @@ impl PhysicalDeviceProperties {
|
||||
extensions.push(ext::mesh_shader::NAME);
|
||||
}
|
||||
|
||||
// Require `VK_KHR_fragment_shader_barycentric` if the associated feature was requested
|
||||
if requested_features.intersects(wgt::Features::SHADER_BARYCENTRICS) {
|
||||
extensions.push(khr::fragment_shader_barycentric::NAME);
|
||||
}
|
||||
|
||||
extensions
|
||||
}
|
||||
|
||||
@@ -1638,6 +1667,13 @@ impl super::InstanceShared {
|
||||
features2 = features2.push_next(next);
|
||||
}
|
||||
|
||||
if capabilities.supports_extension(khr::fragment_shader_barycentric::NAME) {
|
||||
let next = features
|
||||
.shader_barycentrics
|
||||
.insert(vk::PhysicalDeviceFragmentShaderBarycentricFeaturesKHR::default());
|
||||
features2 = features2.push_next(next);
|
||||
}
|
||||
|
||||
unsafe { get_device_properties.get_physical_device_features2(phd, &mut features2) };
|
||||
features2.features
|
||||
} else {
|
||||
@@ -2135,6 +2171,10 @@ impl super::Adapter {
|
||||
capabilities.push(spv::Capability::ClipDistance);
|
||||
}
|
||||
|
||||
if features.intersects(wgt::Features::SHADER_BARYCENTRICS) {
|
||||
capabilities.push(spv::Capability::FragmentBarycentricKHR);
|
||||
}
|
||||
|
||||
let mut flags = spv::WriterFlags::empty();
|
||||
flags.set(
|
||||
spv::WriterFlags::DEBUG,
|
||||
|
||||
Reference in new issue
Block a user