Commit f0fb42f5 authored by Chris Blume's avatar Chris Blume Committed by Commit Bot

Use macros for Vulkan functions

Currently, users of Vulkan need to get the global function pointer
class. And calls into those functions look like:
vulkan_function_pointers->vkCreateDevice();

Our OpenGL code hides that behind macros. This patch adds macros to
mimic the OpenGL code in Chrome.

Now that looks like:
vkCreateDevice();

BUG=856360,848101

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: If3aff1719b366748b9236a9e4c9e7ec69260be18
Reviewed-on: https://chromium-review.googlesource.com/1116195
Commit-Queue: Chris Blume <cblume@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571226}
parent ca733ee5
...@@ -66,8 +66,8 @@ bool VulkanInProcessContextProvider::Initialize() { ...@@ -66,8 +66,8 @@ bool VulkanInProcessContextProvider::Initialize() {
gpu::VulkanFunctionPointers* vulkan_function_pointers = gpu::VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers(); gpu::GetVulkanFunctionPointers();
auto interface = sk_make_sp<GrVkInterface>( auto interface = sk_make_sp<GrVkInterface>(
make_unified_getter(vulkan_function_pointers->vkGetInstanceProcAddr, make_unified_getter(vulkan_function_pointers->vkGetInstanceProcAddrFn,
vulkan_function_pointers->vkGetDeviceProcAddr), vulkan_function_pointers->vkGetDeviceProcAddrFn),
backend_context.fInstance, backend_context.fDevice, backend_context.fInstance, backend_context.fDevice,
backend_context.fExtensions); backend_context.fExtensions);
backend_context.fInterface.reset(interface.release()); backend_context.fInterface.reset(interface.release());
......
...@@ -111,9 +111,15 @@ LICENSE_AND_HEADER = """\ ...@@ -111,9 +111,15 @@ LICENSE_AND_HEADER = """\
""" """
def WriteFunctionDeclarations(file, functions): def WriteFunctionDeclarations(file, functions):
template = Template(' PFN_$name $name = nullptr;\n') template = Template(' PFN_${name} ${name}Fn = nullptr;\n')
for func in functions: for func in functions:
file.write(template.substitute(func)); file.write(template.substitute(func))
def WriteMacros(file, functions):
template = Template(
'#define $name gpu::GetVulkanFunctionPointers()->${name}Fn\n')
for func in functions:
file.write(template.substitute(func))
def GenerateHeaderFile(file, unassociated_functions, instance_functions, def GenerateHeaderFile(file, unassociated_functions, instance_functions,
physical_device_functions, device_functions, physical_device_functions, device_functions,
...@@ -155,7 +161,7 @@ struct VulkanFunctionPointers { ...@@ -155,7 +161,7 @@ struct VulkanFunctionPointers {
base::NativeLibrary vulkan_loader_library_ = nullptr; base::NativeLibrary vulkan_loader_library_ = nullptr;
// Unassociated functions // Unassociated functions
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = nullptr; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddrFn = nullptr;
""") """)
WriteFunctionDeclarations(file, unassociated_functions) WriteFunctionDeclarations(file, unassociated_functions)
...@@ -168,7 +174,7 @@ struct VulkanFunctionPointers { ...@@ -168,7 +174,7 @@ struct VulkanFunctionPointers {
WriteFunctionDeclarations(file, instance_functions) WriteFunctionDeclarations(file, instance_functions)
file.write("""\ file.write("""\
PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR = nullptr; PFN_vkDestroySurfaceKHR vkDestroySurfaceKHRFn = nullptr;
// Physical Device functions // Physical Device functions
""") """)
...@@ -177,11 +183,11 @@ struct VulkanFunctionPointers { ...@@ -177,11 +183,11 @@ struct VulkanFunctionPointers {
file.write("""\ file.write("""\
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
vkGetPhysicalDeviceSurfaceCapabilitiesKHR = nullptr; vkGetPhysicalDeviceSurfaceCapabilitiesKHRFn = nullptr;
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR PFN_vkGetPhysicalDeviceSurfaceFormatsKHR
vkGetPhysicalDeviceSurfaceFormatsKHR = nullptr; vkGetPhysicalDeviceSurfaceFormatsKHRFn = nullptr;
PFN_vkGetPhysicalDeviceSurfaceSupportKHR PFN_vkGetPhysicalDeviceSurfaceSupportKHR
vkGetPhysicalDeviceSurfaceSupportKHR = nullptr; vkGetPhysicalDeviceSurfaceSupportKHRFn = nullptr;
// Device functions // Device functions
""") """)
...@@ -214,32 +220,87 @@ struct VulkanFunctionPointers { ...@@ -214,32 +220,87 @@ struct VulkanFunctionPointers {
} // namespace gpu } // namespace gpu
// Unassociated functions
""")
WriteMacros(file, [ { 'name': 'vkGetInstanceProcAddr' } ])
WriteMacros(file, unassociated_functions)
file.write("""\
// Instance functions
""")
WriteMacros(file, instance_functions)
WriteMacros(file, [ { 'name': 'vkDestroySurfaceKHR' } ])
file.write("""\
// Physical Device functions
""")
WriteMacros(file, physical_device_functions)
WriteMacros(file, [
{ 'name': 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR' },
{ 'name': 'vkGetPhysicalDeviceSurfaceFormatsKHR' },
{ 'name': 'vkGetPhysicalDeviceSurfaceSupportKHR' },
])
file.write("""\
// Device functions
""")
WriteMacros(file, device_functions)
file.write("""\
// Queue functions
""")
WriteMacros(file, queue_functions)
file.write("""\
// Command buffer functions
""")
WriteMacros(file, command_buffer_functions)
file.write("""\
// Swapchain functions
""")
WriteMacros(file, swapchain_functions)
file.write("""\
#endif // GPU_VULKAN_VULKAN_FUNCTION_POINTERS_H_ #endif // GPU_VULKAN_VULKAN_FUNCTION_POINTERS_H_
""") """)
def WriteFunctionPointerInitialization(file, proc_addr_function, parent, def WriteFunctionPointerInitialization(file, proc_addr_function, parent,
functions): functions):
template = Template(""" $name = reinterpret_cast<PFN_$name>( template = Template(""" ${name}Fn = reinterpret_cast<PFN_${name}>(
$get_proc_addr($parent, "$name")); $get_proc_addr($parent, "$name"));
if (!$name) if (!${name}Fn)
return false; return false;
""") """)
for func in functions: for func in functions:
file.write(template.substitute(name=func['name'], get_proc_addr = file.write(template.substitute(name=func['name'], get_proc_addr =
proc_addr_function, parent=parent)) proc_addr_function, parent=parent))
def WriteUnassociatedFunctionPointerInitialization(file, functions): def WriteUnassociatedFunctionPointerInitialization(file, functions):
WriteFunctionPointerInitialization(file, 'vkGetInstanceProcAddr', 'nullptr', WriteFunctionPointerInitialization(file, 'vkGetInstanceProcAddrFn', 'nullptr',
functions) functions)
def WriteInstanceFunctionPointerInitialization(file, functions): def WriteInstanceFunctionPointerInitialization(file, functions):
WriteFunctionPointerInitialization(file, 'vkGetInstanceProcAddr', WriteFunctionPointerInitialization(file, 'vkGetInstanceProcAddrFn',
'vk_instance', functions) 'vk_instance', functions)
def WriteDeviceFunctionPointerInitialization(file, functions): def WriteDeviceFunctionPointerInitialization(file, functions):
WriteFunctionPointerInitialization(file, 'vkGetDeviceProcAddr', 'vk_device', WriteFunctionPointerInitialization(file, 'vkGetDeviceProcAddrFn', 'vk_device',
functions) functions)
def GenerateSourceFile(file, unassociated_functions, instance_functions, def GenerateSourceFile(file, unassociated_functions, instance_functions,
...@@ -269,10 +330,10 @@ bool VulkanFunctionPointers::BindUnassociatedFunctionPointers() { ...@@ -269,10 +330,10 @@ bool VulkanFunctionPointers::BindUnassociatedFunctionPointers() {
// vkGetInstanceProcAddr must be handled specially since it gets its function // vkGetInstanceProcAddr must be handled specially since it gets its function
// pointer through base::GetFunctionPOinterFromNativeLibrary(). Other Vulkan // pointer through base::GetFunctionPOinterFromNativeLibrary(). Other Vulkan
// functions don't do this. // functions don't do this.
vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>( vkGetInstanceProcAddrFn = reinterpret_cast<PFN_vkGetInstanceProcAddr>(
base::GetFunctionPointerFromNativeLibrary(vulkan_loader_library_, base::GetFunctionPointerFromNativeLibrary(vulkan_loader_library_,
"vkGetInstanceProcAddr")); "vkGetInstanceProcAddr"));
if (!vkGetInstanceProcAddr) if (!vkGetInstanceProcAddrFn)
return false; return false;
""") """)
......
...@@ -38,11 +38,8 @@ bool VulkanCommandBuffer::Initialize() { ...@@ -38,11 +38,8 @@ bool VulkanCommandBuffer::Initialize() {
: VK_COMMAND_BUFFER_LEVEL_SECONDARY; : VK_COMMAND_BUFFER_LEVEL_SECONDARY;
command_buffer_info.commandBufferCount = 1; command_buffer_info.commandBufferCount = 1;
VulkanFunctionPointers* vulkan_function_pointers = result =
gpu::GetVulkanFunctionPointers(); vkAllocateCommandBuffers(device, &command_buffer_info, &command_buffer_);
result = vulkan_function_pointers->vkAllocateCommandBuffers(
device, &command_buffer_info, &command_buffer_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkAllocateCommandBuffers() failed: " << result; DLOG(ERROR) << "vkAllocateCommandBuffers() failed: " << result;
return false; return false;
...@@ -52,8 +49,8 @@ bool VulkanCommandBuffer::Initialize() { ...@@ -52,8 +49,8 @@ bool VulkanCommandBuffer::Initialize() {
fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fence_create_info.flags = VK_FENCE_CREATE_SIGNALED_BIT; fence_create_info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
result = vulkan_function_pointers->vkCreateFence(device, &fence_create_info, result =
nullptr, &submission_fence_); vkCreateFence(device, &fence_create_info, nullptr, &submission_fence_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateFence(submission) failed: " << result; DLOG(ERROR) << "vkCreateFence(submission) failed: " << result;
return false; return false;
...@@ -64,20 +61,15 @@ bool VulkanCommandBuffer::Initialize() { ...@@ -64,20 +61,15 @@ bool VulkanCommandBuffer::Initialize() {
} }
void VulkanCommandBuffer::Destroy() { void VulkanCommandBuffer::Destroy() {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
if (VK_NULL_HANDLE != submission_fence_) { if (VK_NULL_HANDLE != submission_fence_) {
DCHECK(SubmissionFinished()); DCHECK(SubmissionFinished());
vulkan_function_pointers->vkDestroyFence(device, submission_fence_, vkDestroyFence(device, submission_fence_, nullptr);
nullptr);
submission_fence_ = VK_NULL_HANDLE; submission_fence_ = VK_NULL_HANDLE;
} }
if (VK_NULL_HANDLE != command_buffer_) { if (VK_NULL_HANDLE != command_buffer_) {
vulkan_function_pointers->vkFreeCommandBuffers( vkFreeCommandBuffers(device, command_pool_->handle(), 1, &command_buffer_);
device, command_pool_->handle(), 1, &command_buffer_);
command_buffer_ = VK_NULL_HANDLE; command_buffer_ = VK_NULL_HANDLE;
} }
} }
...@@ -90,9 +82,6 @@ bool VulkanCommandBuffer::Submit(uint32_t num_wait_semaphores, ...@@ -90,9 +82,6 @@ bool VulkanCommandBuffer::Submit(uint32_t num_wait_semaphores,
DCHECK(primary_); DCHECK(primary_);
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkSubmitInfo submit_info = {}; VkSubmitInfo submit_info = {};
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submit_info.commandBufferCount = 1; submit_info.commandBufferCount = 1;
...@@ -105,15 +94,15 @@ bool VulkanCommandBuffer::Submit(uint32_t num_wait_semaphores, ...@@ -105,15 +94,15 @@ bool VulkanCommandBuffer::Submit(uint32_t num_wait_semaphores,
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
result = vulkan_function_pointers->vkResetFences( result =
device_queue_->GetVulkanDevice(), 1, &submission_fence_); vkResetFences(device_queue_->GetVulkanDevice(), 1, &submission_fence_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkResetFences() failed: " << result; DLOG(ERROR) << "vkResetFences() failed: " << result;
return false; return false;
} }
result = vulkan_function_pointers->vkQueueSubmit( result = vkQueueSubmit(device_queue_->GetVulkanQueue(), 1, &submit_info,
device_queue_->GetVulkanQueue(), 1, &submit_info, submission_fence_); submission_fence_);
PostExecution(); PostExecution();
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
...@@ -127,11 +116,7 @@ bool VulkanCommandBuffer::Submit(uint32_t num_wait_semaphores, ...@@ -127,11 +116,7 @@ bool VulkanCommandBuffer::Submit(uint32_t num_wait_semaphores,
void VulkanCommandBuffer::Enqueue(VkCommandBuffer primary_command_buffer) { void VulkanCommandBuffer::Enqueue(VkCommandBuffer primary_command_buffer) {
DCHECK(!primary_); DCHECK(!primary_);
VulkanFunctionPointers* vulkan_function_pointers = vkCmdExecuteCommands(primary_command_buffer, 1, &command_buffer_);
gpu::GetVulkanFunctionPointers();
vulkan_function_pointers->vkCmdExecuteCommands(primary_command_buffer, 1,
&command_buffer_);
PostExecution(); PostExecution();
} }
...@@ -142,20 +127,13 @@ void VulkanCommandBuffer::Clear() { ...@@ -142,20 +127,13 @@ void VulkanCommandBuffer::Clear() {
} }
void VulkanCommandBuffer::Wait(uint64_t timeout) { void VulkanCommandBuffer::Wait(uint64_t timeout) {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
vulkan_function_pointers->vkWaitForFences(device, 1, &submission_fence_, true, vkWaitForFences(device, 1, &submission_fence_, true, timeout);
timeout);
} }
bool VulkanCommandBuffer::SubmissionFinished() { bool VulkanCommandBuffer::SubmissionFinished() {
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
VulkanFunctionPointers* vulkan_function_pointers = return VK_SUCCESS == vkGetFenceStatus(device, submission_fence_);
gpu::GetVulkanFunctionPointers();
return VK_SUCCESS ==
vulkan_function_pointers->vkGetFenceStatus(device, submission_fence_);
} }
void VulkanCommandBuffer::PostExecution() { void VulkanCommandBuffer::PostExecution() {
...@@ -171,16 +149,11 @@ void VulkanCommandBuffer::PostExecution() { ...@@ -171,16 +149,11 @@ void VulkanCommandBuffer::PostExecution() {
void VulkanCommandBuffer::ResetIfDirty() { void VulkanCommandBuffer::ResetIfDirty() {
DCHECK(!recording_); DCHECK(!recording_);
if (record_type_ == RECORD_TYPE_DIRTY) { if (record_type_ == RECORD_TYPE_DIRTY) {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
// Block if command buffer is still in use. This can be externally avoided // Block if command buffer is still in use. This can be externally avoided
// using the asynchronous SubmissionFinished() function. // using the asynchronous SubmissionFinished() function.
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
vulkan_function_pointers->vkWaitForFences(device, 1, &submission_fence_, vkWaitForFences(device, 1, &submission_fence_, true, UINT64_MAX);
true, UINT64_MAX); VkResult result = vkResetCommandBuffer(command_buffer_, 0);
VkResult result =
vulkan_function_pointers->vkResetCommandBuffer(command_buffer_, 0);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkResetCommandBuffer() failed: " << result; DLOG(ERROR) << "vkResetCommandBuffer() failed: " << result;
} else { } else {
...@@ -190,10 +163,7 @@ void VulkanCommandBuffer::ResetIfDirty() { ...@@ -190,10 +163,7 @@ void VulkanCommandBuffer::ResetIfDirty() {
} }
CommandBufferRecorderBase::~CommandBufferRecorderBase() { CommandBufferRecorderBase::~CommandBufferRecorderBase() {
VulkanFunctionPointers* vulkan_function_pointers = VkResult result = vkEndCommandBuffer(handle_);
gpu::GetVulkanFunctionPointers();
VkResult result = vulkan_function_pointers->vkEndCommandBuffer(handle_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkEndCommandBuffer() failed: " << result; DLOG(ERROR) << "vkEndCommandBuffer() failed: " << result;
} }
...@@ -202,14 +172,10 @@ CommandBufferRecorderBase::~CommandBufferRecorderBase() { ...@@ -202,14 +172,10 @@ CommandBufferRecorderBase::~CommandBufferRecorderBase() {
ScopedMultiUseCommandBufferRecorder::ScopedMultiUseCommandBufferRecorder( ScopedMultiUseCommandBufferRecorder::ScopedMultiUseCommandBufferRecorder(
VulkanCommandBuffer& command_buffer) VulkanCommandBuffer& command_buffer)
: CommandBufferRecorderBase(command_buffer) { : CommandBufferRecorderBase(command_buffer) {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
ValidateMultiUse(command_buffer); ValidateMultiUse(command_buffer);
VkCommandBufferBeginInfo begin_info = {}; VkCommandBufferBeginInfo begin_info = {};
begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
VkResult result = VkResult result = vkBeginCommandBuffer(handle_, &begin_info);
vulkan_function_pointers->vkBeginCommandBuffer(handle_, &begin_info);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkBeginCommandBuffer() failed: " << result; DLOG(ERROR) << "vkBeginCommandBuffer() failed: " << result;
...@@ -219,15 +185,11 @@ ScopedMultiUseCommandBufferRecorder::ScopedMultiUseCommandBufferRecorder( ...@@ -219,15 +185,11 @@ ScopedMultiUseCommandBufferRecorder::ScopedMultiUseCommandBufferRecorder(
ScopedSingleUseCommandBufferRecorder::ScopedSingleUseCommandBufferRecorder( ScopedSingleUseCommandBufferRecorder::ScopedSingleUseCommandBufferRecorder(
VulkanCommandBuffer& command_buffer) VulkanCommandBuffer& command_buffer)
: CommandBufferRecorderBase(command_buffer) { : CommandBufferRecorderBase(command_buffer) {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
ValidateSingleUse(command_buffer); ValidateSingleUse(command_buffer);
VkCommandBufferBeginInfo begin_info = {}; VkCommandBufferBeginInfo begin_info = {};
begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
VkResult result = VkResult result = vkBeginCommandBuffer(handle_, &begin_info);
vulkan_function_pointers->vkBeginCommandBuffer(handle_, &begin_info);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkBeginCommandBuffer() failed: " << result; DLOG(ERROR) << "vkBeginCommandBuffer() failed: " << result;
......
...@@ -20,9 +20,6 @@ VulkanCommandPool::~VulkanCommandPool() { ...@@ -20,9 +20,6 @@ VulkanCommandPool::~VulkanCommandPool() {
} }
bool VulkanCommandPool::Initialize() { bool VulkanCommandPool::Initialize() {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkCommandPoolCreateInfo command_pool_create_info = {}; VkCommandPoolCreateInfo command_pool_create_info = {};
command_pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; command_pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
command_pool_create_info.flags = command_pool_create_info.flags =
...@@ -30,9 +27,9 @@ bool VulkanCommandPool::Initialize() { ...@@ -30,9 +27,9 @@ bool VulkanCommandPool::Initialize() {
command_pool_create_info.queueFamilyIndex = command_pool_create_info.queueFamilyIndex =
device_queue_->GetVulkanQueueIndex(); device_queue_->GetVulkanQueueIndex();
VkResult result = vulkan_function_pointers->vkCreateCommandPool( VkResult result =
device_queue_->GetVulkanDevice(), &command_pool_create_info, nullptr, vkCreateCommandPool(device_queue_->GetVulkanDevice(),
&handle_); &command_pool_create_info, nullptr, &handle_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateCommandPool() failed: " << result; DLOG(ERROR) << "vkCreateCommandPool() failed: " << result;
return false; return false;
...@@ -43,12 +40,8 @@ bool VulkanCommandPool::Initialize() { ...@@ -43,12 +40,8 @@ bool VulkanCommandPool::Initialize() {
void VulkanCommandPool::Destroy() { void VulkanCommandPool::Destroy() {
DCHECK_EQ(0u, command_buffer_count_); DCHECK_EQ(0u, command_buffer_count_);
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
if (VK_NULL_HANDLE != handle_) { if (VK_NULL_HANDLE != handle_) {
vulkan_function_pointers->vkDestroyCommandPool( vkDestroyCommandPool(device_queue_->GetVulkanDevice(), handle_, nullptr);
device_queue_->GetVulkanDevice(), handle_, nullptr);
handle_ = VK_NULL_HANDLE; handle_ = VK_NULL_HANDLE;
} }
} }
......
...@@ -22,8 +22,6 @@ bool VulkanDescriptorLayout::Initialize( ...@@ -22,8 +22,6 @@ bool VulkanDescriptorLayout::Initialize(
const std::vector<VkDescriptorSetLayoutBinding>& layout) { const std::vector<VkDescriptorSetLayoutBinding>& layout) {
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkDescriptorSetLayoutCreateInfo layout_create_info = {}; VkDescriptorSetLayoutCreateInfo layout_create_info = {};
layout_create_info.sType = layout_create_info.sType =
...@@ -31,8 +29,8 @@ bool VulkanDescriptorLayout::Initialize( ...@@ -31,8 +29,8 @@ bool VulkanDescriptorLayout::Initialize(
layout_create_info.bindingCount = static_cast<uint32_t>(layout.size()); layout_create_info.bindingCount = static_cast<uint32_t>(layout.size());
layout_create_info.pBindings = layout.data(); layout_create_info.pBindings = layout.data();
result = vulkan_function_pointers->vkCreateDescriptorSetLayout( result = vkCreateDescriptorSetLayout(device, &layout_create_info, nullptr,
device, &layout_create_info, nullptr, &handle_); &handle_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateDescriptorSetLayout() failed: " << result; DLOG(ERROR) << "vkCreateDescriptorSetLayout() failed: " << result;
return false; return false;
...@@ -43,11 +41,8 @@ bool VulkanDescriptorLayout::Initialize( ...@@ -43,11 +41,8 @@ bool VulkanDescriptorLayout::Initialize(
void VulkanDescriptorLayout::Destroy() { void VulkanDescriptorLayout::Destroy() {
if (VK_NULL_HANDLE != handle_) { if (VK_NULL_HANDLE != handle_) {
VulkanFunctionPointers* vulkan_function_pointers = vkDestroyDescriptorSetLayout(device_queue_->GetVulkanDevice(), handle_,
gpu::GetVulkanFunctionPointers(); nullptr);
vulkan_function_pointers->vkDestroyDescriptorSetLayout(
device_queue_->GetVulkanDevice(), handle_, nullptr);
handle_ = VK_NULL_HANDLE; handle_ = VK_NULL_HANDLE;
} }
} }
......
...@@ -23,8 +23,6 @@ bool VulkanDescriptorPool::Initialize( ...@@ -23,8 +23,6 @@ bool VulkanDescriptorPool::Initialize(
uint32_t max_descriptor_sets, uint32_t max_descriptor_sets,
const std::vector<VkDescriptorPoolSize>& pool_sizes) { const std::vector<VkDescriptorPoolSize>& pool_sizes) {
DCHECK_EQ(static_cast<VkDescriptorPool>(VK_NULL_HANDLE), handle_); DCHECK_EQ(static_cast<VkDescriptorPool>(VK_NULL_HANDLE), handle_);
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
max_descriptor_sets_ = max_descriptor_sets; max_descriptor_sets_ = max_descriptor_sets;
VkDescriptorPoolCreateInfo descriptor_pool_create_info = {}; VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
...@@ -37,9 +35,9 @@ bool VulkanDescriptorPool::Initialize( ...@@ -37,9 +35,9 @@ bool VulkanDescriptorPool::Initialize(
static_cast<uint32_t>(pool_sizes.size()); static_cast<uint32_t>(pool_sizes.size());
descriptor_pool_create_info.pPoolSizes = pool_sizes.data(); descriptor_pool_create_info.pPoolSizes = pool_sizes.data();
VkResult result = vulkan_function_pointers->vkCreateDescriptorPool( VkResult result =
device_queue_->GetVulkanDevice(), &descriptor_pool_create_info, nullptr, vkCreateDescriptorPool(device_queue_->GetVulkanDevice(),
&handle_); &descriptor_pool_create_info, nullptr, &handle_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateDescriptorPool() failed: " << result; DLOG(ERROR) << "vkCreateDescriptorPool() failed: " << result;
return false; return false;
...@@ -51,10 +49,7 @@ bool VulkanDescriptorPool::Initialize( ...@@ -51,10 +49,7 @@ bool VulkanDescriptorPool::Initialize(
void VulkanDescriptorPool::Destroy() { void VulkanDescriptorPool::Destroy() {
DCHECK_EQ(0u, descriptor_count_); DCHECK_EQ(0u, descriptor_count_);
if (VK_NULL_HANDLE != handle_) { if (VK_NULL_HANDLE != handle_) {
VulkanFunctionPointers* vulkan_function_pointers = vkDestroyDescriptorPool(device_queue_->GetVulkanDevice(), handle_, nullptr);
gpu::GetVulkanFunctionPointers();
vulkan_function_pointers->vkDestroyDescriptorPool(
device_queue_->GetVulkanDevice(), handle_, nullptr);
handle_ = VK_NULL_HANDLE; handle_ = VK_NULL_HANDLE;
} }
......
...@@ -20,8 +20,6 @@ VulkanDescriptorSet::~VulkanDescriptorSet() { ...@@ -20,8 +20,6 @@ VulkanDescriptorSet::~VulkanDescriptorSet() {
bool VulkanDescriptorSet::Initialize(const VulkanDescriptorLayout* layout) { bool VulkanDescriptorSet::Initialize(const VulkanDescriptorLayout* layout) {
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkDescriptorSetLayout layout_handle = layout->handle(); VkDescriptorSetLayout layout_handle = layout->handle();
...@@ -31,8 +29,7 @@ bool VulkanDescriptorSet::Initialize(const VulkanDescriptorLayout* layout) { ...@@ -31,8 +29,7 @@ bool VulkanDescriptorSet::Initialize(const VulkanDescriptorLayout* layout) {
set_allocate_info.descriptorSetCount = 1; set_allocate_info.descriptorSetCount = 1;
set_allocate_info.pSetLayouts = &layout_handle; set_allocate_info.pSetLayouts = &layout_handle;
result = vulkan_function_pointers->vkAllocateDescriptorSets( result = vkAllocateDescriptorSets(device, &set_allocate_info, &handle_);
device, &set_allocate_info, &handle_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkAllocateDescriptorSets() failed: " << result; DLOG(ERROR) << "vkAllocateDescriptorSets() failed: " << result;
return false; return false;
...@@ -44,11 +41,7 @@ bool VulkanDescriptorSet::Initialize(const VulkanDescriptorLayout* layout) { ...@@ -44,11 +41,7 @@ bool VulkanDescriptorSet::Initialize(const VulkanDescriptorLayout* layout) {
void VulkanDescriptorSet::Destroy() { void VulkanDescriptorSet::Destroy() {
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
if (VK_NULL_HANDLE != handle_) { if (VK_NULL_HANDLE != handle_) {
VulkanFunctionPointers* vulkan_function_pointers = vkFreeDescriptorSets(device, descriptor_pool_->handle(), 1, &handle_);
gpu::GetVulkanFunctionPointers();
vulkan_function_pointers->vkFreeDescriptorSets(
device, descriptor_pool_->handle(), 1, &handle_);
handle_ = VK_NULL_HANDLE; handle_ = VK_NULL_HANDLE;
} }
} }
...@@ -61,9 +54,6 @@ void VulkanDescriptorSet::WriteToDescriptorSet( ...@@ -61,9 +54,6 @@ void VulkanDescriptorSet::WriteToDescriptorSet(
const VkDescriptorImageInfo* image_info, const VkDescriptorImageInfo* image_info,
const VkDescriptorBufferInfo* buffer_info, const VkDescriptorBufferInfo* buffer_info,
const VkBufferView* texel_buffer_view) { const VkBufferView* texel_buffer_view) {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkWriteDescriptorSet write_descriptor_set = {}; VkWriteDescriptorSet write_descriptor_set = {};
write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write_descriptor_set.dstSet = handle_; write_descriptor_set.dstSet = handle_;
...@@ -75,8 +65,8 @@ void VulkanDescriptorSet::WriteToDescriptorSet( ...@@ -75,8 +65,8 @@ void VulkanDescriptorSet::WriteToDescriptorSet(
write_descriptor_set.pBufferInfo = buffer_info; write_descriptor_set.pBufferInfo = buffer_info;
write_descriptor_set.pTexelBufferView = texel_buffer_view; write_descriptor_set.pTexelBufferView = texel_buffer_view;
vulkan_function_pointers->vkUpdateDescriptorSets( vkUpdateDescriptorSets(device_queue_->GetVulkanDevice(), 1,
device_queue_->GetVulkanDevice(), 1, &write_descriptor_set, 0, nullptr); &write_descriptor_set, 0, nullptr);
} }
void VulkanDescriptorSet::CopyFromDescriptorSet( void VulkanDescriptorSet::CopyFromDescriptorSet(
...@@ -86,9 +76,6 @@ void VulkanDescriptorSet::CopyFromDescriptorSet( ...@@ -86,9 +76,6 @@ void VulkanDescriptorSet::CopyFromDescriptorSet(
uint32_t dst_binding, uint32_t dst_binding,
uint32_t dst_array_element, uint32_t dst_array_element,
uint32_t descriptor_count) { uint32_t descriptor_count) {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkCopyDescriptorSet copy_descriptor_set = {}; VkCopyDescriptorSet copy_descriptor_set = {};
copy_descriptor_set.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; copy_descriptor_set.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
copy_descriptor_set.srcSet = source_set->handle(); copy_descriptor_set.srcSet = source_set->handle();
...@@ -99,8 +86,8 @@ void VulkanDescriptorSet::CopyFromDescriptorSet( ...@@ -99,8 +86,8 @@ void VulkanDescriptorSet::CopyFromDescriptorSet(
copy_descriptor_set.dstArrayElement = dst_array_element; copy_descriptor_set.dstArrayElement = dst_array_element;
copy_descriptor_set.descriptorCount = descriptor_count; copy_descriptor_set.descriptorCount = descriptor_count;
vulkan_function_pointers->vkUpdateDescriptorSets( vkUpdateDescriptorSets(device_queue_->GetVulkanDevice(), 0, nullptr, 1,
device_queue_->GetVulkanDevice(), 0, nullptr, 1, &copy_descriptor_set); &copy_descriptor_set);
} }
VulkanDescriptorSet::VulkanDescriptorSet(VulkanDeviceQueue* device_queue, VulkanDescriptorSet::VulkanDescriptorSet(VulkanDeviceQueue* device_queue,
......
...@@ -25,23 +25,19 @@ bool VulkanDeviceQueue::Initialize( ...@@ -25,23 +25,19 @@ bool VulkanDeviceQueue::Initialize(
uint32_t options, uint32_t options,
const std::vector<const char*>& required_extensions, const std::vector<const char*>& required_extensions,
const GetPresentationSupportCallback& get_presentation_support) { const GetPresentationSupportCallback& get_presentation_support) {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
if (VK_NULL_HANDLE == vk_instance_) if (VK_NULL_HANDLE == vk_instance_)
return false; return false;
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
uint32_t device_count = 0; uint32_t device_count = 0;
result = vulkan_function_pointers->vkEnumeratePhysicalDevices( result = vkEnumeratePhysicalDevices(vk_instance_, &device_count, nullptr);
vk_instance_, &device_count, nullptr);
if (VK_SUCCESS != result || device_count == 0) if (VK_SUCCESS != result || device_count == 0)
return false; return false;
std::vector<VkPhysicalDevice> devices(device_count); std::vector<VkPhysicalDevice> devices(device_count);
result = vulkan_function_pointers->vkEnumeratePhysicalDevices( result =
vk_instance_, &device_count, devices.data()); vkEnumeratePhysicalDevices(vk_instance_, &device_count, devices.data());
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkEnumeratePhysicalDevices() failed: " << result; DLOG(ERROR) << "vkEnumeratePhysicalDevices() failed: " << result;
return false; return false;
...@@ -56,12 +52,11 @@ bool VulkanDeviceQueue::Initialize( ...@@ -56,12 +52,11 @@ bool VulkanDeviceQueue::Initialize(
for (size_t i = 0; i < devices.size(); ++i) { for (size_t i = 0; i < devices.size(); ++i) {
const VkPhysicalDevice& device = devices[i]; const VkPhysicalDevice& device = devices[i];
uint32_t queue_count = 0; uint32_t queue_count = 0;
vulkan_function_pointers->vkGetPhysicalDeviceQueueFamilyProperties( vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_count, nullptr);
device, &queue_count, nullptr);
if (queue_count) { if (queue_count) {
std::vector<VkQueueFamilyProperties> queue_properties(queue_count); std::vector<VkQueueFamilyProperties> queue_properties(queue_count);
vulkan_function_pointers->vkGetPhysicalDeviceQueueFamilyProperties( vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_count,
device, &queue_count, queue_properties.data()); queue_properties.data());
for (size_t n = 0; n < queue_properties.size(); ++n) { for (size_t n = 0; n < queue_properties.size(); ++n) {
if ((queue_properties[n].queueFlags & queue_flags) != queue_flags) if ((queue_properties[n].queueFlags & queue_flags) != queue_flags)
continue; continue;
...@@ -98,8 +93,8 @@ bool VulkanDeviceQueue::Initialize( ...@@ -98,8 +93,8 @@ bool VulkanDeviceQueue::Initialize(
std::vector<const char*> enabled_layer_names; std::vector<const char*> enabled_layer_names;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
uint32_t num_device_layers = 0; uint32_t num_device_layers = 0;
result = vulkan_function_pointers->vkEnumerateDeviceLayerProperties( result = vkEnumerateDeviceLayerProperties(vk_physical_device_,
vk_physical_device_, &num_device_layers, nullptr); &num_device_layers, nullptr);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkEnumerateDeviceLayerProperties(NULL) failed: " DLOG(ERROR) << "vkEnumerateDeviceLayerProperties(NULL) failed: "
<< result; << result;
...@@ -107,7 +102,7 @@ bool VulkanDeviceQueue::Initialize( ...@@ -107,7 +102,7 @@ bool VulkanDeviceQueue::Initialize(
} }
std::vector<VkLayerProperties> device_layers(num_device_layers); std::vector<VkLayerProperties> device_layers(num_device_layers);
result = vulkan_function_pointers->vkEnumerateDeviceLayerProperties( result = vkEnumerateDeviceLayerProperties(
vk_physical_device_, &num_device_layers, device_layers.data()); vk_physical_device_, &num_device_layers, device_layers.data());
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkEnumerateDeviceLayerProperties() failed: " << result; DLOG(ERROR) << "vkEnumerateDeviceLayerProperties() failed: " << result;
...@@ -138,31 +133,27 @@ bool VulkanDeviceQueue::Initialize( ...@@ -138,31 +133,27 @@ bool VulkanDeviceQueue::Initialize(
device_create_info.enabledExtensionCount = enabled_extensions.size(); device_create_info.enabledExtensionCount = enabled_extensions.size();
device_create_info.ppEnabledExtensionNames = enabled_extensions.data(); device_create_info.ppEnabledExtensionNames = enabled_extensions.data();
result = vulkan_function_pointers->vkCreateDevice( result = vkCreateDevice(vk_physical_device_, &device_create_info, nullptr,
vk_physical_device_, &device_create_info, nullptr, &vk_device_); &vk_device_);
if (VK_SUCCESS != result) if (VK_SUCCESS != result)
return false; return false;
enabled_extensions_ = gfx::ExtensionSet(std::begin(enabled_extensions), enabled_extensions_ = gfx::ExtensionSet(std::begin(enabled_extensions),
std::end(enabled_extensions)); std::end(enabled_extensions));
vulkan_function_pointers->BindDeviceFunctionPointers(vk_device_); gpu::GetVulkanFunctionPointers()->BindDeviceFunctionPointers(vk_device_);
if (gfx::HasExtension(enabled_extensions_, VK_KHR_SWAPCHAIN_EXTENSION_NAME)) if (gfx::HasExtension(enabled_extensions_, VK_KHR_SWAPCHAIN_EXTENSION_NAME))
vulkan_function_pointers->BindSwapchainFunctionPointers(vk_device_); gpu::GetVulkanFunctionPointers()->BindSwapchainFunctionPointers(vk_device_);
vulkan_function_pointers->vkGetDeviceQueue(vk_device_, queue_index, 0, vkGetDeviceQueue(vk_device_, queue_index, 0, &vk_queue_);
&vk_queue_);
return true; return true;
} }
void VulkanDeviceQueue::Destroy() { void VulkanDeviceQueue::Destroy() {
if (VK_NULL_HANDLE != vk_device_) { if (VK_NULL_HANDLE != vk_device_) {
VulkanFunctionPointers* vulkan_function_pointers = vkDestroyDevice(vk_device_, nullptr);
gpu::GetVulkanFunctionPointers();
vulkan_function_pointers->vkDestroyDevice(vk_device_, nullptr);
vk_device_ = VK_NULL_HANDLE; vk_device_ = VK_NULL_HANDLE;
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -49,8 +49,6 @@ bool VulkanImageView::Initialize(VkImage image, ...@@ -49,8 +49,6 @@ bool VulkanImageView::Initialize(VkImage image,
format_ = format; format_ = format;
DCHECK_GT(image_type, IMAGE_TYPE_INVALID); DCHECK_GT(image_type, IMAGE_TYPE_INVALID);
DCHECK_LT(image_type, NUM_IMAGE_TYPES); DCHECK_LT(image_type, NUM_IMAGE_TYPES);
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkImageSubresourceRange image_subresource_range = {}; VkImageSubresourceRange image_subresource_range = {};
image_subresource_range.aspectMask = kAspectFlags[image_type]; image_subresource_range.aspectMask = kAspectFlags[image_type];
...@@ -69,9 +67,9 @@ bool VulkanImageView::Initialize(VkImage image, ...@@ -69,9 +67,9 @@ bool VulkanImageView::Initialize(VkImage image,
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY}; VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY};
image_view_create_info.subresourceRange = image_subresource_range; image_view_create_info.subresourceRange = image_subresource_range;
VkResult result = vulkan_function_pointers->vkCreateImageView( VkResult result =
device_queue_->GetVulkanDevice(), &image_view_create_info, nullptr, vkCreateImageView(device_queue_->GetVulkanDevice(),
&handle_); &image_view_create_info, nullptr, &handle_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateImageView() failed: " << result; DLOG(ERROR) << "vkCreateImageView() failed: " << result;
return false; return false;
...@@ -87,11 +85,7 @@ bool VulkanImageView::Initialize(VkImage image, ...@@ -87,11 +85,7 @@ bool VulkanImageView::Initialize(VkImage image,
void VulkanImageView::Destroy() { void VulkanImageView::Destroy() {
if (VK_NULL_HANDLE != handle_) { if (VK_NULL_HANDLE != handle_) {
VulkanFunctionPointers* vulkan_function_pointers = vkDestroyImageView(device_queue_->GetVulkanDevice(), handle_, nullptr);
gpu::GetVulkanFunctionPointers();
vulkan_function_pointers->vkDestroyImageView(
device_queue_->GetVulkanDevice(), handle_, nullptr);
image_type_ = IMAGE_TYPE_INVALID; image_type_ = IMAGE_TYPE_INVALID;
handle_ = VK_NULL_HANDLE; handle_ = VK_NULL_HANDLE;
} }
......
...@@ -34,8 +34,8 @@ bool VulkanImplementationAndroid::InitializeVulkanInstance() { ...@@ -34,8 +34,8 @@ bool VulkanImplementationAndroid::InitializeVulkanInstance() {
} }
// Initialize platform function pointers // Initialize platform function pointers
vkCreateAndroidSurfaceKHR_ = reinterpret_cast<PFN_vkCreateAndroidSurfaceKHR>( vkCreateAndroidSurfaceKHR_ =
vulkan_function_pointers->vkGetInstanceProcAddr( reinterpret_cast<PFN_vkCreateAndroidSurfaceKHR>(vkGetInstanceProcAddr(
vulkan_instance_.vk_instance(), "vkCreateAndroidSurfaceKHR")); vulkan_instance_.vk_instance(), "vkCreateAndroidSurfaceKHR"));
if (!vkCreateAndroidSurfaceKHR_) { if (!vkCreateAndroidSurfaceKHR_) {
vulkan_instance_.Destroy(); vulkan_instance_.Destroy();
...@@ -51,15 +51,12 @@ VkInstance VulkanImplementationAndroid::GetVulkanInstance() { ...@@ -51,15 +51,12 @@ VkInstance VulkanImplementationAndroid::GetVulkanInstance() {
std::unique_ptr<VulkanSurface> VulkanImplementationAndroid::CreateViewSurface( std::unique_ptr<VulkanSurface> VulkanImplementationAndroid::CreateViewSurface(
gfx::AcceleratedWidget window) { gfx::AcceleratedWidget window) {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkSurfaceKHR surface; VkSurfaceKHR surface;
VkAndroidSurfaceCreateInfoKHR surface_create_info = {}; VkAndroidSurfaceCreateInfoKHR surface_create_info = {};
surface_create_info.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; surface_create_info.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
surface_create_info.window = window; surface_create_info.window = window;
result = vulkan_function_pointers->vkCreateAndroidSurfaceKHR( result = vkCreateAndroidSurfaceKHR(GetVulkanInstance(), &surface_create_info,
GetVulkanInstance(), &surface_create_info, nullptr, &surface); nullptr, &surface);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateAndroidSurfaceKHR() failed: " << result; DLOG(ERROR) << "vkCreateAndroidSurfaceKHR() failed: " << result;
return nullptr; return nullptr;
......
...@@ -68,8 +68,8 @@ bool VulkanInstance::Initialize( ...@@ -68,8 +68,8 @@ bool VulkanInstance::Initialize(
std::end(required_extensions)); std::end(required_extensions));
uint32_t num_instance_exts = 0; uint32_t num_instance_exts = 0;
result = vulkan_function_pointers->vkEnumerateInstanceExtensionProperties( result = vkEnumerateInstanceExtensionProperties(nullptr, &num_instance_exts,
nullptr, &num_instance_exts, nullptr); nullptr);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkEnumerateInstanceExtensionProperties(NULL) failed: " DLOG(ERROR) << "vkEnumerateInstanceExtensionProperties(NULL) failed: "
<< result; << result;
...@@ -77,8 +77,8 @@ bool VulkanInstance::Initialize( ...@@ -77,8 +77,8 @@ bool VulkanInstance::Initialize(
} }
std::vector<VkExtensionProperties> instance_exts(num_instance_exts); std::vector<VkExtensionProperties> instance_exts(num_instance_exts);
result = vulkan_function_pointers->vkEnumerateInstanceExtensionProperties( result = vkEnumerateInstanceExtensionProperties(nullptr, &num_instance_exts,
nullptr, &num_instance_exts, instance_exts.data()); instance_exts.data());
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkEnumerateInstanceExtensionProperties() failed: " DLOG(ERROR) << "vkEnumerateInstanceExtensionProperties() failed: "
<< result; << result;
...@@ -96,8 +96,7 @@ bool VulkanInstance::Initialize( ...@@ -96,8 +96,7 @@ bool VulkanInstance::Initialize(
std::vector<const char*> enabled_layer_names; std::vector<const char*> enabled_layer_names;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
uint32_t num_instance_layers = 0; uint32_t num_instance_layers = 0;
result = vulkan_function_pointers->vkEnumerateInstanceLayerProperties( result = vkEnumerateInstanceLayerProperties(&num_instance_layers, nullptr);
&num_instance_layers, nullptr);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkEnumerateInstanceLayerProperties(NULL) failed: " DLOG(ERROR) << "vkEnumerateInstanceLayerProperties(NULL) failed: "
<< result; << result;
...@@ -105,8 +104,8 @@ bool VulkanInstance::Initialize( ...@@ -105,8 +104,8 @@ bool VulkanInstance::Initialize(
} }
std::vector<VkLayerProperties> instance_layers(num_instance_layers); std::vector<VkLayerProperties> instance_layers(num_instance_layers);
result = vulkan_function_pointers->vkEnumerateInstanceLayerProperties( result = vkEnumerateInstanceLayerProperties(&num_instance_layers,
&num_instance_layers, instance_layers.data()); instance_layers.data());
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkEnumerateInstanceLayerProperties() failed: " << result; DLOG(ERROR) << "vkEnumerateInstanceLayerProperties() failed: " << result;
return false; return false;
...@@ -134,8 +133,7 @@ bool VulkanInstance::Initialize( ...@@ -134,8 +133,7 @@ bool VulkanInstance::Initialize(
instance_create_info.enabledExtensionCount = enabled_extensions.size(); instance_create_info.enabledExtensionCount = enabled_extensions.size();
instance_create_info.ppEnabledExtensionNames = enabled_extensions.data(); instance_create_info.ppEnabledExtensionNames = enabled_extensions.data();
result = vulkan_function_pointers->vkCreateInstance(&instance_create_info, result = vkCreateInstance(&instance_create_info, nullptr, &vk_instance_);
nullptr, &vk_instance_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateInstance() failed: " << result; DLOG(ERROR) << "vkCreateInstance() failed: " << result;
return false; return false;
...@@ -149,8 +147,8 @@ bool VulkanInstance::Initialize( ...@@ -149,8 +147,8 @@ bool VulkanInstance::Initialize(
if (debug_report_enabled_) { if (debug_report_enabled_) {
PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallbackEXT = PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallbackEXT =
reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>( reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(
vulkan_function_pointers->vkGetInstanceProcAddr( vkGetInstanceProcAddr(vk_instance_,
vk_instance_, "vkCreateDebugReportCallbackEXT")); "vkCreateDebugReportCallbackEXT"));
DCHECK(vkCreateDebugReportCallbackEXT); DCHECK(vkCreateDebugReportCallbackEXT);
VkDebugReportCallbackCreateInfoEXT cb_create_info = {}; VkDebugReportCallbackCreateInfoEXT cb_create_info = {};
...@@ -185,32 +183,30 @@ bool VulkanInstance::Initialize( ...@@ -185,32 +183,30 @@ bool VulkanInstance::Initialize(
return false; return false;
if (gfx::HasExtension(enabled_extensions_, VK_KHR_SURFACE_EXTENSION_NAME)) { if (gfx::HasExtension(enabled_extensions_, VK_KHR_SURFACE_EXTENSION_NAME)) {
vulkan_function_pointers->vkDestroySurfaceKHR = vkDestroySurfaceKHR = reinterpret_cast<PFN_vkDestroySurfaceKHR>(
reinterpret_cast<PFN_vkDestroySurfaceKHR>( vkGetInstanceProcAddr(vk_instance_, "vkDestroySurfaceKHR"));
vulkan_function_pointers->vkGetInstanceProcAddr( if (!vkDestroySurfaceKHR)
vk_instance_, "vkDestroySurfaceKHR"));
if (!vulkan_function_pointers->vkDestroySurfaceKHR)
return false; return false;
vulkan_function_pointers->vkGetPhysicalDeviceSurfaceCapabilitiesKHR = vkGetPhysicalDeviceSurfaceCapabilitiesKHR =
reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR>( reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR>(
vulkan_function_pointers->vkGetInstanceProcAddr( vkGetInstanceProcAddr(vk_instance_,
vk_instance_, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR")); "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"));
if (!vulkan_function_pointers->vkGetPhysicalDeviceSurfaceCapabilitiesKHR) if (!vkGetPhysicalDeviceSurfaceCapabilitiesKHR)
return false; return false;
vulkan_function_pointers->vkGetPhysicalDeviceSurfaceFormatsKHR = vkGetPhysicalDeviceSurfaceFormatsKHR =
reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR>( reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR>(
vulkan_function_pointers->vkGetInstanceProcAddr( vkGetInstanceProcAddr(vk_instance_,
vk_instance_, "vkGetPhysicalDeviceSurfaceFormatsKHR")); "vkGetPhysicalDeviceSurfaceFormatsKHR"));
if (!vulkan_function_pointers->vkGetPhysicalDeviceSurfaceFormatsKHR) if (!vkGetPhysicalDeviceSurfaceFormatsKHR)
return false; return false;
vulkan_function_pointers->vkGetPhysicalDeviceSurfaceSupportKHR = vkGetPhysicalDeviceSurfaceSupportKHR =
reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceSupportKHR>( reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceSupportKHR>(
vulkan_function_pointers->vkGetInstanceProcAddr( vkGetInstanceProcAddr(vk_instance_,
vk_instance_, "vkGetPhysicalDeviceSurfaceSupportKHR")); "vkGetPhysicalDeviceSurfaceSupportKHR"));
if (!vulkan_function_pointers->vkGetPhysicalDeviceSurfaceSupportKHR) if (!vkGetPhysicalDeviceSurfaceSupportKHR)
return false; return false;
} }
...@@ -218,23 +214,22 @@ bool VulkanInstance::Initialize( ...@@ -218,23 +214,22 @@ bool VulkanInstance::Initialize(
} }
void VulkanInstance::Destroy() { void VulkanInstance::Destroy() {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
if (debug_report_enabled_) { if (debug_report_enabled_) {
PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT = PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT =
reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>( reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(
vulkan_function_pointers->vkGetInstanceProcAddr( vkGetInstanceProcAddr(vk_instance_,
vk_instance_, "vkDestroyDebugReportCallbackEXT")); "vkDestroyDebugReportCallbackEXT"));
DCHECK(vkDestroyDebugReportCallbackEXT); DCHECK(vkDestroyDebugReportCallbackEXT);
vkDestroyDebugReportCallbackEXT(vk_instance_, error_callback_, nullptr); vkDestroyDebugReportCallbackEXT(vk_instance_, error_callback_, nullptr);
vkDestroyDebugReportCallbackEXT(vk_instance_, warning_callback_, nullptr); vkDestroyDebugReportCallbackEXT(vk_instance_, warning_callback_, nullptr);
} }
#endif #endif
if (vk_instance_ != VK_NULL_HANDLE) { if (vk_instance_ != VK_NULL_HANDLE) {
vulkan_function_pointers->vkDestroyInstance(vk_instance_, nullptr); vkDestroyInstance(vk_instance_, nullptr);
} }
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
if (vulkan_function_pointers->vulkan_loader_library_) if (vulkan_function_pointers->vulkan_loader_library_)
base::UnloadNativeLibrary(vulkan_function_pointers->vulkan_loader_library_); base::UnloadNativeLibrary(vulkan_function_pointers->vulkan_loader_library_);
vulkan_function_pointers->vulkan_loader_library_ = nullptr; vulkan_function_pointers->vulkan_loader_library_ = nullptr;
......
...@@ -170,9 +170,6 @@ bool VulkanRenderPass::Initialize(const VulkanSwapChain* swap_chain, ...@@ -170,9 +170,6 @@ bool VulkanRenderPass::Initialize(const VulkanSwapChain* swap_chain,
DCHECK(frame_buffers_.empty()); DCHECK(frame_buffers_.empty());
DCHECK(render_pass_data.ValidateData(swap_chain)); DCHECK(render_pass_data.ValidateData(swap_chain));
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
...@@ -278,8 +275,8 @@ bool VulkanRenderPass::Initialize(const VulkanSwapChain* swap_chain, ...@@ -278,8 +275,8 @@ bool VulkanRenderPass::Initialize(const VulkanSwapChain* swap_chain,
render_pass_create_info.subpassCount = subpass_descs.size(); render_pass_create_info.subpassCount = subpass_descs.size();
render_pass_create_info.pSubpasses = subpass_descs.data(); render_pass_create_info.pSubpasses = subpass_descs.data();
result = vulkan_function_pointers->vkCreateRenderPass( result = vkCreateRenderPass(device, &render_pass_create_info, nullptr,
device, &render_pass_create_info, nullptr, &render_pass_); &render_pass_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateRenderPass() failed: " << result; DLOG(ERROR) << "vkCreateRenderPass() failed: " << result;
return false; return false;
...@@ -331,8 +328,8 @@ bool VulkanRenderPass::Initialize(const VulkanSwapChain* swap_chain, ...@@ -331,8 +328,8 @@ bool VulkanRenderPass::Initialize(const VulkanSwapChain* swap_chain,
framebuffer_create_info.height = height; framebuffer_create_info.height = height;
framebuffer_create_info.layers = layers; framebuffer_create_info.layers = layers;
result = vulkan_function_pointers->vkCreateFramebuffer( result = vkCreateFramebuffer(device, &framebuffer_create_info, nullptr,
device, &framebuffer_create_info, nullptr, &frame_buffers_[i]); &frame_buffers_[i]);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateFramebuffer() failed: " << result; DLOG(ERROR) << "vkCreateFramebuffer() failed: " << result;
return false; return false;
...@@ -344,18 +341,14 @@ bool VulkanRenderPass::Initialize(const VulkanSwapChain* swap_chain, ...@@ -344,18 +341,14 @@ bool VulkanRenderPass::Initialize(const VulkanSwapChain* swap_chain,
void VulkanRenderPass::Destroy() { void VulkanRenderPass::Destroy() {
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
for (VkFramebuffer frame_buffer : frame_buffers_) { for (VkFramebuffer frame_buffer : frame_buffers_) {
vulkan_function_pointers->vkDestroyFramebuffer(device, frame_buffer, vkDestroyFramebuffer(device, frame_buffer, nullptr);
nullptr);
} }
frame_buffers_.clear(); frame_buffers_.clear();
if (VK_NULL_HANDLE != render_pass_) { if (VK_NULL_HANDLE != render_pass_) {
vulkan_function_pointers->vkDestroyRenderPass(device, render_pass_, vkDestroyRenderPass(device, render_pass_, nullptr);
nullptr);
render_pass_ = VK_NULL_HANDLE; render_pass_ = VK_NULL_HANDLE;
} }
...@@ -370,9 +363,6 @@ void VulkanRenderPass::BeginRenderPass( ...@@ -370,9 +363,6 @@ void VulkanRenderPass::BeginRenderPass(
DCHECK(!executing_); DCHECK(!executing_);
DCHECK_NE(0u, num_sub_passes_); DCHECK_NE(0u, num_sub_passes_);
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
executing_ = true; executing_ = true;
execution_type_ = exec_inline ? VK_SUBPASS_CONTENTS_INLINE execution_type_ = exec_inline ? VK_SUBPASS_CONTENTS_INLINE
: VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS; : VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS;
...@@ -390,26 +380,20 @@ void VulkanRenderPass::BeginRenderPass( ...@@ -390,26 +380,20 @@ void VulkanRenderPass::BeginRenderPass(
static_cast<uint32_t>(attachment_clear_values_.size()); static_cast<uint32_t>(attachment_clear_values_.size());
begin_info.pClearValues = attachment_clear_values_.data(); begin_info.pClearValues = attachment_clear_values_.data();
vulkan_function_pointers->vkCmdBeginRenderPass(recorder.handle(), &begin_info, vkCmdBeginRenderPass(recorder.handle(), &begin_info, execution_type_);
execution_type_);
} }
void VulkanRenderPass::NextSubPass(const CommandBufferRecorderBase& recorder) { void VulkanRenderPass::NextSubPass(const CommandBufferRecorderBase& recorder) {
DCHECK(executing_); DCHECK(executing_);
DCHECK_LT(current_sub_pass_ + 1, num_sub_passes_); DCHECK_LT(current_sub_pass_ + 1, num_sub_passes_);
VulkanFunctionPointers* vulkan_function_pointers = vkCmdNextSubpass(recorder.handle(), execution_type_);
gpu::GetVulkanFunctionPointers();
vulkan_function_pointers->vkCmdNextSubpass(recorder.handle(),
execution_type_);
current_sub_pass_++; current_sub_pass_++;
} }
void VulkanRenderPass::EndRenderPass( void VulkanRenderPass::EndRenderPass(
const CommandBufferRecorderBase& recorder) { const CommandBufferRecorderBase& recorder) {
DCHECK(executing_); DCHECK(executing_);
VulkanFunctionPointers* vulkan_function_pointers = vkCmdEndRenderPass(recorder.handle());
gpu::GetVulkanFunctionPointers();
vulkan_function_pointers->vkCmdEndRenderPass(recorder.handle());
executing_ = false; executing_ = false;
} }
......
...@@ -22,8 +22,6 @@ VulkanSampler::~VulkanSampler() { ...@@ -22,8 +22,6 @@ VulkanSampler::~VulkanSampler() {
bool VulkanSampler::Initialize(const SamplerOptions& options) { bool VulkanSampler::Initialize(const SamplerOptions& options) {
DCHECK_EQ(static_cast<VkSampler>(VK_NULL_HANDLE), handle_); DCHECK_EQ(static_cast<VkSampler>(VK_NULL_HANDLE), handle_);
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkSamplerCreateInfo sampler_create_info = {}; VkSamplerCreateInfo sampler_create_info = {};
sampler_create_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; sampler_create_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
...@@ -43,9 +41,8 @@ bool VulkanSampler::Initialize(const SamplerOptions& options) { ...@@ -43,9 +41,8 @@ bool VulkanSampler::Initialize(const SamplerOptions& options) {
sampler_create_info.unnormalizedCoordinates = sampler_create_info.unnormalizedCoordinates =
options.unnormalized_coordinates; options.unnormalized_coordinates;
VkResult result = vulkan_function_pointers->vkCreateSampler( VkResult result = vkCreateSampler(device_queue_->GetVulkanDevice(),
device_queue_->GetVulkanDevice(), &sampler_create_info, nullptr, &sampler_create_info, nullptr, &handle_);
&handle_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateSampler() failed: " << result; DLOG(ERROR) << "vkCreateSampler() failed: " << result;
return false; return false;
...@@ -56,10 +53,7 @@ bool VulkanSampler::Initialize(const SamplerOptions& options) { ...@@ -56,10 +53,7 @@ bool VulkanSampler::Initialize(const SamplerOptions& options) {
void VulkanSampler::Destroy() { void VulkanSampler::Destroy() {
if (VK_NULL_HANDLE != handle_) { if (VK_NULL_HANDLE != handle_) {
VulkanFunctionPointers* vulkan_function_pointers = vkDestroySampler(device_queue_->GetVulkanDevice(), handle_, nullptr);
gpu::GetVulkanFunctionPointers();
vulkan_function_pointers->vkDestroySampler(device_queue_->GetVulkanDevice(),
handle_, nullptr);
handle_ = VK_NULL_HANDLE; handle_ = VK_NULL_HANDLE;
} }
} }
......
...@@ -27,8 +27,6 @@ bool VulkanShaderModule::InitializeSPIRV(ShaderType type, ...@@ -27,8 +27,6 @@ bool VulkanShaderModule::InitializeSPIRV(ShaderType type,
std::string entry_point, std::string entry_point,
std::string source) { std::string source) {
DCHECK_EQ(static_cast<VkShaderModule>(VK_NULL_HANDLE), handle_); DCHECK_EQ(static_cast<VkShaderModule>(VK_NULL_HANDLE), handle_);
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
shader_type_ = type; shader_type_ = type;
name_ = std::move(name); name_ = std::move(name);
entry_point_ = std::move(entry_point); entry_point_ = std::move(entry_point);
...@@ -48,9 +46,9 @@ bool VulkanShaderModule::InitializeSPIRV(ShaderType type, ...@@ -48,9 +46,9 @@ bool VulkanShaderModule::InitializeSPIRV(ShaderType type,
shader_module_create_info.codeSize = source.length(); shader_module_create_info.codeSize = source.length();
VkShaderModule shader_module = VK_NULL_HANDLE; VkShaderModule shader_module = VK_NULL_HANDLE;
VkResult result = vulkan_function_pointers->vkCreateShaderModule( VkResult result =
device_queue_->GetVulkanDevice(), &shader_module_create_info, nullptr, vkCreateShaderModule(device_queue_->GetVulkanDevice(),
&shader_module); &shader_module_create_info, nullptr, &shader_module);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
std::stringstream ss; std::stringstream ss;
ss << "vkCreateShaderModule() failed: " << result; ss << "vkCreateShaderModule() failed: " << result;
...@@ -65,10 +63,7 @@ bool VulkanShaderModule::InitializeSPIRV(ShaderType type, ...@@ -65,10 +63,7 @@ bool VulkanShaderModule::InitializeSPIRV(ShaderType type,
void VulkanShaderModule::Destroy() { void VulkanShaderModule::Destroy() {
if (handle_ != VK_NULL_HANDLE) { if (handle_ != VK_NULL_HANDLE) {
VulkanFunctionPointers* vulkan_function_pointers = vkDestroyShaderModule(device_queue_->GetVulkanDevice(), handle_, nullptr);
gpu::GetVulkanFunctionPointers();
vulkan_function_pointers->vkDestroyShaderModule(
device_queue_->GetVulkanDevice(), handle_, nullptr);
handle_ = VK_NULL_HANDLE; handle_ = VK_NULL_HANDLE;
} }
......
...@@ -43,11 +43,9 @@ bool VulkanSurface::Initialize(VulkanDeviceQueue* device_queue, ...@@ -43,11 +43,9 @@ bool VulkanSurface::Initialize(VulkanDeviceQueue* device_queue,
device_queue_ = device_queue; device_queue_ = device_queue;
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkBool32 present_support; VkBool32 present_support;
if (vulkan_function_pointers->vkGetPhysicalDeviceSurfaceSupportKHR( if (vkGetPhysicalDeviceSurfaceSupportKHR(
device_queue_->GetVulkanPhysicalDevice(), device_queue_->GetVulkanPhysicalDevice(),
device_queue_->GetVulkanQueueIndex(), surface_, device_queue_->GetVulkanQueueIndex(), surface_,
&present_support) != VK_SUCCESS) { &present_support) != VK_SUCCESS) {
...@@ -61,7 +59,7 @@ bool VulkanSurface::Initialize(VulkanDeviceQueue* device_queue, ...@@ -61,7 +59,7 @@ bool VulkanSurface::Initialize(VulkanDeviceQueue* device_queue,
// Get list of supported formats. // Get list of supported formats.
uint32_t format_count = 0; uint32_t format_count = 0;
result = vulkan_function_pointers->vkGetPhysicalDeviceSurfaceFormatsKHR( result = vkGetPhysicalDeviceSurfaceFormatsKHR(
device_queue_->GetVulkanPhysicalDevice(), surface_, &format_count, device_queue_->GetVulkanPhysicalDevice(), surface_, &format_count,
nullptr); nullptr);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
...@@ -70,7 +68,7 @@ bool VulkanSurface::Initialize(VulkanDeviceQueue* device_queue, ...@@ -70,7 +68,7 @@ bool VulkanSurface::Initialize(VulkanDeviceQueue* device_queue,
} }
std::vector<VkSurfaceFormatKHR> formats(format_count); std::vector<VkSurfaceFormatKHR> formats(format_count);
result = vulkan_function_pointers->vkGetPhysicalDeviceSurfaceFormatsKHR( result = vkGetPhysicalDeviceSurfaceFormatsKHR(
device_queue_->GetVulkanPhysicalDevice(), surface_, &format_count, device_queue_->GetVulkanPhysicalDevice(), surface_, &format_count,
formats.data()); formats.data());
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
...@@ -111,7 +109,7 @@ bool VulkanSurface::Initialize(VulkanDeviceQueue* device_queue, ...@@ -111,7 +109,7 @@ bool VulkanSurface::Initialize(VulkanDeviceQueue* device_queue,
// Get Surface Information. // Get Surface Information.
VkSurfaceCapabilitiesKHR surface_caps; VkSurfaceCapabilitiesKHR surface_caps;
result = vulkan_function_pointers->vkGetPhysicalDeviceSurfaceCapabilitiesKHR( result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
device_queue_->GetVulkanPhysicalDevice(), surface_, &surface_caps); device_queue_->GetVulkanPhysicalDevice(), surface_, &surface_caps);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkGetPhysicalDeviceSurfaceCapabilitiesKHR() failed: " DLOG(ERROR) << "vkGetPhysicalDeviceSurfaceCapabilitiesKHR() failed: "
...@@ -135,11 +133,8 @@ bool VulkanSurface::Initialize(VulkanDeviceQueue* device_queue, ...@@ -135,11 +133,8 @@ bool VulkanSurface::Initialize(VulkanDeviceQueue* device_queue,
} }
void VulkanSurface::Destroy() { void VulkanSurface::Destroy() {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
swap_chain_.Destroy(); swap_chain_.Destroy();
vulkan_function_pointers->vkDestroySurfaceKHR(vk_instance_, surface_, vkDestroySurfaceKHR(vk_instance_, surface_, nullptr);
nullptr);
surface_ = VK_NULL_HANDLE; surface_ = VK_NULL_HANDLE;
} }
...@@ -152,9 +147,7 @@ VulkanSwapChain* VulkanSurface::GetSwapChain() { ...@@ -152,9 +147,7 @@ VulkanSwapChain* VulkanSurface::GetSwapChain() {
} }
void VulkanSurface::Finish() { void VulkanSurface::Finish() {
VulkanFunctionPointers* vulkan_function_pointers = vkQueueWaitIdle(device_queue_->GetVulkanQueue());
gpu::GetVulkanFunctionPointers();
vulkan_function_pointers->vkQueueWaitIdle(device_queue_->GetVulkanQueue());
} }
} // namespace gpu } // namespace gpu
...@@ -36,8 +36,6 @@ void VulkanSwapChain::Destroy() { ...@@ -36,8 +36,6 @@ void VulkanSwapChain::Destroy() {
} }
gfx::SwapResult VulkanSwapChain::SwapBuffers() { gfx::SwapResult VulkanSwapChain::SwapBuffers() {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
...@@ -61,14 +59,14 @@ gfx::SwapResult VulkanSwapChain::SwapBuffers() { ...@@ -61,14 +59,14 @@ gfx::SwapResult VulkanSwapChain::SwapBuffers() {
present_info.pSwapchains = &swap_chain_; present_info.pSwapchains = &swap_chain_;
present_info.pImageIndices = &current_image_; present_info.pImageIndices = &current_image_;
result = vulkan_function_pointers->vkQueuePresentKHR(queue, &present_info); result = vkQueuePresentKHR(queue, &present_info);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
return gfx::SwapResult::SWAP_FAILED; return gfx::SwapResult::SWAP_FAILED;
} }
// Acquire then next image. // Acquire then next image.
result = vulkan_function_pointers->vkAcquireNextImageKHR( result = vkAcquireNextImageKHR(device, swap_chain_, UINT64_MAX,
device, swap_chain_, UINT64_MAX, next_present_semaphore_, VK_NULL_HANDLE, next_present_semaphore_, VK_NULL_HANDLE,
&current_image_); &current_image_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkAcquireNextImageKHR() failed: " << result; DLOG(ERROR) << "vkAcquireNextImageKHR() failed: " << result;
...@@ -88,8 +86,6 @@ bool VulkanSwapChain::InitializeSwapChain( ...@@ -88,8 +86,6 @@ bool VulkanSwapChain::InitializeSwapChain(
VkSurfaceKHR surface, VkSurfaceKHR surface,
const VkSurfaceCapabilitiesKHR& surface_caps, const VkSurfaceCapabilitiesKHR& surface_caps,
const VkSurfaceFormatKHR& surface_format) { const VkSurfaceFormatKHR& surface_format) {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
...@@ -111,8 +107,8 @@ bool VulkanSwapChain::InitializeSwapChain( ...@@ -111,8 +107,8 @@ bool VulkanSwapChain::InitializeSwapChain(
swap_chain_create_info.oldSwapchain = swap_chain_; swap_chain_create_info.oldSwapchain = swap_chain_;
VkSwapchainKHR new_swap_chain = VK_NULL_HANDLE; VkSwapchainKHR new_swap_chain = VK_NULL_HANDLE;
result = vulkan_function_pointers->vkCreateSwapchainKHR( result = vkCreateSwapchainKHR(device, &swap_chain_create_info, nullptr,
device, &swap_chain_create_info, nullptr, &new_swap_chain); &new_swap_chain);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateSwapchainKHR() failed: " << result; DLOG(ERROR) << "vkCreateSwapchainKHR() failed: " << result;
return false; return false;
...@@ -128,13 +124,10 @@ bool VulkanSwapChain::InitializeSwapChain( ...@@ -128,13 +124,10 @@ bool VulkanSwapChain::InitializeSwapChain(
} }
void VulkanSwapChain::DestroySwapChain() { void VulkanSwapChain::DestroySwapChain() {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
if (swap_chain_ != VK_NULL_HANDLE) { if (swap_chain_ != VK_NULL_HANDLE) {
vulkan_function_pointers->vkDestroySwapchainKHR(device, swap_chain_, vkDestroySwapchainKHR(device, swap_chain_, nullptr);
nullptr);
swap_chain_ = VK_NULL_HANDLE; swap_chain_ = VK_NULL_HANDLE;
} }
} }
...@@ -142,22 +135,19 @@ void VulkanSwapChain::DestroySwapChain() { ...@@ -142,22 +135,19 @@ void VulkanSwapChain::DestroySwapChain() {
bool VulkanSwapChain::InitializeSwapImages( bool VulkanSwapChain::InitializeSwapImages(
const VkSurfaceCapabilitiesKHR& surface_caps, const VkSurfaceCapabilitiesKHR& surface_caps,
const VkSurfaceFormatKHR& surface_format) { const VkSurfaceFormatKHR& surface_format) {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
uint32_t image_count = 0; uint32_t image_count = 0;
result = vulkan_function_pointers->vkGetSwapchainImagesKHR( result = vkGetSwapchainImagesKHR(device, swap_chain_, &image_count, nullptr);
device, swap_chain_, &image_count, nullptr);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkGetSwapchainImagesKHR(NULL) failed: " << result; DLOG(ERROR) << "vkGetSwapchainImagesKHR(NULL) failed: " << result;
return false; return false;
} }
std::vector<VkImage> images(image_count); std::vector<VkImage> images(image_count);
result = vulkan_function_pointers->vkGetSwapchainImagesKHR( result =
device, swap_chain_, &image_count, images.data()); vkGetSwapchainImagesKHR(device, swap_chain_, &image_count, images.data());
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkGetSwapchainImagesKHR(images) failed: " << result; DLOG(ERROR) << "vkGetSwapchainImagesKHR(images) failed: " << result;
return false; return false;
...@@ -196,15 +186,14 @@ bool VulkanSwapChain::InitializeSwapImages( ...@@ -196,15 +186,14 @@ bool VulkanSwapChain::InitializeSwapImages(
image_data->image = images[i]; image_data->image = images[i];
// Setup semaphores. // Setup semaphores.
result = vulkan_function_pointers->vkCreateSemaphore( result = vkCreateSemaphore(device, &semaphore_create_info, nullptr,
device, &semaphore_create_info, nullptr, &image_data->render_semaphore); &image_data->render_semaphore);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateSemaphore(render) failed: " << result; DLOG(ERROR) << "vkCreateSemaphore(render) failed: " << result;
return false; return false;
} }
result = vulkan_function_pointers->vkCreateSemaphore( result = vkCreateSemaphore(device, &semaphore_create_info, nullptr,
device, &semaphore_create_info, nullptr,
&image_data->present_semaphore); &image_data->present_semaphore);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateSemaphore(present) failed: " << result; DLOG(ERROR) << "vkCreateSemaphore(present) failed: " << result;
...@@ -218,10 +207,9 @@ bool VulkanSwapChain::InitializeSwapImages( ...@@ -218,10 +207,9 @@ bool VulkanSwapChain::InitializeSwapImages(
// command buffer. // command buffer.
ScopedSingleUseCommandBufferRecorder recorder(*image_data->command_buffer); ScopedSingleUseCommandBufferRecorder recorder(*image_data->command_buffer);
image_memory_barrier.image = images[i]; image_memory_barrier.image = images[i];
vulkan_function_pointers->vkCmdPipelineBarrier( vkCmdPipelineBarrier(recorder.handle(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
recorder.handle(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, nullptr, 0,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, nullptr, 1, &image_memory_barrier);
&image_memory_barrier);
// Create the image view. // Create the image view.
image_data->image_view.reset(new VulkanImageView(device_queue_)); image_data->image_view.reset(new VulkanImageView(device_queue_));
...@@ -232,16 +220,16 @@ bool VulkanSwapChain::InitializeSwapImages( ...@@ -232,16 +220,16 @@ bool VulkanSwapChain::InitializeSwapImages(
} }
} }
result = vulkan_function_pointers->vkCreateSemaphore( result = vkCreateSemaphore(device, &semaphore_create_info, nullptr,
device, &semaphore_create_info, nullptr, &next_present_semaphore_); &next_present_semaphore_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateSemaphore(next_present) failed: " << result; DLOG(ERROR) << "vkCreateSemaphore(next_present) failed: " << result;
return false; return false;
} }
// Acquire the initial buffer. // Acquire the initial buffer.
result = vulkan_function_pointers->vkAcquireNextImageKHR( result = vkAcquireNextImageKHR(device, swap_chain_, UINT64_MAX,
device, swap_chain_, UINT64_MAX, next_present_semaphore_, VK_NULL_HANDLE, next_present_semaphore_, VK_NULL_HANDLE,
&current_image_); &current_image_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkAcquireNextImageKHR() failed: " << result; DLOG(ERROR) << "vkAcquireNextImageKHR() failed: " << result;
...@@ -255,13 +243,10 @@ bool VulkanSwapChain::InitializeSwapImages( ...@@ -255,13 +243,10 @@ bool VulkanSwapChain::InitializeSwapImages(
} }
void VulkanSwapChain::DestroySwapImages() { void VulkanSwapChain::DestroySwapImages() {
VulkanFunctionPointers* vulkan_function_pointers =
gpu::GetVulkanFunctionPointers();
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
if (VK_NULL_HANDLE != next_present_semaphore_) { if (VK_NULL_HANDLE != next_present_semaphore_) {
vulkan_function_pointers->vkDestroySemaphore( vkDestroySemaphore(device, next_present_semaphore_, nullptr);
device, next_present_semaphore_, nullptr);
next_present_semaphore_ = VK_NULL_HANDLE; next_present_semaphore_ = VK_NULL_HANDLE;
} }
...@@ -282,14 +267,12 @@ void VulkanSwapChain::DestroySwapImages() { ...@@ -282,14 +267,12 @@ void VulkanSwapChain::DestroySwapImages() {
// Destroy Semaphores. // Destroy Semaphores.
if (VK_NULL_HANDLE != image_data->present_semaphore) { if (VK_NULL_HANDLE != image_data->present_semaphore) {
vulkan_function_pointers->vkDestroySemaphore( vkDestroySemaphore(device, image_data->present_semaphore, nullptr);
device, image_data->present_semaphore, nullptr);
image_data->present_semaphore = VK_NULL_HANDLE; image_data->present_semaphore = VK_NULL_HANDLE;
} }
if (VK_NULL_HANDLE != image_data->render_semaphore) { if (VK_NULL_HANDLE != image_data->render_semaphore) {
vulkan_function_pointers->vkDestroySemaphore( vkDestroySemaphore(device, image_data->render_semaphore, nullptr);
device, image_data->render_semaphore, nullptr);
image_data->render_semaphore = VK_NULL_HANDLE; image_data->render_semaphore = VK_NULL_HANDLE;
} }
......
...@@ -41,7 +41,7 @@ bool VulkanImplementationX11::InitializeVulkanInstance() { ...@@ -41,7 +41,7 @@ bool VulkanImplementationX11::InitializeVulkanInstance() {
// Initialize platform function pointers // Initialize platform function pointers
vkGetPhysicalDeviceXlibPresentationSupportKHR_ = vkGetPhysicalDeviceXlibPresentationSupportKHR_ =
reinterpret_cast<PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR>( reinterpret_cast<PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR>(
vulkan_function_pointers->vkGetInstanceProcAddr( vkGetInstanceProcAddr(
vulkan_instance_.vk_instance(), vulkan_instance_.vk_instance(),
"vkGetPhysicalDeviceXlibPresentationSupportKHR")); "vkGetPhysicalDeviceXlibPresentationSupportKHR"));
if (!vkGetPhysicalDeviceXlibPresentationSupportKHR_) { if (!vkGetPhysicalDeviceXlibPresentationSupportKHR_) {
...@@ -49,8 +49,8 @@ bool VulkanImplementationX11::InitializeVulkanInstance() { ...@@ -49,8 +49,8 @@ bool VulkanImplementationX11::InitializeVulkanInstance() {
return false; return false;
} }
vkCreateXlibSurfaceKHR_ = reinterpret_cast<PFN_vkCreateXlibSurfaceKHR>( vkCreateXlibSurfaceKHR_ =
vulkan_function_pointers->vkGetInstanceProcAddr( reinterpret_cast<PFN_vkCreateXlibSurfaceKHR>(vkGetInstanceProcAddr(
vulkan_instance_.vk_instance(), "vkCreateXlibSurfaceKHR")); vulkan_instance_.vk_instance(), "vkCreateXlibSurfaceKHR"));
if (!vkCreateXlibSurfaceKHR_) { if (!vkCreateXlibSurfaceKHR_) {
vulkan_instance_.Destroy(); vulkan_instance_.Destroy();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment