Skip to content

Commit

Permalink
Vulkan: Adding null driver as device option
Browse files Browse the repository at this point in the history
Bug: angleproject:2159

Plumbing to allow VK Mock ICD to be selected as the Vulkan driver.

Adding new ANGLE env var "ANGLE_VK_ICD_JSON" to point to json file
of mock ICD in angle and use this to override Vk loader ICD search
path.

At Vulkan renderer initialization time, enable the Mock ICD if device
is EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE.

Default physicalDevice is still the first detected device.
If Mock ICD is requested but not available, fall back to the first
device that was detected.

Added a VULKAN_NULL() testing config that uses Vulkan as renderer but
NULL as device. Turned on Vulkan NULL testing for DrawCallPerf.

Change-Id: I04e15c14e998448f8c98f9fd72e796389f297993
Reviewed-on: https://chromium-review.googlesource.com/961494
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
  • Loading branch information
tobine authored and Commit Bot committed Mar 28, 2018
1 parent 8a02d3b commit a3b220f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 14 deletions.
61 changes: 56 additions & 5 deletions src/libANGLE/renderer/vulkan/RendererVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "platform/Platform.h"

// Consts
namespace
{
const uint32_t kMockVendorID = 0xba5eba11;
const uint32_t kMockDeviceID = 0xf005ba11;
constexpr char kMockDeviceName[] = "Vulkan Mock Device";
} // anonymous namespace

namespace rx
{

Expand Down Expand Up @@ -125,7 +133,7 @@ class ScopedVkLoaderEnvironment : angle::NonCopyable
// Override environment variable to use the ANGLE layers.
if (mEnableValidationLayers)
{
if (!angle::PrependPathToEnvironmentVar(g_VkLoaderLayersPathEnv, ANGLE_VK_LAYERS_DIR))
if (!angle::PrependPathToEnvironmentVar(g_VkLoaderLayersPathEnv, ANGLE_VK_DATA_DIR))
{
ERR() << "Error setting environment for Vulkan layers init.";
mEnableValidationLayers = false;
Expand Down Expand Up @@ -251,11 +259,53 @@ RendererVk::~RendererVk()
mPhysicalDevice = VK_NULL_HANDLE;
}

void ChoosePhysicalDevice(const std::vector<VkPhysicalDevice> &physicalDevices,
bool preferMockICD,
VkPhysicalDevice *physicalDeviceOut,
VkPhysicalDeviceProperties *physicalDevicePropertiesOut)
{
ASSERT(!physicalDevices.empty());
if (preferMockICD)
{
for (const VkPhysicalDevice &physicalDevice : physicalDevices)
{
vkGetPhysicalDeviceProperties(physicalDevice, physicalDevicePropertiesOut);
if ((kMockVendorID == physicalDevicePropertiesOut->vendorID) &&
(kMockDeviceID == physicalDevicePropertiesOut->deviceID) &&
(strcmp(kMockDeviceName, physicalDevicePropertiesOut->deviceName) == 0))
{
*physicalDeviceOut = physicalDevice;
return;
}
}
WARN() << "Vulkan Mock Driver was requested but Mock Device was not found. Using default "
"physicalDevice instead.";
}

// Fall back to first device.
*physicalDeviceOut = physicalDevices[0];
vkGetPhysicalDeviceProperties(*physicalDeviceOut, physicalDevicePropertiesOut);
}

vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *wsiName)
{
ScopedVkLoaderEnvironment scopedEnvironment(ShouldUseDebugLayers(attribs));
mEnableValidationLayers = scopedEnvironment.canEnableValidationLayers();

bool enableNullDriver = false;
#if !defined(ANGLE_PLATFORM_ANDROID)
// Mock ICD does not currently run on Android
enableNullDriver = (attribs.get(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE,
EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE) ==
EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE);
if (enableNullDriver)
{
// Override environment variable to use built Mock ICD
// ANGLE_VK_ICD_JSON gets set to the built mock ICD in BUILD.gn
ANGLE_VK_CHECK(angle::SetEnvironmentVar(g_VkICDPathEnv, ANGLE_VK_ICD_JSON),
VK_ERROR_INITIALIZATION_FAILED);
}
#endif // !defined(ANGLE_PLATFORM_ANDROID)
// Gather global layer properties.
uint32_t instanceLayerCount = 0;
ANGLE_VK_TRY(vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr));
Expand Down Expand Up @@ -348,10 +398,11 @@ vk::Error RendererVk::initialize(const egl::AttributeMap &attribs, const char *w
ANGLE_VK_CHECK(physicalDeviceCount > 0, VK_ERROR_INITIALIZATION_FAILED);

// TODO(jmadill): Handle multiple physical devices. For now, use the first device.
physicalDeviceCount = 1;
ANGLE_VK_TRY(vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, &mPhysicalDevice));

vkGetPhysicalDeviceProperties(mPhysicalDevice, &mPhysicalDeviceProperties);
std::vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount);
ANGLE_VK_TRY(
vkEnumeratePhysicalDevices(mInstance, &physicalDeviceCount, physicalDevices.data()));
ChoosePhysicalDevice(physicalDevices, enableNullDriver, &mPhysicalDevice,
&mPhysicalDeviceProperties);

// Ensure we can find a graphics queue family.
uint32_t queueCount = 0;
Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/vulkan/vk_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ vk::Error AllocateBufferOrImageMemory(RendererVk *renderer,
} // anonymous namespace

const char *g_VkLoaderLayersPathEnv = "VK_LAYER_PATH";
const char *g_VkICDPathEnv = "VK_ICD_FILENAMES";

const char *VulkanResultString(VkResult result)
{
Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/vulkan/vk_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ bool GetAvailableValidationLayers(const std::vector<VkLayerProperties> &layerPro
uint32_t *enabledLayerCount);

extern const char *g_VkLoaderLayersPathEnv;
extern const char *g_VkICDPathEnv;

enum class TextureDimension
{
Expand Down
6 changes: 4 additions & 2 deletions src/tests/perf_tests/DrawCallPerf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ ANGLE_INSTANTIATE_TEST(DrawCallPerfBenchmark,
DrawArrays(DrawCallPerfOpenGLOrGLESParams(true, true), false),
DrawArrays(DrawCallPerfOpenGLOrGLESParams(true, false), true),
DrawArrays(DrawCallPerfValidationOnly(), false),
DrawArrays(DrawCallPerfVulkanParams(false), false),
DrawArrays(DrawCallPerfVulkanParams(false), true));
DrawArrays(DrawCallPerfVulkanParams(true, false), true),
DrawArrays(DrawCallPerfVulkanParams(true, false), false),
DrawArrays(DrawCallPerfVulkanParams(false, false), false),
DrawArrays(DrawCallPerfVulkanParams(false, false), true));

} // namespace
4 changes: 2 additions & 2 deletions src/tests/perf_tests/DrawCallPerfParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ DrawCallPerfParams DrawCallPerfValidationOnly()
return params;
}

DrawCallPerfParams DrawCallPerfVulkanParams(bool renderToTexture)
DrawCallPerfParams DrawCallPerfVulkanParams(bool useNullDevice, bool renderToTexture)
{
DrawCallPerfParams params;
params.eglParameters = VULKAN();
params.eglParameters = useNullDevice ? VULKAN_NULL() : VULKAN();
params.useFBO = renderToTexture;
return params;
}
2 changes: 1 addition & 1 deletion src/tests/perf_tests/DrawCallPerfParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ DrawCallPerfParams DrawCallPerfD3D11Params(bool useNullDevice, bool renderToText
DrawCallPerfParams DrawCallPerfD3D9Params(bool useNullDevice, bool renderToTexture);
DrawCallPerfParams DrawCallPerfOpenGLOrGLESParams(bool useNullDevice, bool renderToTexture);
DrawCallPerfParams DrawCallPerfValidationOnly();
DrawCallPerfParams DrawCallPerfVulkanParams(bool renderToTexture);
DrawCallPerfParams DrawCallPerfVulkanParams(bool useNullDevice, bool renderToTexture);

#endif // TESTS_PERF_TESTS_DRAW_CALL_PERF_PARAMS_H_
16 changes: 16 additions & 0 deletions src/tests/test_utils/angle_test_configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ EGLPlatformParameters VULKAN()
return EGLPlatformParameters(EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE);
}

EGLPlatformParameters VULKAN_NULL()
{
return EGLPlatformParameters(EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE, EGL_DONT_CARE, EGL_DONT_CARE,
EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE);
}

} // namespace egl_platform

// ANGLE tests platforms
Expand Down Expand Up @@ -671,9 +677,19 @@ PlatformParameters ES1_VULKAN()
return PlatformParameters(1, 0, egl_platform::VULKAN());
}

PlatformParameters ES1_VULKAN_NULL()
{
return PlatformParameters(1, 0, egl_platform::VULKAN_NULL());
}

PlatformParameters ES2_VULKAN()
{
return PlatformParameters(2, 0, egl_platform::VULKAN());
}

PlatformParameters ES2_VULKAN_NULL()
{
return PlatformParameters(2, 0, egl_platform::VULKAN_NULL());
}

} // namespace angle
3 changes: 3 additions & 0 deletions src/tests/test_utils/angle_test_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ EGLPlatformParameters OPENGLES_NULL();
EGLPlatformParameters OPENGL_OR_GLES(bool useNullDevice);

EGLPlatformParameters VULKAN();
EGLPlatformParameters VULKAN_NULL();

} // namespace egl_platform

Expand Down Expand Up @@ -167,7 +168,9 @@ PlatformParameters ES3_NULL();
PlatformParameters ES31_NULL();

PlatformParameters ES1_VULKAN();
PlatformParameters ES1_VULKAN_NULL();
PlatformParameters ES2_VULKAN();
PlatformParameters ES2_VULKAN_NULL();

} // namespace angle

Expand Down
9 changes: 5 additions & 4 deletions third_party/vulkan-validation-layers/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ config("vulkan_loader_config") {
"src/loader",
]
defines = [
"ANGLE_VK_LAYERS_DIR=\"$data_dir\"",
"ANGLE_VK_DATA_DIR=\"$data_dir\"",
"ANGLE_VK_ICD_JSON=\"$data_dir/VkICD_mock_icd.json\"",
"API_NAME=\"Vulkan\"",
]

Expand Down Expand Up @@ -524,12 +525,12 @@ if (!is_android) {

# The layer JSON files are part of the necessary data deps.
outputs = [
"$root_out_dir/$data_dir/icd/VkICD_mock_icd.json",
"$root_out_dir/$data_dir/VkICD_mock_icd.json",
]
data = [
"$root_out_dir/$data_dir/icd/VkICD_mock_icd.json",
"$root_out_dir/$data_dir/VkICD_mock_icd.json",
]
args += [ rebase_path("$root_out_dir/$data_dir/icd", root_build_dir) ]
args += [ rebase_path("$root_out_dir/$data_dir", root_build_dir) ]
}
}

Expand Down

0 comments on commit a3b220f

Please sign in to comment.