Skip to content

Commit

Permalink
Add support for VK_KHR_image_format_list.
Browse files Browse the repository at this point in the history
Fixes #2753.
  • Loading branch information
AWoloszyn committed May 24, 2019
1 parent c107b16 commit 4422630
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 17 deletions.
3 changes: 3 additions & 0 deletions gapis/api/vulkan/api/enums.api
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ enum VkStructureType {
VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR = 1000146003,
VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2_KHR = 1000146004,

//@extension("VK_KHR_image_format_list")
VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR = 1000147000

//@extension("VK_KHR_dedicated_allocation")
VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR = 1000127000,
VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR = 1000127001,
Expand Down
12 changes: 12 additions & 0 deletions gapis/api/vulkan/api/image.api
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
map!(u32, u32) QueueFamilyIndices
VkImageLayout InitialLayout
ref!DedicatedAllocationBufferImageCreateInfoNV DedicatedAllocationNV
ref!ImageFormatList ViewFormatList
}

@resource
Expand Down Expand Up @@ -197,6 +198,17 @@ cmd VkResult vkCreateImage(
DedicatedAllocation: ext.dedicatedAllocation
)
}
case VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR: {
ext := as!VkImageFormatListCreateInfoKHR*(next.Ptr)[0]
ifl := new!ImageFormatList()
if (ext.viewFormatCount > 0) {
formats := ext.pViewFormats[0:ext.viewFormatCount]
for j in (0 .. ext.viewFormatCount) {
ifl.viewFormats[j] = formats[j]
}
}
imageInfo.ViewFormatList = ifl
}
}
next.Ptr = as!VulkanStructHeader*(next.Ptr)[0:1][0].PNext
}
Expand Down
10 changes: 9 additions & 1 deletion gapis/api/vulkan/api/properties_features_requirements.api
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,15 @@ sub void GetPhysicalDeviceImageFormatProperties2(
next := MutableVoidPtr(as!void*(info.pNext))
for i in (0 .. numPNext) {
sType := as!const VkStructureType*(next.Ptr)[0:1][0]
_ = sType
switch sType {
case VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR: {
ext := as!VkImageFormatListCreateInfoKHR*(next.Ptr)[0]
if (ext.viewFormatCount > 0) {
_ = ext.pViewFormats[0:ext.viewFormatCount]
}
}
default: {}
}
// TODO: handle extensions for VkPhysicalDeviceImageFormatInfo2
next.Ptr = as!VulkanStructHeader*(next.Ptr)[0:1][0].PNext
}
Expand Down
53 changes: 53 additions & 0 deletions gapis/api/vulkan/extensions/khr_image_format_list.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Based off of the original vulkan.h header file which has the following
// license.

// Copyright (c) 2015 The Khronos Group Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and/or associated documentation files (the
// "Materials"), to deal in the Materials without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Materials, and to
// permit persons to whom the Materials are furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Materials.
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.

@extension("VK_KHR_image_format_list") define VK_KHR_IMAGE_FORMAT_LIST 1
@extension("VK_KHR_image_format_list") define VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME "VK_KHR_image_format_list"


@extension("VK_KHR_image_format_list")
class VkImageFormatListCreateInfoKHR {
VkStructureType sType
const void* pNext
u32 viewFormatCount
const VkFormat* pViewFormats
}

@internal class ImageFormatList {
map!(u32, VkFormat) viewFormats
}
45 changes: 29 additions & 16 deletions gapis/api/vulkan/extensions/khr_swapchain.api
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,7 @@ cmd VkResult vkCreateSwapchainKHR(
if !(device in Devices) { vkErrorInvalidDevice(device) }
if pCreateInfo == null { vkErrorNullPointer("VkSwapchainCreateInfoKHR") }
create_info := pCreateInfo[0]
if create_info.pNext != null {
numPNext := numberOfPNext(create_info.pNext)
next := MutableVoidPtr(as!void*(create_info.pNext))
for i in (0 .. numPNext) {
sType := as!const VkStructureType*(next.Ptr)[0:1][0]
switch sType {
case VK_STRUCTURE_TYPE_VIRTUAL_SWAPCHAIN_PNEXT: {
ext := as!VirtualSwapchainPNext*(next.Ptr)[0:1][0]
if ext.surfaceCreateInfo != null {
_ = as!VkStructureType*(ext.surfaceCreateInfo)[0:1][0]
}
}
}
next.Ptr = as!VulkanStructHeader*(next.Ptr)[0:1][0].PNext
}
}

queueFamilyIndices := create_info.pQueueFamilyIndices[0:create_info.queueFamilyIndexCount]

swapchainObject := new!SwapchainObject(Device: device,
Expand Down Expand Up @@ -155,6 +140,34 @@ cmd VkResult vkCreateSwapchainKHR(
queueFamilyIndices[i]
}

if create_info.pNext != null {
numPNext := numberOfPNext(create_info.pNext)
next := MutableVoidPtr(as!void*(create_info.pNext))
for i in (0 .. numPNext) {
sType := as!const VkStructureType*(next.Ptr)[0:1][0]
switch sType {
case VK_STRUCTURE_TYPE_VIRTUAL_SWAPCHAIN_PNEXT: {
ext := as!VirtualSwapchainPNext*(next.Ptr)[0:1][0]
if ext.surfaceCreateInfo != null {
_ = as!VkStructureType*(ext.surfaceCreateInfo)[0:1][0]
}
}
case VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR: {
ext := as!VkImageFormatListCreateInfoKHR*(next.Ptr)[0]
ifl := new!ImageFormatList()
if (ext.viewFormatCount > 0) {
formats := ext.pViewFormats[0:ext.viewFormatCount]
for j in (0 .. ext.viewFormatCount) {
ifl.viewFormats[j] = formats[j]
}
}
swapchainObject.Info.ViewFormatList = ifl
}
}
next.Ptr = as!VulkanStructHeader*(next.Ptr)[0:1][0].PNext
}
}

handle := ?
if pSwapchain == null { vkErrorNullPointer("VkSwapchain") }
pSwapchain[0] = handle
Expand Down
11 changes: 11 additions & 0 deletions gapis/api/vulkan/image_primer.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,17 @@ func vkCreateImage(sb *stateBuilder, dev VkDevice, info ImageInfo, handle VkImag
).Ptr())
}

if !info.ViewFormatList().IsNil() {
pNext = NewVoidᶜᵖ(sb.MustAllocReadData(
NewVkImageFormatListCreateInfoKHR(sb.ta,
VkStructureType_VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR, // sType
pNext, // pNext
uint32(info.ViewFormatList().ViewFormats().Len()), // viewFormatCount
NewVkFormatᶜᵖ(sb.MustUnpackReadMap(info.ViewFormatList().ViewFormats().All()).Ptr()), // pViewFormats
),
).Ptr())
}

create := sb.cb.VkCreateImage(
dev, sb.MustAllocReadData(
NewVkImageCreateInfo(sb.ta,
Expand Down
13 changes: 13 additions & 0 deletions gapis/api/vulkan/state_rebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,19 @@ func (sb *stateBuilder) createSwapchain(swp SwapchainObjectʳ) {
swp.Info().Extent().Width(),
swp.Info().Extent().Height(),
)

pNext := NewVoidᶜᵖ(memory.Nullptr)
if !swp.Info().ViewFormatList().IsNil() {
pNext = NewVoidᶜᵖ(sb.MustAllocReadData(
NewVkImageFormatListCreateInfoKHR(sb.ta,
VkStructureType_VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR, // sType
pNext, // pNext
uint32(swp.Info().ViewFormatList().ViewFormats().Len()), // viewFormatCount
NewVkFormatᶜᵖ(sb.MustUnpackReadMap(swp.Info().ViewFormatList().ViewFormats().All()).Ptr()), // pViewFormats
),
).Ptr())
}

sb.write(sb.cb.VkCreateSwapchainKHR(
swp.Device(),
sb.MustAllocReadData(NewVkSwapchainCreateInfoKHR(sb.ta,
Expand Down
2 changes: 2 additions & 0 deletions gapis/api/vulkan/vulkan.api
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import "extensions/khr_variable_pointers.api"
import "extensions/khr_sampler_ycbcr_conversion.api"
import "extensions/amd_draw_indirect_count.api"
import "extensions/khr_draw_indirect_count.api"
import "extensions/khr_image_format_list.api"

import "android/vulkan_android.api"
import "linux/vulkan_linux.api"
Expand Down Expand Up @@ -237,6 +238,7 @@ sub ref!ExtensionSet supportedDeviceExtensions() {
supported.ExtensionNames["VK_AMD_draw_indirect_count"] = true
supported.ExtensionNames["VK_KHR_draw_indirect_count"] = true
supported.ExtensionNames["VK_KHR_sampler_ycbcr_conversion"] = true
supported.ExtensionNames["VK_KHR_image_format_list"] = true
return supported
}

Expand Down

0 comments on commit 4422630

Please sign in to comment.