| Index: src/gpu/vk/GrVkExtensions.cpp
|
| diff --git a/src/gpu/vk/GrVkExtensions.cpp b/src/gpu/vk/GrVkExtensions.cpp
|
| index c84dda359fa84c1690662aa51d04214756a2afc4..73cd8091a82d6b652cd278cde762f1e0ad821e8e 100644
|
| --- a/src/gpu/vk/GrVkExtensions.cpp
|
| +++ b/src/gpu/vk/GrVkExtensions.cpp
|
| @@ -30,50 +30,28 @@ static int find_string(const SkTArray<SkString>& strings, const char ext[]) {
|
| return idx;
|
| }
|
|
|
| -GrVkExtensions::GrVkExtensions(const GrVkExtensions& that)
|
| - : fInstanceExtensionStrings(new SkTArray<SkString>)
|
| - , fDeviceExtensionStrings(new SkTArray<SkString>)
|
| - , fInstanceLayerStrings(new SkTArray<SkString>)
|
| - , fDeviceLayerStrings(new SkTArray<SkString>) {
|
| - *this = that;
|
| -}
|
| +#define GET_PROC_LOCAL(inst, F) PFN_vk ## F F = (PFN_vk ## F) vkGetInstanceProcAddr(inst, "vk" #F)
|
|
|
| -GrVkExtensions& GrVkExtensions::operator=(const GrVkExtensions& that) {
|
| - *fInstanceExtensionStrings = *that.fInstanceExtensionStrings;
|
| - *fDeviceExtensionStrings = *that.fDeviceExtensionStrings;
|
| - *fInstanceLayerStrings = *that.fInstanceLayerStrings;
|
| - *fDeviceLayerStrings = *that.fDeviceLayerStrings;
|
| +bool GrVkExtensions::initInstance(uint32_t specVersion) {
|
|
|
| - fInitialized = that.fInitialized;
|
| - return *this;
|
| -}
|
| + GET_PROC_LOCAL(nullptr, EnumerateInstanceExtensionProperties);
|
| + GET_PROC_LOCAL(nullptr, EnumerateInstanceLayerProperties);
|
|
|
| -bool GrVkExtensions::init(
|
| - uint32_t specVersion,
|
| - VkPhysicalDevice physDev,
|
| - PFN_vkEnumerateInstanceExtensionProperties enumerateInstanceExtensionProperties,
|
| - PFN_vkEnumerateDeviceExtensionProperties enumerateDeviceExtensionProperties,
|
| - PFN_vkEnumerateInstanceLayerProperties enumerateInstanceLayerProperties,
|
| - PFN_vkEnumerateDeviceLayerProperties enumerateDeviceLayerProperties) {
|
| - fInitialized = false;
|
| - this->reset();
|
| SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
|
|
|
| - if (!enumerateInstanceExtensionProperties ||
|
| - !enumerateDeviceExtensionProperties ||
|
| - !enumerateInstanceLayerProperties ||
|
| - !enumerateDeviceLayerProperties) {
|
| + if (!EnumerateInstanceExtensionProperties ||
|
| + !EnumerateInstanceLayerProperties) {
|
| return false;
|
| }
|
|
|
| // instance layers
|
| uint32_t layerCount = 0;
|
| - VkResult res = enumerateInstanceLayerProperties(&layerCount, nullptr);
|
| + VkResult res = EnumerateInstanceLayerProperties(&layerCount, nullptr);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| VkLayerProperties* layers = new VkLayerProperties[layerCount];
|
| - res = enumerateInstanceLayerProperties(&layerCount, layers);
|
| + res = EnumerateInstanceLayerProperties(&layerCount, layers);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| @@ -90,12 +68,12 @@ bool GrVkExtensions::init(
|
| // instance extensions
|
| // via Vulkan implementation and implicitly enabled layers
|
| uint32_t extensionCount = 0;
|
| - res = enumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
|
| + res = EnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount];
|
| - res = enumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions);
|
| + res = EnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| @@ -113,13 +91,13 @@ bool GrVkExtensions::init(
|
| layerCount = fInstanceLayerStrings->count();
|
| for (uint32_t layerIndex = 0; layerIndex < layerCount; ++layerIndex) {
|
| uint32_t extensionCount = 0;
|
| - res = enumerateInstanceExtensionProperties((*fInstanceLayerStrings)[layerIndex].c_str(),
|
| + res = EnumerateInstanceExtensionProperties((*fInstanceLayerStrings)[layerIndex].c_str(),
|
| &extensionCount, nullptr);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount];
|
| - res = enumerateInstanceExtensionProperties((*fInstanceLayerStrings)[layerIndex].c_str(),
|
| + res = EnumerateInstanceExtensionProperties((*fInstanceLayerStrings)[layerIndex].c_str(),
|
| &extensionCount, extensions);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| @@ -136,14 +114,29 @@ bool GrVkExtensions::init(
|
| delete[] extensions;
|
| }
|
|
|
| + return true;
|
| +}
|
| +
|
| +bool GrVkExtensions::initDevice(uint32_t specVersion, VkInstance inst, VkPhysicalDevice physDev) {
|
| +
|
| + GET_PROC_LOCAL(inst, EnumerateDeviceExtensionProperties);
|
| + GET_PROC_LOCAL(inst, EnumerateDeviceLayerProperties);
|
| +
|
| + SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
|
| +
|
| + if (!EnumerateDeviceExtensionProperties ||
|
| + !EnumerateDeviceLayerProperties) {
|
| + return false;
|
| + }
|
| +
|
| // device layers
|
| - layerCount = 0;
|
| - res = enumerateDeviceLayerProperties(physDev, &layerCount, nullptr);
|
| + uint32_t layerCount = 0;
|
| + VkResult res = EnumerateDeviceLayerProperties(physDev, &layerCount, nullptr);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| - layers = new VkLayerProperties[layerCount];
|
| - res = enumerateDeviceLayerProperties(physDev, &layerCount, layers);
|
| + VkLayerProperties* layers = new VkLayerProperties[layerCount];
|
| + res = EnumerateDeviceLayerProperties(physDev, &layerCount, layers);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| @@ -160,13 +153,13 @@ bool GrVkExtensions::init(
|
|
|
| // device extensions
|
| // via Vulkan implementation and implicitly enabled layers
|
| - extensionCount = 0;
|
| - res = enumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, nullptr);
|
| + uint32_t extensionCount = 0;
|
| + res = EnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, nullptr);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| - extensions = new VkExtensionProperties[extensionCount];
|
| - res = enumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, extensions);
|
| + VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount];
|
| + res = EnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, extensions);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| @@ -184,16 +177,16 @@ bool GrVkExtensions::init(
|
| layerCount = fDeviceLayerStrings->count();
|
| for (uint32_t layerIndex = 0; layerIndex < layerCount; ++layerIndex) {
|
| uint32_t extensionCount = 0;
|
| - res = enumerateDeviceExtensionProperties(physDev,
|
| - (*fDeviceLayerStrings)[layerIndex].c_str(),
|
| - &extensionCount, nullptr);
|
| + res = EnumerateDeviceExtensionProperties(physDev,
|
| + (*fDeviceLayerStrings)[layerIndex].c_str(),
|
| + &extensionCount, nullptr);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount];
|
| - res = enumerateDeviceExtensionProperties(physDev,
|
| - (*fDeviceLayerStrings)[layerIndex].c_str(),
|
| - &extensionCount, extensions);
|
| + res = EnumerateDeviceExtensionProperties(physDev,
|
| + (*fDeviceLayerStrings)[layerIndex].c_str(),
|
| + &extensionCount, extensions);
|
| if (VK_SUCCESS != res) {
|
| return false;
|
| }
|
| @@ -208,147 +201,25 @@ bool GrVkExtensions::init(
|
| delete[] extensions;
|
| }
|
|
|
| - fInitialized = true;
|
| return true;
|
| }
|
|
|
| -
|
| bool GrVkExtensions::hasInstanceExtension(const char ext[]) const {
|
| - SkASSERT(fInitialized);
|
| -
|
| return find_string(*fInstanceExtensionStrings, ext) >= 0;
|
| }
|
|
|
| bool GrVkExtensions::hasDeviceExtension(const char ext[]) const {
|
| - SkASSERT(fInitialized);
|
| -
|
| return find_string(*fDeviceExtensionStrings, ext) >= 0;
|
| }
|
|
|
| bool GrVkExtensions::hasInstanceLayer(const char ext[]) const {
|
| - SkASSERT(fInitialized);
|
| -
|
| return find_string(*fInstanceLayerStrings, ext) >= 0;
|
| }
|
|
|
| bool GrVkExtensions::hasDeviceLayer(const char ext[]) const {
|
| - SkASSERT(fInitialized);
|
| -
|
| return find_string(*fDeviceLayerStrings, ext) >= 0;
|
| }
|
|
|
| -
|
| -bool GrVkExtensions::removeInstanceExtension(const char ext[]) {
|
| - SkASSERT(fInitialized);
|
| - int idx = find_string(*fInstanceExtensionStrings, ext);
|
| - if (idx >= 0) {
|
| - // This is not terribly effecient but we really only expect this function to be called at
|
| - // most a handful of times when our test programs start.
|
| - SkAutoTDelete< SkTArray<SkString> > oldStrings(fInstanceExtensionStrings.release());
|
| - fInstanceExtensionStrings.reset(new SkTArray<SkString>(oldStrings->count() - 1));
|
| - fInstanceExtensionStrings->push_back_n(idx, &oldStrings->front());
|
| - fInstanceExtensionStrings->push_back_n(oldStrings->count() - idx-1, &(*oldStrings)[idx]+1);
|
| - return true;
|
| - } else {
|
| - return false;
|
| - }
|
| -}
|
| -
|
| -bool GrVkExtensions::removeDeviceExtension(const char ext[]) {
|
| - SkASSERT(fInitialized);
|
| - int idx = find_string(*fDeviceExtensionStrings, ext);
|
| - if (idx >= 0) {
|
| - // This is not terribly effecient but we really only expect this function to be called at
|
| - // most a handful of times when our test programs start.
|
| - SkAutoTDelete< SkTArray<SkString> > oldStrings(fDeviceExtensionStrings.release());
|
| - fDeviceExtensionStrings.reset(new SkTArray<SkString>(oldStrings->count() - 1));
|
| - fDeviceExtensionStrings->push_back_n(idx, &oldStrings->front());
|
| - fDeviceExtensionStrings->push_back_n(oldStrings->count() - idx-1, &(*oldStrings)[idx] + 1);
|
| - return true;
|
| - }
|
| - else {
|
| - return false;
|
| - }
|
| -}
|
| -
|
| -bool GrVkExtensions::removeInstanceLayer(const char ext[]) {
|
| - SkASSERT(fInitialized);
|
| - int idx = find_string(*fInstanceLayerStrings, ext);
|
| - if (idx >= 0) {
|
| - // This is not terribly effecient but we really only expect this function to be called at
|
| - // most a handful of times when our test programs start.
|
| - SkAutoTDelete< SkTArray<SkString> > oldStrings(fInstanceLayerStrings.release());
|
| - fInstanceLayerStrings.reset(new SkTArray<SkString>(oldStrings->count() - 1));
|
| - fInstanceLayerStrings->push_back_n(idx, &oldStrings->front());
|
| - fInstanceLayerStrings->push_back_n(oldStrings->count() - idx - 1, &(*oldStrings)[idx] + 1);
|
| - return true;
|
| - }
|
| - else {
|
| - return false;
|
| - }
|
| -}
|
| -
|
| -bool GrVkExtensions::removeDeviceLayer(const char ext[]) {
|
| - SkASSERT(fInitialized);
|
| - int idx = find_string(*fDeviceLayerStrings, ext);
|
| - if (idx >= 0) {
|
| - // This is not terribly effecient but we really only expect this function to be called at
|
| - // most a handful of times when our test programs start.
|
| - SkAutoTDelete< SkTArray<SkString> > oldStrings(fDeviceLayerStrings.release());
|
| - fDeviceLayerStrings.reset(new SkTArray<SkString>(oldStrings->count() - 1));
|
| - fDeviceLayerStrings->push_back_n(idx, &oldStrings->front());
|
| - fDeviceLayerStrings->push_back_n(oldStrings->count() - idx - 1, &(*oldStrings)[idx] + 1);
|
| - return true;
|
| - }
|
| - else {
|
| - return false;
|
| - }
|
| -}
|
| -
|
| -void GrVkExtensions::addInstanceExtension(const char ext[]) {
|
| - int idx = find_string(*fInstanceExtensionStrings, ext);
|
| - if (idx < 0) {
|
| - // This is not the most effecient approach since we end up doing a full sort of the
|
| - // extensions after the add
|
| - fInstanceExtensionStrings->push_back().set(ext);
|
| - SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
|
| - SkTQSort(&fInstanceExtensionStrings->front(), &fInstanceExtensionStrings->back(), cmp);
|
| - }
|
| -}
|
| -
|
| -void GrVkExtensions::addDeviceExtension(const char ext[]) {
|
| - int idx = find_string(*fDeviceExtensionStrings, ext);
|
| - if (idx < 0) {
|
| - // This is not the most effecient approach since we end up doing a full sort of the
|
| - // extensions after the add
|
| - fDeviceExtensionStrings->push_back().set(ext);
|
| - SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
|
| - SkTQSort(&fDeviceExtensionStrings->front(), &fDeviceExtensionStrings->back(), cmp);
|
| - }
|
| -}
|
| -
|
| -void GrVkExtensions::addInstanceLayer(const char ext[]) {
|
| - int idx = find_string(*fInstanceLayerStrings, ext);
|
| - if (idx < 0) {
|
| - // This is not the most effecient approach since we end up doing a full sort of the
|
| - // extensions after the add
|
| - fInstanceLayerStrings->push_back().set(ext);
|
| - SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
|
| - SkTQSort(&fInstanceLayerStrings->front(), &fInstanceLayerStrings->back(), cmp);
|
| - }
|
| -}
|
| -
|
| -void GrVkExtensions::addDeviceLayer(const char ext[]) {
|
| - int idx = find_string(*fDeviceLayerStrings, ext);
|
| - if (idx < 0) {
|
| - // This is not the most effecient approach since we end up doing a full sort of the
|
| - // extensions after the add
|
| - fDeviceLayerStrings->push_back().set(ext);
|
| - SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
|
| - SkTQSort(&fDeviceLayerStrings->front(), &fDeviceLayerStrings->back(), cmp);
|
| - }
|
| -}
|
| -
|
| void GrVkExtensions::print(const char* sep) const {
|
| if (nullptr == sep) {
|
| sep = " ";
|
|
|