public override void Export(ShaderWriter writer, ref ShaderSubProgram subProgram)
        {
            byte[] exportData = subProgram.ProgramData;
            int    dataOffset = 0;

            if (DXDataHeader.HasHeader(m_graphicApi))
            {
                dataOffset = DXDataHeader.GetDataOffset(writer.Version, m_graphicApi);
                uint fourCC = BitConverter.ToUInt32(exportData, dataOffset);
                if (fourCC != DXBCFourCC)
                {
                    throw new Exception("Magic number doesn't match");
                }
            }

            int    dataLength       = exportData.Length - dataOffset;
            IntPtr unmanagedPointer = Marshal.AllocHGlobal(dataLength);

            Marshal.Copy(exportData, dataOffset, unmanagedPointer, dataLength);

            D3DCompiler.D3DCompiler.D3DDisassemble(unmanagedPointer, (uint)dataLength, 0, null, out IDxcBlob disassembly);
            string disassemblyText = GetStringFromBlob(disassembly);

            ExportListing(writer, disassemblyText);

            Marshal.FreeHGlobal(unmanagedPointer);
        }
Ejemplo n.º 2
0
        public override void Export(ShaderWriter writer, ref ShaderSubProgram subProgram)
        {
            using (MemoryStream stream = new MemoryStream(subProgram.ProgramData))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    DXDataHeader header = new DXDataHeader();
                    header.Read(reader, writer.Version);

                    // HACK: since we can't restore UAV info and HLSLcc requires it, process such shader with default exporter
                    if (header.UAVs > 0)
                    {
                        base.Export(writer, ref subProgram);
                    }
                    else
                    {
                        byte[] exportData       = DXShaderProgramRestorer.RestoreProgramData(reader, writer.Version, ref subProgram);
                        WrappedGlExtensions ext = new WrappedGlExtensions();
                        ext.ARB_explicit_attrib_location  = 1;
                        ext.ARB_explicit_uniform_location = 1;
                        ext.ARB_shading_language_420pack  = 0;
                        ext.OVR_multiview = 0;
                        ext.EXT_shader_framebuffer_fetch = 0;
                        Shader shader = Shader.TranslateFromMem(exportData, WrappedGLLang.LANG_DEFAULT, ext);
                        if (shader.OK == 0)
                        {
                            base.Export(writer, ref subProgram);
                        }
                        else
                        {
                            ExportListing(writer, shader.Text);
                        }
                    }
                }
            }
        }