Skip to content

Commit

Permalink
Make DX12 ~~great~~ compile again!
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jun 8, 2017
1 parent 190728a commit 7fb8e62
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 138 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
8 changes: 4 additions & 4 deletions examples/trianglell/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -376,7 +376,7 @@ fn main() {
None,
);
}

//
let mut running = true;
while running {
Expand Down Expand Up @@ -416,7 +416,7 @@ fn main() {
}

// TODO: should transition to (_, Present) -> Present (for d3d12)

cmd_buffer.finish()
};

Expand Down
167 changes: 91 additions & 76 deletions src/backend/dx12ll/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 {
Expand Down Expand Up @@ -71,39 +78,36 @@ 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
);
}
}
}

fn copy_image(&mut self, src: &native::Image, dest: &native::Image) {
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!()
}

Expand Down Expand Up @@ -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!()
}

Expand Down Expand Up @@ -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<R>) {
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);
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -341,21 +351,21 @@ 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)
}

fn copy_image(&mut self, src: &native::Image, dest: &native::Image) {
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()
}
}
}
)
}
Expand All @@ -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<R>) {
self.0.bind_index_buffer(ibv)
}

fn bind_vertex_buffers(&mut self, vbs: pso::VertexBufferSet<R>) {
Expand All @@ -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)
}
}
)
}
Expand Down Expand Up @@ -431,122 +445,123 @@ 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<command::InstanceParams>) {
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<command::InstanceParams>) {

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<R>) {
unimplemented!()
}

fn bind_vertex_buffers(&mut self, vbs: pso::VertexBufferSet<R>) {

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) {

}
}

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> { }
Loading

0 comments on commit 7fb8e62

Please sign in to comment.