Skip to content

Commit efe72b1

Browse files
committed
[dx12] update d3d12 to 0.3 and use explicit linking
1 parent 3cd88e2 commit efe72b1

File tree

9 files changed

+166
-168
lines changed

9 files changed

+166
-168
lines changed

src/backend/dx12/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ auxil = { path = "../../auxil/auxil", version = "0.2", package = "gfx-auxil", fe
2323
hal = { path = "../../hal", version = "0.4", package = "gfx-hal" }
2424
range-alloc = { path = "../../auxil/range-alloc", version = "0.1" }
2525
bitflags = "1"
26-
native = { version = "0.2.2", package = "d3d12" }
26+
native = { package = "d3d12", version = "0.3", features = ["libloading"] }
2727
log = { version = "0.4" }
2828
smallvec = "0.6"
2929
spirv_cross = { version = "0.16", features = ["hlsl"] }

src/backend/dx12/src/command.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ use winapi::{
3232
Interface,
3333
};
3434

35-
use device::{ViewInfo, IDENTITY_MAPPING};
36-
use native::descriptor;
3735
use smallvec::SmallVec;
3836

3937
use crate::{
@@ -676,12 +674,12 @@ impl CommandBuffer {
676674
stencil: Option<u32>,
677675
rects: &[d3d12::D3D12_RECT],
678676
) {
679-
let mut flags = native::command_list::ClearFlags::empty();
677+
let mut flags = native::ClearFlags::empty();
680678
if depth.is_some() {
681-
flags |= native::command_list::ClearFlags::DEPTH;
679+
flags |= native::ClearFlags::DEPTH;
682680
}
683681
if stencil.is_some() {
684-
flags |= native::command_list::ClearFlags::STENCIL;
682+
flags |= native::ClearFlags::STENCIL;
685683
}
686684

687685
self.raw.clear_depth_stencil_view(
@@ -1482,7 +1480,7 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
14821480

14831481
let mut rtv_pool = descriptors_cpu::HeapLinear::new(
14841482
device,
1485-
descriptor::HeapType::Rtv,
1483+
native::DescriptorHeapType::Rtv,
14861484
clear_rects.len(),
14871485
);
14881486

@@ -1496,7 +1494,7 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
14961494
caps: image::ViewCapabilities::empty(),
14971495
view_kind: image::ViewKind::D2Array,
14981496
format: attachment.dxgi_format,
1499-
component_mapping: IDENTITY_MAPPING,
1497+
component_mapping: device::IDENTITY_MAPPING,
15001498
range: image::SubresourceRange {
15011499
aspects: Aspects::COLOR,
15021500
levels: attachment.mip_levels.0 .. attachment.mip_levels.1,
@@ -1519,7 +1517,7 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
15191517

15201518
let mut dsv_pool = descriptors_cpu::HeapLinear::new(
15211519
device,
1522-
descriptor::HeapType::Dsv,
1520+
native::DescriptorHeapType::Dsv,
15231521
clear_rects.len(),
15241522
);
15251523

@@ -1533,7 +1531,7 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
15331531
caps: image::ViewCapabilities::empty(),
15341532
view_kind: image::ViewKind::D2Array,
15351533
format: attachment.dxgi_format,
1536-
component_mapping: IDENTITY_MAPPING,
1534+
component_mapping: device::IDENTITY_MAPPING,
15371535
range: image::SubresourceRange {
15381536
aspects: if depth.is_some() {
15391537
Aspects::DEPTH
@@ -1650,17 +1648,17 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
16501648
// Descriptor heap for the current blit, only storing the src image
16511649
let (srv_heap, _) = device.create_descriptor_heap(
16521650
1,
1653-
descriptor::HeapType::CbvSrvUav,
1654-
descriptor::HeapFlags::SHADER_VISIBLE,
1651+
native::DescriptorHeapType::CbvSrvUav,
1652+
native::DescriptorHeapFlags::SHADER_VISIBLE,
16551653
0,
16561654
);
1657-
let srv_desc = Device::build_image_as_shader_resource_desc(&ViewInfo {
1655+
let srv_desc = Device::build_image_as_shader_resource_desc(&device::ViewInfo {
16581656
resource: src.resource,
16591657
kind: src.kind,
16601658
caps: src.view_caps,
16611659
view_kind: image::ViewKind::D2Array, // TODO
16621660
format: src.default_view_format.unwrap(),
1663-
component_mapping: IDENTITY_MAPPING,
1661+
component_mapping: device::IDENTITY_MAPPING,
16641662
range: image::SubresourceRange {
16651663
aspects: format::Aspects::COLOR, // TODO
16661664
levels: 0 .. src.descriptor.MipLevels as _,
@@ -1698,7 +1696,7 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
16981696
// WORKAROUND: renderdoc crashes if we destroy the pool too early
16991697
let rtv_pool = Device::create_descriptor_heap_impl(
17001698
device,
1701-
descriptor::HeapType::Rtv,
1699+
native::DescriptorHeapType::Rtv,
17021700
false,
17031701
num_layers as _,
17041702
);
@@ -2526,7 +2524,7 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
25262524

25272525
unsafe fn begin_query(&mut self, query: query::Query<Backend>, flags: query::ControlFlags) {
25282526
let query_ty = match query.pool.ty {
2529-
native::query::HeapType::Occlusion => {
2527+
native::QueryHeapType::Occlusion => {
25302528
if flags.contains(query::ControlFlags::PRECISE) {
25312529
self.occlusion_query = Some(OcclusionQuery::Precise(query.id));
25322530
d3d12::D3D12_QUERY_TYPE_OCCLUSION
@@ -2537,8 +2535,8 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
25372535
d3d12::D3D12_QUERY_TYPE_BINARY_OCCLUSION
25382536
}
25392537
}
2540-
native::query::HeapType::Timestamp => panic!("Timestap queries are issued via "),
2541-
native::query::HeapType::PipelineStatistics => {
2538+
native::QueryHeapType::Timestamp => panic!("Timestap queries are issued via "),
2539+
native::QueryHeapType::PipelineStatistics => {
25422540
self.pipeline_stats_query = Some(query.id);
25432541
d3d12::D3D12_QUERY_TYPE_PIPELINE_STATISTICS
25442542
}
@@ -2552,19 +2550,19 @@ impl com::CommandBuffer<Backend> for CommandBuffer {
25522550
unsafe fn end_query(&mut self, query: query::Query<Backend>) {
25532551
let id = query.id;
25542552
let query_ty = match query.pool.ty {
2555-
native::query::HeapType::Occlusion
2553+
native::QueryHeapType::Occlusion
25562554
if self.occlusion_query == Some(OcclusionQuery::Precise(id)) =>
25572555
{
25582556
self.occlusion_query = None;
25592557
d3d12::D3D12_QUERY_TYPE_OCCLUSION
25602558
}
2561-
native::query::HeapType::Occlusion
2559+
native::QueryHeapType::Occlusion
25622560
if self.occlusion_query == Some(OcclusionQuery::Binary(id)) =>
25632561
{
25642562
self.occlusion_query = None;
25652563
d3d12::D3D12_QUERY_TYPE_BINARY_OCCLUSION
25662564
}
2567-
native::query::HeapType::PipelineStatistics
2565+
native::QueryHeapType::PipelineStatistics
25682566
if self.pipeline_stats_query == Some(id) =>
25692567
{
25702568
self.pipeline_stats_query = None;

src/backend/dx12/src/conv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hal::{
1919
pso,
2020
};
2121

22-
use native::descriptor::ShaderVisibility;
22+
use native::ShaderVisibility;
2323

2424
pub fn map_format(format: Format) -> Option<DXGI_FORMAT> {
2525
use hal::format::Format::*;

src/backend/dx12/src/descriptors_cpu.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use native::descriptor::{CpuDescriptor, HeapFlags, HeapType};
1+
use native::{CpuDescriptor, DescriptorHeapFlags, DescriptorHeapType};
22
use std::{collections::HashSet, fmt};
33

44
// Linear stack allocator for CPU descriptor heaps.
@@ -17,8 +17,8 @@ impl fmt::Debug for HeapLinear {
1717
}
1818

1919
impl HeapLinear {
20-
pub fn new(device: native::Device, ty: HeapType, size: usize) -> Self {
21-
let (heap, _hr) = device.create_descriptor_heap(size as _, ty, HeapFlags::empty(), 0);
20+
pub fn new(device: native::Device, ty: DescriptorHeapType, size: usize) -> Self {
21+
let (heap, _hr) = device.create_descriptor_heap(size as _, ty, DescriptorHeapFlags::empty(), 0);
2222

2323
HeapLinear {
2424
handle_size: device.get_descriptor_increment_size(ty) as _,
@@ -74,9 +74,9 @@ impl fmt::Debug for Heap {
7474
}
7575

7676
impl Heap {
77-
pub fn new(device: native::Device, ty: HeapType) -> Self {
77+
pub fn new(device: native::Device, ty: DescriptorHeapType) -> Self {
7878
let (heap, _hr) =
79-
device.create_descriptor_heap(HEAP_SIZE_FIXED as _, ty, HeapFlags::empty(), 0);
79+
device.create_descriptor_heap(HEAP_SIZE_FIXED as _, ty, DescriptorHeapFlags::empty(), 0);
8080

8181
Heap {
8282
handle_size: device.get_descriptor_increment_size(ty) as _,
@@ -109,7 +109,7 @@ impl Heap {
109109

110110
pub struct DescriptorCpuPool {
111111
device: native::Device,
112-
ty: HeapType,
112+
ty: DescriptorHeapType,
113113
heaps: Vec<Heap>,
114114
free_list: HashSet<usize>,
115115
}
@@ -121,7 +121,7 @@ impl fmt::Debug for DescriptorCpuPool {
121121
}
122122

123123
impl DescriptorCpuPool {
124-
pub fn new(device: native::Device, ty: HeapType) -> Self {
124+
pub fn new(device: native::Device, ty: DescriptorHeapType) -> Self {
125125
DescriptorCpuPool {
126126
device,
127127
ty,

src/backend/dx12/src/device.rs

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use hal::{
5050
use crate::{
5151
command as cmd,
5252
conv,
53-
descriptor,
5453
descriptors_cpu,
5554
pool::{CommandPool, CommandPoolAllocator},
5655
resource as r,
@@ -65,8 +64,11 @@ use crate::{
6564
QUEUE_FAMILIES,
6665
};
6766
use native::{
68-
command_list::IndirectArgument,
69-
pso::{CachedPSO, PipelineStateFlags, PipelineStateSubobject, Subobject},
67+
CachedPSO,
68+
IndirectArgument,
69+
PipelineStateFlags,
70+
PipelineStateSubobject,
71+
Subobject,
7072
};
7173

7274
// Register space used for root constants.
@@ -506,7 +508,7 @@ impl Device {
506508

507509
pub(crate) fn create_descriptor_heap_impl(
508510
device: native::Device,
509-
heap_type: descriptor::HeapType,
511+
heap_type: native::DescriptorHeapType,
510512
shader_visible: bool,
511513
capacity: usize,
512514
) -> r::DescriptorHeap {
@@ -516,9 +518,9 @@ impl Device {
516518
capacity as _,
517519
heap_type,
518520
if shader_visible {
519-
descriptor::HeapFlags::SHADER_VISIBLE
521+
native::DescriptorHeapFlags::SHADER_VISIBLE
520522
} else {
521-
descriptor::HeapFlags::empty()
523+
native::DescriptorHeapFlags::empty()
522524
},
523525
0,
524526
);
@@ -1050,7 +1052,7 @@ impl Device {
10501052
};
10511053
let rtv_heap = Device::create_descriptor_heap_impl(
10521054
self.raw,
1053-
descriptor::HeapType::Rtv,
1055+
native::DescriptorHeapType::Rtv,
10541056
false,
10551057
config.image_count as _,
10561058
);
@@ -1531,9 +1533,9 @@ impl d::Device<B> for Device {
15311533
"\tRoot constant set={} range {:?}",
15321534
ROOT_CONSTANT_SPACE, root_constant.range
15331535
);
1534-
parameters.push(descriptor::RootParameter::constants(
1536+
parameters.push(native::RootParameter::constants(
15351537
conv::map_shader_visibility(root_constant.stages),
1536-
descriptor::Binding {
1538+
native::Binding {
15371539
register: root_constant.range.start as _,
15381540
space: ROOT_CONSTANT_SPACE,
15391541
},
@@ -1587,10 +1589,10 @@ impl d::Device<B> for Device {
15871589
}
15881590

15891591
let describe = |bind: &pso::DescriptorSetLayoutBinding, ty| {
1590-
descriptor::DescriptorRange::new(
1592+
native::DescriptorRange::new(
15911593
ty,
15921594
bind.count as _,
1593-
descriptor::Binding {
1595+
native::Binding {
15941596
register: bind.binding as _,
15951597
space,
15961598
},
@@ -1605,7 +1607,7 @@ impl d::Device<B> for Device {
16051607

16061608
if content.is_dynamic() {
16071609
// Root Descriptor
1608-
let binding = descriptor::Binding {
1610+
let binding = native::Binding {
16091611
register: bind.binding as _,
16101612
space,
16111613
};
@@ -1614,7 +1616,7 @@ impl d::Device<B> for Device {
16141616
descriptors.push(r::RootDescriptor {
16151617
offset: root_offset,
16161618
});
1617-
parameters.push(descriptor::RootParameter::cbv_descriptor(
1619+
parameters.push(native::RootParameter::cbv_descriptor(
16181620
visibility, binding,
16191621
));
16201622
root_offset += 2;
@@ -1625,18 +1627,18 @@ impl d::Device<B> for Device {
16251627
} else {
16261628
// Descriptor table ranges
16271629
if content.contains(r::DescriptorContent::CBV) {
1628-
ranges.push(describe(bind, descriptor::DescriptorRangeType::CBV));
1630+
ranges.push(describe(bind, native::DescriptorRangeType::CBV));
16291631
}
16301632
if content.contains(r::DescriptorContent::SRV) {
1631-
ranges.push(describe(bind, descriptor::DescriptorRangeType::SRV));
1633+
ranges.push(describe(bind, native::DescriptorRangeType::SRV));
16321634
}
16331635
if content.contains(r::DescriptorContent::UAV) {
1634-
ranges.push(describe(bind, descriptor::DescriptorRangeType::UAV));
1636+
ranges.push(describe(bind, native::DescriptorRangeType::UAV));
16351637
}
16361638
}
16371639
}
16381640
if ranges.len() > range_base {
1639-
parameters.push(descriptor::RootParameter::descriptor_table(
1641+
parameters.push(native::RootParameter::descriptor_table(
16401642
visibility,
16411643
&ranges[range_base ..],
16421644
));
@@ -1648,11 +1650,11 @@ impl d::Device<B> for Device {
16481650
for bind in set.bindings.iter() {
16491651
let content = r::DescriptorContent::from(bind.ty);
16501652
if content.contains(r::DescriptorContent::SAMPLER) {
1651-
ranges.push(describe(bind, descriptor::DescriptorRangeType::Sampler));
1653+
ranges.push(describe(bind, native::DescriptorRangeType::Sampler));
16521654
}
16531655
}
16541656
if ranges.len() > range_base {
1655-
parameters.push(descriptor::RootParameter::descriptor_table(
1657+
parameters.push(native::RootParameter::descriptor_table(
16561658
visibility,
16571659
&ranges[range_base ..],
16581660
));
@@ -1674,12 +1676,16 @@ impl d::Device<B> for Device {
16741676
debug_assert_eq!(ranges.len(), total);
16751677

16761678
// TODO: error handling
1677-
let ((signature_raw, error), _hr) = native::RootSignature::serialize(
1678-
descriptor::RootSignatureVersion::V1_0,
1679+
let (signature_raw, error) = match self.library.serialize_root_signature(
1680+
native::RootSignatureVersion::V1_0,
16791681
&parameters,
16801682
&[],
1681-
descriptor::RootSignatureFlags::ALLOW_IA_INPUT_LAYOUT,
1682-
);
1683+
native::RootSignatureFlags::ALLOW_IA_INPUT_LAYOUT,
1684+
) {
1685+
Ok((pair, hr)) if winerror::SUCCEEDED(hr) => pair,
1686+
Ok((_, hr)) => panic!("Can't serialize root signature: {:?}", hr),
1687+
Err(e) => panic!("Can't find serialization function: {:?}", e),
1688+
};
16831689

16841690
if !error.is_null() {
16851691
error!(
@@ -1691,7 +1697,6 @@ impl d::Device<B> for Device {
16911697

16921698
// TODO: error handling
16931699
let (signature, _hr) = self.raw.create_root_signature(signature_raw, 0);
1694-
signature_raw.destroy();
16951700

16961701
Ok(r::PipelineLayout {
16971702
raw: signature,
@@ -2835,7 +2840,7 @@ impl d::Device<B> for Device {
28352840
let max_size = 1u64 << 12; //arbitrary
28362841
descriptor_update_pools.push(descriptors_cpu::HeapLinear::new(
28372842
self.raw,
2838-
descriptor::HeapType::CbvSrvUav,
2843+
native::DescriptorHeapType::CbvSrvUav,
28392844
max_size as _,
28402845
));
28412846
}
@@ -2901,7 +2906,7 @@ impl d::Device<B> for Device {
29012906
let max_size = 1u64 << 12; //arbitrary
29022907
descriptor_update_pools.push(descriptors_cpu::HeapLinear::new(
29032908
self.raw,
2904-
descriptor::HeapType::CbvSrvUav,
2909+
native::DescriptorHeapType::CbvSrvUav,
29052910
max_size as _,
29062911
));
29072912
heap = descriptor_update_pools.last_mut().unwrap();
@@ -3309,9 +3314,9 @@ impl d::Device<B> for Device {
33093314
count: query::Id,
33103315
) -> Result<r::QueryPool, query::CreationError> {
33113316
let heap_ty = match query_ty {
3312-
query::Type::Occlusion => native::query::HeapType::Occlusion,
3313-
query::Type::PipelineStatistics(_) => native::query::HeapType::PipelineStatistics,
3314-
query::Type::Timestamp => native::query::HeapType::Timestamp,
3317+
query::Type::Occlusion => native::QueryHeapType::Occlusion,
3318+
query::Type::PipelineStatistics(_) => native::QueryHeapType::PipelineStatistics,
3319+
query::Type::Timestamp => native::QueryHeapType::Timestamp,
33153320
};
33163321

33173322
let (query_heap, hr) = self.raw.create_query_heap(heap_ty, count, 0);

0 commit comments

Comments
 (0)