统一对象实例化在render中

ink-soul 2024-04-08 11:10:30 +08:00
parent eaf10107ae
commit 83d35012e6
10 changed files with 214 additions and 274 deletions

View File

@ -37,7 +37,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageCallback(VkDebugReportFlagsEXT flags,
/* /*
VkResult VulkanExampleBase::createInstance(bool enableValidation) VkResult VulkanExampleBase::createInstance(bool enableValidation)
{ {
setter.settings.validation = enableValidation; PlumageRender::Setter::settings.validation = enableValidation;
// Validation can also be forced via a define // Validation can also be forced via a define
#if defined(_VALIDATION) #if defined(_VALIDATION)

View File

@ -42,7 +42,7 @@ void PlumageRender::renderMain::buildCommandBuffers()
cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
VkClearValue clearValues[3]; VkClearValue clearValues[3];
if (setter.settings.multiSampling) { if (PlumageRender::Setter::settings.multiSampling) {
clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 1.0f } }; clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 1.0f } };
clearValues[1].color = { { 0.0f, 0.0f, 0.0f, 1.0f } }; clearValues[1].color = { { 0.0f, 0.0f, 0.0f, 1.0f } };
clearValues[2].depthStencil = { 1.0f, 0 }; clearValues[2].depthStencil = { 1.0f, 0 };
@ -57,9 +57,9 @@ void PlumageRender::renderMain::buildCommandBuffers()
renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.renderPass = renderPass;
renderPassBeginInfo.renderArea.offset.x = 0; renderPassBeginInfo.renderArea.offset.x = 0;
renderPassBeginInfo.renderArea.offset.y = 0; renderPassBeginInfo.renderArea.offset.y = 0;
renderPassBeginInfo.renderArea.extent.width = setter.settings.width; renderPassBeginInfo.renderArea.extent.width =PlumageRender::renderMain::settings.width;
renderPassBeginInfo.renderArea.extent.height = setter.settings.height; renderPassBeginInfo.renderArea.extent.height =PlumageRender::renderMain::settings.height;
renderPassBeginInfo.clearValueCount = setter.settings.multiSampling ? 3 : 2; renderPassBeginInfo.clearValueCount =PlumageRender::renderMain::settings.multiSampling ? 3 : 2;
renderPassBeginInfo.pClearValues = clearValues; renderPassBeginInfo.pClearValues = clearValues;
@ -73,14 +73,14 @@ void PlumageRender::renderMain::buildCommandBuffers()
vkCmdBeginRenderPass(currentCB, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); vkCmdBeginRenderPass(currentCB, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
VkViewport viewport{}; VkViewport viewport{};
viewport.width = (float)setter.settings.width; viewport.width = (float)PlumageRender::Setter::settings.width;
viewport.height = (float)setter.settings.height; viewport.height = (float)PlumageRender::Setter::settings.height;
viewport.minDepth = 0.0f; viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f; viewport.maxDepth = 1.0f;
vkCmdSetViewport(currentCB, 0, 1, &viewport); vkCmdSetViewport(currentCB, 0, 1, &viewport);
VkRect2D scissor{}; VkRect2D scissor{};
scissor.extent = { setter.settings.width, setter.settings.height }; scissor.extent = {PlumageRender::renderMain::settings.width,PlumageRender::renderMain::settings.height };
vkCmdSetScissor(currentCB, 0, 1, &scissor); vkCmdSetScissor(currentCB, 0, 1, &scissor);
VkDeviceSize offsets[1] = { 0 }; VkDeviceSize offsets[1] = { 0 };
@ -115,7 +115,7 @@ void PlumageRender::renderMain::buildCommandBuffers()
} }
// User interface // User interface
if (!setter.settings.headless) if (!PlumageRender::Setter::settings.headless)
{ {
gui->draw(currentCB); gui->draw(currentCB);
} }
@ -128,24 +128,12 @@ void PlumageRender::renderMain::buildCommandBuffers()
} }
void PlumageRender::renderMain::loadScene(std::string filename)
{
std::cout << "Loading scene from " << filename << std::endl;
models.scene.destroy(device);
animationIndex = 0;
animationTimer = 0.0f;
auto tStart = std::chrono::high_resolution_clock::now();
models.scene.loadFromFile(filename, vulkanDevice, queue);
auto tFileLoad = std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - tStart).count();
std::cout << "Loading took " << tFileLoad << " ms" << std::endl;
camera.setPosition({ 0.0f, 0.0f, -1.0f });
camera.setRotation({ 0.0f, 0.0f, 0.0f });
}
void PlumageRender::renderMain::loadEnvironment(std::string filename) void PlumageRender::renderMain::loadEnvironment(std::string filename)
{ {
std::cout << "Loading environment from " << filename << std::endl; std::cout << "Loading environment from " << filename << std::endl;
if (textures.environmentCube.image) { if (PlumageRender::renderMain::pbrmaterial.textures.environmentCube.image) {
textures.environmentCube.destroy(); textures.environmentCube.destroy();
textures.irradianceCube.destroy(); textures.irradianceCube.destroy();
textures.prefilteredCube.destroy(); textures.prefilteredCube.destroy();
@ -172,13 +160,13 @@ void PlumageRender::renderMain::loadAssets()
readDirectory(assetpath + "environments", "*.ktx", environments, false); readDirectory(assetpath + "environments", "*.ktx", environments, false);
textures.empty.loadFromFile(setter.filePath.emptyEnvmapFilePath, VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); textures.empty.loadFromFile(PlumageRender::Setter::filePath.emptyEnvmapFilePath, VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
std::string sceneFile = setter.filePath.glTFModelFilePath; std::string sceneFile =PlumageRender::renderMain::filePath.glTFModelFilePath;
std::string envMapFile = setter.filePath.envMapFilePath; std::string envMapFile =PlumageRender::renderMain::filePath.envMapFilePath;
loadScene(sceneFile.c_str()); loadScene(sceneFile.c_str());
models.skybox.loadFromFile(setter.filePath.skyboxModleFilePath, vulkanDevice, queue); models.skybox.loadFromFile(PlumageRender::Setter::filePath.skyboxModleFilePath, vulkanDevice, queue);
loadEnvironment(envMapFile.c_str()); loadEnvironment(envMapFile.c_str());
} }
@ -191,76 +179,6 @@ void PlumageRender::renderMain::setupNodeDescriptorSet(glTFModel::Node* node)
} }
void PlumageRender::renderMain::setupDescriptors()
{
/*
Descriptor sets
*/
// Scene (matrices and environment maps)
{
for (auto i = 0; i < descriptorSets.size(); i++) {
VkDescriptorSetAllocateInfo descriptorSetAllocInfo{};
descriptorSetAllocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
descriptorSetAllocInfo.descriptorPool = descriptorPool;
descriptorSetAllocInfo.pSetLayouts = &descriptorSetLayouts.scene;
descriptorSetAllocInfo.descriptorSetCount = 1;
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorSetAllocInfo, &descriptorSets[i].scene));
std::array<VkWriteDescriptorSet, 5> writeDescriptorSets{};
writeDescriptorSets[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
writeDescriptorSets[0].descriptorCount = 1;
writeDescriptorSets[0].dstSet = descriptorSets[i].scene;
writeDescriptorSets[0].dstBinding = 0;
writeDescriptorSets[0].pBufferInfo = &uniformBuffers[i].scene.descriptor;
writeDescriptorSets[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSets[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
writeDescriptorSets[1].descriptorCount = 1;
writeDescriptorSets[1].dstSet = descriptorSets[i].scene;
writeDescriptorSets[1].dstBinding = 1;
writeDescriptorSets[1].pBufferInfo = &uniformBuffers[i].params.descriptor;
writeDescriptorSets[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSets[2].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
writeDescriptorSets[2].descriptorCount = 1;
writeDescriptorSets[2].dstSet = descriptorSets[i].scene;
writeDescriptorSets[2].dstBinding = 2;
writeDescriptorSets[2].pImageInfo = &textures.irradianceCube.descriptor;
writeDescriptorSets[3].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSets[3].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
writeDescriptorSets[3].descriptorCount = 1;
writeDescriptorSets[3].dstSet = descriptorSets[i].scene;
writeDescriptorSets[3].dstBinding = 3;
writeDescriptorSets[3].pImageInfo = &textures.prefilteredCube.descriptor;
writeDescriptorSets[4].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSets[4].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
writeDescriptorSets[4].descriptorCount = 1;
writeDescriptorSets[4].dstSet = descriptorSets[i].scene;
writeDescriptorSets[4].dstBinding = 4;
writeDescriptorSets[4].pImageInfo = &textures.lutBrdf.descriptor;
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
}
}
// Material (samplers)
{
}
}
// generate two cube maps // generate two cube maps
// irradiance cube map // irradiance cube map
@ -591,13 +509,13 @@ void PlumageRender::renderMain::generateCubemaps()
pipelineCI.pStages = shaderStages.data(); pipelineCI.pStages = shaderStages.data();
pipelineCI.renderPass = renderpass; pipelineCI.renderPass = renderpass;
shaderStages[0] = loadShader(device, setter.filePath.filterVertShaderPath, VK_SHADER_STAGE_VERTEX_BIT); shaderStages[0] = loadShader(device,PlumageRender::renderMain::filePath.filterVertShaderPath, VK_SHADER_STAGE_VERTEX_BIT);
switch (target) { switch (target) {
case IRRADIANCE: case IRRADIANCE:
shaderStages[1] = loadShader(device, setter.filePath.irradianceFragShaderPath, VK_SHADER_STAGE_FRAGMENT_BIT); shaderStages[1] = loadShader(device,PlumageRender::renderMain::filePath.irradianceFragShaderPath, VK_SHADER_STAGE_FRAGMENT_BIT);
break; break;
case PREFILTEREDENV: case PREFILTEREDENV:
shaderStages[1] = loadShader(device, setter.filePath.prefilterEnvmapFragShaderPath, VK_SHADER_STAGE_FRAGMENT_BIT); shaderStages[1] = loadShader(device,PlumageRender::renderMain::filePath.prefilterEnvmapFragShaderPath, VK_SHADER_STAGE_FRAGMENT_BIT);
break; break;
}; };
VkPipeline pipeline; VkPipeline pipeline;
@ -1002,8 +920,8 @@ void PlumageRender::renderMain::generateBRDFLUT()
// Look-up-table (from BRDF) pipeline // Look-up-table (from BRDF) pipeline
shaderStages = { shaderStages = {
loadShader(device,setter.filePath.brdfVertShaderPath, VK_SHADER_STAGE_VERTEX_BIT), loadShader(device,PlumageRender::Setter::filePath.brdfVertShaderPath, VK_SHADER_STAGE_VERTEX_BIT),
loadShader(device,setter.filePath.brdfFragShaderPath, VK_SHADER_STAGE_FRAGMENT_BIT) loadShader(device,PlumageRender::Setter::filePath.brdfFragShaderPath, VK_SHADER_STAGE_FRAGMENT_BIT)
}; };
VkPipeline pipeline; VkPipeline pipeline;
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipeline)); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipeline));
@ -1064,15 +982,6 @@ void PlumageRender::renderMain::generateBRDFLUT()
// Prepare and initialize uniform buffer containing shader uniforms // Prepare and initialize uniform buffer containing shader uniforms
void PlumageRender::renderMain::prepareUniformBuffers()
{
for (auto& uniformBuffer : uniformBuffers) {
uniformBuffer.scene.create(vulkanDevice, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, sizeof(shaderDataScene));
uniformBuffer.skybox.create(vulkanDevice, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, sizeof(shaderDataSkybox));
uniformBuffer.params.create(vulkanDevice, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, sizeof(shaderData));
}
updateUniformBuffers();
}
// 更新统一缓冲区 done // 更新统一缓冲区 done
void PlumageRender::renderMain::updateUniformBuffers() void PlumageRender::renderMain::updateUniformBuffers()
@ -1134,9 +1043,9 @@ void PlumageRender::renderMain::prepare()
prepareUniformBuffers(); prepareUniformBuffers();
setupDescriptors(); setupDescriptors();
preparePipelines(); preparePipelines();
if (!setter.settings.headless) if (!PlumageRender::Setter::settings.headless)
{ {
gui = new UI(vulkanDevice, renderPass, queue, pipelineCache, setter.settings.sampleCount); gui = new UI(vulkanDevice, renderPass, queue, pipelineCache,PlumageRender::renderMain::settings.sampleCount);
updateUIOverlay(); updateUIOverlay();
} }
buildCommandBuffers(); buildCommandBuffers();
@ -1148,7 +1057,7 @@ void PlumageRender::renderMain::setupCamera()
{ {
camera.type = Camera::CameraType::lookat; camera.type = Camera::CameraType::lookat;
camera.setPerspective(45.0f, (float)setter.settings.width / (float)setter.settings.height, 0.1f, 256.0f); camera.setPerspective(45.0f, (float)PlumageRender::Setter::settings.width / (float)PlumageRender::Setter::settings.height, 0.1f, 256.0f);
camera.rotationSpeed = 0.25f; camera.rotationSpeed = 0.25f;
camera.movementSpeed = 0.1f; camera.movementSpeed = 0.1f;
camera.setPosition({ 0.0f, 0.0f, -1.0f }); camera.setPosition({ 0.0f, 0.0f, -1.0f });
@ -1201,8 +1110,8 @@ void PlumageRender::renderMain::writeImageToFile(std::string filePath)
imageCreateCI.imageType = VK_IMAGE_TYPE_2D; imageCreateCI.imageType = VK_IMAGE_TYPE_2D;
// Note that vkCmdBlitImage (if supported) will also do format conversions if the swapchain color format would differ // Note that vkCmdBlitImage (if supported) will also do format conversions if the swapchain color format would differ
imageCreateCI.format = VK_FORMAT_R8G8B8A8_UNORM; imageCreateCI.format = VK_FORMAT_R8G8B8A8_UNORM;
imageCreateCI.extent.width = setter.settings.width; imageCreateCI.extent.width =PlumageRender::renderMain::settings.width;
imageCreateCI.extent.height = setter.settings.height; imageCreateCI.extent.height =PlumageRender::renderMain::settings.height;
imageCreateCI.extent.depth = 1; imageCreateCI.extent.depth = 1;
imageCreateCI.arrayLayers = 1; imageCreateCI.arrayLayers = 1;
imageCreateCI.mipLevels = 1; imageCreateCI.mipLevels = 1;
@ -1257,8 +1166,8 @@ void PlumageRender::renderMain::writeImageToFile(std::string filePath)
{ {
// Define the region to blit (we will blit the whole swapchain image) // Define the region to blit (we will blit the whole swapchain image)
VkOffset3D blitSize; VkOffset3D blitSize;
blitSize.x = setter.settings.width; blitSize.x =PlumageRender::renderMain::settings.width;
blitSize.y = setter.settings.height; blitSize.y =PlumageRender::renderMain::settings.height;
blitSize.z = 1; blitSize.z = 1;
VkImageBlit imageBlitRegion{}; VkImageBlit imageBlitRegion{};
imageBlitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; imageBlitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
@ -1285,8 +1194,8 @@ void PlumageRender::renderMain::writeImageToFile(std::string filePath)
imageCopyRegion.srcSubresource.layerCount = 1; imageCopyRegion.srcSubresource.layerCount = 1;
imageCopyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; imageCopyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
imageCopyRegion.dstSubresource.layerCount = 1; imageCopyRegion.dstSubresource.layerCount = 1;
imageCopyRegion.extent.width = setter.settings.width; imageCopyRegion.extent.width =PlumageRender::renderMain::settings.width;
imageCopyRegion.extent.height = setter.settings.height; imageCopyRegion.extent.height =PlumageRender::renderMain::settings.height;
imageCopyRegion.extent.depth = 1; imageCopyRegion.extent.depth = 1;
// Issue the copy command // Issue the copy command
@ -1310,7 +1219,7 @@ void PlumageRender::renderMain::writeImageToFile(std::string filePath)
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
VkImageSubresourceRange{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }); VkImageSubresourceRange{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
if (!setter.settings.headless) if (!PlumageRender::Setter::settings.headless)
{ {
// Transition back the swap chain image after the blit is done // Transition back the swap chain image after the blit is done
vks::tools::insertImageMemoryBarrier( vks::tools::insertImageMemoryBarrier(
@ -1347,16 +1256,16 @@ void PlumageRender::renderMain::writeImageToFile(std::string filePath)
colorSwizzle = (std::find(formatsBGR.begin(), formatsBGR.end(), swapChain.colorFormat) != formatsBGR.end()); colorSwizzle = (std::find(formatsBGR.begin(), formatsBGR.end(), swapChain.colorFormat) != formatsBGR.end());
} }
if (setter.settings.outputPNGimage) if (PlumageRender::Setter::settings.outputPNGimage)
{ {
if (colorSwizzle) if (colorSwizzle)
{ {
// 暂时不改此处需要将BGR通道改成RGB格式 // 暂时不改此处需要将BGR通道改成RGB格式
stbi_write_png(filePath.c_str(), setter.settings.width, setter.settings.height, 4, data, static_cast<int>(subResourceLayout.rowPitch)); stbi_write_png(filePath.c_str(),PlumageRender::renderMain::settings.width,PlumageRender::renderMain::settings.height, 4, data, static_cast<int>(subResourceLayout.rowPitch));
} }
else else
{ {
stbi_write_png(filePath.c_str(), setter.settings.width, setter.settings.height, 4, data, static_cast<int>(subResourceLayout.rowPitch)); stbi_write_png(filePath.c_str(),PlumageRender::renderMain::settings.width,PlumageRender::renderMain::settings.height, 4, data, static_cast<int>(subResourceLayout.rowPitch));
} }
} }
@ -1366,13 +1275,13 @@ void PlumageRender::renderMain::writeImageToFile(std::string filePath)
std::ofstream file(filePath, std::ios::out | std::ios::binary); std::ofstream file(filePath, std::ios::out | std::ios::binary);
// ppm header // ppm header
file << "P6\n" << setter.settings.width << "\n" << setter.settings.height << "\n" << 255 << "\n"; file << "P6\n" <<PlumageRender::renderMain::settings.width << "\n" <<PlumageRender::renderMain::settings.height << "\n" << 255 << "\n";
// ppm binary pixel data // ppm binary pixel data
for (uint32_t y = 0; y < setter.settings.height; y++) for (uint32_t y = 0; y <PlumageRender::renderMain::settings.height; y++)
{ {
unsigned int* row = (unsigned int*)data; unsigned int* row = (unsigned int*)data;
for (uint32_t x = 0; x < setter.settings.width; x++) for (uint32_t x = 0; x <PlumageRender::renderMain::settings.width; x++)
{ {
if (colorSwizzle) if (colorSwizzle)
{ {
@ -1406,15 +1315,15 @@ void PlumageRender::renderMain::writeImageToFile(std::string filePath)
void PlumageRender::renderMain::outputImageSequence() void PlumageRender::renderMain::outputImageSequence()
{ {
// 比较已保存的帧数和设置里的开始帧数,在生成前清理上一次生成的图片序列 // 比较已保存的帧数和设置里的开始帧数,在生成前清理上一次生成的图片序列
if (savedFrameCounter == setter.settings.startFrameCount) if (savedFrameCounter ==PlumageRender::renderMain::settings.startFrameCount)
{ {
std::cout << "clean up directory for image sequence generation" << std::endl; std::cout << "clean up directory for image sequence generation" << std::endl;
removeImageSequence(); removeImageSequence();
} }
// 根据显卡编号设置输出路径todo提前到配置里 // 根据显卡编号设置输出路径todo提前到配置里
setter.filePath.deviceSpecFilePath = setter.filePath.imageOutputPath + "/device" + std::to_string(selectedPhysicalDeviceIndex); PlumageRender::renderMain::filePath.deviceSpecFilePath =PlumageRender::renderMain::filePath.imageOutputPath + "/device" + std::to_string(selectedPhysicalDeviceIndex);
// 非第一次生成,生成结束的边界条件 // 非第一次生成,生成结束的边界条件
if (savedFrameCounter > setter.settings.endFrameIndex) if (savedFrameCounter >PlumageRender::renderMain::settings.endFrameIndex)
{ {
// 避免重复改变为true带来的无效性能开销 // 避免重复改变为true带来的无效性能开销
if (signal.imageSequenceOutputComplete) if (signal.imageSequenceOutputComplete)
@ -1425,20 +1334,20 @@ void PlumageRender::renderMain::outputImageSequence()
signal.imageSequenceOutputComplete = true; signal.imageSequenceOutputComplete = true;
// 构造ffmpeg脚本需要的路径变量(提前到配置) // 构造ffmpeg脚本需要的路径变量(提前到配置)
std::string fileName = "/%dresult.ppm"; std::string fileName = "/%dresult.ppm";
setter.filePath.totalImageOutputPath = setter.filePath.deviceSpecFilePath + fileName; PlumageRender::Setter::filePath.totalImageOutputPath =PlumageRender::renderMain::filePath.deviceSpecFilePath + fileName;
return; return;
} }
// 路径存在性检查,不存在则创建 // 路径存在性检查,不存在则创建
if (!std::filesystem::exists(setter.filePath.deviceSpecFilePath.c_str())) if (!std::filesystem::exists(PlumageRender::Setter::filePath.deviceSpecFilePath.c_str()))
{ {
std::filesystem::create_directories(setter.filePath.deviceSpecFilePath.c_str()); std::filesystem::create_directories(PlumageRender::Setter::filePath.deviceSpecFilePath.c_str());
} }
// 拼接图片序列编号到路径里 // 拼接图片序列编号到路径里
std::string fileName ="/" + std::to_string(savedFrameCounter) + "result.ppm"; std::string fileName ="/" + std::to_string(savedFrameCounter) + "result.ppm";
setter.filePath.totalImageOutputPath = setter.filePath.deviceSpecFilePath + fileName; PlumageRender::Setter::filePath.totalImageOutputPath =PlumageRender::renderMain::filePath.deviceSpecFilePath + fileName;
//std::cout << outputPath << std::endl; //std::cout << outputPath << std::endl;
// 写入文件 // 写入文件
writeImageToFile(setter.filePath.totalImageOutputPath.c_str()); writeImageToFile(PlumageRender::Setter::filePath.totalImageOutputPath.c_str());
// 写入一帧后已保存帧数+1 // 写入一帧后已保存帧数+1
savedFrameCounter++; savedFrameCounter++;
} }
@ -1456,7 +1365,7 @@ void PlumageRender::renderMain::imageSequenceToVideo()
return; return;
} }
// 拼接视频保存的设备编号路径(提前到配置文件进行) // 拼接视频保存的设备编号路径(提前到配置文件进行)
std::string deviceFilePath = setter.filePath.videoOutputPath + "/device" + std::to_string(selectedPhysicalDeviceIndex); std::string deviceFilePath =PlumageRender::renderMain::filePath.videoOutputPath + "/device" + std::to_string(selectedPhysicalDeviceIndex);
// 判断路径是否存在,不存在则创建 // 判断路径是否存在,不存在则创建
if (std::filesystem::exists(deviceFilePath.c_str())) if (std::filesystem::exists(deviceFilePath.c_str()))
{ {
@ -1465,12 +1374,12 @@ void PlumageRender::renderMain::imageSequenceToVideo()
// 构造结果视频路径 // 构造结果视频路径
std::string resultVideoPath = deviceFilePath + "/result.mp4"; std::string resultVideoPath = deviceFilePath + "/result.mp4";
// 构造脚本需要参数,图片序列路径和设定的帧率 // 构造脚本需要参数,图片序列路径和设定的帧率
std::string commandLineImageSequencePath = setter.filePath.totalImageOutputPath; std::string commandLineImageSequencePath =PlumageRender::renderMain::filePath.totalImageOutputPath;
//std::string commandLineCodecAndResultPath = resultVideoPath; //std::string commandLineCodecAndResultPath = resultVideoPath;
std::string commandLineFrameRate = std::to_string(setter.settings.videoFrameRate); std::string commandLineFrameRate = std::to_string(PlumageRender::renderMain::settings.videoFrameRate);
// 根据不同系统使用不同脚本 // 根据不同系统使用不同脚本
#if defined(_WIN32) #if defined(_WIN32)
std::string commandLine = setter.filePath.image2videoBatFilePath + " " + commandLineFrameRate + " " + commandLineImageSequencePath + " " + resultVideoPath; std::string commandLine =PlumageRender::renderMain::filePath.image2videoBatFilePath + " " + commandLineFrameRate + " " + commandLineImageSequencePath + " " + resultVideoPath;
#else #else
std::string commandLine = filePath.image2videoShFilePath + " " + commandLineFrameRate + " " + commandLineImageSequencePath + " " + resultVideoPath; std::string commandLine = filePath.image2videoShFilePath + " " + commandLineFrameRate + " " + commandLineImageSequencePath + " " + resultVideoPath;
#endif #endif
@ -1486,7 +1395,7 @@ void PlumageRender::renderMain::imageSequenceToVideo()
void PlumageRender::renderMain::removeImageSequence() void PlumageRender::renderMain::removeImageSequence()
{ {
// 函数非第一次运行的边界条件 // 函数非第一次运行的边界条件
if (savedFrameCounter != setter.settings.startFrameCount) if (savedFrameCounter !=PlumageRender::renderMain::settings.startFrameCount)
{ {
// 检查视频输出完成的标志位 // 检查视频输出完成的标志位
if (!signal.imageSequenceToVideoComplete) if (!signal.imageSequenceToVideoComplete)
@ -1496,9 +1405,9 @@ void PlumageRender::renderMain::removeImageSequence()
} }
// 遍历删除图片序列文件和空文件夹 // 遍历删除图片序列文件和空文件夹
if (std::filesystem::exists(setter.filePath.deviceSpecFilePath)) if (std::filesystem::exists(PlumageRender::Setter::filePath.deviceSpecFilePath))
{ {
for (const auto& entry : std::filesystem::directory_iterator(setter.filePath.deviceSpecFilePath)) for (const auto& entry : std::filesystem::directory_iterator(PlumageRender::Setter::filePath.deviceSpecFilePath))
{ {
if (std::filesystem::is_directory(entry.path())) if (std::filesystem::is_directory(entry.path()))
{ {
@ -1509,7 +1418,7 @@ void PlumageRender::renderMain::removeImageSequence()
std::filesystem::remove(entry.path()); std::filesystem::remove(entry.path());
} }
} }
std::filesystem::remove(setter.filePath.deviceSpecFilePath); std::filesystem::remove(PlumageRender::Setter::filePath.deviceSpecFilePath);
std::cout << "clean up complete" << std::endl; std::cout << "clean up complete" << std::endl;
} }
return; return;
@ -1524,7 +1433,7 @@ void PlumageRender::renderMain::render()
return; return;
} }
if (!setter.settings.headless) if (!PlumageRender::Setter::settings.headless)
{ {
updateUIOverlay(); updateUIOverlay();
} }
@ -1587,7 +1496,7 @@ void PlumageRender::renderMain::render()
frameIndex %= renderAhead; frameIndex %= renderAhead;
if (!paused) { if (!paused) {
if (setter.settings.rotateModel) { if (PlumageRender::Setter::settings.rotateModel) {
modelrot.y += frameTimer * 35.0f; modelrot.y += frameTimer * 35.0f;
if (modelrot.y > 360.0f) { if (modelrot.y > 360.0f) {
modelrot.y -= 360.0f; modelrot.y -= 360.0f;
@ -1601,7 +1510,7 @@ void PlumageRender::renderMain::render()
models.scene.updateAnimation(animationIndex, animationTimer); models.scene.updateAnimation(animationIndex, animationTimer);
} }
updateShaderData(); updateShaderData();
if (setter.settings.rotateModel) { if (PlumageRender::Setter::settings.rotateModel) {
updateUniformBuffers(); updateUniformBuffers();
} }
} }
@ -1648,7 +1557,7 @@ PlumageRender* plumageRender;
plumageRender = new PlumageRender(); plumageRender = new PlumageRender();
plumageRender->initVulkan(); plumageRender->initVulkan();
if (!plumageRender->setter.settings.headless) if (!plumageRender->PlumageRender::Setter::settings.headless)
{ {
plumageRender->setupWindow(hInstance, WndProc); plumageRender->setupWindow(hInstance, WndProc);
} }
@ -1664,9 +1573,9 @@ int main()
{ {
PlumageRender::renderMain* plumageRender; PlumageRender::renderMain* plumageRender;
PlumageRender::Setter setter; PlumageRender::Setter setter;
if (!setter.settings.headless) if (!PlumageRender::Setter::settings.headless)
{ {
plumageRender->initWindow(setter.settings.width, setter.settings.height); plumageRender->initWindow(PlumageRender::Setter::settings.width,PlumageRender::renderMain::settings.height);
} }
plumageRender->initVulkan(); plumageRender->initVulkan();

View File

@ -26,6 +26,7 @@
#include <VulkanUtils.hpp> #include <VulkanUtils.hpp>
#include "renderSetter.h" #include "renderSetter.h"
#include "vulkanFoundation.h" #include "vulkanFoundation.h"
#include "camera.hpp"
#define STB_IMAGE_WRITE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h" #include "stb_image_write.h"
@ -40,13 +41,20 @@ namespace PlumageRender
GLFWwindow* window; GLFWwindow* window;
static VulkanBackend::VulkanFoundation vkFoundation;
static PlumageRender::Setter::Settings settings;
static PlumageRender::Setter::FilePath filePath;
static PBR::Material pbrmaterial;
static PlumageRender::RenderInput renderInput;
static PlumageRender::RenderOutput renderOutput;
static Camera camera;
PlumageRender::Setter setter; struct Models
{
bool wireframe = false; glTFModel::Model scene;
bool normalMapping = true; glTFModel::Model skybox;
bool ToneMapping = true; };
bool pbrEnabled = true; static Models models;
struct stat struct stat
{ {
@ -54,28 +62,15 @@ namespace PlumageRender
} info; } info;
glm::vec3 modelrot = glm::vec3(0.0f); glm::vec3 modelrot = glm::vec3(0.0f);
glm::vec3 modelPos = glm::vec3(0.0f); glm::vec3 modelPos = glm::vec3(0.0f);
uint32_t frameIndex = 0; uint32_t frameIndex = 0;
//VkImage swapChainImage; //VkImage swapChainImage;
int32_t animationIndex = 0;
float animationTimer = 0.0f;
bool animate = true;
struct LightSource { struct LightSource {
glm::vec3 color = glm::vec3(1.0f); glm::vec3 color = glm::vec3(1.0f);
@ -108,7 +103,7 @@ namespace PlumageRender
UI* gui; UI* gui;
uint64_t savedFrameCounter = setter.settings.startFrameCount; uint64_t savedFrameCounter = settings.startFrameCount;
bool framebufferResized = false; bool framebufferResized = false;

View File

@ -0,0 +1,21 @@
#include "renderIO.h"
void PlumageRender::RenderInput::loadScene()
{
std::string filename = PlumageRender::renderMain::filePath.glTFModelFilePath;
std::cout << "Loading scene from " << filename << std::endl;
PlumageRender::renderMain::models.scene.destroy(PlumageRender::renderMain::vkFoundation.device);
animationIndex = 0;
animationTimer = 0.0f;
auto tStart = std::chrono::high_resolution_clock::now();
PlumageRender::renderMain::models.scene.loadFromFile(filename, PlumageRender::renderMain::vkFoundation.vulkanDevice, PlumageRender::renderMain::vkFoundation.graphicQueue);
auto tFileLoad = std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - tStart).count();
std::cout << "Loading took " << tFileLoad << " ms" << std::endl;
PlumageRender::renderMain::camera.setPosition({ 0.0f, 0.0f, -1.0f });
PlumageRender::renderMain::camera.setRotation({ 0.0f, 0.0f, 0.0f });
}
void PlumageRender::RenderInput::loadEnvironment(std::string fileName)
{
}

View File

@ -3,6 +3,8 @@
#include <map> #include <map>
#include <string> #include <string>
#include "render.h"
namespace PlumageRender namespace PlumageRender
{ {
class RenderInput class RenderInput
@ -23,8 +25,17 @@ namespace PlumageRender
std::map<std::string, std::string> scenes; std::map<std::string, std::string> scenes;
std::string selectedScene = "DamagedHelmet"; std::string selectedScene = "DamagedHelmet";
void loadScene();
void loadEnvironment(std::string fileName);
private: private:
int32_t animationIndex = 0;
float animationTimer = 0.0f;
}; };
RenderInput::RenderInput() RenderInput::RenderInput()

View File

@ -32,6 +32,7 @@ namespace PlumageRender
bool headless = true; // 无头开关 bool headless = true; // 无头开关
bool outputPNGimage = false; // 输出图片序列格式为PNG四通道 bool outputPNGimage = false; // 输出图片序列格式为PNG四通道
bool enableSaveToImageSequeue = false; // 图片序列开关(暂时弃用) bool enableSaveToImageSequeue = false; // 图片序列开关(暂时弃用)
bool animate = true; // 动画开关
uint32_t MaxFrameInFlight = 2; // 最大并行渲染帧数通常为2此时CPU和GPU并行处理 uint32_t MaxFrameInFlight = 2; // 最大并行渲染帧数通常为2此时CPU和GPU并行处理
uint32_t endFrameIndex = 75; // 图片序列结束帧 uint32_t endFrameIndex = 75; // 图片序列结束帧
bool enableIMGUI = false; // gui使用imgui bool enableIMGUI = false; // gui使用imgui
@ -40,7 +41,8 @@ namespace PlumageRender
uint32_t selectedPhysicalDeviceIndex = 0; uint32_t selectedPhysicalDeviceIndex = 0;
VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_4_BIT; // 多重采样倍率 VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_4_BIT; // 多重采样倍率
} settings; }settings;
struct FilePath struct FilePath
{ {
@ -98,12 +100,15 @@ namespace PlumageRender
std::string image2videoBatFilePath = getAssetPath() + "script/image2video.bat"; std::string image2videoBatFilePath = getAssetPath() + "script/image2video.bat";
std::string image2videoShFilePath = getAssetPath() + "script/image2video.sh"; std::string image2videoShFilePath = getAssetPath() + "script/image2video.sh";
} filePath; }filePath;
private: private:
void getSettingFromCommandLine(); void getSettingFromCommandLine();
}; };
Setter::Setter() Setter::Setter()

View File

@ -7,7 +7,7 @@ void PlumageRender::PlumageGUI::updateUIOverlay()
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
ImVec2 lastDisplaySize = io.DisplaySize; ImVec2 lastDisplaySize = io.DisplaySize;
io.DisplaySize = ImVec2((float)setter.settings.width, (float)setter.settings.height); io.DisplaySize = ImVec2((float)PlumageRender::renderMain::settings.width, (float)PlumageRender::renderMain::settings.height);
io.DeltaTime = frameTimer; io.DeltaTime = frameTimer;
io.MousePos = ImVec2(mousePos.x, mousePos.y); io.MousePos = ImVec2(mousePos.x, mousePos.y);
@ -58,7 +58,7 @@ void PlumageRender::PlumageGUI::updateUIOverlay()
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::string stringFilename = converter.to_bytes(filename); std::string stringFilename = converter.to_bytes(filename);
loadScene(stringFilename); loadScene(stringFilename);
setupDescriptors(); PlumageRender::renderMain::vkFoundation.createDescriptorSets();
updateCBs = true; updateCBs = true;
PlumageRender::RenderInput::signal.imageSequenceOutputComplete = false; PlumageRender::RenderInput::signal.imageSequenceOutputComplete = false;
PlumageRender::RenderInput::signal.imageSequenceToVideoComplete = false; PlumageRender::RenderInput::signal.imageSequenceToVideoComplete = false;
@ -77,7 +77,7 @@ void PlumageRender::PlumageGUI::updateUIOverlay()
setupDescriptors(); setupDescriptors();
updateCBs = true; updateCBs = true;
} }
if (gui->checkbox(chineseUI.environmentBackGround, &setter.settings.displayBackground)) { if (gui->checkbox(chineseUI.environmentBackGround, &PlumageRender::Setter::settings.displayBackground)) {
updateShaderParams = true; updateShaderParams = true;
} }
if (gui->slider("Exposure", &VulkanBackend::VulkanFoundation::shaderData.exposure, 0.1f, 10.0f)) { if (gui->slider("Exposure", &VulkanBackend::VulkanFoundation::shaderData.exposure, 0.1f, 10.0f)) {

View File

@ -3,10 +3,10 @@
#include "ui.hpp" #include "ui.hpp"
#include "VulkanDevice.hpp" #include "VulkanDevice.hpp"
#include "vulkanFoundation.h"
#include "renderSetter.h" #include "renderSetter.h"
#include "renderIO.h" #include "renderIO.h"
#include "render.h"
namespace PlumageRender namespace PlumageRender
{ {
class PlumageGUI class PlumageGUI

View File

@ -65,7 +65,7 @@ void VulkanBackend::VulkanFoundation::initVulkan()
void VulkanBackend::VulkanFoundation::createInstance() void VulkanBackend::VulkanFoundation::createInstance()
{ {
// check validation layers // check validation layers
if (setter.settings.validation && !checkValidationLayerSupport()) if (PlumageRender::Setter::settings.validation && !checkValidationLayerSupport())
{ {
throw std::runtime_error("validation layers requsted,but not available"); throw std::runtime_error("validation layers requsted,but not available");
} }
@ -92,7 +92,7 @@ void VulkanBackend::VulkanFoundation::createInstance()
// enable validation layer if available in createInfo // enable validation layer if available in createInfo
VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo{}; VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo{};
if (setter.settings.validation) if (PlumageRender::Setter::settings.validation)
{ {
createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size()); createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
createInfo.ppEnabledLayerNames = validationLayers.data(); createInfo.ppEnabledLayerNames = validationLayers.data();
@ -143,7 +143,7 @@ bool VulkanBackend::VulkanFoundation::checkValidationLayerSupport()
std::vector<const char*> VulkanBackend::VulkanFoundation::getRequiredExtensions() std::vector<const char*> VulkanBackend::VulkanFoundation::getRequiredExtensions()
{ {
std::vector<const char*> extensions; std::vector<const char*> extensions;
if (!setter.settings.headless) if (!PlumageRender::Setter::settings.headless)
{ {
uint32_t glfwExtensionCount = 0; uint32_t glfwExtensionCount = 0;
const char** glfwExtensions; const char** glfwExtensions;
@ -152,7 +152,7 @@ std::vector<const char*> VulkanBackend::VulkanFoundation::getRequiredExtensions(
std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount); std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);
} }
if (setter.settings.validation) if (PlumageRender::Setter::settings.validation)
{ {
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
@ -165,7 +165,7 @@ std::vector<const char*> VulkanBackend::VulkanFoundation::getRequiredExtensions(
void VulkanBackend::VulkanFoundation::setupDebugMessager() void VulkanBackend::VulkanFoundation::setupDebugMessager()
{ {
if (!setter.settings.validation) if (!PlumageRender::Setter::settings.validation)
{ {
return; return;
} }
@ -222,7 +222,7 @@ VkResult VulkanBackend::VulkanFoundation::CreateDebugUtilsMessengerEXT(VkInstanc
void VulkanBackend::VulkanFoundation::createSurface() void VulkanBackend::VulkanFoundation::createSurface()
{ {
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
return; return;
} }
@ -247,9 +247,9 @@ void VulkanBackend::VulkanFoundation::pickPhysicalDevice()
} }
std::vector<VkPhysicalDevice> devices(deviceCount); std::vector<VkPhysicalDevice> devices(deviceCount);
vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data()); vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());
if (setter.settings.selectedPhysicalDeviceIndex != NULL) if (PlumageRender::Setter::settings.selectedPhysicalDeviceIndex != NULL)
{ {
physicalDevice = devices[setter.settings.selectedPhysicalDeviceIndex]; physicalDevice = devices[PlumageRender::Setter::settings.selectedPhysicalDeviceIndex];
} }
for (const auto& device : devices) for (const auto& device : devices)
@ -269,7 +269,7 @@ void VulkanBackend::VulkanFoundation::pickPhysicalDevice()
bool VulkanBackend::VulkanFoundation::isDeviceSuitable(VkPhysicalDevice device) bool VulkanBackend::VulkanFoundation::isDeviceSuitable(VkPhysicalDevice device)
{ {
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
bool extensionsSupported = checkDeviceExtensionSupport(device); bool extensionsSupported = checkDeviceExtensionSupport(device);
return extensionsSupported; return extensionsSupported;
@ -320,7 +320,7 @@ VulkanBackend::VulkanFoundation::QueueFamilyIndices VulkanBackend::VulkanFoundat
// 检查显示队列支持 // 检查显示队列支持
int i = 0; int i = 0;
if (!setter.settings.headless) if (!PlumageRender::Setter::settings.headless)
{ {
vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport); vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport);
} }
@ -331,7 +331,7 @@ VulkanBackend::VulkanFoundation::QueueFamilyIndices VulkanBackend::VulkanFoundat
indices.graphicsFamily = i; indices.graphicsFamily = i;
} }
// 无头下不需要检查present queue // 无头下不需要检查present queue
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
if (indices.isGraphicsFamilyComplete()) if (indices.isGraphicsFamilyComplete())
{ {
@ -390,7 +390,7 @@ void VulkanBackend::VulkanFoundation::createLogicalDevice()
QueueFamilyIndices indices = findQueueFamilies(physicalDevice); QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos; std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
VkDeviceQueueCreateInfo queueCreateInfo{}; VkDeviceQueueCreateInfo queueCreateInfo{};
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
@ -423,7 +423,7 @@ void VulkanBackend::VulkanFoundation::createLogicalDevice()
} }
std::vector<const char*> enabledExtensions{}; std::vector<const char*> enabledExtensions{};
if (!setter.settings.headless) if (!PlumageRender::Setter::settings.headless)
{ {
for (auto swapchainExtension: swapchainExtensions) for (auto swapchainExtension: swapchainExtensions)
{ {
@ -440,7 +440,7 @@ void VulkanBackend::VulkanFoundation::createLogicalDevice()
deviceCreateInfo.ppEnabledExtensionNames = enabledExtensions.data(); deviceCreateInfo.ppEnabledExtensionNames = enabledExtensions.data();
//新版本vulkan已不对实例和设备特定验证层做区分此处保证兼容性 //新版本vulkan已不对实例和设备特定验证层做区分此处保证兼容性
if (setter.settings.validation) if (PlumageRender::Setter::settings.validation)
{ {
deviceCreateInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size()); deviceCreateInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
deviceCreateInfo.ppEnabledLayerNames = validationLayers.data(); deviceCreateInfo.ppEnabledLayerNames = validationLayers.data();
@ -456,7 +456,7 @@ void VulkanBackend::VulkanFoundation::createLogicalDevice()
} }
vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicQueue); vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicQueue);
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue); vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);
} }
@ -468,7 +468,7 @@ void VulkanBackend::VulkanFoundation::createLogicalDevice()
void VulkanBackend::VulkanFoundation::createSwapChain() void VulkanBackend::VulkanFoundation::createSwapChain()
{ {
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
return; return;
} }
@ -561,7 +561,7 @@ VkPresentModeKHR VulkanBackend::VulkanFoundation::chooseSwapPresentMode(const st
// If v-sync is not requested, try to find a mailbox mode // If v-sync is not requested, try to find a mailbox mode
// It's the lowest latency non-tearing present mode available // It's the lowest latency non-tearing present mode available
if (!setter.settings.vsync) if (!PlumageRender::Setter::settings.vsync)
{ {
for (size_t i = 0; i < presentModeCount; i++) for (size_t i = 0; i < presentModeCount; i++)
{ {
@ -607,23 +607,23 @@ void VulkanBackend::VulkanFoundation::createImageView()
{ {
VkFormat colorAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM; VkFormat colorAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
VkFormat depthFormat = findDepthFormat(); VkFormat depthFormat = findDepthFormat();
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
if (setter.settings.multiSampling) if (PlumageRender::Setter::settings.multiSampling)
{ {
VkImageCreateInfo imageCI{}; VkImageCreateInfo imageCI{};
imageCI.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imageCI.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageCI.imageType = VK_IMAGE_TYPE_2D; imageCI.imageType = VK_IMAGE_TYPE_2D;
imageCI.format = colorAttachmentFormat; imageCI.format = colorAttachmentFormat;
imageCI.extent.width = setter.settings.width; imageCI.extent.width = PlumageRender::renderMain::settings.width;
imageCI.extent.height = setter.settings.height; imageCI.extent.height =PlumageRender::renderMain::settings.height;
imageCI.extent.depth = 1; imageCI.extent.depth = 1;
imageCI.mipLevels = 1; imageCI.mipLevels = 1;
imageCI.arrayLayers = 1; imageCI.arrayLayers = 1;
imageCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE; imageCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
imageCI.tiling = VK_IMAGE_TILING_OPTIMAL; imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
imageCI.samples = setter.settings.sampleCount; imageCI.samples =PlumageRender::renderMain::settings.sampleCount;
imageCI.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; imageCI.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
imageCI.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; imageCI.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
@ -660,14 +660,14 @@ void VulkanBackend::VulkanFoundation::createImageView()
// Depth target // Depth target
imageCI.imageType = VK_IMAGE_TYPE_2D; imageCI.imageType = VK_IMAGE_TYPE_2D;
imageCI.format = depthFormat; imageCI.format = depthFormat;
imageCI.extent.width = setter.settings.width; imageCI.extent.width =PlumageRender::renderMain::settings.width;
imageCI.extent.height = setter.settings.height; imageCI.extent.height =PlumageRender::renderMain::settings.height;
imageCI.extent.depth = 1; imageCI.extent.depth = 1;
imageCI.mipLevels = 1; imageCI.mipLevels = 1;
imageCI.arrayLayers = 1; imageCI.arrayLayers = 1;
imageCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE; imageCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
imageCI.tiling = VK_IMAGE_TILING_OPTIMAL; imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
imageCI.samples = setter.settings.sampleCount; imageCI.samples =PlumageRender::renderMain::settings.sampleCount;
imageCI.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; imageCI.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
imageCI.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; imageCI.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
VK_CHECK_RESULT(vkCreateImage(device, &imageCI, nullptr, &multisampleTarget.depthAttachment.image)); VK_CHECK_RESULT(vkCreateImage(device, &imageCI, nullptr, &multisampleTarget.depthAttachment.image));
@ -700,8 +700,8 @@ void VulkanBackend::VulkanFoundation::createImageView()
imageCI.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imageCI.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageCI.imageType = VK_IMAGE_TYPE_2D; imageCI.imageType = VK_IMAGE_TYPE_2D;
imageCI.format = colorAttachmentFormat; imageCI.format = colorAttachmentFormat;
imageCI.extent.width = setter.settings.width; imageCI.extent.width =PlumageRender::renderMain::settings.width;
imageCI.extent.height = setter.settings.height; imageCI.extent.height =PlumageRender::renderMain::settings.height;
imageCI.extent.depth = 1; imageCI.extent.depth = 1;
imageCI.mipLevels = 1; imageCI.mipLevels = 1;
imageCI.arrayLayers = 1; imageCI.arrayLayers = 1;
@ -749,8 +749,8 @@ void VulkanBackend::VulkanFoundation::createImageView()
image.pNext = NULL; image.pNext = NULL;
image.imageType = VK_IMAGE_TYPE_2D; image.imageType = VK_IMAGE_TYPE_2D;
image.format = depthFormat; image.format = depthFormat;
image.extent.width = setter.settings.width; image.extent.width =PlumageRender::renderMain::settings.width;
image.extent.height = setter.settings.height; image.extent.height =PlumageRender::renderMain::settings.height;
image.extent.depth = 1; image.extent.depth = 1;
image.mipLevels = 1; image.mipLevels = 1;
image.arrayLayers = 1; image.arrayLayers = 1;
@ -836,7 +836,7 @@ void VulkanBackend::VulkanFoundation::createRenderPass()
VkFormat colorAttachmentFormat; VkFormat colorAttachmentFormat;
VkFormat depthAttachmentFormat = findDepthFormat(); VkFormat depthAttachmentFormat = findDepthFormat();
VkImageLayout colorAttachmentFinallayout; VkImageLayout colorAttachmentFinallayout;
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
colorAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM; colorAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
colorAttachmentFinallayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; colorAttachmentFinallayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
@ -847,12 +847,12 @@ void VulkanBackend::VulkanFoundation::createRenderPass()
colorAttachmentFinallayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; colorAttachmentFinallayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
} }
if (setter.settings.multiSampling) { if (PlumageRender::Setter::settings.multiSampling) {
std::array<VkAttachmentDescription, 4> attachments = {}; std::array<VkAttachmentDescription, 4> attachments = {};
// Multisampled attachment that we render to // Multisampled attachment that we render to
attachments[0].format = colorAttachmentFormat; attachments[0].format = colorAttachmentFormat;
attachments[0].samples = setter.settings.sampleCount; attachments[0].samples =PlumageRender::renderMain::settings.sampleCount;
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE; attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
@ -873,7 +873,7 @@ void VulkanBackend::VulkanFoundation::createRenderPass()
// Multisampled depth attachment we render to // Multisampled depth attachment we render to
attachments[2].format = depthAttachmentFormat; attachments[2].format = depthAttachmentFormat;
attachments[2].samples = setter.settings.sampleCount; attachments[2].samples =PlumageRender::renderMain::settings.sampleCount;
attachments[2].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; attachments[2].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachments[2].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; attachments[2].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachments[2].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachments[2].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
@ -1136,8 +1136,8 @@ void VulkanBackend::VulkanFoundation::createGraphicPipeline()
VkPipelineMultisampleStateCreateInfo multisampleStateCI{}; VkPipelineMultisampleStateCreateInfo multisampleStateCI{};
multisampleStateCI.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; multisampleStateCI.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
if (setter.settings.multiSampling) { if (PlumageRender::Setter::settings.multiSampling) {
multisampleStateCI.rasterizationSamples = setter.settings.sampleCount; multisampleStateCI.rasterizationSamples =PlumageRender::renderMain::settings.sampleCount;
} }
std::vector<VkDynamicState> dynamicStateEnables = { std::vector<VkDynamicState> dynamicStateEnables = {
@ -1158,7 +1158,7 @@ void VulkanBackend::VulkanFoundation::createGraphicPipeline()
pipelineLayoutCI.setLayoutCount = static_cast<uint32_t>(setLayouts.size()); pipelineLayoutCI.setLayoutCount = static_cast<uint32_t>(setLayouts.size());
pipelineLayoutCI.pSetLayouts = setLayouts.data(); pipelineLayoutCI.pSetLayouts = setLayouts.data();
VkPushConstantRange pushConstantRange{}; VkPushConstantRange pushConstantRange{};
pushConstantRange.size = sizeof(pbrMaterial.pushConstBlockMaterial); pushConstantRange.size = sizeof(PlumageRender::renderMain::pbrmaterial.pushConstBlockMaterial);
pushConstantRange.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; pushConstantRange.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
pipelineLayoutCI.pushConstantRangeCount = 1; pipelineLayoutCI.pushConstantRangeCount = 1;
pipelineLayoutCI.pPushConstantRanges = &pushConstantRange; pipelineLayoutCI.pPushConstantRanges = &pushConstantRange;
@ -1200,14 +1200,14 @@ void VulkanBackend::VulkanFoundation::createGraphicPipeline()
pipelineCI.stageCount = static_cast<uint32_t>(shaderStages.size()); pipelineCI.stageCount = static_cast<uint32_t>(shaderStages.size());
pipelineCI.pStages = shaderStages.data(); pipelineCI.pStages = shaderStages.data();
if (setter.settings.multiSampling) { if (PlumageRender::Setter::settings.multiSampling) {
multisampleStateCI.rasterizationSamples = setter.settings.sampleCount; multisampleStateCI.rasterizationSamples =PlumageRender::renderMain::settings.sampleCount;
} }
// Skybox pipeline (background cube) // Skybox pipeline (background cube)
shaderStages = { shaderStages = {
loadShader(device,setter.filePath.skyboxVertShaderPath, VK_SHADER_STAGE_VERTEX_BIT), loadShader(device,PlumageRender::Setter::filePath.skyboxVertShaderPath, VK_SHADER_STAGE_VERTEX_BIT),
loadShader(device,setter.filePath.skyboxFragShaderPath, VK_SHADER_STAGE_FRAGMENT_BIT) loadShader(device,PlumageRender::Setter::filePath.skyboxFragShaderPath, VK_SHADER_STAGE_FRAGMENT_BIT)
}; };
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.skybox)); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.skybox));
for (auto shaderStage : shaderStages) { for (auto shaderStage : shaderStages) {
@ -1216,8 +1216,8 @@ void VulkanBackend::VulkanFoundation::createGraphicPipeline()
// PBR pipeline // PBR pipeline
shaderStages = { shaderStages = {
loadShader(device,setter.filePath.pbrVertShaderPath, VK_SHADER_STAGE_VERTEX_BIT), loadShader(device,PlumageRender::Setter::filePath.pbrVertShaderPath, VK_SHADER_STAGE_VERTEX_BIT),
loadShader(device,setter.filePath.pbrFragShaderPath, VK_SHADER_STAGE_FRAGMENT_BIT) loadShader(device,PlumageRender::Setter::filePath.pbrFragShaderPath, VK_SHADER_STAGE_FRAGMENT_BIT)
}; };
depthStencilStateCI.depthWriteEnable = VK_TRUE; depthStencilStateCI.depthWriteEnable = VK_TRUE;
depthStencilStateCI.depthTestEnable = VK_TRUE; depthStencilStateCI.depthTestEnable = VK_TRUE;
@ -1248,9 +1248,9 @@ void VulkanBackend::VulkanFoundation::createGraphicPipeline()
void VulkanBackend::VulkanFoundation::createFramebuffer() void VulkanBackend::VulkanFoundation::createFramebuffer()
{ {
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
if (setter.settings.multiSampling) if (PlumageRender::Setter::settings.multiSampling)
{ {
for (int i = 0; i < frameRange; i++) for (int i = 0; i < frameRange; i++)
{ {
@ -1264,8 +1264,8 @@ void VulkanBackend::VulkanFoundation::createFramebuffer()
framebufferCreateInfo.renderPass = renderPass; framebufferCreateInfo.renderPass = renderPass;
framebufferCreateInfo.attachmentCount = 4; framebufferCreateInfo.attachmentCount = 4;
framebufferCreateInfo.pAttachments = attachments; framebufferCreateInfo.pAttachments = attachments;
framebufferCreateInfo.width = setter.settings.width; framebufferCreateInfo.width =PlumageRender::renderMain::settings.width;
framebufferCreateInfo.height = setter.settings.height; framebufferCreateInfo.height =PlumageRender::renderMain::settings.height;
framebufferCreateInfo.layers = 1; framebufferCreateInfo.layers = 1;
VK_CHECK_RESULT(vkCreateFramebuffer(device, &framebufferCreateInfo, nullptr, &framebuffers[i])); VK_CHECK_RESULT(vkCreateFramebuffer(device, &framebufferCreateInfo, nullptr, &framebuffers[i]));
@ -1284,8 +1284,8 @@ void VulkanBackend::VulkanFoundation::createFramebuffer()
framebufferCreateInfo.renderPass = renderPass; framebufferCreateInfo.renderPass = renderPass;
framebufferCreateInfo.attachmentCount = 2; framebufferCreateInfo.attachmentCount = 2;
framebufferCreateInfo.pAttachments = attachments; framebufferCreateInfo.pAttachments = attachments;
framebufferCreateInfo.width = setter.settings.width; framebufferCreateInfo.width =PlumageRender::renderMain::settings.width;
framebufferCreateInfo.height = setter.settings.height; framebufferCreateInfo.height =PlumageRender::renderMain::settings.height;
framebufferCreateInfo.layers = 1; framebufferCreateInfo.layers = 1;
VK_CHECK_RESULT(vkCreateFramebuffer(device, &framebufferCreateInfo, nullptr, &framebuffers[i])); VK_CHECK_RESULT(vkCreateFramebuffer(device, &framebufferCreateInfo, nullptr, &framebuffers[i]));
@ -1305,7 +1305,7 @@ void VulkanBackend::VulkanFoundation::createSwapChainFramebuffer()
uint32_t attachmentCount; uint32_t attachmentCount;
VkImageView attachments[attachmentCount]; VkImageView attachments[attachmentCount];
if (setter.settings.multiSampling) { if (PlumageRender::Setter::settings.multiSampling) {
attachmentCount = 4; attachmentCount = 4;
attachments[0] = multisampleTarget.colorAttachment.view; attachments[0] = multisampleTarget.colorAttachment.view;
attachments[1] = multisampleTarget.depthAttachment.view; attachments[1] = multisampleTarget.depthAttachment.view;
@ -1323,8 +1323,8 @@ void VulkanBackend::VulkanFoundation::createSwapChainFramebuffer()
frameBufferCI.renderPass = renderPass; frameBufferCI.renderPass = renderPass;
frameBufferCI.attachmentCount = attachmentCount; frameBufferCI.attachmentCount = attachmentCount;
frameBufferCI.pAttachments = attachments; frameBufferCI.pAttachments = attachments;
frameBufferCI.width = setter.settings.width; frameBufferCI.width =PlumageRender::renderMain::settings.width;
frameBufferCI.height = setter.settings.height; frameBufferCI.height =PlumageRender::renderMain::settings.height;
frameBufferCI.layers = 1; frameBufferCI.layers = 1;
@ -1332,7 +1332,7 @@ void VulkanBackend::VulkanFoundation::createSwapChainFramebuffer()
// Create frame buffers for every swap chain image // Create frame buffers for every swap chain image
framebuffers.resize(swapChainImageViews.size()); framebuffers.resize(swapChainImageViews.size());
for (uint32_t i = 0; i < swapChainImageViews.size(); i++) { for (uint32_t i = 0; i < swapChainImageViews.size(); i++) {
if (setter.settings.multiSampling) { if (PlumageRender::Setter::settings.multiSampling) {
attachments[3] = swapChainImageViews[i]; attachments[3] = swapChainImageViews[i];
} }
else { else {
@ -1365,7 +1365,7 @@ void VulkanBackend::VulkanFoundation::createCommandPool()
void VulkanBackend::VulkanFoundation::createUniformBuffer() void VulkanBackend::VulkanFoundation::createUniformBuffer()
{ {
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
uniformBuffers.resize(frameRange); uniformBuffers.resize(frameRange);
} }
@ -1389,9 +1389,9 @@ void VulkanBackend::VulkanFoundation::updateUniformBuffers()
shaderDataScene.view = camera.matrices.view; shaderDataScene.view = camera.matrices.view;
// Center and scale model // Center and scale model
float scale = (1.0f / std::max(models.scene.aabb[0][0], std::max(models.scene.aabb[1][1], models.scene.aabb[2][2]))) * 0.5f; float scale = (1.0f / std::max(PlumageRender::renderMain::models.scene.aabb[0][0], std::max(PlumageRender::renderMain::models.scene.aabb[1][1], PlumageRender::renderMain::models.scene.aabb[2][2]))) * 0.5f;
glm::vec3 translate = -glm::vec3(models.scene.aabb[3][0], models.scene.aabb[3][1], models.scene.aabb[3][2]); glm::vec3 translate = -glm::vec3(PlumageRender::renderMain::models.scene.aabb[3][0], PlumageRender::renderMain::models.scene.aabb[3][1], PlumageRender::renderMain::models.scene.aabb[3][2]);
translate += -0.5f * glm::vec3(models.scene.aabb[0][0], models.scene.aabb[1][1], models.scene.aabb[2][2]); translate += -0.5f * glm::vec3(PlumageRender::renderMain::models.scene.aabb[0][0], PlumageRender::renderMain::models.scene.aabb[1][1], PlumageRender::renderMain::models.scene.aabb[2][2]);
shaderDataScene.model = glm::mat4(1.0f); shaderDataScene.model = glm::mat4(1.0f);
shaderDataScene.model[0][0] = scale; shaderDataScene.model[0][0] = scale;
@ -1423,7 +1423,7 @@ void VulkanBackend::VulkanFoundation::createDescriptorPool()
// Environment samplers (radiance, irradiance, brdflut) // Environment samplers (radiance, irradiance, brdflut)
imageSamplerCount += 3; imageSamplerCount += 3;
std::vector<glTFModel::Model*> modellist = { &models.skybox, &models.scene }; std::vector<glTFModel::Model*> modellist = { &PlumageRender::renderMain::models.skybox, &PlumageRender::renderMain::models.scene };
for (auto& model : modellist) { for (auto& model : modellist) {
for (auto& material : model->materials) { for (auto& material : model->materials) {
imageSamplerCount += 5; imageSamplerCount += 5;
@ -1450,7 +1450,7 @@ void VulkanBackend::VulkanFoundation::createDescriptorPool()
void VulkanBackend::VulkanFoundation::createDescriptorSets() void VulkanBackend::VulkanFoundation::createDescriptorSets()
{ {
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
descriptorSets.resize(frameRange); descriptorSets.resize(frameRange);
} }
@ -1500,21 +1500,21 @@ void VulkanBackend::VulkanFoundation::createSceneDescriptorSets()
writeDescriptorSets[2].descriptorCount = 1; writeDescriptorSets[2].descriptorCount = 1;
writeDescriptorSets[2].dstSet = descriptorSets[i].scene; writeDescriptorSets[2].dstSet = descriptorSets[i].scene;
writeDescriptorSets[2].dstBinding = 2; writeDescriptorSets[2].dstBinding = 2;
writeDescriptorSets[2].pImageInfo = &pbrMaterial.textures.irradianceCube.descriptor; writeDescriptorSets[2].pImageInfo = &PlumageRender::renderMain::pbrmaterial.textures.irradianceCube.descriptor;
writeDescriptorSets[3].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writeDescriptorSets[3].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSets[3].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; writeDescriptorSets[3].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
writeDescriptorSets[3].descriptorCount = 1; writeDescriptorSets[3].descriptorCount = 1;
writeDescriptorSets[3].dstSet = descriptorSets[i].scene; writeDescriptorSets[3].dstSet = descriptorSets[i].scene;
writeDescriptorSets[3].dstBinding = 3; writeDescriptorSets[3].dstBinding = 3;
writeDescriptorSets[3].pImageInfo = &pbrMaterial.textures.prefilteredCube.descriptor; writeDescriptorSets[3].pImageInfo = &PlumageRender::renderMain::pbrmaterial.textures.prefilteredCube.descriptor;
writeDescriptorSets[4].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writeDescriptorSets[4].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSets[4].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; writeDescriptorSets[4].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
writeDescriptorSets[4].descriptorCount = 1; writeDescriptorSets[4].descriptorCount = 1;
writeDescriptorSets[4].dstSet = descriptorSets[i].scene; writeDescriptorSets[4].dstSet = descriptorSets[i].scene;
writeDescriptorSets[4].dstBinding = 4; writeDescriptorSets[4].dstBinding = 4;
writeDescriptorSets[4].pImageInfo = &pbrMaterial.textures.lutBrdf.descriptor; writeDescriptorSets[4].pImageInfo = &PlumageRender::renderMain::pbrmaterial.textures.lutBrdf.descriptor;
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
@ -1525,7 +1525,7 @@ void VulkanBackend::VulkanFoundation::createSceneDescriptorSets()
void VulkanBackend::VulkanFoundation::createMaterialDescriptorSets() void VulkanBackend::VulkanFoundation::createMaterialDescriptorSets()
{ {
for (auto& material : models.scene.materials) for (auto& material : PlumageRender::renderMain::models.scene.materials)
{ {
VkDescriptorSetAllocateInfo descriptorSetAllocInfo{}; VkDescriptorSetAllocateInfo descriptorSetAllocInfo{};
descriptorSetAllocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; descriptorSetAllocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@ -1536,11 +1536,11 @@ void VulkanBackend::VulkanFoundation::createMaterialDescriptorSets()
std::vector<VkDescriptorImageInfo> imageDescriptors = std::vector<VkDescriptorImageInfo> imageDescriptors =
{ {
pbrMaterial.textures.empty.descriptor, PlumageRender::renderMain::pbrmaterial.textures.empty.descriptor,
pbrMaterial.textures.empty.descriptor, PlumageRender::renderMain::pbrmaterial.textures.empty.descriptor,
material.normalTexture ? material.normalTexture->descriptor : pbrMaterial.textures.empty.descriptor, material.normalTexture ? material.normalTexture->descriptor : PlumageRender::renderMain::pbrmaterial.textures.empty.descriptor,
material.occlusionTexture ? material.occlusionTexture->descriptor : pbrMaterial.textures.empty.descriptor, material.occlusionTexture ? material.occlusionTexture->descriptor : PlumageRender::renderMain::pbrmaterial.textures.empty.descriptor,
material.emissiveTexture ? material.emissiveTexture->descriptor : pbrMaterial.textures.empty.descriptor material.emissiveTexture ? material.emissiveTexture->descriptor : PlumageRender::renderMain::pbrmaterial.textures.empty.descriptor
}; };
if (material.pbrWorkflows.metallicRoughness) if (material.pbrWorkflows.metallicRoughness)
@ -1585,7 +1585,7 @@ void VulkanBackend::VulkanFoundation::createModelNodeDescriptorSets()
{ {
// Per-Node descriptor set // Per-Node descriptor set
for (auto& node : models.scene.nodes) for (auto& node : PlumageRender::renderMain::models.scene.nodes)
{ {
setupglTFNodeDescriptorSet(node); setupglTFNodeDescriptorSet(node);
} }
@ -1651,7 +1651,7 @@ void VulkanBackend::VulkanFoundation::createSkyboxDescriptorSets()
writeDescriptorSets[2].descriptorCount = 1; writeDescriptorSets[2].descriptorCount = 1;
writeDescriptorSets[2].dstSet = descriptorSets[i].skybox; writeDescriptorSets[2].dstSet = descriptorSets[i].skybox;
writeDescriptorSets[2].dstBinding = 2; writeDescriptorSets[2].dstBinding = 2;
writeDescriptorSets[2].pImageInfo = &pbrMaterial.textures.prefilteredCube.descriptor; writeDescriptorSets[2].pImageInfo = &PlumageRender::renderMain::pbrmaterial.textures.prefilteredCube.descriptor;
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr); vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr);
} }
@ -1662,7 +1662,7 @@ void VulkanBackend::VulkanFoundation::createSkyboxDescriptorSets()
void VulkanBackend::VulkanFoundation::allocateCommandBuffers() void VulkanBackend::VulkanFoundation::allocateCommandBuffers()
{ {
// resize // resize
if (setter.settings.headless) if (PlumageRender::Setter::settings.headless)
{ {
commandbuffers.resize(frameRange); commandbuffers.resize(frameRange);
} }
@ -1686,7 +1686,7 @@ void VulkanBackend::VulkanFoundation::createCommandBuffer()
cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
VkClearValue clearValues[3]; VkClearValue clearValues[3];
if (setter.settings.multiSampling) { if (PlumageRender::Setter::settings.multiSampling) {
clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 1.0f } }; clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 1.0f } };
clearValues[1].color = { { 0.0f, 0.0f, 0.0f, 1.0f } }; clearValues[1].color = { { 0.0f, 0.0f, 0.0f, 1.0f } };
clearValues[2].depthStencil = { 1.0f, 0 }; clearValues[2].depthStencil = { 1.0f, 0 };
@ -1701,9 +1701,9 @@ void VulkanBackend::VulkanFoundation::createCommandBuffer()
renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.renderPass = renderPass;
renderPassBeginInfo.renderArea.offset.x = 0; renderPassBeginInfo.renderArea.offset.x = 0;
renderPassBeginInfo.renderArea.offset.y = 0; renderPassBeginInfo.renderArea.offset.y = 0;
renderPassBeginInfo.renderArea.extent.width = setter.settings.width; renderPassBeginInfo.renderArea.extent.width =PlumageRender::renderMain::settings.width;
renderPassBeginInfo.renderArea.extent.height = setter.settings.height; renderPassBeginInfo.renderArea.extent.height =PlumageRender::renderMain::settings.height;
renderPassBeginInfo.clearValueCount = setter.settings.multiSampling ? 3 : 2; renderPassBeginInfo.clearValueCount =PlumageRender::renderMain::settings.multiSampling ? 3 : 2;
renderPassBeginInfo.pClearValues = clearValues; renderPassBeginInfo.pClearValues = clearValues;
for (uint32_t i = 0; i < commandbuffers.size(); ++i) for (uint32_t i = 0; i < commandbuffers.size(); ++i)
@ -1716,25 +1716,25 @@ void VulkanBackend::VulkanFoundation::createCommandBuffer()
vkCmdBeginRenderPass(currentCB, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); vkCmdBeginRenderPass(currentCB, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
VkViewport viewport{}; VkViewport viewport{};
viewport.width = (float)setter.settings.width; viewport.width = (float)PlumageRender::Setter::settings.width;
viewport.height = (float)setter.settings.height; viewport.height = (float)PlumageRender::Setter::settings.height;
viewport.minDepth = 0.0f; viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f; viewport.maxDepth = 1.0f;
vkCmdSetViewport(currentCB, 0, 1, &viewport); vkCmdSetViewport(currentCB, 0, 1, &viewport);
VkRect2D scissor{}; VkRect2D scissor{};
scissor.extent = { setter.settings.width, setter.settings.height }; scissor.extent = {PlumageRender::renderMain::settings.width,PlumageRender::renderMain::settings.height };
vkCmdSetScissor(currentCB, 0, 1, &scissor); vkCmdSetScissor(currentCB, 0, 1, &scissor);
VkDeviceSize offsets[1] = { 0 }; VkDeviceSize offsets[1] = { 0 };
if (setter.settings.displayBackground) { if (PlumageRender::Setter::settings.displayBackground) {
vkCmdBindDescriptorSets(currentCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets[i].skybox, 0, nullptr); vkCmdBindDescriptorSets(currentCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets[i].skybox, 0, nullptr);
vkCmdBindPipeline(currentCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.skybox); vkCmdBindPipeline(currentCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.skybox);
models.skybox.draw(currentCB); PlumageRender::renderMain::models.skybox.draw(currentCB);
} }
glTFModel::Model& model = models.scene; glTFModel::Model& model = PlumageRender::renderMain::models.scene;
vkCmdBindVertexBuffers(currentCB, 0, 1, &model.vertices.buffer, offsets); vkCmdBindVertexBuffers(currentCB, 0, 1, &model.vertices.buffer, offsets);
if (model.indices.buffer != VK_NULL_HANDLE) { if (model.indices.buffer != VK_NULL_HANDLE) {
@ -1758,7 +1758,7 @@ void VulkanBackend::VulkanFoundation::createCommandBuffer()
} }
// User interface // User interface
if (!setter.settings.headless) if (!PlumageRender::Setter::settings.headless)
{ {
gui->draw(currentCB); gui->draw(currentCB);
} }
@ -1850,16 +1850,16 @@ void VulkanBackend::VulkanFoundation::createglTFNodeCommandBuffer(glTFModel::Nod
void VulkanBackend::VulkanFoundation::createFenceAndSemaphore() void VulkanBackend::VulkanFoundation::createFenceAndSemaphore()
{ {
waitFences.resize(setter.settings.MaxFrameInFlight); waitFences.resize(PlumageRender::Setter::settings.MaxFrameInFlight);
presentCompleteSemaphores.resize(setter.settings.MaxFrameInFlight); presentCompleteSemaphores.resize(PlumageRender::Setter::settings.MaxFrameInFlight);
renderCompleteSemaphores.resize(setter.settings.MaxFrameInFlight); renderCompleteSemaphores.resize(PlumageRender::Setter::settings.MaxFrameInFlight);
// Command buffer execution fences // Command buffer execution fences
for (auto& waitFence : waitFences) { for (auto& waitFence : waitFences) {
VkFenceCreateInfo fenceCI{ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT }; VkFenceCreateInfo fenceCI{ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
VK_CHECK_RESULT(vkCreateFence(device, &fenceCI, nullptr, &waitFence)); VK_CHECK_RESULT(vkCreateFence(device, &fenceCI, nullptr, &waitFence));
} }
if (!setter.settings.headless) if (!PlumageRender::Setter::settings.headless)
{ {
for (auto& semaphore : presentCompleteSemaphores) { for (auto& semaphore : presentCompleteSemaphores) {
VkSemaphoreCreateInfo semaphoreCI{ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; VkSemaphoreCreateInfo semaphoreCI{ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };

View File

@ -36,9 +36,12 @@ namespace VulkanBackend
const int MAX_FRAME_IN_FLIGHT = 2; const int MAX_FRAME_IN_FLIGHT = 2;
const int frameRange = setter.settings.endFrameIndex - setter.settings.startFrameCount; const int frameRange =PlumageRender::renderMain::settings.endFrameIndex -PlumageRender::renderMain::settings.startFrameCount;
static VkDevice device; static VkDevice device;
static vks::VulkanDevice* vulkanDevice;
static VkQueue graphicQueue;
struct ShaderData { struct ShaderData {
glm::vec4 lightDir; glm::vec4 lightDir;
@ -54,13 +57,14 @@ namespace VulkanBackend
void initVulkan(); void initVulkan();
// 创建描述符集合
void createDescriptorSets();
private: private:
PlumageRender::Setter setter;
PBR::Material pbrMaterial;
vks::VulkanDevice* vulkanDevice;
VkInstance instance; VkInstance instance;
@ -95,7 +99,7 @@ namespace VulkanBackend
VkSurfaceKHR surface; VkSurfaceKHR surface;
VkPhysicalDeviceFeatures deviceFeatures; VkPhysicalDeviceFeatures deviceFeatures;
VkQueue graphicQueue;
VkQueue presentQueue; VkQueue presentQueue;
@ -134,11 +138,7 @@ namespace VulkanBackend
FrameBufferAttachment depthAttachment; FrameBufferAttachment depthAttachment;
} multisampleTarget; } multisampleTarget;
struct Models
{
glTFModel::Model scene;
glTFModel::Model skybox;
} models;
struct DescriptorSetLayouts { struct DescriptorSetLayouts {
VkDescriptorSetLayout scene; VkDescriptorSetLayout scene;
@ -267,8 +267,7 @@ namespace VulkanBackend
// 创建描述符池 // 创建描述符池
void createDescriptorPool(); void createDescriptorPool();
// 创建描述符集合
void createDescriptorSets();
void createSceneDescriptorSets(); void createSceneDescriptorSets();
void createMaterialDescriptorSets(); void createMaterialDescriptorSets();