5#include <vulkan/vulkan.h>
29#include <vulkan/vulkan_xcb.h>
35struct QueueFamilyIndices
37 int32_t mGraphicsFamily = -1;
38 int32_t mPresentFamily = -1;
42 return mGraphicsFamily >= 0 &&
47struct SwapChainSupportDetails
49 VkSurfaceCapabilitiesKHR capabilities;
50 std::vector<VkSurfaceFormatKHR> formats;
51 std::vector<VkPresentModeKHR> presentModes;
57 int32_t mStartIndex = -1;
58 int32_t mEndIndex = -1;
75 void BeginVkRenderPass(
const RenderPassSetup& rpSetup,
bool insertBarrier, glm::vec4 clearColor = {});
77 void EndVkRenderPass();
78 void CommitPipeline();
79 void DrawLines(
const std::vector<Line>& lines);
80 void DrawFullscreen();
81 void BindFullscreenVertexBuffer(VkCommandBuffer cb);
84 void CreateSwapchain();
85 void RecreateSwapchain(
bool recreateSurface);
87 VkPhysicalDevice GetPhysicalDevice();
93 VkExtent2D& GetSwapchainExtent();
94 VkFormat GetSwapchainFormat();
95 VkFormat GetSceneColorFormat();
96 Image* GetSceneColorImage();
97 Image* GetSwapchainImage();
99 Pipeline* GetBoundPipeline();
101 void SavePipelineCacheToFile();
103 void SetViewport(int32_t x, int32_t y, int32_t width, int32_t height,
bool handlePrerotation,
bool useSceneRes);
104 void SetScissor(int32_t x, int32_t y, int32_t width, int32_t height,
bool handlePrerotation,
bool useSceneRes);
106 void CreateCommandBuffers();
111 void SetMultiBufferFrameOffset(uint32_t offset) { mMultiBufferFrameOffset = offset; }
112 uint32_t GetMultiBufferFrameOffset()
const {
return mMultiBufferFrameOffset; }
115 Image* GetShadowMapImage();
118 VkCommandPool GetCommandPool();
119 VkQueue GetGraphicsQueue();
121 void UpdateGlobalDescriptorSet();
122 void UpdateGlobalUniformData();
124 void BindGlobalDescriptorSet();
128 bool IsValidationEnabled()
const;
129 bool IsRayTracingSupported()
const;
130 bool HasFeatureWideLines()
const;
131 bool HasFeatureFillModeNonSolid()
const;
133 bool AreMaterialsEnabled()
const;
134 void EnableMaterials(
bool enable);
136 void BeginGpuTimestamp(
const char* name);
137 void EndGpuTimestamp(
const char* name);
138 void ReadTimeQueryResults();
143 void RenderPostProcessChain();
145 VkSurfaceTransformFlagBitsKHR GetPreTransformFlag()
const;
147 uint32_t GetSceneWidth();
148 uint32_t GetSceneHeight();
150 const VkPhysicalDeviceProperties& GetDeviceProperties()
const;
151 UniformBuffer* GetFrameUniformBuffer();
153 Shader* GetGlobalShader(
const std::string& name);
158 void SetVertexShader(
Shader* shader);
159 void SetFragmentShader(
Shader* shader);
160 void SetComputeShader(
Shader* shader);
161 void SetVertexShader(
const std::string& globalName);
162 void SetFragmentShader(
const std::string& globalName);
163 void SetComputeShader(
const std::string& globalName);
164 void SetRenderPass(VkRenderPass renderPass);
166 void SetRasterizerDiscard(
bool discard);
167 void SetPrimitiveTopology(VkPrimitiveTopology primitiveToplogy);
168 void SetPolygonMode(VkPolygonMode polygonMode);
169 void SetLineWidth(
float lineWidth);
170 void SetDynamicLineWidth(
bool dynamicLineWidth);
171 void SetCullMode(VkCullModeFlags cullMode);
172 void SetFrontFace(VkFrontFace frontFace);
173 void SetDepthBias(
float depthBias);
174 void SetDepthTestEnabled(
bool enabled);
175 void SetDepthWriteEnabled(
bool enabled);
176 void SetDepthCompareOp(VkCompareOp compareOp);
177 void SetBlendState(VkPipelineColorBlendAttachmentState blendState, uint32_t index = 0);
178 void SetBlendState(
BasicBlendState basicBlendState, uint32_t index = 0);
179 void SetBlendEnable(
bool enable, uint32_t index = 0);
180 void SetBlendColorOp(VkBlendFactor src, VkBlendFactor dst, VkBlendOp op, uint32_t index = 0);
181 void SetBlendAlphaOp(VkBlendFactor src, VkBlendFactor dst, VkBlendOp op, uint32_t index = 0);
182 void SetColorWriteMask(VkColorComponentFlags writeMask, uint32_t index = 0);
187 static VKAPI_ATTR VkBool32 VKAPI_CALL DebugCallback(
188 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
189 VkDebugUtilsMessageTypeFlagsEXT messageType,
190 const VkDebugUtilsMessengerCallbackDataEXT* callbackData,
193 void CreateInstance();
194 void CreateDebugCallback();
195 void CreateSurface();
196 void CreateLogicalDevice();
197 void CreateFrameUniformBuffer();
198 void DestroyFrameUniformBuffer();
199 void CreateRenderPasses();
200 void DestroyRenderPasses();
201 void CreateCommandPool();
202 void CreateSemaphores();
204 void CreateDescriptorPools();
205 void DestroyDescriptorPools();
206 void CreateDepthImage();
207 void CreateSceneColorImage();
208 void CreateShadowMapImage();
209 void CreateQueryPools();
210 void DestroyQueryPools();
211 void RecreateSurface();
212 void CreateGlobalShaders();
213 void DestroyGlobalShaders();
217 void PickPhysicalDevice();
218 bool IsDeviceSuitable(VkPhysicalDevice device);
219 VkSurfaceFormatKHR ChooseSwapSurfaceFormat(
const std::vector<VkSurfaceFormatKHR>& availableFormats);
220 VkPresentModeKHR ChooseSwapPresentMode(
const std::vector<VkPresentModeKHR>& availableModes);
221 VkExtent2D ChooseSwapExtent(
const VkSurfaceCapabilitiesKHR& capabilities);
222 QueueFamilyIndices FindQueueFamilies(VkPhysicalDevice device);
223 SwapChainSupportDetails QuerySwapChainSupport(VkPhysicalDevice device);
225 bool CheckValidationLayerSupport(
228 bool CheckDeviceExtensionSupport(
229 VkPhysicalDevice device,
230 const char** extensions,
233 void DestroySwapchain();
234 void DestroyDebugCallback();
239 VkInstance mInstance = VK_NULL_HANDLE;
240 VkDebugReportCallbackEXT mCallback = VK_NULL_HANDLE;
241 VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE;
242 VkDevice mDevice = VK_NULL_HANDLE;
243 VkQueue mGraphicsQueue = VK_NULL_HANDLE;
244 VkQueue mPresentQueue = VK_NULL_HANDLE;
245 VkSurfaceKHR mSurface = VK_NULL_HANDLE;
246 uint32_t mGraphicsQueueFamily = 0;
247 uint32_t mPresentQueueFamily = 0;
252 VkDescriptorPool mImguiDescriptorPool = VK_NULL_HANDLE;
255 VkCommandPool mCommandPool = VK_NULL_HANDLE;
256 std::vector<VkCommandBuffer> mCommandBuffers;
259 VkSwapchainKHR mSwapchain = VK_NULL_HANDLE;
260 std::vector<VkImage> mSwapchainImages;
261 std::vector<VkImageView> mSwapchainImageViews;
262 VkFormat mSwapchainImageFormat = VK_FORMAT_UNDEFINED;
263 VkExtent2D mSwapchainExtent = {};
264 std::vector<Image*> mExtSwapchainImages;
268 VkRenderPass mImguiRenderPass = VK_NULL_HANDLE;
271 Image* mShadowMapImage =
nullptr;
272 Image* mSceneColorImage =
nullptr;
273 VkFormat mSceneColorImageFormat;
274 Image* mDepthImage =
nullptr;
275 VkFormat mDepthImageFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
278 VkSemaphore mImageAvailableSemaphore[MAX_FRAMES] = {};
279 VkSemaphore mRenderFinishedSemaphore[MAX_FRAMES] = {};
280 VkFence mWaitFences[MAX_FRAMES] = {};
284 Pipeline* mBoundPipeline =
nullptr;
287 std::unordered_map<std::string, Shader*> mGlobalShaders;
288 DescriptorSet mGlobalDescriptorSet;
289 DescriptorSet mDebugDescriptorSet;
290 DescriptorSet mPostProcessDescriptorSet;
291 UniformBuffer* mFrameUniformBuffer =
nullptr;
295 DestroyQueue mDestroyQueue;
302 VkDebugUtilsMessengerEXT mDebugMessenger = VK_NULL_HANDLE;
303 uint32_t mEnabledExtensionCount = 0;
305 uint32_t mEnabledLayersCount = 0;
309 std::vector<GpuTimespan> mGpuTimespans[MAX_FRAMES];
310 VkQueryPool mTimeQueryPools[MAX_FRAMES] = { };
311 int32_t mNumTimestamps[MAX_FRAMES] = { };
312 float mTimestampPeriod = 0.0f;
313 bool mTimestampsSupported =
false;
322 int32_t mFrameIndex = 0;
323 int32_t mFrameNumber = 0;
324 uint32_t mSwapchainImageIndex = 0;
326 int32_t mNumLinesAllocated = 0;
327 Buffer* mLineVertexBuffer =
nullptr;
328 bool mInitialized =
false;
329 bool mEnableMaterials =
false;
330 bool mSupportsRayTracing =
false;
331 bool mFeatureWideLines =
false;
332 bool mFeatureFillModeNonSolid =
false;
334 VkSurfaceTransformFlagBitsKHR mPreTransformFlag = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
335 uint32_t mMultiBufferFrameOffset = 0;
336 float mResolutionScale = 1.0f;
337 uint32_t mSceneWidth = 0;
338 uint32_t mSceneHeight = 0;
339 VkPhysicalDeviceProperties mDeviceProperties;
340 Buffer* mFullScreenVertexBuffer =
nullptr;
344 class Node3D* ProcessHitCheck(
World* world, int32_t pixelX, int32_t pixelY, uint32_t* outInstance =
nullptr);
346 void CreateHitCheck();
347 void DestroyHitCheck();
349 Image* mHitCheckImage =
nullptr;
350 Buffer* mHitCheckBuffer =
nullptr;
355void CreateVulkanContext();
356void DestroyVulkanContext();
357VulkanContext* GetVulkanContext();
bool Initialize()
Definition Engine.cpp:417
RenderPassId
Definition GraphicsTypes.h:89
VertexType
Definition Vertex.h:7
#define MAX_ENABLED_LAYERS
Definition VulkanConstants.h:4
#define MAX_ENABLED_EXTENSIONS
Definition VulkanConstants.h:3
BasicBlendState
Definition VulkanTypes.h:21
uint32_t GetFrameNumber()
Definition VulkanUtils.cpp:326
VkCommandBuffer GetCommandBuffer()
Definition VulkanUtils.cpp:341
uint32_t GetFrameIndex()
Definition VulkanUtils.cpp:321
DestroyQueue * GetDestroyQueue()
Definition VulkanUtils.cpp:331
Definition DescriptorLayoutCache.h:8
Definition DescriptorPool.h:7
Definition PipelineCache.h:9
Definition PostProcessChain.h:10
Definition RayTracer.h:15
Definition RenderPassCache.h:59
void BeginFrame()
Definition ImGuizmo.cpp:982
Definition EngineTypes.h:343
Definition VulkanTypes.h:30
Definition VulkanTypes.h:85