Fixing pipeline cache again to fix environment mapping

This commit is contained in:
2025-07-12 16:25:49 +02:00
parent d81ea5f8e5
commit 3cc1a67664
4 changed files with 36 additions and 12 deletions
+4 -6
View File
@@ -345,11 +345,9 @@ struct CookTorrance : IBRDF
float3 k_s = F;
float3 k_d = 1 - k_s;
k_d *= 1 - metallic;
float3 diffuse = baseColor;
float3 specular = 0;
#ifdef IMAGE_BASED_LIGHTING
float3 irradiance = pLightEnv.irradianceMap.SampleLevel(pLightEnv.irradianceSampler, normal, 4).rgb;
diffuse *= irradiance;
float3 diffuse = irradiance * baseColor;
float3 r = reflect(-viewDir_WS, normal);
@@ -357,8 +355,8 @@ struct CookTorrance : IBRDF
float3 prefilteredColor = pLightEnv.prefilteredMap.SampleLevel(pLightEnv.irradianceSampler, r, roughness * MAX_REFLECTION_LOD).xyz;
float2 envBRDF = pLightEnv.brdfLUT.Sample(pLightEnv.lutSampler, float2(max(dot(normal, viewDir_WS), 0), roughness)).rg;
specular = prefilteredColor * (F * envBRDF.x + envBRDF.y);
#endif
float3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y);
return (k_d * diffuse + specular) * ambientOcclusion;
}
float getAlpha()
+23 -4
View File
@@ -105,6 +105,7 @@ EnvironmentLoader::EnvironmentLoader(Gfx::PGraphics graphics) : graphics(graphic
lutVert = graphics->createVertexShader({4});
lutFrag = graphics->createFragmentShader({5});
Gfx::OPipelineLayout emptyLayout = graphics->createPipelineLayout("LUTlayout");
emptyLayout->create();
{
graphics->beginDebugRegion("PrecomputeBRDF");
lutTexture = graphics->createTexture2D(TextureCreateInfo{
@@ -247,7 +248,7 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
.size = {SOURCE_RESOLUTION, SOURCE_RESOLUTION},
.offset = {0, 0},
},
"EnvironmentRenderPass");
"CubemapGeneration");
Gfx::PGraphicsPipeline cubeRenderPipeline = graphics->createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo{
.vertexShader = cubeRenderVertex,
.fragmentShader = cubeRenderFrag,
@@ -299,12 +300,21 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
convolutedViews[i], Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE)},
},
{},
{
Gfx::SubPassDependency{
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_SHADER_READ_BIT,
},
},
{
.size = {CONVOLUTED_RESOLUTION, CONVOLUTED_RESOLUTION},
.offset = {0, 0},
},
"EnvironmentRenderPass");
"ConvolutionRenderPass");
Gfx::PGraphicsPipeline convolutionPipeline = graphics->createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo{
.vertexShader = cubeRenderVertex,
.fragmentShader = convolutionFrag,
@@ -352,7 +362,16 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
views[i], Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE)},
},
{},
{
Gfx::SubPassDependency{
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_SHADER_READ_BIT,
},
},
{
.size = {prefilterViewports[mip]->getWidth(), prefilterViewports[mip]->getHeight()},
.offset = {0, 0},
+1 -1
View File
@@ -127,7 +127,7 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
createInfo.defines["VISIBILITY"] = "1";
}
if (permutation.imageBasedLighting) {
createInfo.defines["IMAGE_BASE_LIGHTING"] = "1";
createInfo.defines["IMAGE_BASED_LIGHTING"] = "1";
}
if (permutation.dumpIntermediates) {
createInfo.dumpIntermediate = true;
+8 -1
View File
@@ -108,7 +108,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
.pSpecializationInfo = nullptr,
};
}
hash = CRC::Calculate(stageInfos.data(), stageInfos.size() * sizeof(VkVertexInputAttributeDescription), CRC::CRC_32(), hash);
hash = CRC::Calculate(stageInfos.data(), stageInfos.size() * sizeof(VkPipelineShaderStageCreateInfo), CRC::CRC_32(), hash);
VkPipelineInputAssemblyStateCreateInfo assemblyInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
@@ -144,6 +144,8 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
.depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor,
.lineWidth = gfxInfo.rasterizationState.lineWidth,
};
hash = CRC::Calculate(&rasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo), CRC::CRC_32(), hash);
VkPipelineMultisampleStateCreateInfo multisampleState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
.pNext = nullptr,
@@ -154,6 +156,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
.alphaToCoverageEnable = gfxInfo.multisampleState.alphaCoverageEnable,
.alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable,
};
hash = CRC::Calculate(&multisampleState, sizeof(VkPipelineMultisampleStateCreateInfo), CRC::CRC_32(), hash);
VkPipelineDepthStencilStateCreateInfo depthStencilState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
.pNext = nullptr,
@@ -167,6 +170,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
.minDepthBounds = gfxInfo.depthStencilState.minDepthBounds,
.maxDepthBounds = gfxInfo.depthStencilState.maxDepthBounds,
};
hash = CRC::Calculate(&multisampleState, sizeof(VkPipelineMultisampleStateCreateInfo), CRC::CRC_32(), hash);
Array<VkPipelineColorBlendAttachmentState> blendAttachments;
for (uint32 i = 0; i < gfxInfo.colorBlend.attachmentCount; ++i) {
const Gfx::ColorBlendState::BlendAttachment& attachment = gfxInfo.colorBlend.blendAttachments[i];
@@ -181,6 +185,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
.colorWriteMask = attachment.colorWriteMask,
};
}
hash = CRC::Calculate(blendAttachments.data(), blendAttachments.size() * sizeof(VkPipelineColorBlendAttachmentState), CRC::CRC_32(), hash);
VkPipelineColorBlendStateCreateInfo blendState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
.pNext = nullptr,
@@ -196,10 +201,12 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
StaticArray<VkDynamicState, 2> dynamicEnabled;
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_VIEWPORT;
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR;
hash = CRC::Calculate(dynamicEnabled.data(), dynamicEnabled.size() * sizeof(VkDynamicState), CRC::CRC_32(), hash);
if (graphicsPipelines.contains(hash)) {
return graphicsPipelines[hash];
}
VkPipelineDynamicStateCreateInfo dynamicState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
.pNext = nullptr,