diff --git a/Cargo.toml b/Cargo.toml index 2ff7b679714..8e83e76aca0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,7 @@ gfx_window_sdl = { path = "src/window/sdl", version = "0.7" } [target.'cfg(windows)'.dependencies] gfx_device_dx11 = { path = "src/backend/dx11", version = "0.6" } -# gfx_device_dx12ll = { path = "src/backend/dx12ll", version = "0.1" } +gfx_device_dx12ll = { path = "src/backend/dx12ll", version = "0.1" } gfx_window_dxgi = { path = "src/window/dxgi", version = "0.8" } [[example]] diff --git a/appveyor.yml b/appveyor.yml index 3c68f5e244d..e912deec7f6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,8 +1,8 @@ environment: matrix: - - TARGET: 1.16.0-x86_64-pc-windows + - TARGET: 1.18.0-x86_64-pc-windows COMPILER: gnu - - TARGET: 1.16.0-x86_64-pc-windows + - TARGET: 1.18.0-x86_64-pc-windows COMPILER: msvc - TARGET: nightly-x86_64-pc-windows COMPILER: msvc diff --git a/examples/trianglell/main.rs b/examples/trianglell/main.rs index 676d04355e4..e3ffdbc1715 100644 --- a/examples/trianglell/main.rs +++ b/examples/trianglell/main.rs @@ -24,7 +24,7 @@ extern crate gfx_device_metalll as back; extern crate winit; extern crate image; -use gfx_corell::{buffer, command, format, pass, pso, shade, state, target, +use gfx_corell::{buffer, command, format, pass, pso, shade, state, target, Device, CommandPool, GraphicsCommandPool, CommandQueue, GraphicsCommandBuffer, ProcessingCommandBuffer, TransferCommandBuffer, PrimaryCommandBuffer, Primitive, Instance, Adapter, Surface, SwapChain, QueueFamily, QueueSubmit, Factory, SubPass, FrameSync}; @@ -75,7 +75,7 @@ fn main() { let surface = instance.create_surface(&window); let queue_descs = physical_devices[0].get_queue_families().map(|family| { (family, family.num_queues()) }); - + for device in &physical_devices { println!("{:?}", device.get_info()); } @@ -376,7 +376,7 @@ fn main() { None, ); } - + // let mut running = true; while running { @@ -416,7 +416,7 @@ fn main() { } // TODO: should transition to (_, Present) -> Present (for d3d12) - + cmd_buffer.finish() }; diff --git a/src/backend/dx12ll/src/command.rs b/src/backend/dx12ll/src/command.rs index 469aa41a6b2..a385aefa7c2 100644 --- a/src/backend/dx12ll/src/command.rs +++ b/src/backend/dx12ll/src/command.rs @@ -13,11 +13,13 @@ // limitations under the License. use comptr::ComPtr; +use std::ops; use std::ptr; use winapi; use winapi::*; use core::{self, command, memory, pso, state, target, IndexType, VertexCount, VertexOffset}; +use core::buffer::IndexBufferView; use data; use native::{self, CommandBuffer, GeneralCommandBuffer, GraphicsCommandBuffer, ComputeCommandBuffer, TransferCommandBuffer, SubpassCommandBuffer, RenderPass, FrameBuffer}; @@ -36,10 +38,15 @@ impl CommandBuffer { { let mut transition_barriers = Vec::new(); - // TODO: very experimental state! for barrier in image_barriers { - let state_src = data::map_resource_state(barrier.state_src); - let state_dst = data::map_resource_state(barrier.state_dst); + let state_src = match barrier.state_src { + memory::ImageStateSrc::Present(access) => unimplemented!(), + memory::ImageStateSrc::State(access, layout) => data::map_image_resource_state(access, layout) + }; + let state_dst = match barrier.state_dst { + memory::ImageStateDst::Present => unimplemented!(), + memory::ImageStateDst::State(access, layout) => data::map_image_resource_state(access, layout) + }; transition_barriers.push( winapi::D3D12_RESOURCE_BARRIER { @@ -71,31 +78,28 @@ impl CommandBuffer { unimplemented!() } - fn copy_buffer(&mut self, src: &native::Buffer, dst: &native::Buffer, regions: Option<&[command::BufferCopy]>) { - match regions { - Some(regions) => { - // copy each region - for region in regions { - unsafe { - self.inner.CopyBufferRegion( - dst.resource.as_mut_ptr(), // pDstResource - region.dst as UINT64, // DstOffset - src.resource.as_mut_ptr(), // pSrcResource - region.src as UINT64, // SrcOffset - region.size as UINT64, // NumBytes - ); - } - } - } - None => { - // copy the whole resource + fn copy_buffer(&mut self, src: &native::Buffer, dst: &native::Buffer, regions: &[command::BufferCopy]) { + if true { //TODO + // copy each region + for region in regions { unsafe { - self.inner.CopyResource( + self.inner.CopyBufferRegion( dst.resource.as_mut_ptr(), // pDstResource + region.dst as UINT64, // DstOffset src.resource.as_mut_ptr(), // pSrcResource + region.src as UINT64, // SrcOffset + region.size as UINT64, // NumBytes ); } } + } else { + // copy the whole resource + unsafe { + self.inner.CopyResource( + dst.resource.as_mut_ptr(), // pDstResource + src.resource.as_mut_ptr(), // pSrcResource + ); + } } } @@ -103,7 +107,7 @@ impl CommandBuffer { unimplemented!() } - fn copy_buffer_to_image(&mut self) { + fn copy_buffer_to_image(&mut self, src: &native::Buffer, dst: &native::Image, layout: memory::ImageLayout, regions: &[command::BufferImageCopy]) { unimplemented!() } @@ -140,7 +144,11 @@ impl CommandBuffer { unimplemented!() } - fn bind_descriptor_sets(&mut self) { + fn bind_descriptor_heaps(&mut self, srv_cbv_uav: Option<&native::DescriptorHeap>, samplers: Option<&native::DescriptorHeap>) { + unimplemented!() + } + + fn bind_descriptor_sets(&mut self, layout: &native::PipelineLayout, first_set: usize, sets: &[&native::DescriptorSet]) { unimplemented!() } @@ -207,21 +215,23 @@ impl CommandBuffer { unimplemented!() } - fn bind_index_buffer(&mut self, ib: &native::Buffer, index_type: IndexType) { - let format = match index_type { + fn bind_index_buffer(&mut self, ibv: IndexBufferView) { + let format = match ibv.index_type { IndexType::U16 => winapi::DXGI_FORMAT_R16_UINT, IndexType::U32 => winapi::DXGI_FORMAT_R32_UINT, }; - let location = unsafe { (*ib.resource.as_mut_ptr()).GetGPUVirtualAddress() }; + let location = unsafe { + (*ibv.buffer.resource.as_mut_ptr()).GetGPUVirtualAddress() + }; - let mut ibv = winapi::D3D12_INDEX_BUFFER_VIEW { + let mut ibv_raw = winapi::D3D12_INDEX_BUFFER_VIEW { BufferLocation: location, - SizeInBytes: ib.size, + SizeInBytes: ibv.buffer.size, Format: format, }; unsafe { - self.inner.IASetIndexBuffer(&mut ibv); + self.inner.IASetIndexBuffer(&mut ibv_raw); } } @@ -318,8 +328,8 @@ macro_rules! impl_processing_cmd_buffer { self.0.clear_buffer() } - fn bind_descriptor_sets(&mut self) { - self.0.bind_descriptor_sets() + fn bind_descriptor_heaps(&mut self, srv_cbv_uav: Option<&native::DescriptorHeap>, samplers: Option<&native::DescriptorHeap>) { + self.0.bind_descriptor_heaps(srv_cbv_uav, samplers) } fn push_constants(&mut self) { @@ -341,7 +351,7 @@ macro_rules! impl_transfer_cmd_buffer { self.0.update_buffer(buffer, data, offset) } - fn copy_buffer(&mut self, src: &native::Buffer, dest: &native::Buffer, regions: Option<&[command::BufferCopy]>) { + fn copy_buffer(&mut self, src: &native::Buffer, dest: &native::Buffer, regions: &[command::BufferCopy]) { self.0.copy_buffer(src, dest, regions) } @@ -349,13 +359,13 @@ macro_rules! impl_transfer_cmd_buffer { self.0.copy_image(src, dest) } - fn copy_buffer_to_image(&mut self) { - self.0.copy_buffer_to_image() + fn copy_buffer_to_image(&mut self, src: &native::Buffer, dst: &native::Image, layout: memory::ImageLayout, regions: &[command::BufferImageCopy]) { + self.0.copy_buffer_to_image(src, dst, layout, regions) } fn copy_image_to_buffer(&mut self) { self.0.copy_image_to_buffer() - } + } } ) } @@ -377,8 +387,8 @@ macro_rules! impl_graphics_cmd_buffer { self.0.resolve_image() } - fn bind_index_buffer(&mut self, buffer: &native::Buffer, index_type: IndexType) { - self.0.bind_index_buffer(buffer, index_type) + fn bind_index_buffer(&mut self, ibv: IndexBufferView) { + self.0.bind_index_buffer(ibv) } fn bind_vertex_buffers(&mut self, vbs: pso::VertexBufferSet) { @@ -400,6 +410,10 @@ macro_rules! impl_graphics_cmd_buffer { fn bind_graphics_pipeline(&mut self, pipeline: &native::GraphicsPipeline) { self.0.bind_graphics_pipeline(pipeline) } + + fn bind_graphics_descriptor_sets(&mut self, layout: &native::PipelineLayout, first_set: usize, sets: &[&native::DescriptorSet]) { + self.0.bind_descriptor_sets(layout, first_set, sets) + } } ) } @@ -431,85 +445,86 @@ impl_graphics_cmd_buffer!(ComputeCommandBuffer); // TODO: subpass command buffer -pub struct RenderPassInlineEncoder<'cb, 'rp, 'fb> { - command_list: &'cb mut GraphicsCommandBuffer, +pub struct RenderPassInlineEncoder<'cb, 'rp, 'fb, 'enc: 'cb> { + command_buffer: &'cb mut command::Encoder<'enc, GraphicsCommandBuffer>, render_pass: &'rp RenderPass, framebuffer: &'fb FrameBuffer, } -impl<'cb, 'rp, 'fb> command::RenderPassEncoder<'cb, 'rp, 'fb, GraphicsCommandBuffer, R> for RenderPassInlineEncoder<'cb, 'rp, 'fb> { - type SecondaryEncoder = RenderPassSecondaryEncoder<'cb, 'rp, 'fb>; - type InlineEncoder = RenderPassInlineEncoder<'cb, 'rp, 'fb>; +impl<'cb, 'rp, 'fb, 'enc> command::RenderPassEncoder<'cb, 'rp, 'fb, 'enc, GraphicsCommandBuffer, R> for RenderPassInlineEncoder<'cb, 'rp, 'fb, 'enc> { + type SecondaryEncoder = RenderPassSecondaryEncoder<'cb, 'rp, 'fb, 'enc>; + type InlineEncoder = RenderPassInlineEncoder<'cb, 'rp, 'fb, 'enc>; - fn begin(command_buffer: &'cb mut GraphicsCommandBuffer, + fn begin(command_buffer: &'cb mut command::Encoder<'enc, GraphicsCommandBuffer>, render_pass: &'rp RenderPass, framebuffer: &'fb FrameBuffer, render_area: target::Rect, clear_values: &[command::ClearValue] ) -> Self { RenderPassInlineEncoder { - command_list: command_buffer, - render_pass: render_pass, - framebuffer: framebuffer, + command_buffer, + render_pass, + framebuffer, } } - fn next_subpass(self) -> RenderPassSecondaryEncoder<'cb, 'rp, 'fb> { + fn next_subpass(self) -> Self::SecondaryEncoder { unimplemented!() } - fn next_subpass_inline(self) -> RenderPassInlineEncoder<'cb, 'rp, 'fb>{ + fn next_subpass_inline(self) -> Self::InlineEncoder { unimplemented!() } } -impl<'cb, 'rp, 'fb> command::RenderPassInlineEncoder<'cb, 'rp, 'fb, GraphicsCommandBuffer, R> for RenderPassInlineEncoder<'cb, 'rp, 'fb> { +impl<'cb, 'rp, 'fb, 'enc> command::RenderPassInlineEncoder<'cb, 'rp, 'fb, 'enc, GraphicsCommandBuffer, R> for RenderPassInlineEncoder<'cb, 'rp, 'fb, 'enc> { fn clear_attachment(&mut self) { - + unimplemented!() } fn draw(&mut self, start: VertexCount, count: VertexCount, instance: Option) { - self.command_list.0.draw(start, count, instance) + self.command_buffer.0.draw(start, count, instance) } fn draw_indexed(&mut self, start: VertexCount, count: VertexCount, base: VertexOffset, instance: Option) { - + unimplemented!() } fn draw_indirect(&mut self) { - + unimplemented!() } fn draw_indexed_indirect(&mut self) { - + unimplemented!() } - fn bind_index_buffer(&mut self, ib: &native::Buffer, index_type: IndexType) { - + fn bind_index_buffer(&mut self, ibv: IndexBufferView) { + unimplemented!() } fn bind_vertex_buffers(&mut self, vbs: pso::VertexBufferSet) { - + unimplemented!() } fn set_viewports(&mut self, viewports: &[target::Rect]) { - self.command_list.0.set_viewports(viewports) + self.command_buffer.0.set_viewports(viewports) } fn set_scissors(&mut self, scissors: &[target::Rect]) { - self.command_list.0.set_scissors(scissors) + self.command_buffer.0.set_scissors(scissors) } fn set_ref_values(&mut self, rv: state::RefValues) { - self.command_list.0.set_ref_values(rv) + self.command_buffer.0.set_ref_values(rv) } fn bind_graphics_pipeline(&mut self, pipeline: &native::GraphicsPipeline) { - self.command_list.0.bind_graphics_pipeline(pipeline) + self.command_buffer.0.bind_graphics_pipeline(pipeline) } - fn bind_descriptor_sets(&mut self) { - + fn bind_graphics_descriptor_sets(&mut self, layout: &native::PipelineLayout, first_set: usize, sets: &[&native::DescriptorSet]) { + //self.0.bind_descriptor_sets(vk::PipelineBindPoint::Graphics, layout, first_set, sets) + unimplemented!() } fn push_constants(&mut self) { @@ -517,36 +532,36 @@ impl<'cb, 'rp, 'fb> command::RenderPassInlineEncoder<'cb, 'rp, 'fb, GraphicsComm } } -pub struct RenderPassSecondaryEncoder<'cb, 'rp, 'fb> { - command_list: &'cb mut GraphicsCommandBuffer, +pub struct RenderPassSecondaryEncoder<'cb, 'rp, 'fb, 'enc: 'cb> { + command_buffer: &'cb mut command::Encoder<'enc, GraphicsCommandBuffer>, render_pass: &'rp RenderPass, framebuffer: &'fb FrameBuffer, } -impl<'cb, 'rp, 'fb> command::RenderPassEncoder<'cb, 'rp, 'fb, GraphicsCommandBuffer, R> for RenderPassSecondaryEncoder<'cb, 'rp, 'fb> { - type SecondaryEncoder = RenderPassSecondaryEncoder<'cb, 'rp, 'fb>; - type InlineEncoder = RenderPassInlineEncoder<'cb, 'rp, 'fb>; +impl<'cb, 'rp, 'fb, 'enc> command::RenderPassEncoder<'cb, 'rp, 'fb, 'enc, GraphicsCommandBuffer, R> for RenderPassSecondaryEncoder<'cb, 'rp, 'fb, 'enc> { + type SecondaryEncoder = RenderPassSecondaryEncoder<'cb, 'rp, 'fb, 'enc>; + type InlineEncoder = RenderPassInlineEncoder<'cb, 'rp, 'fb, 'enc>; - fn begin(command_buffer: &'cb mut GraphicsCommandBuffer, + fn begin(command_buffer: &'cb mut command::Encoder<'enc, GraphicsCommandBuffer>, render_pass: &'rp RenderPass, framebuffer: &'fb FrameBuffer, render_area: target::Rect, clear_values: &[command::ClearValue] ) -> Self { RenderPassSecondaryEncoder { - command_list: command_buffer, - render_pass: render_pass, - framebuffer: framebuffer, + command_buffer, + render_pass, + framebuffer, } } - fn next_subpass(self) -> RenderPassSecondaryEncoder<'cb, 'rp, 'fb> { + fn next_subpass(self) -> Self::SecondaryEncoder { unimplemented!() } - fn next_subpass_inline(self) -> RenderPassInlineEncoder<'cb, 'rp, 'fb>{ + fn next_subpass_inline(self) -> Self::InlineEncoder { unimplemented!() } } -impl<'cb, 'rp, 'fb> command::RenderPassSecondaryEncoder<'cb, 'rp, 'fb, GraphicsCommandBuffer, R> for RenderPassSecondaryEncoder<'cb, 'rp, 'fb> { } +impl<'cb, 'rp, 'fb, 'enc> command::RenderPassSecondaryEncoder<'cb, 'rp, 'fb, 'enc, GraphicsCommandBuffer, R> for RenderPassSecondaryEncoder<'cb, 'rp, 'fb, 'enc> { } diff --git a/src/backend/dx12ll/src/data.rs b/src/backend/dx12ll/src/data.rs index 153b6cba491..fe26c7eb4d0 100644 --- a/src/backend/dx12ll/src/data.rs +++ b/src/backend/dx12ll/src/data.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::memory::{self, ResourceState}; +use core::memory::{self, ImageAccess, ImageLayout}; use core::format::Format; use winapi::*; @@ -129,40 +129,29 @@ pub fn map_format(format: Format, is_target: bool) -> Option { }) } -pub fn map_resource_state(resource_state: ResourceState) -> D3D12_RESOURCE_STATES { - // TODO: A huge puzzle \o/ +//TODO: map_buffer_resource_stat { + //handle D3D12_RESOURCE_STATE_INDEX_BUFFER +//} + +pub fn map_image_resource_state(access: ImageAccess, _layout: ImageLayout) -> D3D12_RESOURCE_STATES { let mut state = D3D12_RESOURCE_STATE_COMMON; - if resource_state.contains(memory::INDEX_BUFFER_READ) { - state = state | D3D12_RESOURCE_STATE_INDEX_BUFFER; - } - if resource_state.contains(memory::VERTEX_BUFFER_READ) || - resource_state.contains(memory::CONSTANT_BUFFER_READ) { - state = state | D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER; - } - if resource_state.contains(memory::INDIRECT_COMMAND_READ) { - state = state | D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT; - } - if resource_state.contains(memory::RENDER_TARGET_CLEAR) { + if access.contains(memory::RENDER_TARGET_CLEAR) { state = state | D3D12_RESOURCE_STATE_RENDER_TARGET; } - /* - if resource_state.contains(memory::TRANSFER_SRC) { - state = state | D3D12_RESOURCE_STATE_COPY_SOURCE; - } - if resource_state.contains(memory::TRANSFER_DST) { - state = state | D3D12_RESOURCE_STATE_COPY_DEST; - } - */ - if resource_state.contains(memory::RESOLVE_SRC) { + + if access.contains(memory::RESOLVE_SRC) { state = state | D3D12_RESOURCE_STATE_RESOLVE_SOURCE; } - if resource_state.contains(memory::RESOLVE_DST) { + if access.contains(memory::RESOLVE_DST) { state = state | D3D12_RESOURCE_STATE_RESOLVE_DEST; } - if resource_state.contains(memory::PRESENT) { - state = state | D3D12_RESOURCE_STATE_PRESENT; + if access.contains(memory::TRANSFER_READ) { + state = state | D3D12_RESOURCE_STATE_COPY_SOURCE; + } + if access.contains(memory::TRANSFER_WRITE) { + state = state | D3D12_RESOURCE_STATE_COPY_DEST; } state diff --git a/src/backend/dx12ll/src/factory.rs b/src/backend/dx12ll/src/factory.rs index 37f3eed1a81..0963179c5b4 100644 --- a/src/backend/dx12ll/src/factory.rs +++ b/src/backend/dx12ll/src/factory.rs @@ -23,12 +23,22 @@ use std::{mem, ptr}; use std::os::raw::c_void; use std::collections::BTreeMap; -use core::{self, shade, factory as f}; -use core::SubPass; +use core::{self, buffer, format, image, mapping, memory, pass, shade, factory as f}; use core::pso::{self, EntryPoint}; use {data, state, mirror, native}; use {Factory, Resources as R}; + +#[derive(Debug)] +pub struct UnboundBuffer(native::Buffer); + +#[derive(Debug)] +pub struct UnboundImage(native::Image); + +pub struct Mapping { + //TODO +} + impl Factory { pub fn create_shader_library(&mut self, shaders: &[(EntryPoint, &[u8])]) -> Result { let mut shader_map = BTreeMap::new(); @@ -90,11 +100,17 @@ impl Factory { } impl core::Factory for Factory { - fn create_renderpass(&mut self) -> native::RenderPass { + fn create_heap(&mut self, heap_type: &core::HeapType, size: u64) -> native::Heap { + unimplemented!() + } + + fn create_renderpass(&mut self, attachments: &[pass::Attachment], + subpasses: &[pass::SubpassDesc], dependencies: &[pass::SubpassDependency]) -> native::RenderPass + { unimplemented!() } - fn create_pipeline_layout(&mut self) -> native::PipelineLayout { + fn create_pipeline_layout(&mut self, sets: &[&native::DescriptorSetLayout]) -> native::PipelineLayout { let desc = winapi::D3D12_ROOT_SIGNATURE_DESC { NumParameters: 0, pParameters: ptr::null(), @@ -126,7 +142,7 @@ impl core::Factory for Factory { native::PipelineLayout { inner: signature } } - fn create_graphics_pipelines<'a>(&mut self, descs: &[(&native::ShaderLib, &native::PipelineLayout, SubPass<'a, R>, &pso::GraphicsPipelineDesc)]) + fn create_graphics_pipelines<'a>(&mut self, descs: &[(&native::ShaderLib, &native::PipelineLayout, core::SubPass<'a, R>, &pso::GraphicsPipelineDesc)]) -> Vec> { descs.iter().map(|&(shader_lib, ref signature, _, ref desc)| { @@ -203,7 +219,7 @@ impl core::Factory for Factory { Some((format, _)) => { *rtv = data::map_format(format, true) .unwrap_or(winapi::DXGI_FORMAT_UNKNOWN); - num_rtvs += 1; + num_rtvs += 1; } None => break, } @@ -211,7 +227,7 @@ impl core::Factory for Factory { (rtvs, num_rtvs) }; - + // Setup pipeline description let pso_desc = winapi::D3D12_GRAPHICS_PIPELINE_STATE_DESC { pRootSignature: signature.inner.as_mut_ptr(), // TODO @@ -278,18 +294,52 @@ impl core::Factory for Factory { }).collect() } - fn create_compute_pipelines(&mut self) -> Vec> { + fn create_compute_pipelines(&mut self, descs: &[(&native::ShaderLib, EntryPoint, &native::PipelineLayout)]) -> Vec> { unimplemented!() } fn create_framebuffer(&mut self, renderpass: &native::RenderPass, - color_attachments: &[native::RenderTargetView], depth_stencil_attachments: &[native::DepthStencilView], + color_attachments: &[&native::RenderTargetView], depth_stencil_attachments: &[&native::DepthStencilView], width: u32, height: u32, layers: u32) -> native::FrameBuffer { unimplemented!() } - fn view_image_as_render_target(&mut self, image: &native::Image) -> Result { + fn create_sampler(&mut self, sampler_info: image::SamplerInfo) -> native::Sampler { + unimplemented!() + } + + fn create_buffer(&mut self, size: u64, usage: buffer::Usage) -> Result { + unimplemented!() + } + + fn get_buffer_requirements(&mut self, buffer: &UnboundBuffer) -> memory::MemoryRequirements { + unimplemented!() + } + + fn bind_buffer_memory(&mut self, heap: &native::Heap, offset: u64, buffer: UnboundBuffer) -> Result { + unimplemented!() + } + + fn create_image(&mut self, kind: image::Kind, mip_levels: image::Level, format: format::Format, usage: image::Usage) + -> Result + { + unimplemented!() + } + + fn get_image_requirements(&mut self, image: &UnboundImage) -> memory::MemoryRequirements { + unimplemented!() + } + + fn bind_image_memory(&mut self, heap: &native::Heap, offset: u64, image: UnboundImage) -> Result { + unimplemented!() + } + + fn view_buffer_as_constant(&mut self, buffer: &native::Buffer, offset: usize, size: usize) -> Result { + unimplemented!() + } + + fn view_image_as_render_target(&mut self, image: &native::Image, format: format::Format) -> Result { // TODO: basic implementation only, needs checks and multiple heaps let mut handle = winapi::D3D12_CPU_DESCRIPTOR_HANDLE { ptr: 0 }; unsafe { self.rtv_heap.GetCPUDescriptorHandleForHeapStart(&mut handle) }; @@ -308,4 +358,140 @@ impl core::Factory for Factory { self.next_rtv += 1; Ok(rtv) } + + fn view_image_as_shader_resource(&mut self, image: &native::Image, format: format::Format) -> Result { + unimplemented!() + } + + fn view_image_as_unordered_access(&mut self, image: &native::Image, format: format::Format) -> Result { + unimplemented!() + } + + fn create_descriptor_heap(&mut self, ty: f::DescriptorHeapType, size: usize) -> native::DescriptorHeap { + unimplemented!() + } + + fn create_descriptor_set_pool(&mut self, heap: &native::DescriptorHeap, max_sets: usize, offset: usize, descriptor_pools: &[f::DescriptorPoolDesc]) -> native::DescriptorSetPool { + unimplemented!() + } + + fn create_descriptor_set_layout(&mut self, bindings: &[f::DescriptorSetLayoutBinding]) -> native::DescriptorSetLayout { + unimplemented!() + } + + fn create_descriptor_sets(&mut self, set_pool: &mut native::DescriptorSetPool, layouts: &[&native::DescriptorSetLayout]) -> Vec { + unimplemented!() + } + + fn reset_descriptor_set_pool(&mut self, pool: &mut native::DescriptorSetPool) { + unimplemented!() + } + + fn update_descriptor_sets(&mut self, writes: &[f::DescriptorSetWrite]) { + unimplemented!() + } + + /// Acquire a mapping Reader. + fn read_mapping<'a, T>(&self, buf: &'a native::Buffer, offset: u64, size: u64) + -> Result, mapping::Error> + where T: Copy + { + unimplemented!() + } + + /// Acquire a mapping Writer + fn write_mapping<'a, 'b, T>(&mut self, buf: &'a native::Buffer, offset: u64, size: u64) + -> Result, mapping::Error> + where T: Copy + { + unimplemented!() + } + + fn create_semaphore(&mut self) -> native::Semaphore { + unimplemented!() + } + + fn create_fence(&mut self, signaled: bool) -> native::Fence { + unimplemented!() + } + + fn reset_fences(&mut self, fences: &[&native::Fence]) { + unimplemented!() + } + + fn destroy_heap(&mut self, heap: native::Heap) { + unimplemented!() + } + + fn destroy_shader_lib(&mut self, shader_lib: native::ShaderLib) { + unimplemented!() + } + + fn destroy_renderpass(&mut self, rp: native::RenderPass) { + unimplemented!() + } + + fn destroy_pipeline_layout(&mut self, pl: native::PipelineLayout) { + unimplemented!() + } + + fn destroy_graphics_pipeline(&mut self, pipeline: native::GraphicsPipeline) { + unimplemented!() + } + + fn destroy_compute_pipeline(&mut self, pipeline: native::ComputePipeline) { + unimplemented!() + } + + fn destroy_framebuffer(&mut self, fb: native::FrameBuffer) { + unimplemented!() + } + + fn destroy_buffer(&mut self, buffer: native::Buffer) { + unimplemented!() + } + + fn destroy_image(&mut self, image: native::Image) { + unimplemented!() + } + + fn destroy_render_target_view(&mut self, rtv: native::RenderTargetView) { + unimplemented!() + } + + fn destroy_constant_buffer_view(&mut self, _: native::ConstantBufferView) { + unimplemented!() + } + + fn destroy_shader_resource_view(&mut self, srv: native::ShaderResourceView) { + unimplemented!() + } + + fn destroy_unordered_access_view(&mut self, uav: native::UnorderedAccessView) { + unimplemented!() + } + + fn destroy_sampler(&mut self, sampler: native::Sampler) { + unimplemented!() + } + + fn destroy_descriptor_heap(&mut self, heap: native::DescriptorHeap) { + unimplemented!() + } + + fn destroy_descriptor_set_pool(&mut self, pool: native::DescriptorSetPool) { + unimplemented!() + } + + fn destroy_descriptor_set_layout(&mut self, layout: native::DescriptorSetLayout) { + unimplemented!() + } + + fn destroy_fence(&mut self, fence: native::Fence) { + unimplemented!() + } + + fn destroy_semaphore(&mut self, semaphore: native::Semaphore) { + unimplemented!() + } } diff --git a/src/backend/dx12ll/src/lib.rs b/src/backend/dx12ll/src/lib.rs index 3d4e3e79965..1105af04bcd 100644 --- a/src/backend/dx12ll/src/lib.rs +++ b/src/backend/dx12ll/src/lib.rs @@ -43,6 +43,7 @@ mod native; mod pool; mod state; +pub use command::{RenderPassInlineEncoder, RenderPassSecondaryEncoder}; pub use pool::{GeneralCommandPool, GraphicsCommandPool, ComputeCommandPool, TransferCommandPool, SubpassCommandPool}; @@ -53,7 +54,7 @@ impl core::QueueFamily for QueueFamily { type Surface = Surface; fn supports_present(&self, _surface: &Surface) -> bool { - // + // true } @@ -129,14 +130,19 @@ impl core::Adapter for Adapter { }).collect::>() }).collect(); + let heap_types = unimplemented!(); + let memory_heaps = unimplemented!(); + let factory = Factory::new(device); core::Device { - factory: factory, - general_queues: general_queues, + factory, + general_queues, graphics_queues: Vec::new(), compute_queues: Vec::new(), transfer_queues: Vec::new(), + heap_types, + memory_heaps, _marker: std::marker::PhantomData, } } @@ -208,15 +214,19 @@ impl core::CommandQueue for CommandQueue { type TransferCommandBuffer = native::TransferCommandBuffer; type SubpassCommandBuffer = native::SubpassCommandBuffer; - unsafe fn submit(&mut self, submit: &[Submit]) + unsafe fn submit(&mut self, submit_infos: &[core::QueueSubmit], fence: Option<&mut native::Fence>) where C: core::CommandBuffer { - let mut command_lists = submit.iter().map(|submit| { - submit.get_info().0.as_mut_ptr() + let mut command_lists = submit_infos.iter().map(|submit| { + submit.cmd_buffers.as_ptr() }).collect::>(); self.inner.ExecuteCommandLists(command_lists.len() as u32, command_lists.as_mut_ptr() as *mut *mut _); } + + fn wait_idle(&mut self) { + unimplemented!() + } } pub struct Surface { @@ -298,14 +308,16 @@ pub struct SwapChain { images: Vec, } -impl<'a> core::SwapChain for SwapChain{ +impl<'a> core::SwapChain for SwapChain { + type R = Resources; type Image = native::Image; fn get_images(&mut self) -> &[native::Image] { &self.images } - fn acquire_frame(&mut self) -> core::Frame { + fn acquire_frame(&mut self, sync: core::FrameSync) -> core::Frame { + //TODO: use sync // TODO: we need to block this at some point? (running out of backbuffers) let num_images = self.images.len(); let index = self.next_frame; @@ -457,14 +469,23 @@ impl core::Resources for Resources { type PipelineLayout = native::PipelineLayout; type GraphicsPipeline = native::GraphicsPipeline; type ComputePipeline = native::ComputePipeline; + type UnboundBuffer = factory::UnboundBuffer; type Buffer = native::Buffer; + type UnboundImage = factory::UnboundImage; type Image = native::Image; - type ShaderResourceView = (); - type UnorderedAccessView = (); + type ConstantBufferView = native::ConstantBufferView; + type ShaderResourceView = native::ShaderResourceView; + type UnorderedAccessView = native::UnorderedAccessView; type RenderTargetView = native::RenderTargetView; type DepthStencilView = native::DepthStencilView; type FrameBuffer = native::FrameBuffer; - type Sampler = (); - type Fence = (); - type Semaphore = (); + type Sampler = native::Sampler; + type Semaphore = native::Semaphore; + type Fence = native::Fence; + type Heap = native::Heap; + type Mapping = factory::Mapping; + type DescriptorHeap = native::DescriptorHeap; + type DescriptorSet = native::DescriptorSet; + type DescriptorSetPool = native::DescriptorSetPool; + type DescriptorSetLayout = native::DescriptorSetLayout; } diff --git a/src/backend/dx12ll/src/native.rs b/src/backend/dx12ll/src/native.rs index eb5eda55f5b..5f152d562d5 100644 --- a/src/backend/dx12ll/src/native.rs +++ b/src/backend/dx12ll/src/native.rs @@ -65,6 +65,11 @@ pub struct TransferCommandBuffer(pub CommandBuffer); pub struct SubpassCommandBuffer(pub CommandBuffer); +#[derive(Debug, Hash)] +pub struct Heap { + //TODO +} + #[derive(Clone, Debug, Hash)] pub struct Buffer { pub resource: ComPtr, @@ -80,6 +85,25 @@ pub struct Image { unsafe impl Send for Image {} unsafe impl Sync for Image {} +#[derive(Debug, Hash)] +pub struct Sampler { + //TODO +} + +#[derive(Debug, Hash)] +pub struct ConstantBufferView { + //TODO +} + +#[derive(Debug, Hash)] +pub struct ShaderResourceView { +} + +#[derive(Debug, Hash)] +pub struct UnorderedAccessView { +} + + #[derive(Clone, Debug)] pub struct RenderTargetView { pub handle: winapi::D3D12_CPU_DESCRIPTOR_HANDLE, @@ -91,10 +115,26 @@ pub struct DepthStencilView { } #[derive(Debug)] -pub struct Fence; +pub struct Semaphore; #[derive(Debug)] -pub struct Semaphore; +pub struct Fence; #[derive(Debug)] pub struct FrameBuffer; + +#[derive(Debug)] +pub struct DescriptorHeap { +} + +#[derive(Debug)] +pub struct DescriptorSetPool { +} + +#[derive(Debug)] +pub struct DescriptorSet { +} + +#[derive(Debug)] +pub struct DescriptorSetLayout { +} diff --git a/src/backend/vulkanll/src/command.rs b/src/backend/vulkanll/src/command.rs index 98f2a36ce61..2f30ded9686 100644 --- a/src/backend/vulkanll/src/command.rs +++ b/src/backend/vulkanll/src/command.rs @@ -53,7 +53,7 @@ impl CommandBuffer { // TODO let base_range = vk::ImageSubresourceRange { aspect_mask: vk::IMAGE_ASPECT_COLOR_BIT, - base_mip_level: 0, + base_mip_level: 0, level_count: 1, base_array_layer: 0, layer_count: vk::VK_REMAINING_ARRAY_LAYERS, @@ -167,7 +167,7 @@ impl CommandBuffer { // TODO: use actual subresource range from rtv let base_range = vk::ImageSubresourceRange { aspect_mask: vk::IMAGE_ASPECT_COLOR_BIT, - base_mip_level: 0, + base_mip_level: 0, level_count: 1, base_array_layer: 0, layer_count: vk::VK_REMAINING_ARRAY_LAYERS, @@ -465,7 +465,7 @@ macro_rules! impl_transfer_cmd_buffer { fn copy_image_to_buffer(&mut self) { self.0.copy_image_to_buffer() - } + } } ) } @@ -615,9 +615,9 @@ impl<'cb, 'rp, 'fb, 'enc, C> command::RenderPassEncoder<'cb, 'rp, 'fb, 'enc, C, } RenderPassInlineEncoder { - command_buffer: command_buffer, - render_pass: render_pass, - framebuffer: framebuffer, + command_buffer, + render_pass, + framebuffer, _marker: PhantomData, } }