- rendering to texture requires a separate depth/stencil image as the image used by the main view may be using multisampling

This commit is contained in:
Magnus Norddahl 2019-05-05 01:58:36 +02:00
commit e1ae8bbc59
8 changed files with 50 additions and 10 deletions

View file

@ -55,6 +55,7 @@ void VkRenderBuffers::BeginFrame(int width, int height, int sceneWidth, int scen
if (width != mWidth || height != mHeight || mSamples != samples)
CreateScene(width, height, samples);
CreateCamTexDepthStencil();
CreateShadowmap();
mWidth = width;
@ -142,6 +143,31 @@ void VkRenderBuffers::CreateSceneColor(int width, int height, VkSampleCountFlagB
SceneColorView->SetDebugName("VkRenderBuffers.SceneColorView");
}
void VkRenderBuffers::CreateCamTexDepthStencil()
{
if (CamtexDepthStencil)
return;
auto fb = GetVulkanFrameBuffer();
ImageBuilder builder;
builder.setSize(1024, 1024);
builder.setSamples(VK_SAMPLE_COUNT_1_BIT);
builder.setFormat(SceneDepthStencilFormat);
builder.setUsage(VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
CamtexDepthStencil = builder.create(fb->device);
CamtexDepthStencil->SetDebugName("VkRenderBuffers.CamtexDepthStencil");
ImageViewBuilder viewbuilder;
viewbuilder.setImage(CamtexDepthStencil.get(), SceneDepthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
CamtexDepthStencilView = viewbuilder.create(fb->device);
CamtexDepthStencilView->SetDebugName("VkRenderBuffers.CamtexDepthStencilView");
PipelineBarrier barrier;
barrier.addImage(CamtexDepthStencil.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
barrier.execute(fb->GetDrawCommands(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
}
void VkRenderBuffers::CreateSceneDepthStencil(int width, int height, VkSampleCountFlagBits samples)
{
auto fb = GetVulkanFrameBuffer();