使用d3dcompiler_47.dll编译错误以编译Pixel Shader文件 [英] Compile error using d3dcompiler_47.dll to compile a Pixel Shader file

查看:95
本文介绍了使用d3dcompiler_47.dll编译错误以编译Pixel Shader文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非工作副本Shazzam Shader编辑器,并且有一些Dll导入到一些传统的dll函数。所以我认为我使用它来更新它:

https://msdn.microsoft.com/en-us/library/windows/desktop/hh446872(v = vs.85).aspx [ ^ ]



所以我拿了原始代码并修改它以适应新功能:

I got a non working copy Shazzam Shader Editor, and there are some Dll imports to some legacy dll functions. So I thought I update it a bit using this instead:
https://msdn.microsoft.com/en-us/library/windows/desktop/hh446872(v=vs.85).aspx[^]

So I took the original code and modified it to fit the new function:

<Guid("8BA5FB08-5195-40e2-AC58-0D989C3A0102"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
  Private Interface ID3DXBuffer
      <PreserveSig> _
      Function GetBufferPointer() As IntPtr
      <PreserveSig> _
      Function GetBufferSize() As Integer
  End Interface

  <PreserveSig> _
  <DllImport("d3dcompiler_47.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.Cdecl)> _
  Private Shared Function D3DCompileFromFile(<MarshalAs(UnmanagedType.LPStr)> pFilename As String,
                                                        pDefines As IntPtr,
                                                        pInclude As IntPtr,
                                                        <MarshalAs(UnmanagedType.LPStr)> pEntrypoint As String,
                                                        <MarshalAs(UnmanagedType.LPStr)> pTarget As String,
                                                        flags1 As Integer,
                                                        flags2 As Integer,
                                                        ByRef ppCode As ID3DXBuffer,
                                                        ByRef ppErrorMsgs As ID3DXBuffer) As Integer
  End Function

  Public Sub Compile(ByVal File As HLSLFileHelperClass)
      Dim pFilename As String = File.GetSourceFileFullName
      Dim pDefines As IntPtr = IntPtr.Zero
      Dim pInclude As IntPtr = IntPtr.Zero

      Dim pEntrypoint As String = File.HLSLEntryPoint
      Dim pTarget As String = File.ShaderCompilerVersion.ToString

      Dim flags1 As Integer = 0
      Dim flags2 As Integer = 0
      Dim ppCode As ID3DXBuffer = Nothing
      Dim ppErrorMsgs As ID3DXBuffer = Nothing

      Dim CompileResult As Integer = 0

      CompileResult = D3DCompileFromFile(pFilename,
                                         pDefines,
                                         pInclude,
                                         pEntrypoint,
                                         pTarget,
                                         flags1,
                                         flags2,
                                         ppCode,
                                         ppErrorMsgs)

      If CompileResult <> 0 Then

          Dim errors As IntPtr = ppErrorMsgs.GetBufferPointer()

          Dim size As Integer = ppErrorMsgs.GetBufferSize()

          ErrorText = Marshal.PtrToStringAnsi(errors)
          IsCompiled = False
      Else
          ErrorText = ""
          IsCompiled = True
          Dim psPath = File.GetCompiledFileFullName
          Dim pCompiledPs As IntPtr = ppCode.GetBufferPointer()
          Dim compiledPsSize As Integer = ppCode.GetBufferSize()

          Dim compiledPs = New Byte(compiledPsSize - 1) {}
          Marshal.Copy(pCompiledPs, compiledPs, 0, compiledPs.Length)
          Using psFile = IO.File.Open(psPath, FileMode.Create, FileAccess.Write)
              psFile.Write(compiledPs, 0, compiledPs.Length)
          End Using
      End If

      If ppCode IsNot Nothing Then
          Marshal.ReleaseComObject(ppCode)
      End If
      ppCode = Nothing

      If ppErrorMsgs IsNot Nothing Then
          Marshal.ReleaseComObject(ppErrorMsgs)
      End If
      ppErrorMsgs = Nothing


  End Sub



但是使用此代码我得到以下错误:


However using this code I get the following error:

Additional information: A call to PInvoke function 'WpfAdventuresInPixelShader!WpfAdventuresInPixelShader.ShaderCompiler::D3DCompileFromFile' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

If there is a handler for this exception, the program may be safely continued.





如果我改变该属性:



If I change the attribute from this:

<DllImport("d3dcompiler_47.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.Cdecl)>

到此:

to this:

<DllImport("d3dcompiler_47.dll", CharSet:=CharSet.Auto)>



我从Integer.MinValue -2的编译器得到一个结果.....



那么我需要做些什么来实现这个目标呢?

(哦,我想编译的文件没有任何问题,因为我可以用fxc.exe做到这一点没有任何问题)


I get a result from the compiler of Integer.MinValue -2.....

So what do I need to do to get this working?
(oh, there is nothing wrong with the files I want to compile, as I can do that with the fxc.exe without any problems)

推荐答案

得到它,:

Got it,:
Module Extend
    <Guid("8BA5FB08-5195-40e2-AC58-0D989C3A0102"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
    Public Interface ID3DBlob
        <PreserveSig> _
        Function GetBufferPointer() As IntPtr
        <PreserveSig> _
        Function GetBufferSize() As Integer
    End Interface

    <PreserveSig> _
    <DllImport("d3dcompiler_47.dll", CharSet:=CharSet.Auto)> _
    Public Function D3DCompileFromFile(<MarshalAs(UnmanagedType.LPTStr)> pFilename As String,
                                                          pDefines As IntPtr,
                                                          pInclude As IntPtr,
                                                          <MarshalAs(UnmanagedType.LPStr)> pEntrypoint As String,
                                                          <MarshalAs(UnmanagedType.LPStr)> pTarget As String,
                                                          flags1 As Integer,
                                                          flags2 As Integer,
                                                          ByRef ppCode As ID3DBlob,
                                                          ByRef ppErrorMsgs As ID3DBlob) As Integer
    End Function
End Module



似乎它必须在模块中才能工作,无论如何都要修复它。


Seems that it must be in a Module to work, well that fixed it anyways.


这篇关于使用d3dcompiler_47.dll编译错误以编译Pixel Shader文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆