【问题标题】:How to compile from shader assembler code in DirectX 11?如何从 DirectX 11 中的着色器汇编代码编译?
【发布时间】:2019-04-24 08:22:49
【问题描述】:

D3DXAssembleShader 函数在 DirectX 9 中用于从 Assembly 编译着色器。 DirectX 11 不支持它。有没有其他方法可以从汇编代码创建着色器?

我知道从 fx 或 hlsl 文件编译,但出于我的项目目的,我应该只使用程序集进行编译。

DirectX 9 中使用了以下代码:

static const char VertexShaderCode[] = \
    "vs.3.0\n"
    "dcl_position v0\n"
    "dcl_position o0\n"
    "mov o0, v0\n";
D3DXAssembleShader(VertexShaderCode,sizeof(VertexShaderCode), 0,0, DLL, &VSBuffer, 0);

我正在使用 D3D11 dll 在 DirectX11 中寻找上述代码的替代方案。

我想像下面这样修改我的 asm 文件并创建顶点和像素着色器:

dcl_output o0.xyzw -> dcl_output.o0.zw

我可以在 fx 或 hlsl 文件中做同样的事情吗?

FX 文件:

cbuffer ConstantBuffer : register( b0 )
{
    matrix World;
    matrix View;
    matrix Projection;
}

//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;
    float4 Color : COLOR0;
};

//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VS_OUTPUT VS( float4 Pos : POSITION, float4 Color : COLOR )
{
    VS_OUTPUT output = (VS_OUTPUT)0;
    output.Pos = mul( Pos, World );
    output.Pos = mul( output.Pos, View );
    output.Pos = mul( output.Pos, Projection );
    output.Color = Color;
    return output;
}


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( VS_OUTPUT input ) : SV_Target
{
    return input.Color;
}

【问题讨论】:

    标签: c++ assembly shader directx-11 d3dx


    【解决方案1】:

    Shader Model 4.0、4.1、5.0 或 5.1 不正式支持从 HLSL 着色器程序集进行编译。

    当您使用 fxc.exe 构建时,您将获得反汇编以进行调试和优化

    【讨论】:

    • 是的,我从 fxc.exe 获得了汇编代码,但我想使用 asm 代码来创建着色器
    • 正如我所说,它不受官方支持。请参阅this thread 了解一些非官方选项。
    • 我能够创建顶点着色器,但它在执行过程中崩溃并失败,说明 createVertexShader 方法中的校验和失败。我什至尝试使用未修改的编译着色器对象。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 1970-01-01
    • 2018-10-22
    • 2015-05-12
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    相关资源
    最近更新 更多