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 bool IsVkRenderPassActive()
const {
return mVkRenderPassActive; }
79 void CommitPipeline();
80 void DrawLines(
const std::vector<Line>& lines);
82 const glm::vec3& cameraRight,
const glm::vec3& cameraUp);
83 void DrawFullscreen();
84 void BindFullscreenVertexBuffer(VkCommandBuffer cb);
87 void CreateSwapchain();
88 void RecreateSwapchain(
bool recreateSurface);
90 VkPhysicalDevice GetPhysicalDevice();
96 VkExtent2D& GetSwapchainExtent();
97 VkFormat GetSwapchainFormat();
98 VkFormat GetSceneColorFormat();
99 Image* GetSceneColorImage();
100 Image* GetSwapchainImage();
102 Pipeline* GetBoundPipeline();
104 void SavePipelineCacheToFile();
106 void SetViewport(int32_t x, int32_t y, int32_t width, int32_t height,
bool handlePrerotation,
bool useSceneRes);
107 void SetScissor(int32_t x, int32_t y, int32_t width, int32_t height,
bool handlePrerotation,
bool useSceneRes);
109 void CreateCommandBuffers();
114 void SetMultiBufferFrameOffset(uint32_t offset) { mMultiBufferFrameOffset = offset; }
115 uint32_t GetMultiBufferFrameOffset()
const {
return mMultiBufferFrameOffset; }
118 Image* GetShadowMapImage();
121 VkCommandPool GetCommandPool();
122 VkQueue GetGraphicsQueue();
128 VkRenderPass GetCurrentRenderPass()
const;
130 void UpdateGlobalDescriptorSet();
131 void UpdateGlobalUniformData();
133 void BindGlobalDescriptorSet();
137 bool IsValidationEnabled()
const;
138 bool IsRayTracingSupported()
const;
139 bool HasFeatureWideLines()
const;
140 bool HasFeatureFillModeNonSolid()
const;
142 bool AreMaterialsEnabled()
const;
143 void EnableMaterials(
bool enable);
145 void BeginGpuTimestamp(
const char* name);
146 void EndGpuTimestamp(
const char* name);
147 void ReadTimeQueryResults();
152 void RenderPostProcessChain();
154 VkSurfaceTransformFlagBitsKHR GetPreTransformFlag()
const;
156 uint32_t GetSceneWidth();
157 uint32_t GetSceneHeight();
159 const VkPhysicalDeviceProperties& GetDeviceProperties()
const;
160 UniformBuffer* GetFrameUniformBuffer();
162 Shader* GetGlobalShader(
const std::string& name);
167 void SetVertexShader(
Shader* shader);
168 void SetFragmentShader(
Shader* shader);
169 void SetComputeShader(
Shader* shader);
170 void SetVertexShader(
const std::string& globalName);
171 void SetFragmentShader(
const std::string& globalName);
172 void SetComputeShader(
const std::string& globalName);
173 void SetRenderPass(VkRenderPass renderPass);
175 void SetRasterizerDiscard(
bool discard);
176 void SetPrimitiveTopology(VkPrimitiveTopology primitiveToplogy);
177 void SetPolygonMode(VkPolygonMode polygonMode);
178 void SetLineWidth(
float lineWidth);
179 void SetDynamicLineWidth(
bool dynamicLineWidth);
180 void SetCullMode(VkCullModeFlags cullMode);
181 void SetFrontFace(VkFrontFace frontFace);
182 void SetDepthBias(
float depthBias);
183 void SetDepthTestEnabled(
bool enabled);
184 void SetDepthWriteEnabled(
bool enabled);
185 void SetDepthCompareOp(VkCompareOp compareOp);
186 void SetBlendState(VkPipelineColorBlendAttachmentState blendState, uint32_t index = 0);
187 void SetBlendState(
BasicBlendState basicBlendState, uint32_t index = 0);
188 void SetBlendEnable(
bool enable, uint32_t index = 0);
189 void SetBlendColorOp(VkBlendFactor src, VkBlendFactor dst, VkBlendOp op, uint32_t index = 0);
190 void SetBlendAlphaOp(VkBlendFactor src, VkBlendFactor dst, VkBlendOp op, uint32_t index = 0);
191 void SetColorWriteMask(VkColorComponentFlags writeMask, uint32_t index = 0);
196 static VKAPI_ATTR VkBool32 VKAPI_CALL DebugCallback(
197 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
198 VkDebugUtilsMessageTypeFlagsEXT messageType,
199 const VkDebugUtilsMessengerCallbackDataEXT* callbackData,
202 void CreateInstance();
203 void CreateDebugCallback();
204 void CreateSurface();
205 void CreateLogicalDevice();
206 void CreateFrameUniformBuffer();
207 void DestroyFrameUniformBuffer();
208 void CreateRenderPasses();
209 void DestroyRenderPasses();
210 void CreateCommandPool();
211 void CreateSemaphores();
213 void CreateDescriptorPools();
214 void DestroyDescriptorPools();
215 void CreateDepthImage();
216 void CreateSceneColorImage();
217 void CreateShadowMapImage();
218 void CreateQueryPools();
219 void DestroyQueryPools();
220 void RecreateSurface();
221 void CreateGlobalShaders();
222 void DestroyGlobalShaders();
226 void PickPhysicalDevice();
227 bool IsDeviceSuitable(VkPhysicalDevice device);
228 VkSurfaceFormatKHR ChooseSwapSurfaceFormat(
const std::vector<VkSurfaceFormatKHR>& availableFormats);
229 VkPresentModeKHR ChooseSwapPresentMode(
const std::vector<VkPresentModeKHR>& availableModes);
230 VkExtent2D ChooseSwapExtent(
const VkSurfaceCapabilitiesKHR& capabilities);
231 QueueFamilyIndices FindQueueFamilies(VkPhysicalDevice device);
232 SwapChainSupportDetails QuerySwapChainSupport(VkPhysicalDevice device);
234 bool CheckValidationLayerSupport(
237 bool CheckDeviceExtensionSupport(
238 VkPhysicalDevice device,
239 const char** extensions,
242 void DestroySwapchain();
243 void DestroyDebugCallback();
248 VkInstance mInstance = VK_NULL_HANDLE;
249 VkDebugReportCallbackEXT mCallback = VK_NULL_HANDLE;
250 VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE;
251 VkDevice mDevice = VK_NULL_HANDLE;
252 VkQueue mGraphicsQueue = VK_NULL_HANDLE;
253 VkQueue mPresentQueue = VK_NULL_HANDLE;
254 VkSurfaceKHR mSurface = VK_NULL_HANDLE;
255 uint32_t mGraphicsQueueFamily = 0;
256 uint32_t mPresentQueueFamily = 0;
261 VkDescriptorPool mImguiDescriptorPool = VK_NULL_HANDLE;
264 VkCommandPool mCommandPool = VK_NULL_HANDLE;
265 std::vector<VkCommandBuffer> mCommandBuffers;
268 VkSwapchainKHR mSwapchain = VK_NULL_HANDLE;
269 std::vector<VkImage> mSwapchainImages;
270 std::vector<VkImageView> mSwapchainImageViews;
271 VkFormat mSwapchainImageFormat = VK_FORMAT_UNDEFINED;
272 VkExtent2D mSwapchainExtent = {};
273 std::vector<Image*> mExtSwapchainImages;
277 VkRenderPass mImguiRenderPass = VK_NULL_HANDLE;
280 Image* mShadowMapImage =
nullptr;
281 Image* mSceneColorImage =
nullptr;
282 VkFormat mSceneColorImageFormat;
283 Image* mDepthImage =
nullptr;
284 VkFormat mDepthImageFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
287 VkSemaphore mImageAvailableSemaphore[MAX_FRAMES] = {};
288 VkSemaphore mRenderFinishedSemaphore[MAX_FRAMES] = {};
289 VkFence mWaitFences[MAX_FRAMES] = {};
293 Pipeline* mBoundPipeline =
nullptr;
296 std::unordered_map<std::string, Shader*> mGlobalShaders;
297 DescriptorSet mGlobalDescriptorSet;
298 DescriptorSet mDebugDescriptorSet;
299 DescriptorSet mPostProcessDescriptorSet;
300 UniformBuffer* mFrameUniformBuffer =
nullptr;
304 DestroyQueue mDestroyQueue;
311 VkDebugUtilsMessengerEXT mDebugMessenger = VK_NULL_HANDLE;
312 uint32_t mEnabledExtensionCount = 0;
314 uint32_t mEnabledLayersCount = 0;
318 std::vector<GpuTimespan> mGpuTimespans[MAX_FRAMES];
319 VkQueryPool mTimeQueryPools[MAX_FRAMES] = { };
320 int32_t mNumTimestamps[MAX_FRAMES] = { };
321 float mTimestampPeriod = 0.0f;
322 bool mTimestampsSupported =
false;
331 int32_t mFrameIndex = 0;
332 int32_t mFrameNumber = 0;
333 uint32_t mSwapchainImageIndex = 0;
335 bool mVkRenderPassActive =
false;
336 int32_t mNumLinesAllocated = 0;
337 Buffer* mLineVertexBuffer =
nullptr;
338 int32_t mNumSplatsAllocated = 0;
339 Buffer* mSplatVertexBuffer =
nullptr;
340 bool mInitialized =
false;
341 bool mEnableMaterials =
false;
342 bool mSupportsRayTracing =
false;
343 bool mFeatureWideLines =
false;
344 bool mFeatureFillModeNonSolid =
false;
346 VkSurfaceTransformFlagBitsKHR mPreTransformFlag = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
347 uint32_t mMultiBufferFrameOffset = 0;
348 float mResolutionScale = 1.0f;
349 uint32_t mSceneWidth = 0;
350 uint32_t mSceneHeight = 0;
351 VkPhysicalDeviceProperties mDeviceProperties;
352 Buffer* mFullScreenVertexBuffer =
nullptr;
356 class Node3D* ProcessHitCheck(
World* world, int32_t pixelX, int32_t pixelY, uint32_t* outInstance =
nullptr);
358 void CreateHitCheck();
359 void DestroyHitCheck();
361 Image* mHitCheckImage =
nullptr;
362 Buffer* mHitCheckBuffer =
nullptr;
367void CreateVulkanContext();
368void DestroyVulkanContext();
369VulkanContext* GetVulkanContext();
bool Initialize()
Definition Engine.cpp:545
RenderPassId
Definition GraphicsTypes.h:90
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:483
Definition VulkanTypes.h:30
Definition VulkanTypes.h:85