Commit 327ba857 by Jamie Madill Committed by Commit Bot

Vulkan: Hook up loader code.

This integrates the build files for the loader SDK, and tests the compilation by calling InitInstance. There's no current way to test the runtime behaviour since there's no way for the tests to initialize the Vulkan back-end, that will come in the next CL. BUG=angleproject:1319 Change-Id: Ia8bf96ca068eaf40744c9753b59ffaaa5ada8a73 Reviewed-on: https://chromium-review.googlesource.com/367519 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent f0470974
......@@ -48,4 +48,4 @@ TestResults.qpa
buildtools/
*.pyc
*.TMP
*.VC.db
......@@ -381,6 +381,7 @@ static_library("libANGLE") {
if (angle_enable_vulkan) {
sources += rebase_path(gles_gypi.libangle_vulkan_sources, ".", "src")
deps += [ "//third_party/angle/src/vulkan_support:angle_vulkan" ]
}
if (angle_enable_null) {
......
......@@ -51,7 +51,8 @@
[
'compiler.gypi',
'libGLESv2.gypi',
'libEGL.gypi'
'libEGL.gypi',
'vulkan_support/vulkan.gypi',
],
'targets':
......
......@@ -14,12 +14,41 @@
namespace rx
{
RendererVk::RendererVk() : mCapsInitialized(false)
RendererVk::RendererVk() : mCapsInitialized(false), mInstance(nullptr)
{
}
RendererVk::~RendererVk()
{
vkDestroyInstance(mInstance, nullptr);
}
vk::Error RendererVk::initialize()
{
VkApplicationInfo applicationInfo;
applicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
applicationInfo.pNext = nullptr;
applicationInfo.pApplicationName = "ANGLE";
applicationInfo.applicationVersion = 1;
applicationInfo.pEngineName = "ANGLE";
applicationInfo.engineVersion = 1;
applicationInfo.apiVersion = VK_API_VERSION_1_0;
VkInstanceCreateInfo instanceInfo;
instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instanceInfo.pNext = nullptr;
instanceInfo.flags = 0;
instanceInfo.pApplicationInfo = &applicationInfo;
// TODO(jmadill): Layers and extensions.
instanceInfo.enabledExtensionCount = 0;
instanceInfo.ppEnabledExtensionNames = nullptr;
instanceInfo.enabledLayerCount = 0;
instanceInfo.ppEnabledLayerNames = nullptr;
ANGLE_VK_TRY(vkCreateInstance(&instanceInfo, nullptr, &mInstance));
return vk::NoError();
}
void RendererVk::ensureCapsInitialized() const
......@@ -36,7 +65,7 @@ void RendererVk::generateCaps(gl::Caps * /*outCaps*/,
gl::Extensions * /*outExtensions*/,
gl::Limitations * /* outLimitations */) const
{
// TODO(jmadill): Caps
// TODO(jmadill): Caps.
}
const gl::Caps &RendererVk::getNativeCaps() const
......
......@@ -10,8 +10,11 @@
#ifndef LIBANGLE_RENDERER_VULKAN_RENDERERVK_H_
#define LIBANGLE_RENDERER_VULKAN_RENDERERVK_H_
#include <vulkan/vulkan.h>
#include "common/angleutils.h"
#include "libANGLE/Caps.h"
#include "libANGLE/renderer/vulkan/renderervk_utils.h"
namespace rx
{
......@@ -27,6 +30,8 @@ class RendererVk : angle::NonCopyable
const gl::Extensions &getNativeExtensions() const;
const gl::Limitations &getNativeLimitations() const;
vk::Error initialize();
private:
void ensureCapsInitialized() const;
void generateCaps(gl::Caps *outCaps,
......@@ -39,6 +44,8 @@ class RendererVk : angle::NonCopyable
mutable gl::TextureCapsMap mNativeTextureCaps;
mutable gl::Extensions mNativeExtensions;
mutable gl::Limitations mNativeLimitations;
VkInstance mInstance;
};
} // namespace rx
......
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// renderervk_utils:
// Helper functions for the Vulkan Renderer.
//
#include "renderervk_utils.h"
#include "common/debug.h"
namespace rx
{
namespace
{
GLenum DefaultGLErrorCode(VkResult result)
{
switch (result)
{
case VK_ERROR_OUT_OF_HOST_MEMORY:
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
case VK_ERROR_TOO_MANY_OBJECTS:
return GL_OUT_OF_MEMORY;
default:
return GL_INVALID_OPERATION;
}
}
EGLint DefaultEGLErrorCode(VkResult result)
{
switch (result)
{
case VK_ERROR_OUT_OF_HOST_MEMORY:
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
case VK_ERROR_TOO_MANY_OBJECTS:
return EGL_BAD_ALLOC;
case VK_ERROR_INITIALIZATION_FAILED:
return EGL_NOT_INITIALIZED;
case VK_ERROR_SURFACE_LOST_KHR:
case VK_ERROR_DEVICE_LOST:
return EGL_CONTEXT_LOST;
default:
return EGL_BAD_ACCESS;
}
}
} // anonymous namespace
const char *VulkanResultString(VkResult result)
{
switch (result)
{
case VK_SUCCESS:
return "Command successfully completed.";
case VK_NOT_READY:
return "A fence or query has not yet completed.";
case VK_TIMEOUT:
return "A wait operation has not completed in the specified time.";
case VK_EVENT_SET:
return "An event is signaled.";
case VK_EVENT_RESET:
return "An event is unsignaled.";
case VK_INCOMPLETE:
return "A return array was too small for the result.";
case VK_SUBOPTIMAL_KHR:
return "A swapchain no longer matches the surface properties exactly, but can still be "
"used to present to the surface successfully.";
case VK_ERROR_OUT_OF_HOST_MEMORY:
return "A host memory allocation has failed.";
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
return "A device memory allocation has failed.";
case VK_ERROR_INITIALIZATION_FAILED:
return "Initialization of an object could not be completed for implementation-specific "
"reasons.";
case VK_ERROR_DEVICE_LOST:
return "The logical or physical device has been lost.";
case VK_ERROR_MEMORY_MAP_FAILED:
return "Mapping of a memory object has failed.";
case VK_ERROR_LAYER_NOT_PRESENT:
return "A requested layer is not present or could not be loaded.";
case VK_ERROR_EXTENSION_NOT_PRESENT:
return "A requested extension is not supported.";
case VK_ERROR_FEATURE_NOT_PRESENT:
return "A requested feature is not supported.";
case VK_ERROR_INCOMPATIBLE_DRIVER:
return "The requested version of Vulkan is not supported by the driver or is otherwise "
"incompatible for implementation-specific reasons.";
case VK_ERROR_TOO_MANY_OBJECTS:
return "Too many objects of the type have already been created.";
case VK_ERROR_FORMAT_NOT_SUPPORTED:
return "A requested format is not supported on this device.";
case VK_ERROR_SURFACE_LOST_KHR:
return "A surface is no longer available.";
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
return "The requested window is already connected to a VkSurfaceKHR, or to some other "
"non-Vulkan API.";
case VK_ERROR_OUT_OF_DATE_KHR:
return "A surface has changed in such a way that it is no longer compatible with the "
"swapchain.";
case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
return "The display used by a swapchain does not use the same presentable image "
"layout, or is incompatible in a way that prevents sharing an image.";
case VK_ERROR_VALIDATION_FAILED_EXT:
return "The validation layers detected invalid API usage.";
default:
return "Unknown vulkan error code.";
}
}
namespace vk
{
Error::Error(VkResult result, const char *file, unsigned int line)
: mResult(result), mFile(file), mLine(line)
{
}
Error::~Error()
{
}
Error::Error(const Error &other) = default;
Error &Error::operator=(const Error &other) = default;
gl::Error Error::toGL(GLenum glErrorCode) const
{
if (!isError())
{
return gl::NoError();
}
// TODO(jmadill): Set extended error code to 'vulkan internal error'.
const std::string &message = getExtendedMessage();
return gl::Error(glErrorCode, message.c_str());
}
egl::Error Error::toEGL(EGLint eglErrorCode) const
{
if (!isError())
{
return egl::Error(EGL_SUCCESS);
}
// TODO(jmadill): Set extended error code to 'vulkan internal error'.
const std::string &message = getExtendedMessage();
return egl::Error(eglErrorCode, message.c_str());
}
std::string Error::getExtendedMessage() const
{
std::stringstream errorStream;
errorStream << "Internal Vulkan error: " << VulkanResultString(mResult) << ", in " << mFile
<< ", line " << mLine << ".";
return errorStream.str();
}
Error::operator gl::Error() const
{
return toGL(DefaultGLErrorCode(mResult));
}
Error::operator egl::Error() const
{
return toEGL(DefaultEGLErrorCode(mResult));
}
bool Error::isError() const
{
return (mResult != VK_SUCCESS);
}
} // namespace vk
} // namespace rx
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// renderervk_utils:
// Helper functions for the Vulkan Renderer.
//
#ifndef LIBANGLE_RENDERER_VULKAN_RENDERERVK_UTILS_H_
#define LIBANGLE_RENDERER_VULKAN_RENDERERVK_UTILS_H_
#include <vulkan/vulkan.h>
#include "libANGLE/Error.h"
namespace rx
{
const char *VulkanResultString(VkResult result);
namespace vk
{
class Error final
{
public:
Error(VkResult result, const char *file, unsigned int line);
~Error();
Error(const Error &other);
Error &operator=(const Error &other);
gl::Error toGL(GLenum glErrorCode) const;
egl::Error toEGL(EGLint eglErrorCode) const;
operator gl::Error() const;
operator egl::Error() const;
bool isError() const;
private:
std::string getExtendedMessage() const;
VkResult mResult;
const char *mFile;
unsigned int mLine;
};
// Avoid conflicting with X headers which define "Success".
inline Error NoError()
{
return Error(VK_SUCCESS, nullptr, 0);
}
} // namespace vk
} // namespace rx
#define ANGLE_VK_TRY(command) \
{ \
auto ANGLE_LOCAL_VAR = command; \
if (ANGLE_LOCAL_VAR != VK_SUCCESS) \
{ \
return rx::vk::Error(ANGLE_LOCAL_VAR, __FILE__, __LINE__); \
} \
} \
ANGLE_EMPTY_STATEMENT
#endif // LIBANGLE_RENDERER_VULKAN_RENDERERVK_UTILS_H_
......@@ -635,6 +635,8 @@
'libANGLE/renderer/vulkan/TransformFeedbackVk.h',
'libANGLE/renderer/vulkan/VertexArrayVk.cpp',
'libANGLE/renderer/vulkan/VertexArrayVk.h',
'libANGLE/renderer/vulkan/renderervk_utils.cpp',
'libANGLE/renderer/vulkan/renderervk_utils.h',
],
'libangle_null_sources':
[
......@@ -1025,10 +1027,18 @@
[
'<@(libangle_vulkan_sources)',
],
'dependencies':
[
'vulkan_loader',
],
'defines':
[
'ANGLE_ENABLE_VULKAN',
],
'export_dependent_settings':
[
'vulkan_loader',
],
}],
['angle_enable_null==1',
{
......
# Copyright 2016 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
vulkan_layers_dir = "../../../../vulkan-validation-layers/src/"
vulkan_gypi =
exec_script("//build/gypi_to_gn.py",
[
rebase_path("vulkan.gypi"),
"--replace=<(vulkan_layers_path)=$vulkan_layers_dir",
],
"scope",
[ "vulkan.gypi" ])
config("vulkan_loader_config") {
include_dirs = rebase_path(vulkan_gypi.vulkan_loader_include_dirs, ".", "src")
defines = [
"LAYERS_SOURCE_PATH=\"./gen/third_party/angle/src/vulkan_support/angle/vulkan/json\"",
"DEFAULT_VK_LAYERS_PATH=\".\"",
"API_NAME=\"Vulkan\"",
]
if (is_win) {
defines += [ "VK_USE_PLATFORM_WIN32_KHR" ]
}
}
config("vulkan_loader_internal_config") {
if (is_clang || !is_win) {
cflags = [ "-Wno-unused-function" ]
}
}
static_library("vulkan_loader") {
sources = rebase_path(vulkan_gypi.vulkan_loader_sources, ".", "src")
if (is_win) {
sources += rebase_path(vulkan_gypi.vulkan_loader_win_sources, ".", "src")
if (!is_clang) {
cflags = vulkan_gypi.vulkan_loader_cflags_win
}
configs -= [
"//build/config/win:nominmax",
"//build/config/win:unicode",
]
}
configs += [ ":vulkan_loader_internal_config" ]
public_configs = [ ":vulkan_loader_config" ]
}
# Use this target to include everything ANGLE needs for Vulkan.
group("angle_vulkan") {
deps = [
":vulkan_loader",
]
public_configs = [ ":vulkan_loader_config" ]
}
# Copyright 2016 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'variables':
{
'vulkan_layers_path': '../../third_party/vulkan-validation-layers/src',
'vulkan_loader_sources':
[
'<(vulkan_layers_path)/loader/cJSON.c',
'<(vulkan_layers_path)/loader/cJSON.h',
'<(vulkan_layers_path)/loader/debug_report.c',
'<(vulkan_layers_path)/loader/debug_report.h',
'<(vulkan_layers_path)/loader/dev_ext_trampoline.c',
'<(vulkan_layers_path)/loader/extensions.c',
'<(vulkan_layers_path)/loader/extensions.h',
'<(vulkan_layers_path)/loader/gpa_helper.h',
'<(vulkan_layers_path)/loader/loader.c',
'<(vulkan_layers_path)/loader/loader.h',
'<(vulkan_layers_path)/loader/murmurhash.c',
'<(vulkan_layers_path)/loader/murmurhash.h',
'<(vulkan_layers_path)/loader/table_ops.h',
'<(vulkan_layers_path)/loader/trampoline.c',
'<(vulkan_layers_path)/loader/vk_loader_platform.h',
'<(vulkan_layers_path)/loader/wsi.c',
'<(vulkan_layers_path)/loader/wsi.h',
],
'vulkan_loader_win_sources':
[
'<(vulkan_layers_path)/loader/dirent_on_windows.c',
'<(vulkan_layers_path)/loader/dirent_on_windows.h',
],
'vulkan_loader_include_dirs':
[
'<(vulkan_layers_path)/include',
'<(vulkan_layers_path)/loader',
],
'vulkan_loader_cflags_win':
[
'/wd4054', # Type cast from function pointer
'/wd4055', # Type cast from data pointer
'/wd4100', # Unreferenced formal parameter
'/wd4152', # Nonstandard extension used (pointer conversion)
'/wd4201', # Nonstandard extension used: nameless struct/union
'/wd4214', # Nonstandard extension used: bit field types other than int
'/wd4232', # Nonstandard extension used: address of dllimport is not static
'/wd4706', # Assignment within conditional expression
'/wd4996', # Unsafe stdlib function
],
},
'conditions':
[
['angle_enable_vulkan==1',
{
'targets':
[
{
'target_name': 'vulkan_loader',
'type': 'static_library',
'sources':
[
'<@(vulkan_loader_sources)',
],
'include_dirs':
[
'<@(vulkan_loader_include_dirs)',
],
'defines':
[
'API_NAME="Vulkan"',
],
'msvs_settings':
{
'VCCLCompilerTool':
{
'AdditionalOptions':
[
'<@(vulkan_loader_cflags_win)',
],
},
'VCLinkerTool':
{
'AdditionalDependencies':
[
'shlwapi.lib',
],
},
},
'direct_dependent_settings':
{
'include_dirs':
[
'<@(vulkan_loader_include_dirs)',
],
'msvs_settings':
{
'VCLinkerTool':
{
'AdditionalDependencies':
[
'shlwapi.lib',
],
},
},
'conditions':
[
['OS=="win"',
{
'defines':
[
'VK_USE_PLATFORM_WIN32_KHR',
],
}],
],
},
'conditions':
[
['OS=="win"',
{
'sources':
[
'<@(vulkan_loader_win_sources)',
],
'defines':
[
'VK_USE_PLATFORM_WIN32_KHR',
],
}],
],
},
],
}],
],
}
Name: Vulkan Ecosystem Components
Short Name: Vulkan Layers SDK
Version: N/A
URL: https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers
SOURCE CODE: git clone https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers.git
Date: 06/07/2016
Revision: d9da90d92748c37962766868f8b0354637672c2a
Security Critical: no
License: Apache 2.0
License File: LICENSE.txt
Description:
The Vulkan Ecosystem Components consist of the Vulkan loader and Validation Layers SDK. The layers help
validate Vulkan programs at runtime for development, and the loader is a utility for loading the Vulkan
entry points and hooking them into the correct layers. These are essential for developing Vulkan
applications.
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