ভলকান বাস্তবায়ন করুন

Vulkan is a low-overhead, cross-platform API for high-performance 3D graphics. Like OpenGL ES (GLES) , Vulkan provides tools for creating high-quality, real-time graphics in apps. Advantages of using Vulkan include reductions in CPU overhead and support for the SPIR-V Binary Intermediate language.

Vulkan সফলভাবে প্রয়োগ করার জন্য একটি ডিভাইসে অবশ্যই নিম্নলিখিত বিষয়গুলো অন্তর্ভুক্ত থাকতে হবে:

  • The Vulkan loader, provided by Android.
  • A Vulkan driver, provided by SoCs such as GPU IHVs, that implements the Vulkan API . To support Vulkan functionality, the Android device needs Vulkan-capable GPU hardware and the associated driver. The GPU must also support GLES 3.1 and higher. Consult your SoC vendor to request driver support.

If a device includes a Vulkan driver, the device needs to declare FEATURE_VULKAN_HARDWARE_LEVEL and FEATURE_VULKAN_HARDWARE_VERSION system features, with versions that accurately reflect the capabilities of the device. This helps ensure that the device is in compliance with the Compatibility Definition Document (CDD).

Vulkan loader

Vulkan লোডার platform/frameworks/native/vulkan হলো Vulkan অ্যাপ এবং একটি ডিভাইসের Vulkan ড্রাইভারের মধ্যে প্রধান ইন্টারফেস। Vulkan লোডারটি /system/lib[64]/libvulkan.so তে ইনস্টল করা হয়। লোডারটি কোর Vulkan API এন্ট্রি পয়েন্ট, Android CDD-এর জন্য প্রয়োজনীয় এক্সটেনশনগুলির এন্ট্রি পয়েন্ট এবং আরও অনেক ঐচ্ছিক এক্সটেনশন সরবরাহ করে। Window System Integration (WSI) এক্সটেনশনগুলি লোডার দ্বারা এক্সপোর্ট করা হয় এবং প্রধানত ড্রাইভারের পরিবর্তে লোডারেই প্রয়োগ করা হয়। লোডারটি এমন লেয়ারগুলি গণনা এবং লোড করাও সমর্থন করে যা অতিরিক্ত এক্সটেনশন প্রকাশ করতে পারে এবং ড্রাইভারের দিকে যাওয়ার পথে কোর API কলগুলিকে বাধা দিতে পারে।

The NDK includes a stub libvulkan.so library for linking. The library exports the same symbols as the loader. Apps call the functions exported from the real libvulkan.so library to enter trampoline functions in the loader, which dispatch to the appropriate layer or driver based on their first argument. The vkGet*ProcAddr() call returns the function pointers to which the trampolines dispatch (that is, it calls directly into the core API code). Calling through the function pointers, rather than the exported symbols, is more efficient as it skips the trampoline and dispatch.

Driver enumeration and loading

When the system image is built, Android expects the system to know which GPUs are available. The loader uses the existing HAL mechanism in hardware.h to discover and load the driver. Preferred paths for 32-bit and 64-bit Vulkan drivers are:

/vendor/lib/hw/vulkan.<ro.hardware.vulkan>.so
/vendor/lib/hw/vulkan.<ro.board.platform>.so
/vendor/lib64/hw/vulkan.<ro.hardware.vulkan>.so
/vendor/lib64/hw/vulkan.<ro.board.platform>.so

অ্যান্ড্রয়েড ৭.০ এবং তার পরবর্তী সংস্করণগুলিতে, ভলকান hw_module_t ডেরিভেটিভটি একটি একক hw_module_t struct-কে র‍্যাপ করে; কেবল একটি ড্রাইভার সমর্থিত হয় এবং open() ফাংশনে HWVULKAN_DEVICE_0 নামক কনস্ট্যান্ট স্ট্রিংটি পাস করা হয়।

Vulkan-এর hw_device_t ডেরিভেটিভটি একটি একক ড্রাইভারের সাথে সঙ্গতিপূর্ণ, যা একাধিক ফিজিক্যাল ডিভাইস সমর্থন করতে পারে। hw_device_t স্ট্রাকচারটি vkGetGlobalExtensionProperties() , vkCreateInstance() , এবং vkGetInstanceProcAddr() ফাংশনগুলো এক্সপোর্ট করার জন্য সম্প্রসারিত হতে পারে। লোডারটি hw_device_t স্ট্রাকচারের vkGetInstanceProcAddr() ফাংশনটি কল করার মাধ্যমে অন্য সব VkInstance() , VkPhysicalDevice() , এবং vkGetDeviceProcAddr() ফাংশন খুঁজে নিতে পারে।

অ্যান্ড্রয়েড ১৫ থেকে, লোডারটি ভলকান ড্রাইভার লোড করার জন্য APEX সমর্থন করে। APEX থেকে ভলকান লোড করতে, ro.vulkan.apex ভলকান APEX-এর নামে সেট করুন।

Layer discovery and loading

The Vulkan loader supports enumerating and loading layers that can expose additional extensions and intercept core API calls on their way to the driver. Apps can include layers in their APK. Android doesn't include layers on the system image.

লেয়ার ব্যবহার করার সময় মনে রাখবেন যে, অ্যান্ড্রয়েডের নিরাপত্তা মডেল এবং নীতিমালা অন্যান্য প্ল্যাটফর্ম থেকে উল্লেখযোগ্যভাবে ভিন্ন। বিশেষ করে, অ্যান্ড্রয়েড প্রোডাকশন (নন-রুটেড) ডিভাইসে কোনো নন-ডিবাগেবল প্রসেসে এক্সটার্নাল কোড লোড করার অনুমতি দেয় না, এবং এটি এক্সটার্নাল কোডকে প্রসেসটির মেমরি, স্টেট ইত্যাদি পরিদর্শন বা নিয়ন্ত্রণ করারও অনুমতি দেয় না। এর মধ্যে পরবর্তী পরিদর্শনের জন্য কোর ডাম্প, এপিআই ট্রেস ইত্যাদি ডিস্কে সংরক্ষণ করার উপর নিষেধাজ্ঞাও অন্তর্ভুক্ত। প্রোডাকশন ডিভাইসে শুধুমাত্র নন-ডিবাগেবল অ্যাপের অংশ হিসেবে সরবরাহ করা লেয়ারগুলোই সক্রিয় থাকে, এবং ড্রাইভারগুলো এমন কোনো কার্যকারিতা প্রদান করতে পারবে না যা এই নীতিমালা লঙ্ঘন করে।

Use cases for layers include:

  • Development-time layers — Validation layers and shims for tracing/profiling/debugging tools shouldn't be installed on the system image of production devices. Validation layers and shims for tracing/profiling/debugging tools should be updatable without a system image. Developers who want to use one of these layers during development can modify the app package, for example, by adding a file to their native libraries directory. IHV and OEM engineers who want to diagnose failures in shipping unmodifiable apps are assumed to have access to nonproduction (rooted) builds of the system image, unless those apps are debuggable. For more information see Vulkan validation layers on Android .
  • Utility layers — These layers expose extensions, such as a layer that implements a memory manager for device memory. Developers choose layers, and versions of those layers, to use in their app; different apps using the same layer may still use different versions. Developers choose which of these layers to ship in their app package.
  • Injected (implicit) layers — Includes layers such as frame rate, social network, and game launcher overlays provided by the user or some other app without the app's knowledge or consent. These violate Android's security policies and aren't supported.

For nondebuggable apps, the loader searches for layers only in the app's native library directory and attempts to load any library with a name matching a particular pattern (for example, libVKLayer_foo.so ). These layers are loaded into the app's namespace. As such, they must be built with the NDK.

ডিবাগযোগ্য অ্যাপের জন্য, লোডার /data/local/debug/vulkan লেয়ারগুলো খোঁজে এবং একটি নির্দিষ্ট প্যাটার্নের সাথে মেলে এমন যেকোনো লাইব্রেরি লোড করার চেষ্টা করে। অ্যান্ড্রয়েড ১০ (এপিআই লেভেল ২৯) থেকে শুরু করে, ভলকান অন্য একটি এপিকে থেকে ডেভেলপমেন্ট-টাইম লেয়ারও লোড করতে পারে। উভয় ক্ষেত্রেই, লোডার সিস্টেম সেটিংস ব্যবহার করে প্রতিটি অ্যাপের জন্য আলাদাভাবে কোন লেয়ারগুলো সক্রিয় করবে তা নির্বাচন করে। এই লেয়ারগুলো vkEnumerateInstanceLayerProperties এ তালিকাভুক্ত থাকে (অর্থাৎ, অ্যাপটি এগুলি সম্পর্কে জানতে পারে), যদিও সেগুলি অ্যাপের অনুমতি ছাড়াই লোড হতে পারে।

Android enables layers to be ported with build-environment changes between Android and other platforms. For details on the interface between layers and the loader, see Architecture of the Vulkan Loader Interfaces . The Khronos-maintained validation layers are hosted in Vulkan Validation Layers .

Vulkan API versions and capabilities

নিচের সারণিতে বিভিন্ন অ্যান্ড্রয়েড রিলিজের ভলকান এপিআই সংস্করণগুলো তালিকাভুক্ত করা হয়েছে।
Android Version Vulkan Version
অ্যান্ড্রয়েড ১৬ Vulkan 1.4
Android 13 Vulkan 1.3
Android 9 Vulkan 1.1
Android 7 Vulkan 1.0

Vulkan 1.4 functionality overview

ভলকান ১.৪ পূর্বে ঐচ্ছিক থাকা বেশ কিছু এক্সটেনশনকে ভলকানের মূল কার্যকারিতার অন্তর্ভুক্ত করেছে। এই কার্যকারিতার বেশিরভাগই ভলকান প্রোগ্রামিং ইন্টারফেসের উপর নিয়ন্ত্রণ এবং সূক্ষ্মতা বাড়ানোর উদ্দেশ্যে অন্তর্ভুক্ত করা হয়েছে। ভলকান ১.৩-এর তুলনায় ভলকান ১.৪-এর জন্য হার্ডওয়্যারের প্রয়োজনীয়তা বৃদ্ধি পেয়েছে, যার বেশিরভাগ বাস্তবায়ন ফ্রেমওয়ার্কে নয়, বরং এসওসি-নির্দিষ্ট গ্রাফিক্স ড্রাইভারে করা হয়েছে।

Vulkan 1.3 functionality overview

ভলকান ১.৩ পূর্বে ঐচ্ছিক থাকা বেশ কিছু এক্সটেনশনকে ভলকানের মূল কার্যকারিতার অন্তর্ভুক্ত করেছে। এই কার্যকারিতার বেশিরভাগই ভলকান প্রোগ্রামিং ইন্টারফেসের উপর নিয়ন্ত্রণ এবং সূক্ষ্মতা বাড়ানোর উদ্দেশ্যে অন্তর্ভুক্ত করা হয়েছে। সিঙ্গেল-পাস রেন্ডার পাস ইনস্ট্যান্সগুলোর জন্য এখন আর রেন্ডার পাস অবজেক্ট বা ফ্রেমবাফারের প্রয়োজন নেই। পাইপলাইন স্টেট অবজেক্টের মোট সংখ্যা কমানো সম্ভব হয়েছে এবং এপিআই-এর মধ্যেকার সিনক্রোনাইজেশনকে ঢেলে সাজানো হয়েছে। ভলকান ১.৩-এর জন্য প্রয়োজনীয় হার্ডওয়্যার ভলকান ১.২, ১.১ এবং ১.০-এর মতোই, তবে এর বেশিরভাগ বাস্তবায়ন ফ্রেমওয়ার্কে না থেকে এসওসি-নির্দিষ্ট গ্রাফিক্স ড্রাইভারের মধ্যে করা হয়েছে।

অ্যান্ড্রয়েডের জন্য ভলকান ১.৩-এর সবচেয়ে গুরুত্বপূর্ণ বৈশিষ্ট্যগুলো হলো:

  • Support for single-pass render pass instances
  • শেডার আহ্বান অবিলম্বে বন্ধ করার জন্য সমর্থন
  • পাইপলাইন তৈরি, শেয়ার এবং নিয়ন্ত্রণের ক্ষেত্রে আরও সূক্ষ্ম নিয়ন্ত্রণ

Vulkan 1.3 also includes several smaller features and API usability enhancements. All changes made to the core Vulkan API with minor revision 1.3 can be found at Core Revisions (Vulkan 1.3) .

Vulkan 1.2 functionality overview

Vulkan 1.2 adds a number of features and extensions that simplifies the API surface. This includes a unified Memory Model and additional information that can be queried from a device driver. Vulkan 1.2 has the same hardware requirements as Vulkan 1.0 and 1.1; all of the implementation is in the SoC-specific graphics driver, not the framework.

অ্যান্ড্রয়েডের জন্য ভলকান ১.২-এর সবচেয়ে গুরুত্বপূর্ণ বৈশিষ্ট্য হলো ৮-বিট স্টোরেজের সমর্থন।

Vulkan 1.2-এ আরও বেশ কিছু ছোটখাটো ফিচার এবং API-এর ব্যবহারযোগ্যতার উন্নতি অন্তর্ভুক্ত রয়েছে। মাইনর রিভিশন 1.2-এর মাধ্যমে কোর Vulkan API-তে করা সমস্ত পরিবর্তন Core Revisions (Vulkan 1.2) -এ পাওয়া যাবে।

Vulkan 1.1 functionality overview

ভুলকান ১.১-এ মেমরি/সিঙ্ক্রোনাইজেশন ইন্টারঅপের সমর্থন অন্তর্ভুক্ত রয়েছে, যা OEM-দের ডিভাইসগুলিতে ভুলকান ১.১ সমর্থন করতে সক্ষম করে। এছাড়াও, মেমরি/সিঙ্ক্রোনাইজেশন ইন্টারঅপ ডেভেলপারদেরকে কোনো ডিভাইসে ভুলকান ১.১ সমর্থিত কিনা তা নির্ধারণ করতে এবং সমর্থিত হলে তা কার্যকরভাবে ব্যবহার করতে সক্ষম করে। ভুলকান ১.১-এর জন্য প্রয়োজনীয় হার্ডওয়্যারের শর্তাবলী ভুলকান ১.০-এর মতোই, কিন্তু এর বেশিরভাগ বাস্তবায়ন ফ্রেমওয়ার্কে না থেকে SOC-নির্দিষ্ট গ্রাফিক্স ড্রাইভারের মধ্যে থাকে।

অ্যান্ড্রয়েডের জন্য ভলকান ১.১-এর সবচেয়ে গুরুত্বপূর্ণ বৈশিষ্ট্যগুলো হলো:

  • Support for importing and exporting memory buffers and synchronization objects from outside Vulkan (for interop with camera, codecs, and GLES)
  • Support for YCbCr formats

Vulkan 1.1-এ আরও বেশ কিছু ছোটখাটো ফিচার এবং API-এর ব্যবহারযোগ্যতার উন্নতি অন্তর্ভুক্ত রয়েছে। মাইনর রিভিশন 1.1-এর মাধ্যমে কোর Vulkan API-তে করা সমস্ত পরিবর্তন Core Revisions (Vulkan 1.1) -এ পাওয়া যাবে।

Choose Vulkan support

সকল অ্যান্ড্রয়েড ডিভাইসকে অবশ্যই উপলব্ধ সর্বাধুনিক ভলকান ফিচার সেট সমর্থন করতে হবে, তবে শর্ত হলো ডিভাইসগুলো ৬৪-বিট এবিআই সমর্থন করে এবং সেগুলোর মেমোরি কম থাকা চলবে না।

যেসব ডিভাইস অ্যান্ড্রয়েড ১৬ বা তার পরবর্তী সংস্করণ নিয়ে বাজারে আসে, সেগুলোতে অবশ্যই ভলকান ১.৪ সাপোর্ট থাকতে হবে।

যেসব ডিভাইস অ্যান্ড্রয়েড ১৩ বা তার পরবর্তী সংস্করণ নিয়ে বাজারে আসে, সেগুলোতে অবশ্যই ভলকান ১.৩ সাপোর্ট থাকতে হবে।

যেসব ডিভাইস অ্যান্ড্রয়েড ১০-এর মাধ্যমে চালু হবে, সেগুলোতে অবশ্যই ভলকান ১.১ সমর্থন থাকতে হবে।

অন্যান্য ডিভাইসগুলো ঐচ্ছিকভাবে ভলকান ১.৪, ১.৩, ১.২ এবং ১.১ সমর্থন করতে পারে।

Support a Vulkan version

একটি অ্যান্ড্রয়েড ডিভাইস ভলকান সংস্করণ সমর্থন করে, যদি নিম্নলিখিত শর্তগুলো পূরণ হয়:

  1. Add a Vulkan driver that supports the Vulkan version of interest (this must be one of Vulkan version 1.4, 1.3, 1.1, or 1.0) alongside the additional CDD requirements of the Android version. Alternatively, update an existing Vulkan driver of a lower Vulkan version number.
  2. Vulkan 1.4, 1.3, বা 1.1-এর ক্ষেত্রে, যাচাই করুন যে প্যাকেজ ম্যানেজার দ্বারা ফেরত আসা সিস্টেম ফিচারটি সঠিক Vulkan সংস্করণের জন্য true রিটার্ন করে।
    • For Vulkan 1.4 the feature is PackageManager#hasSystemFeature(PackageManager.FEATURE_VULKAN_HARDWARE_VERSION, 0x404000) .
    • For Vulkan 1.3 the feature is PackageManager#hasSystemFeature(PackageManager.FEATURE_VULKAN_HARDWARE_VERSION, 0x403000) .
    • Vulkan 1.1-এর জন্য ফিচারটি হলো PackageManager#hasSystemFeature(PackageManager.FEATURE_VULKAN_HARDWARE_VERSION, 0x401000)
    উপযুক্ত device.mk ফাইলে নিম্নরূপ একটি নিয়ম যোগ করার মাধ্যমে প্যাকেজ ম্যানেজার Vulkan 1.4, 1.3 এবং 1.1-এর জন্য true রিটার্ন করবে।
    • Add the following for Vulkan 1.4:
      PRODUCT_COPY_FILES += frameworks/native/data/etc/android.hardware.vulkan.version-1_4.xml:
      $(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml
    • Add the following for Vulkan 1.3:
      PRODUCT_COPY_FILES += frameworks/native/data/etc/android.hardware.vulkan.version-1_3.xml:
      $(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml
    • Add the following for Vulkan 1.1:
      PRODUCT_COPY_FILES += frameworks/native/data/etc/android.hardware.vulkan.version-1_1.xml:
      $(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml

Android Baseline profile (ABP)

আমরা সকল অ্যান্ড্রয়েড ডিভাইসকে অ্যান্ড্রয়েড বেসলাইন প্রোফাইল গাইডে বর্ণিত সর্বশেষ অ্যান্ড্রয়েড বেসলাইন ২০২২ প্রোফাইলটি অনুসরণ করতে উৎসাহিত করি।

Any device that supports Android 14 or higher and the Vulkan API, must fulfill all functionality defined in the Android Baseline 2021 profile . The full list of required functionality is enumerated in the Vulkan profile json file, but a key subset of the required functionality includes:

  • Compressed textures through ASTC and ETC.
  • VK_EXT_swapchain_colorspace এর মাধ্যমে পরিবর্তনশীল কালারস্পেসসমূহ।
  • sampleRateShading মাধ্যমে স্যাম্পল শেডিং এবং মাল্টিস্যাম্পল ইন্টারপোলেশন।

Window system integration (WSI)

libvulkan.so তে, ড্রাইভারটি নিম্নলিখিত উইন্ডো সিস্টেম ইন্টিগ্রেশন (WSI) এক্সটেনশনগুলি প্রয়োগ করে:

  • VK_KHR_surface
  • VK_KHR_android_surface
  • VK_KHR_swapchain
  • VK_KHR_driver_properties , যা শুধুমাত্র Android 10-এ Vulkan 1.1-এর জন্য প্রয়োগ করা হয়েছে।
  • VK_GOOGLE_display_timing , যা Android 10-এর যেকোনো Vulkan সংস্করণের জন্য বাস্তবায়িত হয়েছে।

The VkSurfaceKHR and VkSwapchainKHR objects and all interactions with ANativeWindow are handled by the platform and aren't exposed to drivers. The WSI implementation relies on the VK_ANDROID_native_buffer extension, which must be supported by the driver; this extension is used only by the WSI implementation and isn't exposed to apps.

Gralloc usage flags

Vulkan implementations may need swapchain buffers to be allocated with implementation-defined private Gralloc usage flags. When creating a swapchain, Android asks the driver to translate the requested format and image usage flags into Gralloc usage flags by calling:

typedef enum VkSwapchainImageUsageFlagBitsANDROID {
    VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID = 0x00000001,
    VK_SWAPCHAIN_IMAGE_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VkSwapchainImageUsageFlagBitsANDROID;
typedef VkFlags VkSwapchainImageUsageFlagsANDROID;

VkResult VKAPI vkGetSwapchainGrallocUsage2ANDROID(
    VkDevice                          device,
    VkFormat                          format,
    VkImageUsageFlags                 imageUsage,
    VkSwapchainImageUsageFlagsANDROID swapchainUsage,
    uint64_t*                         grallocConsumerUsage,
    uint64_t*                         grallocProducerUsage
);

The format and imageUsage parameters are taken from the VkSwapchainCreateInfoKHR structure. The driver should fill *grallocConsumerUsage and *grallocProducerUsage with the Gralloc usage flags required for the format and usage. The usage flags returned by the driver are combined with the usage flags requested by the swapchain consumer when allocating buffers.

Android 7.x calls an earlier version of VkSwapchainImageUsageFlagsANDROID() , named vkGetSwapchainGrallocUsageANDROID() . Android 8.0 and higher deprecates vkGetSwapchainGrallocUsageANDROID() but still calls vkGetSwapchainGrallocUsageANDROID() if vkGetSwapchainGrallocUsage2ANDROID() isn't provided by the driver:

VkResult VKAPI vkGetSwapchainGrallocUsageANDROID(
    VkDevice            device,
    VkFormat            format,
    VkImageUsageFlags   imageUsage,
    int*                grallocUsage
);

vkGetSwapchainGrallocUsageANDROID() সোয়াপচেইন ব্যবহারের ফ্ল্যাগ বা বর্ধিত গ্র্যালক ব্যবহারের ফ্ল্যাগ সমর্থন করে না।

Gralloc-backed images

VkNativeBufferANDROID হলো একটি vkCreateImage এক্সটেনশন স্ট্রাকচার, যা একটি Gralloc বাফার দ্বারা সমর্থিত ইমেজ তৈরি করার জন্য ব্যবহৃত হয়। VkNativeBufferANDROID VkImageCreateInfo স্ট্রাকচার চেইনের মধ্যে vkCreateImage() ফাংশনে সরবরাহ করা হয়। VkNativeBufferANDROID সহ vkCreateImage() ফাংশনের কলগুলো vkCreateSwapchainKHR ফাংশনের কল চলাকালীন সময়েই সম্পন্ন হয়। WSI ইমপ্লিমেন্টেশনটি সোয়াপচেইনের জন্য অনুরোধ করা সংখ্যক নেটিভ বাফার বরাদ্দ করে, এবং তারপর সেগুলোর প্রতিটির জন্য একটি করে VkImage তৈরি করে:

typedef struct {
    VkStructureType             sType; // must be VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID
    const void*                 pNext;

    // Buffer handle and stride returned from gralloc alloc()
    buffer_handle_t             handle;
    int                         stride;

    // Gralloc format and usage requested when the buffer was allocated.
    int                         format;
    int                         usage;
    // Beginning in Android 8.0, the usage field above is deprecated and the
    // usage2 struct below was added. The usage field is still filled in for
    // compatibility with Android 7.0 drivers. Drivers for Android 8.0
    // should prefer the usage2 struct, especially if the
    // android.hardware.graphics.allocator HAL uses the extended usage bits.
    struct {
        uint64_t                consumer;
        uint64_t                producer;
    } usage2;
} VkNativeBufferANDROID;

When creating a Gralloc-backed image, VkImageCreateInfo has the following data:

  .sType               = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
  .pNext               = the above VkNativeBufferANDROID structure
  .imageType           = VK_IMAGE_TYPE_2D
  .format              = a VkFormat matching the format requested for the gralloc buffer
  .extent              = the 2D dimensions requested for the gralloc buffer
  .mipLevels           = 1
  .arraySize           = 1
  .samples             = 1
  .tiling              = VK_IMAGE_TILING_OPTIMAL
  .usage               = VkSwapchainCreateInfoKHR::imageUsage
  .flags               = 0
  .sharingMode         = VkSwapchainCreateInfoKHR::imageSharingMode
  .queueFamilyCount    = VkSwapchainCreateInfoKHR::queueFamilyIndexCount
  .pQueueFamilyIndices = VkSwapchainCreateInfoKHR::pQueueFamilyIndices

In Android 8.0 and higher, the platform provides a VkSwapchainImageCreateInfoKHR extension structure in the VkImageCreateInfo chain provided to vkCreateImage when any swapchain image usage flags are required for the swapchain. The extension structure contains the swapchain image usage flags:

typedef struct {
    VkStructureType                        sType; // must be VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID
    const void*                            pNext;

    VkSwapchainImageUsageFlagsANDROID      usage;
} VkSwapchainImageCreateInfoANDROID;

অ্যান্ড্রয়েড ১০ এবং তার উপরের সংস্করণগুলিতে, প্ল্যাটফর্মটি VK_KHR_swapchain v70 সমর্থন করে, ফলে ভলকান অ্যাপটি সোয়াপচেইন মেমরি দ্বারা সমর্থিত একটি VkImage তৈরি করতে পারে। অ্যাপটি প্রথমে VkImageCreateInfo স্ট্রাকচারের সাথে চেইন করা একটি VkImageSwapchainCreateInfoKHR স্ট্রাকচার ব্যবহার করে vkCreateImage কল করে। এরপর অ্যাপটি VkBindImageMemoryInfo স্ট্রাকচারের সাথে চেইন করা একটি VkBindImageMemorySwapchainInfoKHR স্ট্রাকচার ব্যবহার করে vkBindImageMemory2(KHR) কল করে। VkBindImageMemorySwapchainInfoKHR স্ট্রাকচারে নির্দিষ্ট করা imageIndex অবশ্যই একটি বৈধ সোয়াপচেইন ইমেজ ইনডেক্স হতে হবে। একই সাথে, প্ল্যাটফর্মটি VkBindImageMemoryInfo চেইনে সংশ্লিষ্ট Gralloc বাফার তথ্যসহ একটি VkNativeBufferANDROID এক্সটেনশন স্ট্রাকচার সরবরাহ করে, ফলে ড্রাইভার জানতে পারে কোন Gralloc বাফারের সাথে VkImage বাইন্ড করতে হবে।

Acquire images

vkAcquireImageANDROID একটি সোয়াপচেইন ইমেজের মালিকানা অর্জন করে এবং একটি বাহ্যিকভাবে সংকেতযুক্ত নেটিভ ফেন্সকে একটি বিদ্যমান VkSemaphore অবজেক্ট এবং একটি বিদ্যমান VkFence অবজেক্ট উভয়ের মধ্যে ইম্পোর্ট করে:

VkResult VKAPI vkAcquireImageANDROID(
    VkDevice            device,
    VkImage             image,
    int                 nativeFenceFd,
    VkSemaphore         semaphore,
    VkFence             fence
);

vkAcquireNextImageKHR চলাকালীন vkAcquireImageANDROID() কল করা হয় অ্যাপ দ্বারা প্রদত্ত VkSemaphore এবং VkFence অবজেক্টগুলিতে একটি নেটিভ ফেন্স ইম্পোর্ট করার জন্য (তবে, এই কলে সেমাফোর এবং ফেন্স উভয় অবজেক্টই ঐচ্ছিক)। ড্রাইভার এই সুযোগটি ব্যবহার করে Gralloc বাফার স্টেটের যেকোনো বাহ্যিক পরিবর্তন শনাক্ত ও পরিচালনা করতে পারে; অনেক ড্রাইভারের ক্ষেত্রে এখানে কিছু করার প্রয়োজন হয় না। এই কলটি VkSemaphore এবং VkFence vkQueueSubmit দ্বারা সিগন্যাল করা পেন্ডিং স্টেটের মতোই অবস্থায় রাখে, ফলে কিউগুলো সেমাফোরের জন্য এবং অ্যাপ ফেন্সের জন্য অপেক্ষা করতে পারে।

যখন অন্তর্নিহিত নেটিভ ফেন্স সিগন্যাল দেয়, তখন উভয় অবজেক্টই সিগন্যালড হয়ে যায়; যদি নেটিভ ফেন্সটি ইতিমধ্যেই সিগন্যাল দিয়ে থাকে, তাহলে এই ফাংশনটি রিটার্ন করার সময় সেমাফোরটি সিগন্যালড অবস্থায় থাকে। ড্রাইভারটি ফেন্স ফাইল ডেসক্রিপ্টরের মালিকানা গ্রহণ করে এবং যখন আর প্রয়োজন হয় না তখন ফেন্স ফাইল ডেসক্রিপ্টরটি বন্ধ করে দেয়। ড্রাইভারকে অবশ্যই এটি করতে হবে, এমনকি যদি কোনো সেমাফোর বা ফেন্স অবজেক্ট সরবরাহ করা না হয়, অথবা যদি vkAcquireImageANDROID ব্যর্থ হয়ে একটি এরর রিটার্ন করে। যদি fenceFd মান -1 হয়, তবে ধরে নেওয়া হয় যেন নেটিভ ফেন্সটি ইতিমধ্যেই সিগন্যালড ছিল।

Release images

vkQueueSignalReleaseImageANDROID বাহ্যিক ব্যবহারের জন্য একটি সোয়াপচেইন ইমেজ প্রস্তুত করে, একটি নেটিভ ফেন্স তৈরি করে, এবং ইনপুট সেমাফোরগুলো সিগন্যাল দেওয়ার পরে নেটিভ ফেন্সটিকে সিগন্যাল দেওয়ার জন্য শিডিউল করে:

VkResult VKAPI vkQueueSignalReleaseImageANDROID(
    VkQueue             queue,
    uint32_t            waitSemaphoreCount,
    const VkSemaphore*  pWaitSemaphores,
    VkImage             image,
    int*                pNativeFenceFd
);

vkQueuePresentKHR() calls vkQueueSignalReleaseImageANDROID() on the provided queue. The driver must produce a native fence that doesn't signal until all waitSemaphoreCount semaphores in pWaitSemaphores signal, and any additional work required to prepare image for presentation completes.

If the wait semaphores (if any) already signaled, and queue is already idle, the driver can set *pNativeFenceFd to -1 instead of an actual native fence file descriptor, indicating that there's nothing to wait for. The caller owns and closes the file descriptor returned in *pNativeFenceFd .

Many drivers can ignore the image parameter, but some may need to prepare CPU-side data structures associated with a Gralloc buffer for use by external image consumers. Preparing buffer contents for use by external consumers must be done asynchronously as part of transitioning the image to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR .

If the image was created with VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID , then the driver must allow vkQueueSignalReleaseImageANDROID() to be called repeatedly without intervening calls to vkAcquireImageANDROID() .

Shared presentable image support

Some devices can share ownership of a single image between the display pipeline and the Vulkan implementation to minimize latency. In Android 9 and higher, the loader conditionally advertises the VK_KHR_shared_presentable_image extension based on the driver's response to a call to vkGetPhysicalDeviceProperties2 .

If the driver doesn't support either Vulkan 1.1 or the VK_KHR_physical_device_properties2 extension, the loader doesn't advertise support for shared presentable images. Otherwise, the loader queries the driver capabilities by calling vkGetPhysicalDeviceProperties2() and including the following structure in the VkPhysicalDeviceProperties2::pNext chain:

typedef struct {
    VkStructureType sType; // must be VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID
    const void*     pNext;
    VkBool32        sharedImage;
} VkPhysicalDevicePresentationPropertiesANDROID;

যদি ড্রাইভার ডিসপ্লে সিস্টেমের সাথে কোনো ইমেজের মালিকানা ভাগ করে নিতে পারে, তাহলে এটি sharedImage মেম্বারটিকে VK_TRUE তে সেট করে।

বৈধতা

OEM-রা CTS ব্যবহার করে তাদের Vulkan ইমপ্লিমেন্টেশন পরীক্ষা করতে পারে, যার মধ্যে নিম্নলিখিত বিষয়গুলো অন্তর্ভুক্ত রয়েছে:

  • CtsDeqpTestCases মডিউলে Khronos Vulkan Conformance টেস্ট রয়েছে, যেগুলোতে Vulkan 1.0, 1.1, 1.2, 1.3, এবং 1.4-এর জন্য ফাংশনাল API টেস্ট অন্তর্ভুক্ত।
  • CtsGraphicsTestCases মডিউলটি পরীক্ষা করে দেখে যে, ডিভাইসটি তার সমর্থিত ভলকান সক্ষমতাগুলোর জন্য সঠিকভাবে কনফিগার করা আছে কি না।

Vulkan feature flag

A device that supports Android 11 or higher and that supports the Vulkan API is required to expose a feature flag, android.software.vulkan.deqp.level . The value of this feature flag is a date, encoded as an integer value. It specifies the date associated with the Vulkan dEQP tests that the device claims to pass.

YYYY-MM-DD ফর্ম্যাটের একটি তারিখকে নিম্নোক্তভাবে একটি ৩২-বিট পূর্ণসংখ্যা হিসাবে এনকোড করা হয়:

  • Bits 0-15 store the year
  • Bits 16-23 store the month
  • Bits 24-31 store the day

The minimum allowed value for the feature flag is 0x07E30301 , which corresponds to the date 2019-03-01, which is the date associated with the Vulkan dEQP tests for Android 10. If the feature flag is at least this value, the device claims to pass all of the Android 10 Vulkan dEQP tests.

Value 0x07E40301 corresponds to the date 2020-03-01, which is the date associated with the Vulkan dEQP tests for Android 11. If the feature flag is at least this value, the device claims to pass all of the Android 11 Vulkan dEQP tests.

Value 0x07E60301 corresponds to the date 2022-03-01, which is the date associated with the Vulkan dEQP tests for Android 13. If the feature flag is at least this value, the device claims to pass all of the Android 13 Vulkan dEQP tests.

A device that exposes a specific feature flag ( ie 0x07E30301 , 0x07E40301 , 0x07E60301 ) claims to pass all Android Vulkan dEQP tests of that feature flag (Android 10, Android 11, Android 13 respectively). This device may pass Vulkan dEQP tests from a later Android release.

Vulkan dEQP forms part of Android CTS. From Android 11, the dEQP test runner component of CTS is aware of the android.software.vulkan.deqp.level feature flag, and skips any Vulkan dEQP tests that - according to this feature flag - the device doesn't claim to support. Such tests are reported as trivially passing.