mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
Further vulkan stuff
This commit is contained in:
parent
129c706cfc
commit
4ddca8607f
@ -56,8 +56,15 @@
|
||||
#include "thin3d/thin3d.h"
|
||||
#include "Windows/GPU/WindowsVulkanContext.h"
|
||||
|
||||
const bool g_validate_ = true;
|
||||
VulkanContext *g_Vulkan;
|
||||
static const bool g_validate_ = true;
|
||||
static VulkanContext *g_Vulkan;
|
||||
|
||||
struct VulkanLogOptions {
|
||||
bool breakOnWarning;
|
||||
bool breakOnError;
|
||||
bool msgBoxOnError;
|
||||
};
|
||||
static VulkanLogOptions g_LogOptions;
|
||||
|
||||
const char *ObjTypeToString(VkDebugReportObjectTypeEXT type) {
|
||||
switch (type) {
|
||||
@ -92,7 +99,8 @@ const char *ObjTypeToString(VkDebugReportObjectTypeEXT type) {
|
||||
}
|
||||
}
|
||||
|
||||
static VkBool32 Vulkan_Dbg(VkDebugReportFlagsEXT msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject, size_t location, int32_t msgCode, const char* pLayerPrefix, const char* pMsg, void *pUserData) {
|
||||
static VkBool32 VKAPI_CALL Vulkan_Dbg(VkDebugReportFlagsEXT msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject, size_t location, int32_t msgCode, const char* pLayerPrefix, const char* pMsg, void *pUserData) {
|
||||
VulkanLogOptions *options = (VulkanLogOptions *)pUserData;
|
||||
std::ostringstream message;
|
||||
|
||||
if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
|
||||
@ -112,8 +120,16 @@ static VkBool32 Vulkan_Dbg(VkDebugReportFlagsEXT msgFlags, VkDebugReportObjectTy
|
||||
OutputDebugStringA(message.str().c_str());
|
||||
OutputDebugStringA("\n");
|
||||
if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
|
||||
// MessageBox(NULL, message.str().c_str(), "Alert", MB_OK);
|
||||
} else {
|
||||
if (options->breakOnError) {
|
||||
DebugBreak();
|
||||
}
|
||||
if (options->msgBoxOnError) {
|
||||
MessageBoxA(NULL, message.str().c_str(), "Alert", MB_OK);
|
||||
}
|
||||
} else if (msgFlags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
|
||||
if (options->breakOnWarning) {
|
||||
DebugBreak();
|
||||
}
|
||||
}
|
||||
#else
|
||||
std::cout << message << std::endl;
|
||||
@ -137,9 +153,16 @@ bool WindowsVulkanContext::Init(HINSTANCE hInst, HWND hWnd, std::string *error_m
|
||||
|
||||
init_glslang();
|
||||
|
||||
g_Vulkan = new VulkanContext("PPSSPP", VULKAN_FLAG_VALIDATE);
|
||||
g_LogOptions.breakOnError = true;
|
||||
g_LogOptions.breakOnWarning = true;
|
||||
g_LogOptions.msgBoxOnError = false;
|
||||
|
||||
g_Vulkan = new VulkanContext("PPSSPP", g_validate_ ? VULKAN_FLAG_VALIDATE : 0);
|
||||
g_Vulkan->CreateDevice(0);
|
||||
g_Vulkan->InitDebugMsgCallback(Vulkan_Dbg);
|
||||
if (g_validate_) {
|
||||
int bits = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT;
|
||||
g_Vulkan->InitDebugMsgCallback(Vulkan_Dbg, bits, &g_LogOptions);
|
||||
}
|
||||
g_Vulkan->InitObjects(hInst, hWnd, true);
|
||||
|
||||
_CrtCheckMemory();
|
||||
|
@ -155,23 +155,23 @@ void vk_transition_to_present(VkCommandBuffer cmd, VkImage image) {
|
||||
}
|
||||
|
||||
void vk_transition_from_present(VkCommandBuffer cmd, VkImage image) {
|
||||
VkImageMemoryBarrier prePresentBarrier = {};
|
||||
prePresentBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
prePresentBarrier.pNext = NULL;
|
||||
prePresentBarrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
prePresentBarrier.dstAccessMask = 0;
|
||||
prePresentBarrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
prePresentBarrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
prePresentBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
prePresentBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
prePresentBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
prePresentBarrier.subresourceRange.baseMipLevel = 0;
|
||||
prePresentBarrier.subresourceRange.levelCount = 1;
|
||||
prePresentBarrier.subresourceRange.baseArrayLayer = 0;
|
||||
prePresentBarrier.subresourceRange.layerCount = 1;
|
||||
prePresentBarrier.image = image;
|
||||
VkImageMemoryBarrier postPresentBarrier = {};
|
||||
postPresentBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
postPresentBarrier.pNext = NULL;
|
||||
postPresentBarrier.srcAccessMask = 0;
|
||||
postPresentBarrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
postPresentBarrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
postPresentBarrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
postPresentBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
postPresentBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
postPresentBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
postPresentBarrier.subresourceRange.baseMipLevel = 0;
|
||||
postPresentBarrier.subresourceRange.levelCount = 1;
|
||||
postPresentBarrier.subresourceRange.baseArrayLayer = 0;
|
||||
postPresentBarrier.subresourceRange.layerCount = 1;
|
||||
postPresentBarrier.image = image;
|
||||
vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
0, 0, nullptr, 0, nullptr, 1, &prePresentBarrier);
|
||||
0, 0, nullptr, 0, nullptr, 1, &postPresentBarrier);
|
||||
}
|
||||
|
||||
VkCommandBuffer VulkanContext::BeginSurfaceRenderPass(VkClearValue clear_values[2]) {
|
||||
@ -193,6 +193,10 @@ VkCommandBuffer VulkanContext::BeginSurfaceRenderPass(VkClearValue clear_values[
|
||||
NULL,
|
||||
¤t_buffer);
|
||||
|
||||
// TODO: Deal with the VK_SUBOPTIMAL_KHR and VK_ERROR_OUT_OF_DATE_KHR
|
||||
// return codes
|
||||
assert(res == VK_SUCCESS);
|
||||
|
||||
VkCommandBufferBeginInfo begin;
|
||||
begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
begin.pNext = NULL;
|
||||
@ -200,10 +204,6 @@ VkCommandBuffer VulkanContext::BeginSurfaceRenderPass(VkClearValue clear_values[
|
||||
begin.pInheritanceInfo = nullptr;
|
||||
vkBeginCommandBuffer(cmd_, &begin);
|
||||
|
||||
// TODO: Deal with the VK_SUBOPTIMAL_KHR and VK_ERROR_OUT_OF_DATE_KHR
|
||||
// return codes
|
||||
assert(res == VK_SUCCESS);
|
||||
|
||||
vk_transition_from_present(cmd_, swapChainBuffers[current_buffer].image);
|
||||
|
||||
VkRenderPassBeginInfo rp_begin;
|
||||
@ -598,7 +598,7 @@ VkResult VulkanContext::CreateDevice(int physical_device) {
|
||||
return res;
|
||||
}
|
||||
|
||||
VkResult VulkanContext::InitDebugMsgCallback(PFN_vkDebugReportCallbackEXT dbgFunc) {
|
||||
VkResult VulkanContext::InitDebugMsgCallback(PFN_vkDebugReportCallbackEXT dbgFunc, int bits, void *userdata) {
|
||||
VkResult res;
|
||||
VkDebugReportCallbackEXT msg_callback;
|
||||
|
||||
@ -618,9 +618,9 @@ VkResult VulkanContext::InitDebugMsgCallback(PFN_vkDebugReportCallbackEXT dbgFun
|
||||
VkDebugReportCallbackCreateInfoEXT cb;
|
||||
cb.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
|
||||
cb.pNext = nullptr;
|
||||
cb.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
|
||||
cb.flags = bits;
|
||||
cb.pfnCallback = dbgFunc;
|
||||
cb.pUserData = NULL;
|
||||
cb.pUserData = userdata;
|
||||
res = dbgCreateMsgCallback(instance_, &cb, nullptr, &msg_callback);
|
||||
switch (res) {
|
||||
case VK_SUCCESS:
|
||||
@ -1427,6 +1427,10 @@ void TransitionImageLayout(
|
||||
image_memory_barrier.subresourceRange.levelCount = 1;
|
||||
image_memory_barrier.subresourceRange.layerCount = 1;
|
||||
|
||||
if (old_image_layout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
|
||||
image_memory_barrier.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
||||
}
|
||||
|
||||
if (old_image_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
|
||||
image_memory_barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
}
|
||||
@ -1443,11 +1447,11 @@ void TransitionImageLayout(
|
||||
}
|
||||
|
||||
if (new_image_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
|
||||
image_memory_barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
|
||||
image_memory_barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
|
||||
}
|
||||
|
||||
if (new_image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
|
||||
image_memory_barrier.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
||||
image_memory_barrier.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
||||
}
|
||||
|
||||
VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||
|
@ -117,7 +117,7 @@ public:
|
||||
|
||||
bool MemoryTypeFromProperties(uint32_t typeBits, VkFlags requirements_mask, uint32_t *typeIndex);
|
||||
|
||||
VkResult InitDebugMsgCallback(PFN_vkDebugReportCallbackEXT dbgFunc);
|
||||
VkResult InitDebugMsgCallback(PFN_vkDebugReportCallbackEXT dbgFunc, int bits, void *userdata = nullptr);
|
||||
void DestroyDebugMsgCallback();
|
||||
|
||||
VkSemaphore acquireSemaphore;
|
||||
|
@ -272,4 +272,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -195,6 +195,9 @@
|
||||
<ProjectReference Include="..\Core\Core.vcxproj">
|
||||
<Project>{533f1d30-d04d-47cc-ad71-20f658907e36}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\ext\glslang.vcxproj">
|
||||
<Project>{edfa2e87-8ac1-4853-95d4-d7594ff81947}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\ext\libkirk\libkirk.vcxproj">
|
||||
<Project>{3baae095-e0ab-4b0e-b5df-ce39c8ae31de}</Project>
|
||||
</ProjectReference>
|
||||
@ -219,4 +222,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user