Skip to content

Prevent typeless textures from creating srv / rtv on initialization#3095

Open
johang88 wants to merge 1 commit intostride3d:masterfrom
johang88:typeless-srv-rtv
Open

Prevent typeless textures from creating srv / rtv on initialization#3095
johang88 wants to merge 1 commit intostride3d:masterfrom
johang88:typeless-srv-rtv

Conversation

@johang88
Copy link
Contributor

PR Details

DirectX 11 does not allow Shader Resource Views or Render Target Views to be created for typeless textures. This change prevents their creation upon texture initialization, which would have given an exception when NativeDevice.CreateShaderResourceView / NativeDevice.CreateRenderTargetView were called. Users can then create views in their desired format using ToTextureView.

Example usage from when I had to interpret the same texture as both SRgb and non SRgb, typeless is required here as creating a non srgb view from an srgb texture is not allowed.

        _stagingDiffuse = Texture.New2D(graphicsDevice, padded, padded,
            PixelFormat.R8G8B8A8_Typeless,
            TextureFlags.RenderTarget | TextureFlags.ShaderResource);

        _stagingDiffuseTargetView = _stagingDiffuse.ToTextureView(new()
        {
            Flags = TextureFlags.RenderTarget,
            Format = PixelFormat.R8G8B8A8_UNorm_SRgb,
            Type = ViewType.Single
        });

        _stagingDiffuseCompressView = _stagingDiffuse.ToTextureView(new()
        {
            Flags = TextureFlags.ShaderResource,
            Format = PixelFormat.R8G8B8A8_UNorm,
            Type = ViewType.Single
        });

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

@xen2
Copy link
Member

xen2 commented Mar 21, 2026

Probably we should do the same for D3D12 (and maybe Vulkan if it works the same)?

@johang88
Copy link
Contributor Author

Good point, I'll have to check how they behave.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants