/* * Copyright 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef GPU_PROFILING_VULKAN_RENDERER #define GPU_PROFILING_VULKAN_RENDERER #include #include #include #include #include class VulkanRenderer { public: void init(); void render(); void cleanup(); void cleanupSwapChain(); void reset(ANativeWindow *newWindow, AAssetManager *newManager); bool initialized = false; private: struct ANativeWindowDeleter { void operator()(ANativeWindow *window) { ANativeWindow_release(window); } }; void createDevice(); void createInstance(); void createSurface(); void pickPhysicalDevice(); void createLogicalDeviceAndQueue(); void createSwapChain(); void createImageViews(); void createRenderPass(); void createGraphicsPipeline(); void createFramebuffers(); void createCommandPool(); void createCommandBuffer(); void createSyncObjects(); bool isDeviceSuitable(VkPhysicalDevice device); VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities); void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex); void recreateSwapChain(); void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory); void establishDisplaySizeIdentity(); std::vector deviceExtensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; std::unique_ptr window; AAssetManager *assetManager; VkInstance instance; VkSurfaceKHR surface; VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; VkDevice device; VkSwapchainKHR swapChain; std::vector swapChainImages; VkFormat swapChainImageFormat; VkExtent2D swapChainExtent; VkExtent2D displaySizeIdentity; std::vector swapChainImageViews; std::vector swapChainFramebuffers; VkCommandPool commandPool; std::vector commandBuffers; VkQueue graphicsQueue; VkQueue presentQueue; VkRenderPass renderPass; VkPipelineLayout pipelineLayout; VkPipeline graphicsPipeline; std::vector imageAvailableSemaphores; std::vector renderFinishedSemaphores; std::vector inFlightFences; uint32_t currentFrame = 0; VkSurfaceTransformFlagBitsKHR pretransformFlag; }; #endif // GPU_PROFILING_VULKAN_RENDERER