Implement vkGetImageMemoryRequirements

This commit is contained in:
msiglreith 2017-12-11 18:45:16 +01:00
parent 468c42a3a2
commit bc7a8107e6
4 changed files with 49 additions and 17 deletions

View file

@ -51,31 +51,31 @@ fn image_features_from_hal(features: format::ImageFeature) -> VkFormatFeatureFla
let mut flags = 0;
if features.contains(format::ImageFeature::SAMPLED) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT as u32;
}
if features.contains(format::ImageFeature::STORAGE) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT as u32;
}
if features.contains(format::ImageFeature::STORAGE_ATOMIC) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT as u32;
}
if features.contains(format::ImageFeature::COLOR_ATTACHMENT) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT as u32;
}
if features.contains(format::ImageFeature::COLOR_ATTACHMENT_BLEND) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT as u32;
}
if features.contains(format::ImageFeature::DEPTH_STENCIL_ATTACHMENT) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT as u32;
}
if features.contains(format::ImageFeature::BLIT_SRC) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_BLIT_SRC_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_BLIT_SRC_BIT as u32;
}
if features.contains(format::ImageFeature::BLIT_DST) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_BLIT_DST_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_BLIT_DST_BIT as u32;
}
if features.contains(format::ImageFeature::SAMPLED_LINEAR) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT as u32;
}
flags
@ -85,16 +85,16 @@ fn buffer_features_from_hal(features: format::BufferFeature) -> VkFormatFeatureF
let mut flags = 0;
if features.contains(format::BufferFeature::UNIFORM_TEXEL) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT as u32;
}
if features.contains(format::BufferFeature::STORAGE_TEXEL) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT as u32;
}
if features.contains(format::BufferFeature::STORAGE_TEXEL_ATOMIC) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT as u32;
}
if features.contains(format::BufferFeature::VERTEX) {
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT as _;
flags |= VkFormatFeatureFlagBits::VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT as u32;
}
flags

View file

@ -288,11 +288,25 @@ extern "C" {
pMemoryRequirements:
*mut VkMemoryRequirements);
}
extern "C" {
pub fn vkGetImageMemoryRequirements(device: VkDevice, image: VkImage,
pMemoryRequirements:
*mut VkMemoryRequirements);
#[inline]
pub extern fn gfxGetImageMemoryRequirements(
gpu: VkDevice,
image: VkImage,
pMemoryRequirements: *mut VkMemoryRequirements,
) {
let req = match *image.deref() {
Image::Image(ref image) => unimplemented!(),
Image::Unbound(ref image) => {
gpu.device.get_image_requirements(image)
}
};
let memory_requirements = unsafe { &mut *pMemoryRequirements };
memory_requirements.size = req.size;
memory_requirements.alignment = req.alignment;
memory_requirements.memoryTypeBits = req.type_mask as _;
}
extern "C" {
pub fn vkGetImageSparseMemoryRequirements(device: VkDevice,
image: VkImage,

View file

@ -75,6 +75,14 @@ pub extern fn vkCreateImageView(
gfxCreateImageView(device, pCreateInfo, pAllocator, pView)
}
#[no_mangle]
pub extern fn vkGetImageMemoryRequirements(
device: VkDevice,
image: VkImage,
pMemoryRequirements: *mut VkMemoryRequirements,
) {
gfxGetImageMemoryRequirements(device, image, pMemoryRequirements)
}
#[no_mangle]
pub extern fn vkDestroyImageView(
device: VkDevice,
imageView: VkImageView,

View file

@ -268,6 +268,16 @@ int main() {
printf("\tvkCreateImage: res=%d\n", res);
assert(!res);
vkGetImageMemoryRequirements(device, depth_image, &mem_reqs);
printf("\tvkGetImageMemoryRequirements\n");
printf(
"\t\tsize: %llx\n"
"\t\talignment: %llx\n"
"\t\tmemoryTypeBits: %x\n",
mem_reqs.size,
mem_reqs.alignment,
mem_reqs.memoryTypeBits);
VkCommandPool cmd_pool = 0;
VkCommandPoolCreateInfo cmd_pool_info = {};
cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;