aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorasuonpaa <34128694+asuonpaa@users.noreply.github.com>2021-02-20 17:10:04 +0200
committerGitHub <noreply@github.com>2021-02-20 15:10:04 +0000
commitdabae26164714abf951c6815a2b4513260f7c6a4 (patch)
tree77ab2ae58362a38c76dcea7444794401a6de7ce2
parent0db8af9f6be1f7abb8030eaa593409d74476133b (diff)
downloadamber-dabae26164714abf951c6815a2b4513260f7c6a4.tar.gz
Add device API version checking for function pointer loading (#943)
Functions from instance extensions promoted to core in a later Vulkan version should only be loaded if the physical device version >= the version.
-rw-r--r--license-checker.cfg2
-rw-r--r--src/vulkan/device.cc12
-rw-r--r--src/vulkan/device.h5
-rw-r--r--src/vulkan/vk-funcs-1-0.inc (renamed from src/vulkan/vk-funcs.inc)1
-rw-r--r--src/vulkan/vk-funcs-1-1.inc1
-rwxr-xr-xtools/update_vk_wrappers.py64
6 files changed, 47 insertions, 38 deletions
diff --git a/license-checker.cfg b/license-checker.cfg
index cc7e4dc..72a470b 100644
--- a/license-checker.cfg
+++ b/license-checker.cfg
@@ -31,7 +31,7 @@
"android_gradle/gradlew",
"android_gradle/settings.gradle",
"android_sample/assets/amber/*.spv",
- "src/vulkan/vk-funcs.inc",
+ "src/vulkan/vk-funcs*.inc",
"tests/cases/*.bin",
"tests/cases/*.txt",
"tools/amber-syntax.vim",
diff --git a/src/vulkan/device.cc b/src/vulkan/device.cc
index d43b367..22cd77a 100644
--- a/src/vulkan/device.cc
+++ b/src/vulkan/device.cc
@@ -385,7 +385,14 @@ Result Device::LoadVulkanPointers(PFN_vkGetInstanceProcAddr getInstanceProcAddr,
if (delegate && delegate->LogGraphicsCalls())
delegate->Log("Loading Vulkan Pointers");
-#include "vk-wrappers.inc"
+#include "vk-wrappers-1-0.inc"
+
+ ptrs_.vkGetPhysicalDeviceProperties(physical_device_,
+ &physical_device_properties_);
+
+ if (SupportsApiVersion(1, 1, 0)) {
+#include "vk-wrappers-1-1.inc"
+ }
return {};
}
@@ -632,9 +639,6 @@ Result Device::Initialize(
"required extensions");
}
- ptrs_.vkGetPhysicalDeviceProperties(physical_device_,
- &physical_device_properties_);
-
ptrs_.vkGetPhysicalDeviceMemoryProperties(physical_device_,
&physical_memory_properties_);
diff --git a/src/vulkan/device.h b/src/vulkan/device.h
index f7796d1..8cd3ba1 100644
--- a/src/vulkan/device.h
+++ b/src/vulkan/device.h
@@ -30,7 +30,8 @@ namespace amber {
namespace vulkan {
struct VulkanPtrs {
-#include "vk-wrappers.h" // NOLINT(build/include)
+#include "vk-wrappers-1-0.h" // NOLINT(build/include)
+#include "vk-wrappers-1-1.h" // NOLINT(build/include)
};
/// Wrapper around a Vulkan Device object.
@@ -71,7 +72,7 @@ class Device {
const VkMemoryPropertyFlags flags) const;
/// Returns true if the memory at |memory_type_index| is host accessible.
bool IsMemoryHostAccessible(uint32_t memory_type_index) const;
- /// Returns true if the memory at |memory_type_index| is host corherent.
+ /// Returns true if the memory at |memory_type_index| is host coherent.
bool IsMemoryHostCoherent(uint32_t memory_type_index) const;
/// Returns the pointers to the Vulkan API methods.
diff --git a/src/vulkan/vk-funcs.inc b/src/vulkan/vk-funcs-1-0.inc
index fb7d3f6..22c37e8 100644
--- a/src/vulkan/vk-funcs.inc
+++ b/src/vulkan/vk-funcs-1-0.inc
@@ -56,7 +56,6 @@ AMBER_VK_FUNC(vkGetImageMemoryRequirements)
AMBER_VK_FUNC(vkGetPhysicalDeviceFormatProperties)
AMBER_VK_FUNC(vkGetPhysicalDeviceMemoryProperties)
AMBER_VK_FUNC(vkGetPhysicalDeviceProperties)
-AMBER_VK_FUNC(vkGetPhysicalDeviceProperties2)
AMBER_VK_FUNC(vkMapMemory)
AMBER_VK_FUNC(vkQueueSubmit)
AMBER_VK_FUNC(vkResetCommandBuffer)
diff --git a/src/vulkan/vk-funcs-1-1.inc b/src/vulkan/vk-funcs-1-1.inc
new file mode 100644
index 0000000..7fca3c5
--- /dev/null
+++ b/src/vulkan/vk-funcs-1-1.inc
@@ -0,0 +1 @@
+AMBER_VK_FUNC(vkGetPhysicalDeviceProperties2)
diff --git a/tools/update_vk_wrappers.py b/tools/update_vk_wrappers.py
index 9acfc8e..0fc9f87 100755
--- a/tools/update_vk_wrappers.py
+++ b/tools/update_vk_wrappers.py
@@ -186,36 +186,40 @@ def main():
outdir = sys.argv[1]
srcdir = sys.argv[2]
- vkfile = os.path.join(srcdir, 'third_party', 'vulkan-headers', 'registry', 'vk.xml')
- incfile = os.path.join(srcdir, 'src', 'vulkan', 'vk-funcs.inc')
-
- data = read_inc(incfile)
-
- wrapper_content = ''
- header_content = ''
- if os.path.isfile(vkfile):
- vk_data = read_vk(vkfile)
- wrapper_content = gen_wrappers(data, vk_data)
- header_content = gen_headers(data, vk_data)
- else:
- wrapper_content = gen_direct(data)
- header_content = gen_direct_headers(data)
-
- outfile = os.path.join(outdir, 'vk-wrappers.inc')
- if os.path.isfile(outfile):
- with open(outfile, 'r') as f:
- if wrapper_content == f.read():
- return
- with open(outfile, 'w') as f:
- f.write(wrapper_content)
-
- hdrfile = os.path.join(outdir, 'vk-wrappers.h')
- if os.path.isfile(hdrfile):
- with open(hdrfile, 'r') as f:
- if header_content == f.read():
- return
- with open(hdrfile, 'w') as f:
- f.write(header_content)
+ vulkan_versions = ("1-0", "1-1")
+
+ for vulkan_version in vulkan_versions:
+
+ vkfile = os.path.join(srcdir, 'third_party', 'vulkan-headers', 'registry', 'vk.xml')
+ incfile = os.path.join(srcdir, 'src', 'vulkan', 'vk-funcs-%s.inc' % vulkan_version)
+
+ data = read_inc(incfile)
+
+ wrapper_content = ''
+ header_content = ''
+ if os.path.isfile(vkfile):
+ vk_data = read_vk(vkfile)
+ wrapper_content = gen_wrappers(data, vk_data)
+ header_content = gen_headers(data, vk_data)
+ else:
+ wrapper_content = gen_direct(data)
+ header_content = gen_direct_headers(data)
+
+ outfile = os.path.join(outdir, 'vk-wrappers-%s.inc' % vulkan_version)
+ if os.path.isfile(outfile):
+ with open(outfile, 'r') as f:
+ if wrapper_content == f.read():
+ return
+ with open(outfile, 'w') as f:
+ f.write(wrapper_content)
+
+ hdrfile = os.path.join(outdir, 'vk-wrappers-%s.h' % vulkan_version)
+ if os.path.isfile(hdrfile):
+ with open(hdrfile, 'r') as f:
+ if header_content == f.read():
+ return
+ with open(hdrfile, 'w') as f:
+ f.write(header_content)
if __name__ == '__main__':