GPU: no blending on integer render targets in host pipelines
The console ignores blending on integer render targets and the title leaves it on (the world has a mesh pipeline blending into an R8_UINT target). D3D12 does not allow it: vkd3d-proton refuses such a pipeline with E_INVALIDARG and its draws are lost. The host pipeline now turns blending off on integer targets; with one description for all targets, each target gets its own copy so the others keep theirs.
This commit is contained in:
1 parent
29f9e89df6
commit
83b37dfcf9
1 file changed
+117
-2
@@ -89,6 +89,65 @@ impl Default for GraphicsState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Integer render target formats: D3D12 cannot blend into them.
|
||||
fn integer_format(f: DXGI_FORMAT) -> bool {
|
||||
matches!(
|
||||
f,
|
||||
DXGI_FORMAT_R32G32B32A32_UINT
|
||||
| DXGI_FORMAT_R32G32B32A32_SINT
|
||||
| DXGI_FORMAT_R32G32B32_UINT
|
||||
| DXGI_FORMAT_R32G32B32_SINT
|
||||
| DXGI_FORMAT_R16G16B16A16_UINT
|
||||
| DXGI_FORMAT_R16G16B16A16_SINT
|
||||
| DXGI_FORMAT_R32G32_UINT
|
||||
| DXGI_FORMAT_R32G32_SINT
|
||||
| DXGI_FORMAT_R10G10B10A2_UINT
|
||||
| DXGI_FORMAT_R8G8B8A8_UINT
|
||||
| DXGI_FORMAT_R8G8B8A8_SINT
|
||||
| DXGI_FORMAT_R16G16_UINT
|
||||
| DXGI_FORMAT_R16G16_SINT
|
||||
| DXGI_FORMAT_R32_UINT
|
||||
| DXGI_FORMAT_R32_SINT
|
||||
| DXGI_FORMAT_R8G8_UINT
|
||||
| DXGI_FORMAT_R8G8_SINT
|
||||
| DXGI_FORMAT_R16_UINT
|
||||
| DXGI_FORMAT_R16_SINT
|
||||
| DXGI_FORMAT_R8_UINT
|
||||
| DXGI_FORMAT_R8_SINT
|
||||
)
|
||||
}
|
||||
|
||||
/// The title's blend state as the host takes it: blending off on integer
|
||||
/// render targets. The console ignores blending there, and titles leave it
|
||||
/// on (the world sets it on an `R8_UINT` target), but D3D12 does not allow
|
||||
/// it: vkd3d-proton refuses such a pipeline with `E_INVALIDARG` ("using
|
||||
/// integer format is not supported"), and its draws are lost. With one
|
||||
/// description for every target, each target gets its own copy so the
|
||||
/// others keep theirs.
|
||||
fn host_blend(blend: &D3D12_BLEND_DESC, targets: &D3D12_RT_FORMAT_ARRAY) -> D3D12_BLEND_DESC {
|
||||
let count = (targets.NumRenderTargets as usize).min(8);
|
||||
let per_target = blend.IndependentBlendEnable.as_bool();
|
||||
let blends = |i: usize| {
|
||||
blend.RenderTarget[if per_target { i } else { 0 }]
|
||||
.BlendEnable
|
||||
.as_bool()
|
||||
};
|
||||
if !(0..count).any(|i| integer_format(targets.RTFormats[i]) && blends(i)) {
|
||||
return *blend;
|
||||
}
|
||||
let mut host = *blend;
|
||||
if !per_target {
|
||||
host.IndependentBlendEnable = true.into();
|
||||
host.RenderTarget = [blend.RenderTarget[0]; 8];
|
||||
}
|
||||
for i in 0..count {
|
||||
if integer_format(targets.RTFormats[i]) {
|
||||
host.RenderTarget[i].BlendEnable = false.into();
|
||||
}
|
||||
}
|
||||
host
|
||||
}
|
||||
|
||||
impl GraphicsState {
|
||||
/// Takes in one subobject of a stream: its type, then its data at +4
|
||||
/// (+8 for those holding pointers).
|
||||
@@ -605,7 +664,7 @@ impl HostPipeline {
|
||||
BytecodeLength: gs.len(),
|
||||
}
|
||||
}),
|
||||
BlendState: g.blend,
|
||||
BlendState: host_blend(&g.blend, &g.targets),
|
||||
SampleMask: g.sample_mask,
|
||||
RasterizerState: g.rasterizer,
|
||||
DepthStencilState: g.depth,
|
||||
@@ -761,7 +820,7 @@ fn mesh_pipeline(
|
||||
root: Sub(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, root.as_raw()),
|
||||
ms: Sub(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS, ms),
|
||||
ps: Sub(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, ps),
|
||||
blend: Sub(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND, g.blend),
|
||||
blend: Sub(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND, host_blend(&g.blend, &g.targets)),
|
||||
mask: Sub(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK, g.sample_mask),
|
||||
raster: Sub(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER, g.rasterizer),
|
||||
depth: Sub(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL, g.depth),
|
||||
@@ -928,4 +987,60 @@ mod tests {
|
||||
"the mesh pipeline was compiled again instead of loaded from the library"
|
||||
);
|
||||
}
|
||||
|
||||
fn targets(formats: &[DXGI_FORMAT]) -> D3D12_RT_FORMAT_ARRAY {
|
||||
let mut t = D3D12_RT_FORMAT_ARRAY {
|
||||
NumRenderTargets: formats.len() as u32,
|
||||
..Default::default()
|
||||
};
|
||||
t.RTFormats[..formats.len()].copy_from_slice(formats);
|
||||
t
|
||||
}
|
||||
|
||||
fn blending(independent: bool) -> D3D12_BLEND_DESC {
|
||||
let mut b = GraphicsState::default().blend;
|
||||
b.IndependentBlendEnable = independent.into();
|
||||
for t in &mut b.RenderTarget {
|
||||
t.BlendEnable = true.into();
|
||||
t.SrcBlend = D3D12_BLEND_SRC_ALPHA;
|
||||
t.DestBlend = D3D12_BLEND_INV_SRC_ALPHA;
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn integer_targets_do_not_blend() {
|
||||
let t = targets(&[
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||
DXGI_FORMAT_R16G16B16A16_FLOAT,
|
||||
DXGI_FORMAT_R8_UINT,
|
||||
]);
|
||||
for independent in [false, true] {
|
||||
let host = host_blend(&blending(independent), &t);
|
||||
assert!(host.IndependentBlendEnable.as_bool());
|
||||
assert!(host.RenderTarget[0].BlendEnable.as_bool());
|
||||
assert!(host.RenderTarget[1].BlendEnable.as_bool());
|
||||
assert!(!host.RenderTarget[2].BlendEnable.as_bool());
|
||||
// The rest of the target's state is the title's.
|
||||
assert_eq!(host.RenderTarget[2].SrcBlend, D3D12_BLEND_SRC_ALPHA);
|
||||
assert_eq!(host.RenderTarget[0].DestBlend, D3D12_BLEND_INV_SRC_ALPHA);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blend_states_without_integer_blending_are_kept() {
|
||||
// No integer target.
|
||||
let b = blending(false);
|
||||
let t = targets(&[DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R11G11B10_FLOAT]);
|
||||
assert_eq!(host_blend(&b, &t), b);
|
||||
// An integer target that does not blend.
|
||||
let mut b = blending(true);
|
||||
b.RenderTarget[1].BlendEnable = false.into();
|
||||
let t = targets(&[DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R32_UINT]);
|
||||
assert_eq!(host_blend(&b, &t), b);
|
||||
// Integer formats past the targets in use.
|
||||
let mut t = targets(&[DXGI_FORMAT_R8G8B8A8_UNORM]);
|
||||
t.RTFormats[1] = DXGI_FORMAT_R8_UINT;
|
||||
assert_eq!(host_blend(&blending(false), &t), blending(false));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user