mirror of
https://github.com/italicsjenga/portability.git
synced 2024-11-26 08:51:31 +11:00
Add support for blending, buffer copy and indexed drawing
This commit is contained in:
parent
cd848a43b9
commit
6102540750
|
@ -1,5 +1,5 @@
|
||||||
use hal::{buffer, command, error, format, image, memory, pass, pso, window};
|
use hal::{buffer, command, error, format, image, memory, pass, pso, window};
|
||||||
use hal::{PatchSize, Primitive};
|
use hal::{IndexType, PatchSize, Primitive};
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
|
@ -568,10 +568,54 @@ pub fn map_color_components(mask: VkColorComponentFlags) -> pso::ColorMask {
|
||||||
unsafe { mem::transmute(mask as u8) }
|
unsafe { mem::transmute(mask as u8) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn map_blend_factor(factor: VkBlendFactor) -> pso::Factor {
|
||||||
|
use hal::pso::Factor::*;
|
||||||
|
use super::VkBlendFactor::*;
|
||||||
|
match factor {
|
||||||
|
VK_BLEND_FACTOR_ZERO => Zero,
|
||||||
|
VK_BLEND_FACTOR_ONE => One,
|
||||||
|
VK_BLEND_FACTOR_SRC_COLOR => SrcColor,
|
||||||
|
VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR => OneMinusSrcColor,
|
||||||
|
VK_BLEND_FACTOR_DST_COLOR => DstColor,
|
||||||
|
VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR => OneMinusDstColor,
|
||||||
|
VK_BLEND_FACTOR_SRC_ALPHA => SrcAlpha,
|
||||||
|
VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA => OneMinusSrcAlpha,
|
||||||
|
VK_BLEND_FACTOR_DST_ALPHA => DstAlpha,
|
||||||
|
VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA => OneMinusDstAlpha,
|
||||||
|
VK_BLEND_FACTOR_CONSTANT_COLOR => ConstColor,
|
||||||
|
VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR => OneMinusConstColor,
|
||||||
|
VK_BLEND_FACTOR_CONSTANT_ALPHA => ConstAlpha,
|
||||||
|
VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA => OneMinusConstAlpha,
|
||||||
|
VK_BLEND_FACTOR_SRC_ALPHA_SATURATE => SrcAlphaSaturate,
|
||||||
|
VK_BLEND_FACTOR_SRC1_COLOR => Src1Color,
|
||||||
|
VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR => OneMinusSrc1Color,
|
||||||
|
VK_BLEND_FACTOR_SRC1_ALPHA => Src1Alpha,
|
||||||
|
VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA => OneMinusSrc1Alpha,
|
||||||
|
_ => panic!("Unexpected blend factor: {:?}", factor),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn map_blend_op(
|
pub fn map_blend_op(
|
||||||
blend_op: VkBlendOp, src_factor: VkBlendFactor, dst_factor: VkBlendFactor,
|
blend_op: VkBlendOp, src_factor: VkBlendFactor, dst_factor: VkBlendFactor,
|
||||||
) -> pso::BlendOp {
|
) -> pso::BlendOp {
|
||||||
unimplemented!()
|
use super::VkBlendOp::*;
|
||||||
|
match blend_op {
|
||||||
|
VK_BLEND_OP_ADD => pso::BlendOp::Add {
|
||||||
|
src: map_blend_factor(src_factor),
|
||||||
|
dst: map_blend_factor(dst_factor)
|
||||||
|
},
|
||||||
|
VK_BLEND_OP_SUBTRACT => pso::BlendOp::Sub {
|
||||||
|
src: map_blend_factor(src_factor),
|
||||||
|
dst: map_blend_factor(dst_factor)
|
||||||
|
},
|
||||||
|
VK_BLEND_OP_REVERSE_SUBTRACT => pso::BlendOp::RevSub {
|
||||||
|
src: map_blend_factor(src_factor),
|
||||||
|
dst: map_blend_factor(dst_factor)
|
||||||
|
},
|
||||||
|
VK_BLEND_OP_MIN => pso::BlendOp::Min,
|
||||||
|
VK_BLEND_OP_MAX => pso::BlendOp::Max,
|
||||||
|
_ => panic!("Unexpected blend operation: {:?}", blend_op),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -654,3 +698,11 @@ pub fn map_tiling(tiling: VkImageTiling) -> image::Tiling {
|
||||||
_ => panic!("Unexpected tiling: {:?}", tiling),
|
_ => panic!("Unexpected tiling: {:?}", tiling),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn map_index_type(ty: VkIndexType) -> IndexType {
|
||||||
|
match ty {
|
||||||
|
VkIndexType::VK_INDEX_TYPE_UINT16 => IndexType::U16,
|
||||||
|
VkIndexType::VK_INDEX_TYPE_UINT32 => IndexType::U32,
|
||||||
|
_ => panic!("Unexpected index type: {:?}", ty),
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ use hal::{
|
||||||
DescriptorPool, Device, Instance, PhysicalDevice, QueueFamily,
|
DescriptorPool, Device, Instance, PhysicalDevice, QueueFamily,
|
||||||
Surface, Swapchain as HalSwapchain, FrameSync,
|
Surface, Swapchain as HalSwapchain, FrameSync,
|
||||||
};
|
};
|
||||||
|
use hal::buffer::IndexBufferView;
|
||||||
use hal::device::WaitFor;
|
use hal::device::WaitFor;
|
||||||
use hal::pool::RawCommandPool;
|
use hal::pool::RawCommandPool;
|
||||||
use hal::command::RawCommandBuffer;
|
use hal::command::RawCommandBuffer;
|
||||||
|
@ -1372,7 +1373,7 @@ pub extern "C" fn gfxCreateGraphicsPipelines(
|
||||||
_pAllocator: *const VkAllocationCallbacks,
|
_pAllocator: *const VkAllocationCallbacks,
|
||||||
pPipelines: *mut VkPipeline,
|
pPipelines: *mut VkPipeline,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
assert!(pipelineCache.is_null());
|
// assert!(pipelineCache.is_null());
|
||||||
|
|
||||||
let infos = unsafe {
|
let infos = unsafe {
|
||||||
slice::from_raw_parts(pCreateInfos, createInfoCount as _)
|
slice::from_raw_parts(pCreateInfos, createInfoCount as _)
|
||||||
|
@ -2262,7 +2263,7 @@ pub extern "C" fn gfxCreateRenderPass(
|
||||||
let dependencies = dependencies
|
let dependencies = dependencies
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|dependency| {
|
.map(|dependency| {
|
||||||
assert_eq!(dependency.dependencyFlags, 0); // TODO
|
// assert_eq!(dependency.dependencyFlags, 0); // TODO
|
||||||
|
|
||||||
let src_pass = map_subpass_ref(dependency.srcSubpass);
|
let src_pass = map_subpass_ref(dependency.srcSubpass);
|
||||||
let dst_pass = map_subpass_ref(dependency.dstSubpass);
|
let dst_pass = map_subpass_ref(dependency.dstSubpass);
|
||||||
|
@ -2552,13 +2553,23 @@ pub extern "C" fn gfxCmdBindDescriptorSets(
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxCmdBindIndexBuffer(
|
pub extern "C" fn gfxCmdBindIndexBuffer(
|
||||||
commandBuffer: VkCommandBuffer,
|
mut commandBuffer: VkCommandBuffer,
|
||||||
buffer: VkBuffer,
|
buffer: VkBuffer,
|
||||||
offset: VkDeviceSize,
|
offset: VkDeviceSize,
|
||||||
indexType: VkIndexType,
|
indexType: VkIndexType,
|
||||||
) {
|
) {
|
||||||
unimplemented!()
|
commandBuffer.bind_index_buffer(
|
||||||
|
IndexBufferView {
|
||||||
|
buffer: match *buffer {
|
||||||
|
Buffer::Buffer(ref b) => b,
|
||||||
|
Buffer::Unbound(_) => panic!("Bound index buffer expected."),
|
||||||
|
},
|
||||||
|
offset,
|
||||||
|
index_type: conv::map_index_type(indexType),
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxCmdBindVertexBuffers(
|
pub extern "C" fn gfxCmdBindVertexBuffers(
|
||||||
mut commandBuffer: VkCommandBuffer,
|
mut commandBuffer: VkCommandBuffer,
|
||||||
|
@ -2606,14 +2617,18 @@ pub extern "C" fn gfxCmdDraw(
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxCmdDrawIndexed(
|
pub extern "C" fn gfxCmdDrawIndexed(
|
||||||
commandBuffer: VkCommandBuffer,
|
mut commandBuffer: VkCommandBuffer,
|
||||||
indexCount: u32,
|
indexCount: u32,
|
||||||
instanceCount: u32,
|
instanceCount: u32,
|
||||||
firstIndex: u32,
|
firstIndex: u32,
|
||||||
vertexOffset: i32,
|
vertexOffset: i32,
|
||||||
firstInstance: u32,
|
firstInstance: u32,
|
||||||
) {
|
) {
|
||||||
unimplemented!()
|
commandBuffer.draw_indexed(
|
||||||
|
firstIndex .. firstIndex + indexCount,
|
||||||
|
vertexOffset,
|
||||||
|
firstInstance .. firstInstance + instanceCount,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxCmdDrawIndirect(
|
pub extern "C" fn gfxCmdDrawIndirect(
|
||||||
|
@ -2654,13 +2669,33 @@ pub extern "C" fn gfxCmdDispatchIndirect(
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxCmdCopyBuffer(
|
pub extern "C" fn gfxCmdCopyBuffer(
|
||||||
commandBuffer: VkCommandBuffer,
|
mut commandBuffer: VkCommandBuffer,
|
||||||
srcBuffer: VkBuffer,
|
srcBuffer: VkBuffer,
|
||||||
dstBuffer: VkBuffer,
|
dstBuffer: VkBuffer,
|
||||||
regionCount: u32,
|
regionCount: u32,
|
||||||
pRegions: *const VkBufferCopy,
|
pRegions: *const VkBufferCopy,
|
||||||
) {
|
) {
|
||||||
unimplemented!()
|
let regions = unsafe {
|
||||||
|
slice::from_raw_parts(pRegions, regionCount as _)
|
||||||
|
}
|
||||||
|
.iter()
|
||||||
|
.map(|r| com::BufferCopy {
|
||||||
|
src: r.srcOffset,
|
||||||
|
dst: r.dstOffset,
|
||||||
|
size: r.size,
|
||||||
|
});
|
||||||
|
|
||||||
|
commandBuffer.copy_buffer(
|
||||||
|
match *srcBuffer {
|
||||||
|
Buffer::Buffer(ref src) => src,
|
||||||
|
Buffer::Unbound(_) => panic!("Bound src buffer expected!"),
|
||||||
|
},
|
||||||
|
match *dstBuffer {
|
||||||
|
Buffer::Buffer(ref dst) => dst,
|
||||||
|
Buffer::Unbound(_) => panic!("Bound dst buffer expected!"),
|
||||||
|
},
|
||||||
|
regions,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxCmdCopyImage(
|
pub extern "C" fn gfxCmdCopyImage(
|
||||||
|
|
Loading…
Reference in a new issue