Skip to content

ResourceFactory.CreateTextureView ignores the requested pixelFormat on a depth-stencil texture #241

Description

@SimonMeysman

Evergine 2026.5.26.921 · .NET 10 · Windows 11 · DX11 head (and WebGPU head where noted).
Desktop application: a 3D viewer for building models.

What happens

We want to sample the stencil plane of a depth-stencil target. We create the texture as typeless and ask for
a stencil-plane view, but the view that reaches the shader has the resource's own format, so the sample returns
zero.

Repro

var desc = new TextureDescription {
    Type = TextureType.Texture2D,
    Format = PixelFormat.R24G8_Typeless,
    Width = w, Height = h, Depth = 1, ArraySize = 1, MipLevels = 1,
    Flags = TextureFlags.DepthStencil | TextureFlags.ShaderResource,
    Usage = ResourceUsage.Default,
    SampleCount = TextureSampleCount.None,
    CpuAccess = ResourceCpuAccess.None,
};
var depth = factory.CreateTexture(ref desc, "mask-depth");

// ask for the STENCIL plane
var view = factory.CreateTextureView(depth, PixelFormat.X24_Typeless_G8_UInt, 0, 1, 0, 1, null);

material.SetTextureViewValue(view, "Mask");   // shader: Texture2D<uint2> Mask : register(t0);

Actual vs expected

  • Expected: the bound SRV has format X24_Typeless_G8_UInt, and Mask.Load(...).g returns the stencil byte.
  • Actual: a RenderDoc capture of the sampling draw shows the bound SRV with viewFormat = D24S8. The
    requested format was dropped in favour of the resource's own. D24S8 is not a legal SRV format on D3D11 (it
    requires R24_UNorm_X8_TYPELESS for depth or X24_TYPELESS_G8_UINT for stencil), so the shader reads zero
    everywhere
    .

Everything either side of this works

Verified in the same capture, so the fault is isolated to the view format:

  • the texture creates fine with DepthStencil | ShaderResource;
  • CreateTextureView returns a DX11TextureView and SetTextureViewValue binds it (note SetTextureValue
    cannot — TextureView does not derive from Texture);
  • the FrameBuffer still renders correctly with the typeless depth attachment;
  • the stencil writes are correct: 743 non-zero texels, all value 1, exactly the silhouette we drew;
  • the read is correctly ordered after the write;
  • the effect exporter accepts Texture2D<uint2> in the shader.

Questions

  1. Is sampling a stencil plane supported, and is pixelFormat meant to be honoured here?
  2. Does the WebGPU backend support sampling a stencil aspect? (Dawn is stricter about this.)

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