2
votes

I'm using SlimDX to create a texture consisting of 13046 different DataRectangles. Here's my code. It's breaking on the Texture2D constructor with "E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)." inParms is just a struct containing handle to a Panel.

public Renderer(Parameters inParms, ref DataRectangle[] inShapes)
    {
        Texture2DDescription description = new Texture2DDescription()
        {
            Width = 500,
            Height = 500,
            MipLevels = 1,
            ArraySize = inShapes.Length,
            Format = Format.R32G32B32_Float,
            SampleDescription = new SampleDescription(1, 0),
            Usage = ResourceUsage.Default,
            BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
            CpuAccessFlags = CpuAccessFlags.None,
            OptionFlags = ResourceOptionFlags.None
        };

        SwapChainDescription chainDescription = new SwapChainDescription()
        {
            BufferCount = 1,
            IsWindowed = true,
            Usage = Usage.RenderTargetOutput,
            ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
            SampleDescription = new SampleDescription(1, 0),
            Flags = SwapChainFlags.None,
            OutputHandle = inParms.Handle,
            SwapEffect = SwapEffect.Discard
        };

        Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, chainDescription, out mDevice, out mSwapChain);

        Texture2D texture = new Texture2D(Device, description, inShapes);
}
1

1 Answers

1
votes

R32G32B32_Float (and pretty much every 3 channels format) is not supported for render target usage.

So you have different options:

  • Use R32G32B32A32_Float instead (means that you will need to change your Data Rectangles as you add an extra channel).
  • Remove the BindFlags.RenderTarget flag. If you only want to read this resource, this flag is not needed. As you provide initial data, you can also change Usage to ResourceUsage.Immutable as well.

Additionally, to check if a Format is supported for a specific resource usage, you can use the following snippet:

    public bool IsFormatSupported(Device dev, FormatSupport usage, Format format)
    {
        FormatSupport support = dev.CheckFormatSupport(format);
        return (support | usage) == support;
    }