Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dual source blending #4022

Merged
merged 6 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2714,8 +2714,8 @@ impl<A: HalApi> Device<A> {
blend_mode.alpha.dst_factor,
] {
if factor.ref_second_blend_source() {
self.require_features(wgt::Features::DUAL_SOURCE_BLENDING)?;
if i == 0 {
self.require_features(wgt::Features::DUAL_SOURCE_BLENDING)?;
pipeline_expects_dual_source_blending = true;
break;
} else {
Expand Down Expand Up @@ -2831,14 +2831,6 @@ impl<A: HalApi> Device<A> {
error,
})?;
validated_stages |= flag;

let dual_source = interface.has_dual_source_blending_entry_point();
if !pipeline_expects_dual_source_blending && dual_source {
return Err(pipeline::CreateRenderPipelineError::ShaderExpectsPipelineToUseDualSourceBlending);
}
if pipeline_expects_dual_source_blending && !dual_source {
return Err(pipeline::CreateRenderPipelineError::PipelineExpectsShaderToUseDualSourceBlending);
}
}

hal::ProgrammableStage {
Expand Down Expand Up @@ -2890,8 +2882,12 @@ impl<A: HalApi> Device<A> {
}

if let Some(ref interface) = shader_module.interface {
shader_expects_dual_source_blending =
interface.is_fragment_entry_dual_source(fragment).expect("Internal error: Fragment entrypoint should not be set in function if not present in shader interface");
shader_expects_dual_source_blending = interface
.fragment_uses_dual_source_blending(&fragment.stage.entry_point)
.map_err(|error| pipeline::CreateRenderPipelineError::Stage {
stage: flag,
error,
})?;
}

Some(hal::ProgrammableStage {
Expand Down
24 changes: 7 additions & 17 deletions wgpu-core/src/validation.rs
freqmod marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -1179,24 +1179,14 @@ impl Interface {
Ok(outputs)
}

pub fn has_dual_source_blending_entry_point(&self) -> bool {
teoxoy marked this conversation as resolved.
Show resolved Hide resolved
self.entry_points
.values()
.any(|point| point.dual_source_blending)
}
pub fn is_fragment_entry_dual_source<'a>(
pub fn fragment_uses_dual_source_blending(
&self,
fragment: &crate::pipeline::FragmentState<'a>,
entry_point_name: &str,
) -> Result<bool, StageError> {
if let Some(entry_point) = self.entry_points.get(&(
naga::ShaderStage::Fragment,
String::from(fragment.stage.entry_point.as_ref()),
)) {
Ok(entry_point.dual_source_blending)
} else {
Err(StageError::MissingEntryPoint(String::from(
fragment.stage.entry_point.as_ref(),
)))
}
let pair = (naga::ShaderStage::Fragment, entry_point_name.to_string());
self.entry_points
.get(&pair)
.ok_or(StageError::MissingEntryPoint(pair.1))
.map(|ep| ep.dual_source_blending)
}
}
3 changes: 1 addition & 2 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,6 @@ impl super::PrivateCapabilities {
None
},
timestamp_query_support,
dual_source_blending: version.at_least((11, 0), (14, 0), os_is_mac),
}
}

Expand Down Expand Up @@ -836,7 +835,7 @@ impl super::PrivateCapabilities {
);
features.set(
F::DUAL_SOURCE_BLENDING,
self.msl_version >= MTLLanguageVersion::V1_2,
self.msl_version >= MTLLanguageVersion::V1_2 && self.dual_source_blending,
);
features.set(F::TEXTURE_COMPRESSION_ASTC, self.format_astc);
features.set(F::TEXTURE_COMPRESSION_ASTC_HDR, self.format_astc_hdr);
Expand Down
2 changes: 0 additions & 2 deletions wgpu-hal/src/metal/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ pub fn map_blend_factor(factor: wgt::BlendFactor) -> metal::MTLBlendFactor {
Bf::OneMinusDstAlpha => OneMinusDestinationAlpha,
Bf::Constant => BlendColor,
Bf::OneMinusConstant => OneMinusBlendColor,
//Bf::ConstantAlpha => BlendAlpha,
//Bf::OneMinusConstantAlpha => OneMinusBlendAlpha,
Bf::SrcAlphaSaturated => SourceAlphaSaturated,
Bf::Src1 => Source1Color,
Bf::OneMinusSrc1 => OneMinusSource1Color,
Expand Down
2 changes: 0 additions & 2 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,6 @@ bitflags::bitflags! {
/// - Vulkan (with dualSrcBlend)
/// - DX12
const DUAL_SOURCE_BLENDING = 1 << 63;

// no more space left
}
}

Expand Down