{"record":{"id":"7039bd45de36db6f","repo":"stride3d/stride","slug":"cannot-initialize-a-read-only-depth-stencil-buffer-not","errorCode":null,"errorMessage":"Cannot initialize a read-only Depth-Stencil Buffer. Not supported on this device.","messagePattern":"Cannot initialize a read-only Depth-Stencil Buffer\\. Not supported on this device\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D12/Texture.Direct3D12.cs","lineNumber":790,"sourceCode":"                {\n                    depthStencilViewDescription.ViewDimension = DsvDimension.Texture2Darray;\n                    depthStencilViewDescription.Texture2DArray.ArraySize = (uint) ArraySize;\n                    depthStencilViewDescription.Texture2DArray.FirstArraySlice = 0;\n                    depthStencilViewDescription.Texture2DArray.MipSlice = 0;\n                }\n                else // Regular Texture (2D)\n                {\n                    depthStencilViewDescription.ViewDimension = DsvDimension.Texture2D;\n                    depthStencilViewDescription.Texture2D.MipSlice = 0;\n                }\n\n                if (MultisampleCount > MultisampleCount.None)\n                    depthStencilViewDescription.ViewDimension = DsvDimension.Texture2Dms;\n\n                if (IsDepthStencilReadOnly)\n                {\n                    if (!IsDepthStencilReadOnlySupported(GraphicsDevice))\n                        throw new NotSupportedException(\"Cannot initialize a read-only Depth-Stencil Buffer. Not supported on this device.\");\n\n                    // Create a Depth-Stencil View on this 2D Texture\n                    depthStencilViewDescription.Flags = DsvFlags.ReadOnlyDepth;\n                    if (HasStencil)\n                        depthStencilViewDescription.Flags |= DsvFlags.ReadOnlyStencil;\n                }\n\n                var descriptorHandle = GraphicsDevice.DepthStencilViewAllocator.Allocate(1);\n\n                NativeDevice.CreateDepthStencilView(NativeResource, in depthStencilViewDescription, descriptorHandle);\n                return descriptorHandle;\n            }\n\n            //\n            // Gets a specific Unordered Access View from the Texture.\n            //\n            CpuDescriptorHandle GetUnorderedAccessView(ViewType viewType, int arrayOrDepthSlice, int mipIndex)\n            {","sourceCodeStart":772,"sourceCodeEnd":808,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D12/Texture.Direct3D12.cs#L772-L808","documentation":"Read-only depth-stencil views (DsvFlags.ReadOnlyDepth / ReadOnlyStencil) require the device to support D3D12 features like OM SetRenderTargets with read-only DSV (TextureFlags-based read-only DSV support). IsDepthStencilReadOnlySupported(GraphicsDevice) checks this; when unsupported, creating a read-only depth-stencil texture throws in InitializeFromImpl.","triggerScenarios":"Creating a Texture with TextureFlags.DepthStencilReadOnly (IsDepthStencilReadOnly true) on a device whose feature level/adapter does not support read-only DSVs.","commonSituations":"Shadow-map or cascaded-shadow renderers that sample depth while it is bound as depth-stencil; running on older hardware or WARP/software adapters; enabling read-only flags unconditionally without checking GraphicsDevice features.","solutions":["Guard creation with Texture.IsDepthStencilReadOnlySupported(GraphicsDevice) and fall back to a plain DepthStencil flag set.","Remove the read-only flag and bind the depth texture separately (unbind as DSV when sampling), or copy to a shader-resource texture.","Upgrade hardware/driver or raise the required feature level so read-only DSVs are supported."],"exampleFix":"// before\nvar flags = TextureFlags.DepthStencilReadOnly | TextureFlags.ShaderResource;\nvar tex = Texture.New2D(device, w, h, PixelFormat.D32.Float, flags);\n// after\nvar flags = Texture.IsDepthStencilReadOnlySupported(device)\n    ? TextureFlags.DepthStencilReadOnly | TextureFlags.ShaderResource\n    : TextureFlags.DepthStencil;\nvar tex = Texture.New2D(device, w, h, PixelFormat.D32.Float, flags);","handlingStrategy":"fallback","validationCode":"var flags = Texture.IsDepthStencilReadOnlySupported(device)\n    ? TextureFlags.DepthStencilReadOnly | TextureFlags.ShaderResource\n    : TextureFlags.DepthStencil | TextureFlags.ShaderResource;","typeGuard":null,"tryCatchPattern":"try { return Texture.New2D(device, w, h, PixelFormat.D32.Float, readOnlyFlags); }\ncatch (NotSupportedException) { return Texture.New2D(device, w, h, PixelFormat.D32.Float, TextureFlags.DepthStencil | TextureFlags.ShaderResource); }","preventionTips":["Always query Texture.IsDepthStencilReadOnlySupported before using DepthStencilReadOnly.","Design renderers to tolerate a plain DSV path (unbind before sampling).","Test on WARP and older GPUs where read-only DSV features may be missing."],"tags":["direct3d12","depth-stencil","device-capability","read-only"],"backgroundTag":"feature-not-enabled","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}