From cdff0843a86a58e3bc4ac8688ed4ba30e44fc320 Mon Sep 17 00:00:00 2001 From: Gustav Sterbrant Date: Sun, 16 Jul 2023 00:36:11 +0100 Subject: [PATCH] Fix validation issues (#156) * Add new barrier constructors for blocking all mips and layers of texture (most common usage) * Use new barrier to fix validation issues now and in the future. --- .../staticui/ultralight/ultralightrenderer.cc | 4 +- code/render/coregraphics/barrier.h | 27 ++++++++--- code/render/coregraphics/texture.cc | 4 +- code/render/fog/volumetricfogcontext.cc | 12 ++--- code/render/frame/framescriptloader.cc | 46 +++++-------------- code/render/lighting/lightcontext.cc | 8 ++-- code/render/posteffects/bloomcontext.cc | 4 +- .../render/posteffects/downsamplingcontext.cc | 4 +- code/render/posteffects/ssaocontext.cc | 17 ++++--- code/render/terrain/terraincontext.cc | 22 ++++----- work/frame/win32/vkdefault.json | 4 +- 11 files changed, 71 insertions(+), 81 deletions(-) diff --git a/code/addons/staticui/ultralight/ultralightrenderer.cc b/code/addons/staticui/ultralight/ultralightrenderer.cc index 08aac3c53..a3132ab0f 100644 --- a/code/addons/staticui/ultralight/ultralightrenderer.cc +++ b/code/addons/staticui/ultralight/ultralightrenderer.cc @@ -198,7 +198,7 @@ UltralightRenderer::UpdateTexture(uint32_t texture_id, ultralight::Ref& frameScript) { "Fog Volume Texture 0" , CoreGraphics::PipelineStage::ComputeShaderWrite - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(fogState.fogVolumeTexture0) }); fogCompute->textureDeps.Add(fogState.zBuffer, { "ZBuffer" , CoreGraphics::PipelineStage::ComputeShaderRead - , CoreGraphics::TextureSubresourceInfo::DepthStencilNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::DepthStencil(fogState.zBuffer) }); fogCompute->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { @@ -241,13 +241,13 @@ VolumetricFogContext::Create(const Ptr& frameScript) { "Fog Volume Texture 0" , CoreGraphics::PipelineStage::ComputeShaderRead - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(fogState.fogVolumeTexture0) }); blurX->textureDeps.Add(fogState.fogVolumeTexture1, { "Fog Volume Texture 1" , CoreGraphics::PipelineStage::ComputeShaderWrite - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(fogState.fogVolumeTexture1) }); blurX->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { @@ -265,13 +265,13 @@ VolumetricFogContext::Create(const Ptr& frameScript) { "Fog Volume Texture 1" , CoreGraphics::PipelineStage::ComputeShaderRead - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(fogState.fogVolumeTexture1) }); blurY->textureDeps.Add(fogState.fogVolumeTexture0, { "Fog Volume Texture 0" , CoreGraphics::PipelineStage::ComputeShaderWrite - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(fogState.fogVolumeTexture0) }); blurY->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { diff --git a/code/render/frame/framescriptloader.cc b/code/render/frame/framescriptloader.cc index 6e1373c4b..def6a918f 100644 --- a/code/render/frame/framescriptloader.cc +++ b/code/render/frame/framescriptloader.cc @@ -280,15 +280,8 @@ FrameScriptLoader::ParseBlit(const Ptr& script, JzonValue* n toBits = CoreGraphics::PixelFormat::ToImageBits(CoreGraphics::TextureGetPixelFormat(toTex)); // add implicit barriers - TextureSubresourceInfo subresFrom, subresTo; - subresFrom.bits = fromBits; - subresFrom.layer = 0; - subresFrom.layerCount = 1; - subresFrom.mip = 0; - subresFrom.mipCount = 1; - - subresTo = subresFrom; - subresTo.bits = toBits; + TextureSubresourceInfo subresFrom = TextureSubresourceInfo::Texture(fromBits, fromTex); + TextureSubresourceInfo subresTo = TextureSubresourceInfo::Texture(toBits, toTex); op->textureDeps.Add(fromTex, Util::MakeTuple(from->string_value, CoreGraphics::PipelineStage::TransferRead, subresFrom)); op->textureDeps.Add(toTex, Util::MakeTuple(to->string_value, CoreGraphics::PipelineStage::TransferWrite, subresTo)); @@ -352,15 +345,8 @@ FrameScriptLoader::ParseCopy(const Ptr& script, JzonValue* n toBits = CoreGraphics::PixelFormat::ToImageBits(CoreGraphics::TextureGetPixelFormat(toTex)); // add implicit barriers - TextureSubresourceInfo subresFrom, subresTo; - subresFrom.bits = fromBits; - subresFrom.layer = 0; - subresFrom.layerCount = 1; - subresFrom.mip = 0; - subresFrom.mipCount = 1; - - subresTo = subresFrom; - subresTo.bits = toBits; + TextureSubresourceInfo subresFrom = TextureSubresourceInfo::Texture(fromBits, fromTex); + TextureSubresourceInfo subresTo = TextureSubresourceInfo::Texture(toBits, toTex); op->textureDeps.Add(fromTex, Util::MakeTuple(from->string_value, CoreGraphics::PipelineStage::TransferRead, subresFrom)); op->textureDeps.Add(toTex, Util::MakeTuple(to->string_value, CoreGraphics::PipelineStage::TransferWrite, subresTo)); @@ -412,18 +398,11 @@ FrameScriptLoader::ParseResolve(const Ptr& script, JzonValue toBits = ImageBitsFromString(to_bits->string_value); // add implicit barriers - TextureSubresourceInfo fromSubres, toSubres; - fromSubres.bits = fromBits; - fromSubres.layer = 0; - fromSubres.layerCount = 1; - fromSubres.mip = 0; - fromSubres.mipCount = 1; - - toSubres = fromSubres; - toSubres.bits = toBits; + TextureSubresourceInfo subresFrom = TextureSubresourceInfo::Texture(fromBits, fromTex); + TextureSubresourceInfo subresTo = TextureSubresourceInfo::Texture(toBits, toTex); - op->textureDeps.Add(fromTex, Util::MakeTuple(from->string_value, CoreGraphics::PipelineStage::TransferRead, fromSubres)); - op->textureDeps.Add(toTex, Util::MakeTuple(to->string_value, CoreGraphics::PipelineStage::TransferWrite, toSubres)); + op->textureDeps.Add(fromTex, Util::MakeTuple(from->string_value, CoreGraphics::PipelineStage::TransferRead, subresFrom)); + op->textureDeps.Add(toTex, Util::MakeTuple(to->string_value, CoreGraphics::PipelineStage::TransferWrite, subresTo)); // setup copy operation op->fromBits = fromBits; @@ -458,12 +437,8 @@ FrameScriptLoader::ParseMipmap(const Ptr& script, JzonValue* bool isDepth = CoreGraphics::PixelFormat::IsDepthFormat(CoreGraphics::TextureGetPixelFormat(ttex)); // add implicit barriers - TextureSubresourceInfo subres; - subres.bits = isDepth ? (CoreGraphics::ImageBits::DepthBits | CoreGraphics::ImageBits::StencilBits) : CoreGraphics::ImageBits::ColorBits; - subres.layer = 0; - subres.layerCount = 1; - subres.mip = 0; - subres.mipCount = 1; + CoreGraphics::ImageBits bits = isDepth ? (CoreGraphics::ImageBits::DepthBits | CoreGraphics::ImageBits::StencilBits) : CoreGraphics::ImageBits::ColorBits; + TextureSubresourceInfo subres = TextureSubresourceInfo::Texture(bits, ttex); op->textureDeps.Add(ttex, Util::MakeTuple(tex->string_value, CoreGraphics::PipelineStage::TransferRead, subres)); // setup copy operation @@ -738,6 +713,7 @@ FrameScriptLoader::ParsePass(const Ptr& script, JzonValue* n { const CoreGraphics::TextureId tex = TextureViewGetTexture(info.attachments[i]); subres.layerCount = TextureGetNumLayers(tex); + subres.mipCount = TextureGetNumMips(tex); if (info.attachmentDepthStencil[i]) { subres.bits = CoreGraphics::ImageBits::StencilBits | CoreGraphics::ImageBits::DepthBits; diff --git a/code/render/lighting/lightcontext.cc b/code/render/lighting/lightcontext.cc index 877602919..55f983eca 100644 --- a/code/render/lighting/lightcontext.cc +++ b/code/render/lighting/lightcontext.cc @@ -335,25 +335,25 @@ LightContext::Create(const Ptr& frameScript) { "LightBuffer" , CoreGraphics::PipelineStage::ComputeShaderWrite - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(textureState.lightingTexture) }); lightsCombine->textureDeps.Add(textureState.aoTexture, { "SSAOBuffer" , CoreGraphics::PipelineStage::ComputeShaderRead - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(textureState.aoTexture) }); lightsCombine->textureDeps.Add(textureState.fogTexture, { "VolumeFogBuffer" , CoreGraphics::PipelineStage::ComputeShaderRead - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(textureState.fogTexture) }); lightsCombine->textureDeps.Add(textureState.reflectionTexture, { "ReflectionBuffer" , CoreGraphics::PipelineStage::ComputeShaderRead - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(textureState.reflectionTexture) }); lightsCombine->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { diff --git a/code/render/posteffects/bloomcontext.cc b/code/render/posteffects/bloomcontext.cc index 110a02b75..71402adb1 100644 --- a/code/render/posteffects/bloomcontext.cc +++ b/code/render/posteffects/bloomcontext.cc @@ -105,14 +105,14 @@ BloomContext::Setup(const Ptr& script) { "LightBuffer" , PipelineStage::ComputeShaderRead - , TextureSubresourceInfo::ColorNoLayer(mips) + , TextureSubresourceInfo::Color(bloomState.lightBuffer) }); upscale->textureDeps.Add( bloomState.bloomBuffer, { "BloomBuffer" , PipelineStage::ComputeShaderWrite - , TextureSubresourceInfo::ColorNoMipNoLayer() + , TextureSubresourceInfo::Color(bloomState.bloomBuffer) }); upscale->func = [](const CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { diff --git a/code/render/posteffects/downsamplingcontext.cc b/code/render/posteffects/downsamplingcontext.cc index 53d94b28e..4769ffc3f 100644 --- a/code/render/posteffects/downsamplingcontext.cc +++ b/code/render/posteffects/downsamplingcontext.cc @@ -218,7 +218,7 @@ DownsamplingContext::Setup(const Ptr& script) { "LightBuffer" , PipelineStage::ComputeShaderWrite - , TextureSubresourceInfo::ColorNoMipNoLayer() + , TextureSubresourceInfo::Color(state.lightBuffer) }); colorDownsamplePass->func = [](const CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) @@ -240,7 +240,7 @@ DownsamplingContext::Setup(const Ptr& script) { "DepthBuffer" , PipelineStage::ComputeShaderWrite - , TextureSubresourceInfo::DepthStencilNoMipNoLayer() + , TextureSubresourceInfo::DepthStencil(state.depthBuffer) }); depthDownsamplePass->func = [](const CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) diff --git a/code/render/posteffects/ssaocontext.cc b/code/render/posteffects/ssaocontext.cc index 8d9107674..1ff7b7b21 100644 --- a/code/render/posteffects/ssaocontext.cc +++ b/code/render/posteffects/ssaocontext.cc @@ -123,7 +123,6 @@ SSAOContext::Setup(const Ptr& script) ssaoState.internalTargets[0] = CreateTexture(tinfo); tinfo.name = "HBAO-Internal1"; ssaoState.internalTargets[1] = CreateTexture(tinfo); - TextureSubresourceInfo subres = TextureSubresourceInfo::ColorNoMipNoLayer(); // setup shaders ssaoState.hbaoShader = ShaderGet("shd:hbao_cs.fxb"); @@ -196,13 +195,13 @@ SSAOContext::Setup(const Ptr& script) { "ZBuffer" , CoreGraphics::PipelineStage::ComputeShaderRead - , CoreGraphics::TextureSubresourceInfo::DepthStencilNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::DepthStencil(ssaoState.zBuffer) }); aoX->textureDeps.Add(ssaoState.internalTargets[0], { "SSAOBuffer0" , CoreGraphics::PipelineStage::ComputeShaderWrite - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(ssaoState.internalTargets[0]) }); aoX->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { @@ -222,13 +221,13 @@ SSAOContext::Setup(const Ptr& script) { "SSAOBuffer0" , CoreGraphics::PipelineStage::ComputeShaderRead - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(ssaoState.internalTargets[0]) }); aoY->textureDeps.Add(ssaoState.internalTargets[1], { "SSAOBuffer1" , CoreGraphics::PipelineStage::ComputeShaderWrite - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(ssaoState.internalTargets[1]) }); aoY->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { @@ -248,13 +247,13 @@ SSAOContext::Setup(const Ptr& script) { "SSAOBuffer1" , CoreGraphics::PipelineStage::ComputeShaderRead - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(ssaoState.internalTargets[1]) }); blurX->textureDeps.Add(ssaoState.internalTargets[0], { "SSAOBuffer0" , CoreGraphics::PipelineStage::ComputeShaderWrite - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(ssaoState.internalTargets[0]) }); blurX->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { @@ -274,13 +273,13 @@ SSAOContext::Setup(const Ptr& script) { "SSAOBuffer1" , CoreGraphics::PipelineStage::ComputeShaderRead - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(ssaoState.internalTargets[0]) }); blurY->textureDeps.Add(ssaoState.ssaoOutput, { "SSAOOutput" , CoreGraphics::PipelineStage::ComputeShaderWrite - , CoreGraphics::TextureSubresourceInfo::ColorNoMipNoLayer() + , CoreGraphics::TextureSubresourceInfo::Color(ssaoState.internalTargets[1]) }); blurY->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { diff --git a/code/render/terrain/terraincontext.cc b/code/render/terrain/terraincontext.cc index b6ee297b4..095989614 100644 --- a/code/render/terrain/terraincontext.cc +++ b/code/render/terrain/terraincontext.cc @@ -635,13 +635,13 @@ TerrainContext::Create(const TerrainSetupSettings& settings) { "Indirection Texture", CoreGraphics::PipelineStage::TransferWrite, - CoreGraphics::TextureSubresourceInfo(ImageBits::ColorBits, 0, TextureGetNumMips(terrainVirtualTileState.indirectionTexture), 0, 1) + CoreGraphics::TextureSubresourceInfo::Color(terrainVirtualTileState.indirectionTexture) }); terrainPrepare->textureDeps.Add(terrainVirtualTileState.indirectionTextureCopy, { "Indirection Texture Copy", CoreGraphics::PipelineStage::TransferRead, - CoreGraphics::TextureSubresourceInfo(ImageBits::ColorBits, 0, TextureGetNumMips(terrainVirtualTileState.indirectionTextureCopy), 0, 1) + CoreGraphics::TextureSubresourceInfo::Color(terrainVirtualTileState.indirectionTextureCopy) }); terrainPrepare->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { @@ -759,13 +759,13 @@ TerrainContext::Create(const TerrainSetupSettings& settings) { "Indirection Texture", CoreGraphics::PipelineStage::TransferRead, - CoreGraphics::TextureSubresourceInfo(ImageBits::ColorBits, 0, TextureGetNumMips(terrainVirtualTileState.indirectionTexture), 0, 1) + CoreGraphics::TextureSubresourceInfo::Color(terrainVirtualTileState.indirectionTexture) }); indirectionCopy->textureDeps.Add(terrainVirtualTileState.indirectionTextureCopy, { "Indirection Texture Copy", CoreGraphics::PipelineStage::TransferWrite, - CoreGraphics::TextureSubresourceInfo(ImageBits::ColorBits, 0, TextureGetNumMips(terrainVirtualTileState.indirectionTextureCopy), 0, 1) + CoreGraphics::TextureSubresourceInfo::Color(terrainVirtualTileState.indirectionTextureCopy) }); indirectionCopy->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { @@ -903,19 +903,19 @@ TerrainContext::Create(const TerrainSetupSettings& settings) { "Terrain Albedo Cache", CoreGraphics::PipelineStage::ColorWrite, - TextureSubresourceInfo::ColorNoMipNoLayer() + TextureSubresourceInfo::Color(terrainVirtualTileState.physicalAlbedoCache) }); cacheUpdate->textureDeps.Add(terrainVirtualTileState.physicalMaterialCache, { "Terrain Albedo Cache", CoreGraphics::PipelineStage::ColorWrite, - TextureSubresourceInfo::ColorNoMipNoLayer() + TextureSubresourceInfo::Color(terrainVirtualTileState.physicalMaterialCache) }); cacheUpdate->textureDeps.Add(terrainVirtualTileState.physicalNormalCache, { "Terrain Albedo Cache", CoreGraphics::PipelineStage::ColorWrite, - TextureSubresourceInfo::ColorNoMipNoLayer() + TextureSubresourceInfo::Color(terrainVirtualTileState.physicalNormalCache) }); cacheUpdate->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { @@ -1009,25 +1009,25 @@ TerrainContext::Create(const TerrainSetupSettings& settings) { "Terrain Albedo Cache", CoreGraphics::PipelineStage::PixelShaderRead, - TextureSubresourceInfo::ColorNoMipNoLayer() + TextureSubresourceInfo::Color(terrainVirtualTileState.physicalAlbedoCache) }); screenSpace->textureDeps.Add(terrainVirtualTileState.physicalMaterialCache, { "Terrain Albedo Cache", CoreGraphics::PipelineStage::PixelShaderRead, - TextureSubresourceInfo::ColorNoMipNoLayer() + TextureSubresourceInfo::Color(terrainVirtualTileState.physicalMaterialCache) }); screenSpace->textureDeps.Add(terrainVirtualTileState.physicalNormalCache, { "Terrain Albedo Cache", CoreGraphics::PipelineStage::PixelShaderRead, - TextureSubresourceInfo::ColorNoMipNoLayer() + TextureSubresourceInfo::Color(terrainVirtualTileState.physicalNormalCache) }); screenSpace->textureDeps.Add(terrainVirtualTileState.indirectionTexture, { "Indirection Texture", CoreGraphics::PipelineStage::PixelShaderRead, - TextureSubresourceInfo::ColorNoLayer(CoreGraphics::TextureGetNumMips(terrainVirtualTileState.indirectionTexture)) + TextureSubresourceInfo::Color(terrainVirtualTileState.indirectionTexture) }); screenSpace->func = [](const CoreGraphics::CmdBufferId cmdBuf, const IndexT frame, const IndexT bufferIndex) { diff --git a/work/frame/win32/vkdefault.json b/work/frame/win32/vkdefault.json index 058e914b4..dd43d78c8 100644 --- a/work/frame/win32/vkdefault.json +++ b/work/frame/win32/vkdefault.json @@ -66,7 +66,7 @@ "name": "BloomBuffer", "format": "R11G11B10F", "relative": true, - "usage": "Render|TransferSource", + "usage": "Render|TransferSource|ReadWrite", "width": 1.0, "height": 1.0, "type": "Texture2D" @@ -122,7 +122,7 @@ "format": "D32S8", "mips": "auto", "relative": true, - "usage": "TransferDestination|Sample", + "usage": "TransferDestination|Sample|ReadWrite", "width": 1.0, "height": 1.0, "type": "Texture2D"