Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Lukas Tietze
MASTERARBEIT😆😜
Commits
7070d28f
Commit
7070d28f
authored
Jun 30, 2020
by
Lukas Tietze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dokumentation ordentlich eingerückt.
parent
724c772b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
62 deletions
+60
-62
src/Lib/src/Core/CgContext.cpp
src/Lib/src/Core/CgContext.cpp
+60
-62
No files found.
src/Lib/src/Core/CgContext.cpp
View file @
7070d28f
...
...
@@ -26,11 +26,6 @@
#include "imgui_impl_vulkan.h"
#include "imgui_impl_glfw.h"
using
lib
::
log
::
Debug
;
using
lib
::
log
::
Error
;
using
lib
::
log
::
Info
;
using
lib
::
log
::
Warning
;
#undef min
#undef max
...
...
@@ -61,8 +56,8 @@ namespace
}
/**
* @brief Behandelt Debug callbacks von Vulkan und stellt sie in einem vereinheitlichten Format dar.
*/
* @brief Behandelt Debug callbacks von Vulkan und stellt sie in einem vereinheitlichten Format dar.
*/
VKAPI_ATTR
vk
::
Bool32
VKAPI_CALL
debugCallback
(
VkDebugUtilsMessageSeverityFlagBitsEXT
messageSeverity
,
VkDebugUtilsMessageTypeFlagsEXT
messageType
,
const
VkDebugUtilsMessengerCallbackDataEXT
*
pCallbackData
,
...
...
@@ -87,11 +82,11 @@ lib::CgContext::CgContext(const AppCreateInfo &info, GLFWwindow *window) : windo
PFN_vkGetInstanceProcAddr
vkGetInstanceProcAddr
=
dl
.
getProcAddress
<
PFN_vkGetInstanceProcAddr
>
(
"vkGetInstanceProcAddr"
);
VULKAN_HPP_DEFAULT_DISPATCHER
.
init
(
vkGetInstanceProcAddr
);
Info
(
"Starting %
\n
Version: %.%.%
\n
TimeStamp: %
\n
BuildType: %"
,
this
->
appInfo
.
appName
,
version
::
Major
,
version
::
Minor
,
version
::
Patch
,
version
::
TimeStamp
,
version
::
Type
);
lib
::
log
::
Info
(
"Starting %
\n
Version: %.%.%
\n
TimeStamp: %
\n
BuildType: %"
,
this
->
appInfo
.
appName
,
version
::
Major
,
version
::
Minor
,
version
::
Patch
,
version
::
TimeStamp
,
version
::
Type
);
try
{
...
...
@@ -128,15 +123,15 @@ lib::CgContext::CgContext(const AppCreateInfo &info, GLFWwindow *window) : windo
this
->
CreateSyncObjects
();
this
->
InitializeImGui
();
this
->
frameIndex
=
0
;
Info
(
"Successfully initialized Vulkan!"
);
lib
::
log
::
Info
(
"Successfully initialized Vulkan!"
);
}
catch
(
CoreInitException
&
e
)
{
Error
(
"Failed to initialize Vulkan!
\n
Reason: %"
,
e
.
what
());
lib
::
log
::
Error
(
"Failed to initialize Vulkan!
\n
Reason: %"
,
e
.
what
());
}
catch
(
std
::
exception
&
e
)
{
Error
(
"Failed to initialize Vulkan after unhandled exception!
\n
What: %!"
,
e
.
what
());
lib
::
log
::
Error
(
"Failed to initialize Vulkan after unhandled exception!
\n
What: %!"
,
e
.
what
());
}
}
...
...
@@ -416,25 +411,28 @@ void lib::CgContext::CreateInstance()
if
(
this
->
appInfo
.
validationInfo
.
useValidationLayers
)
{
std
::
vector
<
const
char
*>
requiredLayers
=
{
"VK_LAYER_KHRONOS_validation"
,
"VK_LAYER_LUNARG_standard_validation"
,
};
constexpr
auto
newLayer
=
"VK_LAYER_KHRONOS_validation"
;
constexpr
auto
legacyLayer
=
"VK_LAYER_LUNARG_standard_validation"
;
for
(
auto
layer
:
required
Layer
s
)
if
(
this
->
CheckLayer
(
new
Layer
)
)
{
if
(
this
->
CheckLayer
(
layer
))
{
usedLayers
.
Add
(
layer
);
}
else
if
(
this
->
appInfo
.
validationInfo
.
requireValidationLayers
)
{
throw
CoreInitException
(
"Not all required Layers are available!"
);
}
else
{
Warning
(
"Not all required Layers are available!"
);
}
usedLayers
.
Add
(
newLayer
);
lib
::
log
::
Info
(
"Using Khronos validation."
);
}
else
if
(
this
->
CheckLayer
(
legacyLayer
))
{
usedLayers
.
Add
(
legacyLayer
);
lib
::
log
::
Info
(
"Using legacy lunarG validation."
);
}
else
if
(
this
->
appInfo
.
validationInfo
.
requireValidationLayers
)
{
throw
CoreInitException
(
"Validation layers were required, but failed to load any!"
);
}
else
{
lib
::
log
::
Warning
(
"Validation layers could not be loaded, but were not required."
);
}
}
...
...
@@ -448,7 +446,7 @@ void lib::CgContext::CreateInstance()
this
->
instance
=
vk
::
createInstance
(
createInfo
);
Info
(
"Successfully created vulkan instance!"
);
lib
::
log
::
Info
(
"Successfully created vulkan instance!"
);
VULKAN_HPP_DEFAULT_DISPATCHER
.
init
(
this
->
instance
);
...
...
@@ -500,7 +498,7 @@ void lib::CgContext::SetupDebugCallbacks()
this
->
debugMessenger
=
this
->
instance
.
createDebugUtilsMessengerEXT
(
createInfo
,
nullptr
);
Info
(
"Successfully set up debug callbacks!"
);
lib
::
log
::
Info
(
"Successfully set up debug callbacks!"
);
}
void
lib
::
CgContext
::
FindPhysicalDevice
()
...
...
@@ -540,9 +538,9 @@ void lib::CgContext::FindPhysicalDevice()
{
auto
rating
=
deviceInfo
.
Rate
(
deviceRequirements
);
Info
(
"Found device
\"
%
\"
with rating %"
,
deviceInfo
.
GetName
(),
rating
);
lib
::
log
::
Info
(
"Found device
\"
%
\"
with rating %"
,
deviceInfo
.
GetName
(),
rating
);
if
(
rating
>
0
&&
(
!
best
.
info
||
rating
>
best
.
rating
))
...
...
@@ -557,11 +555,11 @@ void lib::CgContext::FindPhysicalDevice()
throw
CoreInitException
(
"Could not find any suitable device!"
);
}
Info
(
"Best device is
\"
%
\"
, with a score of %.
\n\t
with max recursion depth %
\n\t
with max triangle count %"
,
best
.
info
->
GetName
(),
best
.
rating
,
best
.
info
->
GetRaytracingProperties
().
maxRecursionDepth
,
best
.
info
->
GetRaytracingProperties
().
maxTriangleCount
);
lib
::
log
::
Info
(
"Best device is
\"
%
\"
, with a score of %.
\n\t
with max recursion depth %
\n\t
with max triangle count %"
,
best
.
info
->
GetName
(),
best
.
rating
,
best
.
info
->
GetRaytracingProperties
().
maxRecursionDepth
,
best
.
info
->
GetRaytracingProperties
().
maxTriangleCount
);
this
->
physicalDeviceInfo
=
*
best
.
info
;
}
...
...
@@ -604,7 +602,7 @@ void lib::CgContext::CreateLogicalDevice()
VULKAN_HPP_DEFAULT_DISPATCHER
.
init
(
this
->
logicalDevice
);
Info
(
"Successfully created logical device!"
);
lib
::
log
::
Info
(
"Successfully created logical device!"
);
}
void
lib
::
CgContext
::
CreateQueues
()
...
...
@@ -614,7 +612,7 @@ void lib::CgContext::CreateQueues()
this
->
bufferStagingQueue
=
this
->
logicalDevice
.
getQueue
(
this
->
physicalDeviceInfo
.
GetBufferStagingQueueFamily
(),
0
);
this
->
computeQueue
=
this
->
logicalDevice
.
getQueue
(
this
->
physicalDeviceInfo
.
GetComputeQueueFamily
(),
0
);
Info
(
"Successfully created queues!"
);
lib
::
log
::
Info
(
"Successfully created queues!"
);
}
void
lib
::
CgContext
::
CreateSurface
()
...
...
@@ -629,7 +627,7 @@ void lib::CgContext::CreateSurface()
this
->
surface
=
surface
;
Info
(
"Successfully created window surface!"
);
lib
::
log
::
Info
(
"Successfully created window surface!"
);
}
void
lib
::
CgContext
::
CreateSwapChain
()
...
...
@@ -678,7 +676,7 @@ void lib::CgContext::CreateSwapChain()
this
->
swapChainImageFormat
=
createInfo
.
imageFormat
;
this
->
swapChain
=
this
->
logicalDevice
.
createSwapchainKHR
(
createInfo
);
Info
(
"Successfully created swap chain!"
);
lib
::
log
::
Info
(
"Successfully created swap chain!"
);
const
auto
swapChainImages
=
this
->
logicalDevice
.
getSwapchainImagesKHR
(
this
->
swapChain
);
...
...
@@ -689,7 +687,7 @@ void lib::CgContext::CreateSwapChain()
this
->
frames
[
i
].
swapChainImage
=
swapChainImages
[
i
];
}
Info
(
"Successfully acquired swap chain images!"
);
lib
::
log
::
Info
(
"Successfully acquired swap chain images!"
);
}
void
lib
::
CgContext
::
CreateImageViews
()
...
...
@@ -699,7 +697,7 @@ void lib::CgContext::CreateImageViews()
frame
.
swapChainImageView
=
lib
::
CreateImageView
(
this
->
logicalDevice
,
frame
.
swapChainImage
,
this
->
swapChainImageFormat
);
}
Info
(
"Successfully created all image views!"
);
lib
::
log
::
Info
(
"Successfully created all image views!"
);
}
void
lib
::
CgContext
::
CreateCommandPool
()
...
...
@@ -719,7 +717,7 @@ void lib::CgContext::CreateCommandPool()
vk
::
CommandPoolCreateFlagBits
::
eTransient
,
this
->
physicalDeviceInfo
.
GetBufferStagingQueueFamily
()));
Info
(
"Successfully created command pools!"
);
lib
::
log
::
Info
(
"Successfully created command pools!"
);
}
void
lib
::
CgContext
::
UpdateCommandBuffer
(
uint32_t
imageIndex
)
...
...
@@ -824,7 +822,7 @@ void lib::CgContext::CreateCommandBuffers()
frame
.
commandBuffer
=
this
->
logicalDevice
.
allocateCommandBuffers
(
allocateInfo
)[
0
];
}
Info
(
"Successfully created command buffers!"
);
lib
::
log
::
Info
(
"Successfully created command buffers!"
);
}
void
lib
::
CgContext
::
CreateSyncObjects
()
...
...
@@ -847,7 +845,7 @@ void lib::CgContext::CreateSyncObjects()
this
->
inFlightFences
.
push_back
(
this
->
logicalDevice
.
createFence
(
fenceCreateInfo
));
}
Info
(
"Successfully created sync objects!"
);
lib
::
log
::
Info
(
"Successfully created sync objects!"
);
}
vk
::
SurfaceFormatKHR
lib
::
CgContext
::
ChooseSurfaceFormat
()
...
...
@@ -863,9 +861,9 @@ vk::SurfaceFormatKHR lib::CgContext::ChooseSurfaceFormat()
}
}
Warning
(
"Could not find the requested color format, using fall back with format=%, color space=%!"
,
vk
::
to_string
(
formats
[
0
].
format
),
vk
::
to_string
(
formats
[
0
].
colorSpace
));
lib
::
log
::
Warning
(
"Could not find the requested color format, using fall back with format=%, color space=%!"
,
vk
::
to_string
(
formats
[
0
].
format
),
vk
::
to_string
(
formats
[
0
].
colorSpace
));
return
formats
[
0
];
}
...
...
@@ -880,9 +878,9 @@ vk::PresentModeKHR lib::CgContext::ChoosePresentMode()
return
requestedFormat
;
}
Warning
(
"Could not find requested format (%), falling back to %"
,
vk
::
to_string
(
requestedFormat
),
vk
::
to_string
(
vk
::
PresentModeKHR
::
eFifo
));
lib
::
log
::
Warning
(
"Could not find requested format (%), falling back to %"
,
vk
::
to_string
(
requestedFormat
),
vk
::
to_string
(
vk
::
PresentModeKHR
::
eFifo
));
return
vk
::
PresentModeKHR
::
eFifo
;
}
...
...
@@ -905,9 +903,9 @@ namespace
{
void
NoticeMissingFile
(
const
std
::
string
&
path
)
{
Error
(
"Failed to load shader: Could not read file
\"
%
\"
! (Current working directory is %)"
,
path
,
std
::
filesystem
::
current_path
());
lib
::
log
::
Error
(
"Failed to load shader: Could not read file
\"
%
\"
! (Current working directory is %)"
,
path
,
std
::
filesystem
::
current_path
());
}
}
// namespace
...
...
@@ -928,7 +926,7 @@ vk::ShaderModule lib::CgContext::LoadShader(const ShaderInfo &info)
if
(
!
CompileShader
(
stringBuf
,
info
,
buf
))
{
Error
(
"Failed to load shader
\"
%
\"
: compilation failed!"
,
info
.
path
);
lib
::
log
::
Error
(
"Failed to load shader
\"
%
\"
: compilation failed!"
,
info
.
path
);
return
vk
::
ShaderModule
();
}
...
...
@@ -1099,7 +1097,7 @@ bool lib::CgContext::TryLoadModel()
}
catch
(
const
ModelLoadException
&
e
)
{
Error
(
"Failed to load model: %"
,
e
.
what
());
lib
::
log
::
Error
(
"Failed to load model: %"
,
e
.
what
());
return
false
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment