Skip to content

GetDefaultView(TEXTURE_VIEW_READ_ONLY_DEPTH_STENCIL) always returns null on Vulkan #764

Description

@Poohl

When creating a texture with BindFlags BIND_SHADER_RESOURCE | BIND_DEPTH_STENCIL, calling GetDefaultView(TEXTURE_VIEW_READ_ONLY_DEPTH_STENCIL) returns a nullpointer because the corresponding default view is invalid. I can however create a view like this manually. Additionally, I'm unable to find a location where this default view would be created, TextureBase.hpp only creates a default view for TEXTURE_VIEW_DEPTH_STENCIL.

The following snippet demonstrates the issue, the ReadOnly DSV is always a nullptr.

void CreateDepthTextureAndViews(Diligent::IRenderDevice* pDevice)
{
	using namespace Diligent;

	TextureDesc TexDesc;
	TexDesc.Name = "MyDepthTex";
	TexDesc.Type = RESOURCE_DIM_TEX_2D;
	TexDesc.Width = 1024;
	TexDesc.Height = 1024;
	TexDesc.MipLevels = 1;
	TexDesc.Format = TEX_FORMAT_D32_FLOAT;
	TexDesc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE;

	RefCntAutoPtr<ITexture> pDepthTex;
	pDevice->CreateTexture(TexDesc, nullptr, &pDepthTex);

	ITextureView* pWritableDSV = pDepthTex->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL);
	ITextureView* pReadOnlyDSV = pDepthTex->GetDefaultView(TEXTURE_VIEW_READ_ONLY_DEPTH_STENCIL);

	printf("Writable DSV: %p\n", pWritableDSV);
	printf("ReadOnly  DSV: %p\n", pReadOnlyDSV);

	TextureViewDesc ViewDesc;
	ViewDesc.Name = "Manual_ReadOnly_DSV";
	ViewDesc.ViewType = TEXTURE_VIEW_DEPTH_STENCIL;
	ViewDesc.TextureDim = RESOURCE_DIM_TEX_2D;
	ViewDesc.Format = TexDesc.Format;
	ViewDesc.MostDetailedMip = 0;
	ViewDesc.NumMipLevels = 1;
	ViewDesc.FirstArraySlice = 0;
	ViewDesc.NumArraySlices = 1;

	RefCntAutoPtr<ITextureView> pManualReadOnlyDSV;
	pDepthTex->CreateView(ViewDesc, &pManualReadOnlyDSV);

	printf("Manually created read-only DSV: %p\n", pManualReadOnlyDSV.RawPtr());
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions