完成SwapChain去除

main-headless
ink-soul 2024-04-16 16:15:39 +08:00
parent 07487be2bf
commit 92d7b95f0f
5 changed files with 24 additions and 36 deletions

View File

@ -225,16 +225,17 @@ namespace vks
} }
VkResult result = vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &logicalDevice); VkResult result = vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &logicalDevice);
/*
if (result == VK_SUCCESS) { if (result == VK_SUCCESS) {
commandPool = createCommandPool(queueFamilyIndices.graphics); commandPool = createCommandPool(queueFamilyIndices.graphics);
} }
*/
this->enabledFeatures = enabledFeatures; this->enabledFeatures = enabledFeatures;
return result; return result;
} }
/** /**
* Create a buffer on the device * Create a buffer on the device
* *
@ -313,6 +314,11 @@ namespace vks
return cmdPool; return cmdPool;
} }
void setCommandPool(VkCommandPool commandPool)
{
this->commandPool = commandPool;
}
/** /**
* Allocate a command buffer from the command pool * Allocate a command buffer from the command pool
* *

View File

@ -126,7 +126,7 @@ void VulkanExampleBase::prepare()
cmdPoolInfo.queueFamilyIndex = queueFamilyIndex; cmdPoolInfo.queueFamilyIndex = queueFamilyIndex;
cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
VK_CHECK_RESULT(vkCreateCommandPool(device, &cmdPoolInfo, nullptr, &cmdPool)); VK_CHECK_RESULT(vkCreateCommandPool(device, &cmdPoolInfo, nullptr, &cmdPool));
vulkanDevice->setCommandPool(cmdPool);
/* /*
Render pass Render pass
*/ */
@ -505,24 +505,6 @@ void VulkanExampleBase::initVulkan()
queueFamilyIndex creation queueFamilyIndex creation
*/ */
const float defaultQueuePriority(0.0f);
VkDeviceQueueCreateInfo queueCreateInfo = {};
uint32_t queueFamilyCount;
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, nullptr);
std::vector<VkQueueFamilyProperties> queueFamilyProperties(queueFamilyCount);
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, queueFamilyProperties.data());
for (uint32_t i = 0; i < static_cast<uint32_t>(queueFamilyProperties.size()); i++) {
if (queueFamilyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
queueFamilyIndex = i;
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queueCreateInfo.queueFamilyIndex = i;
queueCreateInfo.queueCount = 1;
queueCreateInfo.pQueuePriorities = &defaultQueuePriority;
break;
}
}
/* /*
Device creation Device creation
*/ */
@ -538,14 +520,12 @@ void VulkanExampleBase::initVulkan()
exit(res); exit(res);
} }
device = vulkanDevice->logicalDevice; device = vulkanDevice->logicalDevice;
/* /*
Graphics queue Graphics queue
*/ */
vkGetDeviceQueue(device, vulkanDevice->queueFamilyIndices.graphics, 0, &queue); vkGetDeviceQueue(device, vulkanDevice->queueFamilyIndices.graphics, 0, &queue);
queueFamilyIndex = vulkanDevice->queueFamilyIndices.graphics;
/* /*
Suitable depth format Suitable depth format
*/ */

View File

@ -114,7 +114,7 @@ public:
VkFormat colorFormat = VK_FORMAT_R8G8B8A8_SRGB; VkFormat colorFormat = VK_FORMAT_R8G8B8A8_SRGB;
uint32_t queueFamilyIndex; uint32_t queueFamilyIndex;
uint32_t renderingFrameIndex; uint32_t renderingFrameIndex = 3;
struct Signal struct Signal
{ {

View File

@ -321,14 +321,14 @@ PlumageRender::PlumageRender()
} }
std::vector<VkDescriptorPoolSize> poolSizes = { std::vector<VkDescriptorPoolSize> poolSizes = {
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, (4 + meshCount) * swapChain.imageCount }, { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, (4 + meshCount) * renderingFrameIndex },
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, imageSamplerCount * swapChain.imageCount } { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, imageSamplerCount * renderingFrameIndex }
}; };
VkDescriptorPoolCreateInfo descriptorPoolCI{}; VkDescriptorPoolCreateInfo descriptorPoolCI{};
descriptorPoolCI.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; descriptorPoolCI.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
descriptorPoolCI.poolSizeCount = 2; descriptorPoolCI.poolSizeCount = 2;
descriptorPoolCI.pPoolSizes = poolSizes.data(); descriptorPoolCI.pPoolSizes = poolSizes.data();
descriptorPoolCI.maxSets = (2 + materialCount + meshCount) * swapChain.imageCount; descriptorPoolCI.maxSets = (2 + materialCount + meshCount) * renderingFrameIndex;
VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolCI, nullptr, &descriptorPool)); VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolCI, nullptr, &descriptorPool));
/* /*
@ -357,7 +357,7 @@ PlumageRender::PlumageRender()
descriptorSetAllocInfo.descriptorPool = descriptorPool; descriptorSetAllocInfo.descriptorPool = descriptorPool;
descriptorSetAllocInfo.pSetLayouts = &descriptorSetLayouts.scene; descriptorSetAllocInfo.pSetLayouts = &descriptorSetLayouts.scene;
descriptorSetAllocInfo.descriptorSetCount = 1; descriptorSetAllocInfo.descriptorSetCount = 1;
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorSetAllocInfo, &descriptorSets[i].scene)); vkAllocateDescriptorSets(device, &descriptorSetAllocInfo, &descriptorSets[i].scene);
std::array<VkWriteDescriptorSet, 5> writeDescriptorSets{}; std::array<VkWriteDescriptorSet, 5> writeDescriptorSets{};
@ -399,6 +399,7 @@ PlumageRender::PlumageRender()
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
} }
} }
// Material (samplers) // Material (samplers)
{ {
@ -1533,7 +1534,7 @@ PlumageRender::PlumageRender()
0.0f); 0.0f);
} }
void PlumageRender::windowResized() void PlumageRender::windowResized()
{ {
buildCommandBuffers(); buildCommandBuffers();
@ -1542,6 +1543,7 @@ PlumageRender::PlumageRender()
//update UI //update UI
updateUIOverlay(); updateUIOverlay();
} }
void PlumageRender::prepare() void PlumageRender::prepare()
{ {
@ -1986,7 +1988,7 @@ PlumageRender::PlumageRender()
return; return;
} }
updateUIOverlay(); //updateUIOverlay();
//加入写到文件的函数 //加入写到文件的函数
//swapChainImage = swapChain.images[frameIndex]; //swapChainImage = swapChain.images[frameIndex];
//outputImageSequeue(swapChainImage,filePath.imageSequenceFilePath); //outputImageSequeue(swapChainImage,filePath.imageSequenceFilePath);

View File

@ -142,8 +142,8 @@ public:
struct FilePath struct FilePath
{ //model path { //model path
std::string glTFModelFilePath = getAssetPath() + "models/DamagedHelmet/DamagedHelmet.gltf"; std::string glTFModelFilePath = getAssetPath() + "models/DamagedHelmet/DamagedHelmet.gltf";
//std::string modelVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.vert.spv"; std::string modelVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.vert.spv";
//std::string modelFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.frag.spv"; std::string modelFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.frag.spv";
//ui //ui
std::string uiVertShaderPath = getAssetPath() + "shaders/ui.vert.spv"; std::string uiVertShaderPath = getAssetPath() + "shaders/ui.vert.spv";
@ -154,7 +154,7 @@ public:
std::string skyboxVertShaderPath = getAssetPath() + "shaders/skybox.vert.spv"; std::string skyboxVertShaderPath = getAssetPath() + "shaders/skybox.vert.spv";
std::string skyboxFragShaderPath = getAssetPath() + "shaders/skybox.frag.spv"; std::string skyboxFragShaderPath = getAssetPath() + "shaders/skybox.frag.spv";
//std::string iblTexturesFilePath = getAssetPath() + "textures/hdr/gcanyon_cube.ktx"; std::string iblTexturesFilePath = getAssetPath() + "textures/hdr/gcanyon_cube.ktx";
//tonemapping //tonemapping
std::string tonemappingVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/genbrdflut.vert.spv"; std::string tonemappingVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/genbrdflut.vert.spv";
std::string tonemappingEnableFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/tonemapping_enable.frag.spv"; std::string tonemappingEnableFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/tonemapping_enable.frag.spv";
@ -342,7 +342,7 @@ public:
textures.prefilteredCube.destroy(); textures.prefilteredCube.destroy();
textures.lutBrdf.destroy(); textures.lutBrdf.destroy();
textures.empty.destroy(); textures.empty.destroy();
delete gui; //delete gui;
} }