Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DxcCompilationException #826

Open
S3bGrd opened this issue Jul 18, 2024 · 0 comments
Open

DxcCompilationException #826

S3bGrd opened this issue Jul 18, 2024 · 0 comments
Labels
question ❓ Further information is requested untriaged 🧰 A new issue that needs initial triage

Comments

@S3bGrd
Copy link

S3bGrd commented Jul 18, 2024

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.

@S3bGrd S3bGrd added question ❓ Further information is requested untriaged 🧰 A new issue that needs initial triage labels Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❓ Further information is requested untriaged 🧰 A new issue that needs initial triage
Projects
None yet
Development

No branches or pull requests

1 participant