Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ if(TEMPEST_BUILD_VULKAN)
add_definitions(-DVULKAN_HPP_NO_EXCEPTIONS)
add_definitions(-DVULKAN_HPP_NO_SMART_HANDLE)

if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
target_link_directories(${PROJECT_NAME} PRIVATE "$ENV{VULKAN_SDK}/lib")
else()
target_link_directories(${PROJECT_NAME} PRIVATE "$ENV{VULKAN_SDK}/Lib32")
if(NOT ANDROID)
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
target_link_directories(${PROJECT_NAME} PRIVATE "$ENV{VULKAN_SDK}/lib")
else()
target_link_directories(${PROJECT_NAME} PRIVATE "$ENV{VULKAN_SDK}/Lib32")
endif()
endif()

target_include_directories(${PROJECT_NAME} PRIVATE "$ENV{VULKAN_SDK}/include")
Expand Down
5 changes: 5 additions & 0 deletions Engine/exceptions/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class SwapchainSuboptimal : public std::exception {
const char* what() const noexcept override { return "swapchain no longer matches the surface properties"; }
};

class SurfaceLost: public std::exception {
public:
const char* what() const noexcept override { return "surface is no longer valid"; }
};

class IncompleteFboException : public std::exception {
public:
const char* what() const noexcept override { return "inconsistent framebuffer dimensions"; }
Expand Down
4 changes: 2 additions & 2 deletions Engine/gapi/vulkan/vcommandbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static VkImage toVkResource(const AbstractGraphicsApi::BarrierDesc& b) {
}

auto& s = *reinterpret_cast<const VSwapchain*>(b.swapchain);
return s.images[b.swId];
return s.image(b.swId);
}


Expand Down Expand Up @@ -300,7 +300,7 @@ void VCommandBuffer::beginRendering(const FrameBufferDesc& fbo, size_t fboSize,
for(size_t i=0; i<fboSize; ++i) {
if(fbo.sw[i] != nullptr) {
auto& t = *reinterpret_cast<VSwapchain*>(fbo.sw[i]);
imageView = t.views[fbo.imgId[i]];
imageView = t.view(fbo.imgId[i]);
imageFormat = t.format();
}
else {
Expand Down
41 changes: 27 additions & 14 deletions Engine/gapi/vulkan/vdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ void VDevice::deviceQueueProps(VkPhysicalDevice device, VkProps& props) {
static const VkQueueFlags rqFlag = (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT);

const bool graphicsSupport = ((queueFamily.queueFlags & rqFlag)==rqFlag);
const bool presentSupport = VSwapchain::checkPresentSupport(device, i);
const bool presentSupport = VSwapchain::checkPresentationSupport(device, i);

if(graphicsSupport)
graphics = i;
Expand All @@ -843,21 +843,34 @@ void VDevice::deviceQueueProps(VkPhysicalDevice device, VkProps& props) {
props.presentFamily = present;
}

VDevice::SwapChainSupport VDevice::querySwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR surface) {
SwapChainSupport details;
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities);
VDevice::SwapChainSupport VDevice::querySwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR surface) const {
SwapChainSupport support;
vkAssert(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &support.capabilities));

uint32_t formatCount = 0;
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);
details.formats.resize(formatCount);
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, details.formats.data());

uint32_t presentModeCount = 0;
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr);
details.presentModes.resize(presentModeCount);
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, details.presentModes.data());
// NOTE: SurfaceFormats query either works, or returns error.
// Vulkan spec doesn't allow for semi-errors, such as surface-lost
while(true) {
uint32_t formatCount = 0;
vkAssert(vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr));
support.formats.resize(formatCount);
auto code = vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, support.formats.data());
if(code==VK_INCOMPLETE)
continue;
vkAssert(code);
break;
}

return details;
while(true) {
uint32_t presentModeCount = 0;
vkAssert(vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr));
support.presentModes.resize(presentModeCount);
auto code = vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, support.presentModes.data());
if(code==VK_INCOMPLETE)
continue;
vkAssert(code);
break;
}
return support;
}

VDevice::MemIndex VDevice::memoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags props, VkImageTiling tiling) const {
Expand Down
6 changes: 4 additions & 2 deletions Engine/gapi/vulkan/vdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ inline void vkAssert(VkResult code){
case VK_ERROR_OUT_OF_HOST_MEMORY:
//throw std::system_error(Tempest::GraphicsErrc::OutOfHostMemory);
throw std::bad_alloc();
case VK_ERROR_SURFACE_LOST_KHR:
throw SurfaceLost();
case VK_ERROR_DEVICE_LOST:
throw DeviceLostException();

Expand Down Expand Up @@ -395,7 +397,7 @@ class VDevice : public AbstractGraphicsApi::Device {
static void deviceFormatProps(VkPhysicalDevice device, VkProps& props);
static void deviceQueueProps(VkPhysicalDevice device, VkProps& props);

SwapChainSupport querySwapChainSupport(VkSurfaceKHR surface) { return querySwapChainSupport(physicalDevice,surface); }
SwapChainSupport querySwapChainSupport(VkSurfaceKHR surface) const { return querySwapChainSupport(physicalDevice,surface); }
MemIndex memoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags props, VkImageTiling tiling) const;

using DataMgr = UploadEngine<VDevice,VCommandBuffer,VBuffer>;
Expand Down Expand Up @@ -480,7 +482,7 @@ class VDevice : public AbstractGraphicsApi::Device {

void pickPhysicalDevice();

SwapChainSupport querySwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR surface);
SwapChainSupport querySwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR surface) const;
};

}}
Loading
Loading