0

D3DXAssembleShader function was used in DirectX 9 for compiling shaders from Assembly. It's not supported in DirectX 11. Is there any alternative to create shaders from Assembler code?

I am aware of compiling from fx or hlsl files but for my project purposes, I should compile only using assembly.

The following code was used in 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);

I am looking for an alternative to the above code in DirectX11 using D3D11 dll's.

I want to modify my asm file like below and create vertex and pixel shaders:

dcl_output o0.xyzw -> dcl_output.o0.zw

Will I be able to do the same in fx or hlsl file?

FX file:

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;
}
user3264821
  • 175
  • 2
  • 18

1 Answers1

0

Compiling from HLSL shader assembly isn't officially supported for Shader Model 4.0, 4.1, 5.0, or 5.1.

When you build with fxc.exe you get disassembly for debugging & optimization purposes

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • Yeah I got the assembly code from fxc.exe but I wanted to use asm code for creating shaders – user3264821 Apr 24 '19 at 05:40
  • As I said, it's not officially supported. See [this thread](https://stackoverflow.com/questions/50059358/how-can-i-compile-asm-shader-to-fxo-file) for some unofficial options. – Chuck Walbourn Apr 24 '19 at 05:59
  • I am able to create vertex shader but it crashes and fails during execution stating checksum failed in createVertexShader method. I even tried with unmodified compiled shader object. – user3264821 Apr 28 '19 at 14:43