DxcCompilationException

Open
#826 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp

Research direction

Reproduce the failure with ComputeSharp 2.1 on .NET Framework 4.8 using the supplied Scaling shader, then inspect ShaderCompiler.cs and PipelineDataLoader.cs around the reported call path. Check how the DXC invocation handles '-Werror' and compare it with the supported version configuration. Done means the cause is confirmed and a tested resolution or clear compatibility guidance is established.

Written by the indexing model from the issue text.

Description

question :question: untriaged :toolbox:

Hello,
I found your library and wanted to test it for basic purposes, but I am unable to complete.
My (first) goal would be to convert 16bits values to 4x8bits (scaling 16Gray images to 32bits Bgra images).
The shader looks like this :

        [AutoConstructor]
        public partial struct Scaling : IComputeShader
        {
            // Other captured resources or values here...
            public ReadWriteBuffer<int> Source;
            public readonly int min;
            public readonly double scale;

            public void Execute()
            {

                int rgb = (int)(scale * (Source[ThreadIds.X] - min) + 0.5);

                Source[ThreadIds.X] = (rgb << 24) | (rgb << 16) | (rgb << 8) | 255;

            }
        }

and the function that calls it :

        static public void GPUScale16Grayto32Bpp(ref Bitmap src, ref Bitmap dest, int pixel_type)
        {

            ushort max = (ushort)(Math.Pow(2, pixel_type) - 1);
            ushort min = 0x0000;
            double scale = 255.0 / (double)(max - min);

            BitmapData src_data = src.LockBits(
                      new Rectangle(0, 0, src.Width, src.Height),
                      ImageLockMode.ReadOnly, src.PixelFormat);

            Int16[] src_array = new Int16[src.Width * src.Height];
            int[] dst_array = new int[src.Width * src.Height];

            IntPtr ptrFirstPixel = src_data.Scan0;
            Marshal.Copy(ptrFirstPixel, src_array, 0, src_array.Length);
            src.UnlockBits(src_data);

            ReadWriteBuffer<int> buffer_src = GraphicsDevice.GetDefault().AllocateReadWriteBuffer(Array.ConvertAll<Int16,int>(src_array, x => (int)x));
            

            GraphicsDevice.GetDefault().For(buffer_src.Length, new GpuFonctions.Scaling(buffer_src, min, scale));
            

            BitmapData dest_data = dest.LockBits(
                     new Rectangle(0, 0, dest.Width, dest.Height),
                     ImageLockMode.WriteOnly, dest.PixelFormat);
            IntPtr ptrFirstPixel_dest = dest_data.Scan0;

            buffer_src.CopyTo(dst_array, 0);

            Marshal.Copy(dst_array, 0, ptrFirstPixel_dest, dst_array.Length);

            dest.UnlockBits(dest_data);

        }

I get an exception message at Runtime when reaching this line :
PipelineData pipelineData = PipelineDataLoader<T>.GetPipelineData(this.device, threadsX, threadsY, threadsZ, ref shader);

ComputeSharp.Exceptions.DxcCompilationException
HResult=0x80131500
Message=The DXC compiler encountered one or more errors while trying to compile the shader:

Unknown argument: '-Werror'.

Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.
If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.
Source=ComputeSharp.Dynamic
Arborescence des appels de procédure :
à ComputeSharp.Shaders.Translation.ShaderCompiler.ThrowHslsCompilationException(IDxcOperationResult* dxcOperationResult) dans //src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs :ligne 171
à ComputeSharp.Shaders.Translation.ShaderCompiler.Compile(ReadOnlySpan1 source) dans /_/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs :ligne 138 à ComputeSharp.__Internals.ShaderCompiler.LoadDynamicBytecode[TLoader,T](TLoader& loader, Int32 threadsX, Int32 threadsY, Int32 threadsZ, T& shader) dans /_/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs :ligne 37 à STIL_Imaging.GpuFonctions.Scaling.global::ComputeSharp.__Internals.IShader.LoadBytecode[TLoader](TLoader& loader, Int32 threadsX, Int32 threadsY, Int32 threadsZ) dans C:\SVN\Outils_Labo\Trunk\STIL_Imaging\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.IShaderGenerator\STIL_Imaging.GpuFonctions+Scaling.LoadBytecode.g.cs :ligne 15 à ComputeSharp.Shaders.Loading.PipelineDataLoader1.LoadShader(Int32 threadsX, Int32 threadsY, Int32 threadsZ, T& shader, ICachedShader& shaderData) dans /
/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs :ligne 76
à ComputeSharp.Shaders.Loading.PipelineDataLoader`1.GetPipelineData(GraphicsDevice device, Int32 threadsX, Int32 threadsY, Int32 threadsZ, T& shader) dans //src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs :ligne 48
à ComputeSharp.ComputeContext.Run[T](Int32 x, Int32 y, Int32 z, Int32 threadsX, Int32 threadsY, Int32 threadsZ, T& shader) dans /
/src/ComputeSharp/Shaders/ComputeContext.cs :ligne 198
à ComputeSharp.GraphicsDeviceExtensions.For[T](GraphicsDevice device, Int32 x, T& shader) dans /_/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs :ligne 24
à STIL_Imaging.Fonctions.GPUScale16Grayto32Bpp(Bitmap& src, Bitmap& dest, Int32 pixel_type) dans C:\SVN\Outils_Labo\Trunk\STIL_Imaging\GpuBased.cs :ligne 45

I tried different things, but nothing worked so far, and I get the same exception.

I am on VS2022, I updated my projects to sdk style projects, I target .NetFramework 4.8 (due to other old library).
I used Nuget to get the packages ComputeSharp, ComputeSharp.Core, ComputeSharp.Dynamic and ComputeSharp.Pix in version 2.1
The graphic card is a GTX 1050, which seems to be well found.

I am wondering if I may have mixed functions not compatible between version 2.1 and examples of version 3 ?
Or do I miss something obvious ?

Thank you for the feedback.

Dominant language
C#
Stars
3.2k
Forks
148
Avg merge
4h 32m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Sergio0694/ComputeSharp

All issues in Sergio0694/ComputeSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.