Commit 97756e08 authored by Stefan Bodenschatz's avatar Stefan Bodenschatz
Browse files

Merge branch 'develop' of...

Merge branch 'develop' of gitlab.fsi.hochschule-trier.de:GameDevWeek/dependencies/cpp/mirrage into develop
parents 3bfa24b3 40377081
Pipeline #2704 passed with stage
in 13 minutes and 48 seconds
......@@ -37,7 +37,7 @@ if("${EMBED_MODE} " STREQUAL "MSVC ")
execute_process(COMMAND ${CMAKE_COMMAND} -E touch "${EMBED_SRC_FILE}" OUTPUT_QUIET)
else()
if("${EMBED_MODE} " STREQUAL "APPLE ")
set(SECTION ".const_data")
set(SECTION ".const_data, no_dead_strip")
else()
set(SECTION ".section .rodata")
endif()
......
${SECTION}
.global ${ID}
.global ${ID}_size
${SECTION}
${ID}:
.incbin "${DST_DIR}/embedded_assets.zip"
1:
......
......@@ -11,7 +11,6 @@ namespace mirrage::graphic {
class Swapchain : public Window_modification_handler {
public:
Swapchain() = default;
Swapchain(const vk::Device& dev, vk::PhysicalDevice, Window&, vk::SwapchainCreateInfoKHR);
Swapchain(Swapchain&&) = default;
Swapchain& operator=(Swapchain&&) = default;
......@@ -32,9 +31,9 @@ namespace mirrage::graphic {
auto image_format() const noexcept { return _image_format; }
private:
const vk::Device& _device;
const vk::Device* _device;
vk::PhysicalDevice _gpu;
Window& _window;
Window* _window;
vk::SwapchainCreateInfoKHR _info;
vk::UniqueSwapchainKHR _swapchain;
std::vector<vk::Image> _images;
......
......@@ -56,7 +56,10 @@ namespace mirrage::graphic {
};
struct Image_dimensions {
Image_dimensions(std::int32_t width, std::int32_t height, std::int32_t depth, std::int32_t layers)
Image_dimensions(std::int32_t width = 1,
std::int32_t height = 1,
std::int32_t depth = 1,
std::int32_t layers = 1)
: width(width), height(height), depth(depth), layers(layers)
{
}
......@@ -71,22 +74,28 @@ namespace mirrage::graphic {
template <>
struct Image_dimensions_t<Image_type::single_1d> : Image_dimensions {
Image_dimensions_t(std::int32_t width) : Image_dimensions(width, 1, 1, 1) {}
Image_dimensions_t(std::int32_t width = 1) : Image_dimensions(width, 1, 1, 1) {}
};
template <>
struct Image_dimensions_t<Image_type::single_2d> : Image_dimensions {
Image_dimensions_t(std::int32_t width, std::int32_t height) : Image_dimensions(width, height, 1, 1) {}
Image_dimensions_t(std::int32_t width = 1, std::int32_t height = 1)
: Image_dimensions(width, height, 1, 1)
{
}
};
template <>
struct Image_dimensions_t<Image_type::array_2d> : Image_dimensions {
Image_dimensions_t(std::int32_t width, std::int32_t height, std::int32_t layers)
Image_dimensions_t(std::int32_t width = 1, std::int32_t height = 1, std::int32_t layers = 1)
: Image_dimensions(width, height, 1, layers)
{
}
};
template <>
struct Image_dimensions_t<Image_type::cubemap> : Image_dimensions {
Image_dimensions_t(std::int32_t width, std::int32_t height) : Image_dimensions(width, height, 1, 6) {}
Image_dimensions_t(std::int32_t width = 1, std::int32_t height = 1)
: Image_dimensions(width, height, 1, 6)
{
}
};
......@@ -102,7 +111,7 @@ namespace mirrage::graphic {
private:
friend class Device;
const vk::Device& _device;
const vk::Device* _device;
vk::UniqueCommandPool _pool;
Command_buffer_pool(const vk::Device& device, vk::UniqueCommandPool pool);
......@@ -123,7 +132,7 @@ namespace mirrage::graphic {
private:
friend class Device;
const vk::Device& _device;
const vk::Device* _device;
vk::UniqueFence _fence;
Fence(const vk::Device& device, bool signaled);
......
......@@ -10,9 +10,9 @@ namespace mirrage::graphic {
Window& window,
vk::SwapchainCreateInfoKHR info)
: Window_modification_handler(window)
, _device(dev)
, _device(&dev)
, _gpu(gpu)
, _window(window)
, _window(&window)
, _info(info)
, _swapchain(dev.createSwapchainKHRUnique(info))
, _images(dev.getSwapchainImagesKHR(*_swapchain))
......@@ -37,13 +37,14 @@ namespace mirrage::graphic {
ivc.setViewType(vk::ImageViewType::e2D);
ivc.setFormat(_info.imageFormat);
ivc.setSubresourceRange(vk::ImageSubresourceRange{vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1});
_image_views.emplace_back(_device.createImageViewUnique(ivc));
_image_views.emplace_back(_device->createImageViewUnique(ivc));
}
}
auto Swapchain::acquireNextImage(vk::Semaphore s, vk::Fence f) const -> std::size_t
{
return _device.acquireNextImageKHR(*_swapchain, std::numeric_limits<std::uint64_t>::max(), s, f).value;
return _device->acquireNextImageKHR(*_swapchain, std::numeric_limits<std::uint64_t>::max(), s, f)
.value;
}
bool Swapchain::present(vk::Queue& q, std::size_t img_index, vk::Semaphore s)
......@@ -53,25 +54,25 @@ namespace mirrage::graphic {
auto info = vk::PresentInfoKHR{s ? 1u : 0u, &s, 1, &*_swapchain, &img_index_vk};
auto result = vkQueuePresentKHR(VkQueue(q), reinterpret_cast<VkPresentInfoKHR*>(&info));
_window.on_present();
_window->on_present();
if(result != VK_SUCCESS || _recreate_pending) {
_recreate_pending = false;
_device.waitIdle();
_device->waitIdle();
auto capabilities = _gpu.getSurfaceCapabilitiesKHR(_window.surface());
auto capabilities = _gpu.getSurfaceCapabilitiesKHR(_window->surface());
LOG(plog::debug) << "Extends: " << capabilities.currentExtent.width << ", "
<< capabilities.currentExtent.height;
_image_width = _window.width();
_image_height = _window.height();
_image_width = _window->width();
_image_height = _window->height();
_info.oldSwapchain = *_swapchain;
_info.imageExtent.width = gsl::narrow<std::uint32_t>(_image_width);
_info.imageExtent.height = gsl::narrow<std::uint32_t>(_image_height);
_swapchain = _device.createSwapchainKHRUnique(_info);
_images = _device.getSwapchainImagesKHR(*_swapchain);
_swapchain = _device->createSwapchainKHRUnique(_info);
_images = _device->getSwapchainImagesKHR(*_swapchain);
_create_image_views();
......
......@@ -9,31 +9,35 @@
namespace mirrage::graphic {
Command_buffer_pool::Command_buffer_pool(const vk::Device& device, vk::UniqueCommandPool pool)
: _device(device), _pool(std::move(pool))
: _device(&device), _pool(std::move(pool))
{
}
Command_buffer_pool::~Command_buffer_pool() { _device.waitIdle(); }
Command_buffer_pool::~Command_buffer_pool()
{
if(_device)
_device->waitIdle();
}
auto Command_buffer_pool::create_primary(std::int32_t count) -> std::vector<vk::UniqueCommandBuffer>
{
return _device.allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(
return _device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(
*_pool, vk::CommandBufferLevel::ePrimary, gsl::narrow<std::uint32_t>(count)));
}
auto Command_buffer_pool::create_secondary(std::int32_t count) -> std::vector<vk::UniqueCommandBuffer>
{
return _device.allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(
return _device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(
*_pool, vk::CommandBufferLevel::eSecondary, gsl::narrow<std::uint32_t>(count)));
}
Fence::operator bool() const { return _device.getFenceStatus(*_fence) == vk::Result::eSuccess; }
void Fence::reset() { _device.resetFences({*_fence}); }
void Fence::wait() { _device.waitForFences({*_fence}, true, std::numeric_limits<std::uint64_t>::max()); }
Fence::operator bool() const { return _device->getFenceStatus(*_fence) == vk::Result::eSuccess; }
void Fence::reset() { _device->resetFences({*_fence}); }
void Fence::wait() { _device->waitForFences({*_fence}, true, std::numeric_limits<std::uint64_t>::max()); }
Fence::Fence(const vk::Device& device, bool signaled)
: _device(device)
, _fence(_device.createFenceUnique({signaled ? vk::FenceCreateFlags{vk::FenceCreateFlagBits::eSignaled}
: vk::FenceCreateFlags{}}))
: _device(&device)
, _fence(_device->createFenceUnique({signaled ? vk::FenceCreateFlags{vk::FenceCreateFlagBits::eSignaled}
: vk::FenceCreateFlags{}}))
{
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment