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

dx12: Update to latest wio version #1765

Merged
merged 2 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/backend/dx12/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ smallvec = "0.4"
spirv_cross = "0.4.2"
winapi = { version = "0.3", features = ["basetsd","d3d12","d3d12sdklayers","d3d12shader","d3dcommon","d3dcompiler","dxgi1_2","dxgi1_3","dxgi1_4","dxgiformat","dxgitype","handleapi","minwindef","synchapi","unknwnbase","winbase","windef","winerror","winnt","winuser"] }
winit = { version = "0.10", optional = true }
wio = { git = "https://github.com/msiglreith/wio-rs.git", branch = "stable" }
wio = "0.2"
20 changes: 10 additions & 10 deletions src/backend/dx12/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ fn bind_descriptor_sets<'a, T>(
// TODO: Can we bind them always or only once?
// Resize while recording?
let mut heaps = [
set_0.heap_srv_cbv_uav.as_mut() as *mut _,
set_0.heap_samplers.as_mut() as *mut _
set_0.heap_srv_cbv_uav.as_raw(),
set_0.heap_samplers.as_raw(),
];
raw.SetDescriptorHeaps(2, heaps.as_mut_ptr())
}
Expand Down Expand Up @@ -297,11 +297,11 @@ impl CommandBuffer {
}

pub(crate) unsafe fn as_raw_list(&self) -> *mut d3d12::ID3D12CommandList {
self.raw.as_mut() as *mut _ as *mut _
self.raw.as_raw() as *mut _
}

fn reset(&mut self) {
unsafe { self.raw.Reset(self.allocator.as_mut(), ptr::null_mut()); }
unsafe { self.raw.Reset(self.allocator.as_raw(), ptr::null_mut()); }
self.pass_cache = None;
self.cur_subpass = !0;
self.gr_pipeline = PipelineCache::new();
Expand Down Expand Up @@ -1089,7 +1089,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
self.set_compute_bind_point();
unsafe {
self.raw.ExecuteIndirect(
self.signatures.dispatch.as_mut() as *mut _,
self.signatures.dispatch.as_raw(),
1,
buffer.resource,
offset,
Expand Down Expand Up @@ -1410,7 +1410,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
self.set_graphics_bind_point();
unsafe {
self.raw.ExecuteIndirect(
self.signatures.draw.as_mut() as *mut _,
self.signatures.draw.as_raw(),
draw_count,
buffer.resource,
offset,
Expand All @@ -1431,7 +1431,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
self.set_graphics_bind_point();
unsafe {
self.raw.ExecuteIndirect(
self.signatures.draw_indexed.as_mut() as *mut _,
self.signatures.draw_indexed.as_raw(),
draw_count,
buffer.resource,
offset,
Expand Down Expand Up @@ -1470,7 +1470,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {

unsafe {
self.raw.BeginQuery(
query.pool.raw.as_mut() as *mut _,
query.pool.raw.as_raw(),
query_ty,
query.id,
);
Expand Down Expand Up @@ -1506,7 +1506,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {

unsafe {
self.raw.EndQuery(
query.pool.raw.as_mut() as *mut _,
query.pool.raw.as_raw(),
query_ty,
id,
);
Expand All @@ -1533,7 +1533,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
) {
unsafe {
self.raw.EndQuery(
query.pool.raw.as_mut() as *mut _,
query.pool.raw.as_raw(),
d3d12::D3D12_QUERY_TYPE_TIMESTAMP,
query.id,
);
Expand Down
22 changes: 11 additions & 11 deletions src/backend/dx12/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Device {
};
if !winerror::SUCCEEDED(hr) {
error!("D3DCompile error {:x}", hr);
let error = unsafe { ComPtr::<d3dcommon::ID3DBlob>::new(error) };
let error = unsafe { ComPtr::<d3dcommon::ID3DBlob>::from_raw(error) };
let message = unsafe {
let pointer = error.GetBufferPointer();
let size = error.GetBufferSize();
Expand Down Expand Up @@ -384,7 +384,7 @@ impl Device {
if !winerror::SUCCEEDED(hr) {
error!("error on command signature creation: {:x}", hr);
}
unsafe { ComPtr::new(signature) }
unsafe { ComPtr::from_raw(signature) }
}

pub(crate) fn create_descriptor_heap_impl(
Expand Down Expand Up @@ -423,7 +423,7 @@ impl Device {
let allocator = free_list::Allocator::new(capacity as _);

n::DescriptorHeap {
raw: unsafe { ComPtr::new(heap) },
raw: unsafe { ComPtr::from_raw(heap) },
handle_size: descriptor_size as _,
total_handles: capacity as _,
start: n::DualHandle {
Expand Down Expand Up @@ -746,7 +746,7 @@ impl d::Device<B> for Device {
};

Ok(n::Memory {
heap: unsafe { ComPtr::new(heap as _) },
heap: unsafe { ComPtr::from_raw(heap as _) },
type_id: mem_type,
size,
resource,
Expand All @@ -772,7 +772,7 @@ impl d::Device<B> for Device {
}

RawCommandPool {
inner: unsafe { ComPtr::new(command_allocator) },
inner: unsafe { ComPtr::from_raw(command_allocator) },
device: self.raw.clone(),
list_type,
signatures: self.signatures.clone(),
Expand Down Expand Up @@ -1397,7 +1397,7 @@ impl d::Device<B> for Device {

assert_eq!(winerror::S_OK, unsafe {
self.raw.clone().CreatePlacedResource(
memory.heap.as_mut(),
memory.heap.as_raw(),
offset,
&desc,
d3d12::D3D12_RESOURCE_STATE_COMMON,
Expand Down Expand Up @@ -1550,7 +1550,7 @@ impl d::Device<B> for Device {

assert_eq!(winerror::S_OK, unsafe {
self.raw.clone().CreatePlacedResource(
memory.heap.as_mut(),
memory.heap.as_raw(),
offset,
&image.desc,
d3d12::D3D12_RESOURCE_STATE_COMMON,
Expand Down Expand Up @@ -1987,7 +1987,7 @@ impl d::Device<B> for Device {

fn create_fence(&self, signalled: bool) -> n::Fence {
n::Fence {
raw: unsafe { ComPtr::new(self.create_raw_fence(signalled)) },
raw: unsafe { ComPtr::from_raw(self.create_raw_fence(signalled)) },
}
}

Expand Down Expand Up @@ -2073,7 +2073,7 @@ impl d::Device<B> for Device {
});

n::QueryPool {
raw: unsafe { ComPtr::new(handle as *mut _) },
raw: unsafe { ComPtr::from_raw(handle as *mut _) },
ty: heap_ty,
}
}
Expand Down Expand Up @@ -2203,7 +2203,7 @@ impl d::Device<B> for Device {
let hr = unsafe {
// TODO
surface.factory.CreateSwapChainForHwnd(
self.present_queue.as_mut() as *mut _ as *mut _,
self.present_queue.as_raw() as *mut _,
surface.wnd_handle,
&desc,
ptr::null(),
Expand All @@ -2216,7 +2216,7 @@ impl d::Device<B> for Device {
error!("error on swapchain creation 0x{:x}", hr);
}

let swap_chain = unsafe { ComPtr::<dxgi1_4::IDXGISwapChain3>::new(swap_chain as _) };
let swap_chain = unsafe { ComPtr::<dxgi1_4::IDXGISwapChain3>::from_raw(swap_chain as _) };

// Get backbuffer images
let images = (0 .. config.image_count).map(|i| {
Expand Down
74 changes: 39 additions & 35 deletions src/backend/dx12/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,22 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
};

// Create D3D12 device
let mut device_raw = ptr::null_mut();
let hr = unsafe {
d3d12::D3D12CreateDevice(
self.adapter.as_mut() as *mut _ as *mut _,
d3dcommon::D3D_FEATURE_LEVEL_11_0, // Minimum required feature level
&d3d12::IID_ID3D12Device,
&mut device_raw as *mut *mut _ as *mut *mut _,
)
let device_raw = {
let mut device_raw = ptr::null_mut();
let hr = unsafe {
d3d12::D3D12CreateDevice(
self.adapter.as_raw() as *mut _,
d3dcommon::D3D_FEATURE_LEVEL_11_0, // Minimum required feature level
&d3d12::IID_ID3D12Device,
&mut device_raw as *mut *mut _ as *mut *mut _,
)
};
if !winerror::SUCCEEDED(hr) {
error!("error on device creation: {:x}", hr);
}

unsafe { ComPtr::<d3d12::ID3D12Device>::from_raw(device_raw) }
};
if !winerror::SUCCEEDED(hr) {
error!("error on device creation: {:x}", hr);
}
let mut device = Device::new(
unsafe { ComPtr::new(device_raw) },
&self,
);

// Always create the presentation queue in case we want to build a swapchain.
let mut present_queue = {
Expand All @@ -222,7 +222,7 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {

let mut queue = ptr::null_mut();
let hr = unsafe {
device.raw.CreateCommandQueue(
device_raw.CreateCommandQueue(
&queue_desc,
&d3d12::IID_ID3D12CommandQueue,
&mut queue as *mut *mut _ as *mut *mut _,
Expand All @@ -233,9 +233,15 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
error!("error on queue creation: {:x}", hr);
}

unsafe { ComPtr::<d3d12::ID3D12CommandQueue>::new(queue) }
unsafe { ComPtr::<d3d12::ID3D12CommandQueue>::from_raw(queue) }
};

let mut device = Device::new(
device_raw,
&self,
present_queue,
);

let queue_groups = families
.into_iter()
.map(|(family, priorities)| {
Expand All @@ -256,7 +262,7 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
// Number of queues need to be larger than 0 else it
// violates the specification.
let queue = CommandQueue {
raw: present_queue.clone(),
raw: device.present_queue.clone(),
idle_fence: device.create_raw_fence(false),
idle_event: create_idle_event(),
};
Expand All @@ -283,7 +289,7 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {

if winerror::SUCCEEDED(hr) {
let queue = CommandQueue {
raw: unsafe { ComPtr::new(queue) },
raw: unsafe { ComPtr::from_raw(queue) },
idle_fence: device.create_raw_fence(false),
idle_event: create_idle_event(),
};
Expand All @@ -300,12 +306,6 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
})
.collect();

// Avoid calling drop on empty ComPtr
{
mem::swap(&mut device.present_queue, &mut present_queue);
mem::forget(present_queue);
}

*open_guard = true;

Ok(hal::Gpu {
Expand Down Expand Up @@ -358,7 +358,7 @@ impl hal::queue::RawCommandQueue<Backend> for CommandQueue {

if let Some(fence) = fence {
assert_eq!(winerror::S_OK,
self.raw.Signal(fence.raw.as_mut(), 1)
self.raw.Signal(fence.raw.as_raw(), 1)
);
}
}
Expand Down Expand Up @@ -435,7 +435,11 @@ unsafe impl Send for Device {} //blocked by ComPtr
unsafe impl Sync for Device {} //blocked by ComPtr

impl Device {
fn new(mut device: ComPtr<d3d12::ID3D12Device>, physical_device: &PhysicalDevice) -> Self {
fn new(
mut device: ComPtr<d3d12::ID3D12Device>,
physical_device: &PhysicalDevice,
present_queue: ComPtr<d3d12::ID3D12CommandQueue>,
) -> Self {
// Allocate descriptor heaps
let max_rtvs = 256; // TODO
let rtv_pool = native::DescriptorCpuPool {
Expand Down Expand Up @@ -548,7 +552,7 @@ impl Device {
draw_indexed: draw_indexed_signature,
dispatch: dispatch_signature,
},
present_queue: unsafe { ComPtr::new(ptr::null_mut()) }, // filled out on adapter opening
present_queue,
queues: Vec::new(),
open: physical_device.is_open.clone(),
}
Expand Down Expand Up @@ -609,7 +613,7 @@ impl Instance {
}

Instance {
factory: unsafe { ComPtr::new(dxgi_factory) },
factory: unsafe { ComPtr::from_raw(dxgi_factory) },
}
}
}
Expand All @@ -627,7 +631,7 @@ impl hal::Instance for Instance {
let adapter = {
let mut adapter: *mut dxgi::IDXGIAdapter1 = ptr::null_mut();
let hr = unsafe {
self.factory.as_mut().EnumAdapters1(
self.factory.EnumAdapters1(
cur_index,
&mut adapter as *mut *mut _)
};
Expand All @@ -636,7 +640,7 @@ impl hal::Instance for Instance {
break;
}

unsafe { ComPtr::new(adapter as *mut dxgi1_2::IDXGIAdapter2) }
unsafe { ComPtr::from_raw(adapter as *mut dxgi1_2::IDXGIAdapter2) }
};

cur_index += 1;
Expand All @@ -647,7 +651,7 @@ impl hal::Instance for Instance {
let mut device = ptr::null_mut();
let hr = unsafe {
d3d12::D3D12CreateDevice(
adapter.as_mut() as *mut _ as *mut _,
adapter.as_raw() as *mut _,
d3dcommon::D3D_FEATURE_LEVEL_11_0,
&d3d12::IID_ID3D12Device,
&mut device as *mut *mut _ as *mut *mut _,
Expand All @@ -657,7 +661,7 @@ impl hal::Instance for Instance {
continue;
}

unsafe { ComPtr::<d3d12::ID3D12Device>::new(device) }
unsafe { ComPtr::<d3d12::ID3D12Device>::from_raw(device) }
};

// We have found a possible adapter
Expand Down Expand Up @@ -798,12 +802,12 @@ impl hal::Instance for Instance {
let adapter = {
let mut adapter: *mut dxgi1_4::IDXGIAdapter3 = ptr::null_mut();
unsafe {
assert_eq!(winerror::S_OK, self.factory.as_mut().EnumAdapterByLuid(
assert_eq!(winerror::S_OK, self.factory.EnumAdapterByLuid(
adapter_id,
&dxgi1_4::IID_IDXGIAdapter3,
&mut adapter as *mut *mut _ as *mut *mut _,
));
ComPtr::new(adapter)
ComPtr::from_raw(adapter)
}
};

Expand Down
2 changes: 0 additions & 2 deletions src/backend/dx12/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ impl DescriptorSet {
unsafe {
self
.heap_srv_cbv_uav
.as_mut()
.GetGPUDescriptorHandleForHeapStart()
}
}
Expand All @@ -298,7 +297,6 @@ impl DescriptorSet {
unsafe {
self
.heap_samplers
.as_mut()
.GetGPUDescriptorHandleForHeapStart()
}
}
Expand Down
Loading