• Advertisement
Sign in to follow this  

DX11 Is it possible to load asm/FX-Shaders in DirectX11

This topic is 1255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone,


I´m trying to switch form SharpDx9 to SharpDx11. And now I have no idea how to load my old shaders which are a mix of asm and hlsl shaders.

Here is one of the shaders. the assembler parts are extracted from a game. the hlsl-variables are created by me. 


Best regards




texture Tex1 : register( ps, t[0] );
texture Tex2 : register( ps, t[2] );
texture Tex3 : register( ps, t[4] );
texture Tex1Bump : register( ps, t[1] );
texture Tex2Bump : register( ps, t[3] );
texture Tex3Bump : register( ps, t[5] );

texture TexDither : register( ps, t[6] );
texture TexShadowMap : register( ps, t[7] );

sampler2D DiffuseTex1 : register(ps, s[0]) = sampler_state { Texture = (Tex1); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};
sampler2D BumpTex1 : register(ps, s[1]) = sampler_state { Texture = (Tex1Bump); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};
sampler2D DiffuseTex2 : register(ps, s[2]) = sampler_state { Texture = (Tex2); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};
sampler2D BumpTex2 : register(ps, s[3]) = sampler_state { Texture = (Tex2Bump); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};
sampler2D DiffuseTex3 : register(ps, s[4]) = sampler_state { Texture = (Tex3); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};
sampler2D BumpTex3 : register(ps, s[5]) = sampler_state { Texture = (Tex3Bump); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};

sampler2D ShadowMap : register(ps, s[7]) = sampler_state { Texture = (TexShadowMap); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};

sampler2D DitherTex : register(ps, s[15]) = sampler_state { Texture = (TexDither); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};

bool DitherFlag: register( ps, b[4] ) = false;
bool ShadowsFlag: register( ps, b[1] ) = true;

float4 AmbNDiff: register( ps, c[23] ) = float4(1.5,0.002,1.25,0.0);
float3 DitherClipParams: register( ps, c[21] ) = float3(-0.001,1.000,5.656);
float4 DitherTexParams: register( ps, c[20] ) = float4(0.016,0.016,0.008,0.008);
float4 Exposure: register( ps, c[24] ) = float4(0.022,0.98,-0.150,0.000);
float3 FogColor: register( ps, c[29] ) = float3(0.405,0.89,0.720);
float3 LightVec: register( ps, c[14] ) = float3(-0.784,0.5588,-0.196);
float4 SelCascade: register( ps, c[35] ) = float4(0.007,-0.013,0.5,1.0);
float4x3 ShadowMats[4]: register( ps, c[36] );
//    float4(0.002,-0.001,-0.000,0.289),
//    float4(-0.001,-0.002,-0.002,0.487),
//    float4(0.000,-0.000,-0.000,0.989)};
float3x3 ShadowNormalMat: register( ps, c[17] );
float4 ShadowNormalOffset: register( ps, c[22] )= float4(0.318,1.260,5.027,27.862);
float3 SunColor: register( ps, c[15] ) = float3(3.61,3.24,2.560);

// VertexShader parameters

float4 AmbLevel : register( vs, c[30] ) = float4(0.2013,0.450,0.450,10.500);
float3 CameraPos : register( vs, c[32] );
float4 RangeFog : register( vs, c[31] ) = float4(2.718,0.0,0.0,0.000015);
float4x4 ShadowMtx : register( vs, c[24] );
float4 TerrainAmbient : register( vs, c[48] ) = float4(1.00,1.00,1.0,0.0);
float3x2 TexMat1 : register( vs, c[34] ) = float3x2(1.0,0,0,0,1,0);
float3x2 TexMat2 : register( vs, c[36] );
float4 TexUVMod1 : register( vs, c[38] ) = float4(0.0,0.0,1.0,1.0);
float4 TexUVMod2 : register( vs, c[39] ) = float4(0.0,0.0,1.0,1.0);
float4 WorldOffset : register( vs, c[33] )= float4(0.0,0,0,0.0);
float4x3 WorldViewMtx : register( vs, c[9] );
float4x4 WorldViewProjMtx : register( vs, c[20] );

// Vertex Shader

//sampler2D Tex0 : register(s0); 

VertexShader VS_Main = asm
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
// Parameters:
//   float4 AmbLevel;
//   float3 CameraPos;
//   float4 RangeFog;
//   float4x4 ShadowMtx;
//   float4 TerrainAmbient;
//   float3x2 TexMat1;
//   float3x2 TexMat2;
//   float4 TexUVMod1;
//   float4 TexUVMod2;
//   float4 WorldOffset;
//   float4x3 WorldViewMtx;
//   float4x4 WorldViewProjMtx;
// Registers:
//   Name             Reg   Size
//   ---------------- ----- ----
//   WorldViewMtx     c9       3
//   WorldViewProjMtx c20      4
//   ShadowMtx        c24      3
//   AmbLevel         c30      1
//   RangeFog         c31      1
//   CameraPos        c32      1
//   WorldOffset      c33      1
//   TexMat1          c34      2
//   TexMat2          c36      2
//   TexUVMod1        c38      1
//   TexUVMod2        c39      1
//   TerrainAmbient   c48      1

    def c0, 2, -1, -1.44269502, -0
    dcl_position v0
    dcl_normal v1
    dcl_texcoord v2
    dcl_texcoord1 v3
    dcl_color v4
    dcl_color1 v5
    dcl_position o0
    dcl_color o1
    dcl_texcoord8 o2
    dcl_texcoord o3.xyz
    dcl_texcoord1 o4
    dcl_texcoord2 o5
    dcl_texcoord4 o6
    dcl_texcoord6 o7
    dcl_texcoord7 o8.xyz
    mad r0.xyz, v1, c0.x, c0.y
    dp3 r0.w, r0, r0
    rsq r0.w, r0.w
    mul o3.xyz, r0.w, r0
    add r0, c33, v0
    dp4 o0.x, r0, c20
    dp4 o0.y, r0, c21
    dp4 o0.z, r0, c22
    dp4 o0.w, r0, c23
    dp4 o7.w, r0, c11
    add r1.xyz, r0, -c32
    mul r1.xyz, r1, c31.w
    dp3 r0.w, r1, r1
    mul r0.w, r0.w, c0.z
    exp o4.w, r0.w
    mul r1.xyz, v5, v5
    mul r1.xyz, r1, c30
    mov r1.w, v5.w
    add o2, r1, c48
    mad r1.xyz, v2.xyxw, -c0.yyww, -c0.wwyw
    dp3 r2.x, r1, c34
    dp3 r2.y, r1, c35
    mad o5.zw, r2.xyxy, c38.z, c38.xyxy
    mov o5.xy, r2
    mad r1.xyz, v3.xyxw, -c0.yyww, -c0.wwyw
    dp3 r2.x, r1, c36
    dp3 r2.y, r1, c37
    mad o6.zw, r2.xyxy, c39.z, c39.xyxy
    mov o6.xy, r2
    add o4.xyz, -r0, c32
    mad r0, r0.xyzx, -c0.yyyw, -c0.wwwy
    dp4 o8.x, r0, c24
    dp4 o8.y, r0, c25
    dp4 o8.z, r0, c26
    mov o7.xyz, r0
    mov o1, v4

// approximately 36 instruction slots used


// Pixel Shader
PixelShader PS_Main = asm
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
// Parameters:
//   sampler2D DiffuseTex1;
//   float3 DitherClipParams;
//   bool DitherFlag;
//   sampler2D DitherTex;
//   float4 DitherTexParams;
//   float4 Exposure;
//   float3 FogColor;
//   float3 LightVec;
//   float4 SelCascade;
//   sampler2D ShadowMap;
//   float4x3 ShadowMats[4];
//   float3x3 ShadowNormalMat;
//   float4 ShadowNormalOffset;
//   bool ShadowsFlag;
//   float3 SunColor;
// Registers:
//   Name               Reg   Size
//   ------------------ ----- ----
//   ShadowsFlag        b1       1
//   DitherFlag         b4       1
//   LightVec           c14      1
//   SunColor           c15      1
//   ShadowNormalMat    c17      3
//   DitherTexParams    c20      1
//   DitherClipParams   c21      1
//   ShadowNormalOffset c22      1
//   Exposure           c23      1
//   FogColor           c29      1
//   SelCascade         c35      1
//   ShadowMats         c36     12
//   DiffuseTex1        s0       1
//   ShadowMap          s7       1
//   DitherTex          s15      1

    def c0, 8, -3.5, 0, 3
    def c1, 0.308600008, 0.609399974, 0.0820000023, 1
    def c2, 1, 2, 3, 4
    def c3, 1, 0, -1, -2
    def c4, 0.5, 0, 0, 0
    dcl_color v0.w
    dcl_texcoord8 v1
    dcl_texcoord v2.xyz
    dcl_texcoord1 v3
    dcl_texcoord2 v4.xy
    dcl_texcoord7 v5.xyz
    dcl vPos.xy
    dcl_2d s0
    dcl_2d s7
    dcl_2d s15
    dp3 r0.x, v3, v3
    rsq r0.x, r0.x
    if b4
      rcp r0.y, r0.x
      mad r0.zw, vPos.xyxy, c20.xyxy, c20
      texld r1, r0.zwzw, s15
      mul r0.z, r1.w, c21.y
      mad r0.y, r0.y, c21.x, r0.z
      add r1, r0.y, c21.z
      texkill r1
    nrm r1.xyz, v2
    dp3_sat r0.y, r1, c14
    add r0.z, -r0.y, c1.w
    mul r0.w, r0.z, r0.z
    mad r0.z, r0.z, -r0.w, c1.w
    mul r0.y, r0.y, r0.z
    mul r0.y, r0.y, c4.x
    mul_pp r0.xzw, r0.x, v3.xyyz
    dp3_pp r1.w, r1, r0.xzww
    add r1.w, r1.w, r1.w
    mad_pp r0.xzw, r1.w, r1.xyyz, -r0
    if b1
      mad r1.w, v5.z, c35.x, c35.y
      log r1.w, r1.w
      mad r1.w, r1.w, c35.z, c35.w
      max r2.x, r1.w, c0.z
      min r1.w, r2.x, c0.w
      frc r2.x, r1.w
      add r2.x, r1.w, -r2.x
      add r3, r1.w, c3
      add r4, -r1.w, c2
      min r5, r3, r4
      max r3, r5, c0.z
      dp4 r1.w, r3, c22
      dp3 r3.x, r1, c17
      dp3 r3.y, r1, c18
      dp3 r3.z, r1, c19
      mad r1.xyz, r3, r1.w, v5
      add r2.y, r2.x, -c2.y
      mov r1.w, c1.w
      mov r3, c38
      cmp r3, -r2_abs.x, r3, c41
      mov r4, c44
      cmp r4, -r2.y, r4, c47
      cmp r3, r2.y, r4, r3
      dp4 r3.z, r1, r3
      mov r4, c36
      cmp r4, -r2_abs.x, r4, c39
      mov r5, c42
      cmp r5, -r2.y, r5, c45
      cmp r4, r2.y, r5, r4
      dp4 r3.x, r1, r4
      mov r4, c37
      cmp r4, -r2_abs.x, r4, c40
      mov r5, c43
      cmp r5, -r2.y, r5, c46
      cmp r2, r2.y, r5, r4
      dp4 r3.y, r1, r2
      mov r3.w, c1.w
      texldp r1, r3, s7
      mov r1.w, r1.x
      mad_sat r2.x, v0.w, c0.x, c0.y
      add r1.w, -r2.x, c1.w
    dp3_sat_pp r0.x, r0.xzww, c14
    mul r0.x, r0.x, r0.x
    mul r0.z, r0.x, r0.x
    dp2add_pp r0.x, r0.x, r0.z, r0.y
    mul_pp r1.xyz, r1.w, c15
    mad_pp r0, r0.x, r1, v1
    texld r1, v4, s0
    dp3 r2.x, r1, c1
    lrp r3.xyz, c23.w, r2.x, r1
    mad r0.xyz, r3, r0, -c29
    mad_pp oC0.xyz, v3.w, r0, c29
    mul_pp r0.x, r0.w, r1.w
    mov_pp oC0.w, r0.x

// approximately 86 instruction slots used (3 texture, 83 arithmetic)


// Technique Section for Effect Workspace.Effect Group 2.Textured
technique Textured
    pass Pass_0
        Texture[0] = <Tex1>;
        Texture[2] = <Tex2>;
        Texture[4] = <Tex3>;
        Texture[1] = <Tex1Bump>;
        Texture[3] = <Tex2Bump>;
        Texture[5] = <Tex3Bump>;
        Texture[6] = <TexDither>;
        Texture[7] = <TexShadowMap>;

        Sampler[0] = <DiffuseTex1>;
        Sampler[1] = <BumpTex1>;
        Sampler[2] = <DiffuseTex2>;
        Sampler[3] = <BumpTex2>;
        Sampler[4] = <DiffuseTex3>;
        Sampler[5] = <BumpTex3>;
        Sampler[7] = <ShadowMap>;

        //PixelShaderBool[1] = <ShadowsFlag>;
        //PixelShaderBool[4] = <DitherFlag>;

        PixelShaderConstant[14] = <LightVec>;
        PixelShaderConstant[15] = <SunColor>;
        PixelShaderConstant[17] = <ShadowNormalMat>;
        PixelShaderConstant[20] = <DitherTexParams>;
        PixelShaderConstant[21] = <DitherClipParams>;
        PixelShaderConstant[22] = <ShadowNormalOffset>;
        PixelShaderConstant[23] = <AmbNDiff>;
        PixelShaderConstant[24] = <Exposure>;
        PixelShaderConstant[29] = <FogColor>;
        PixelShaderConstant[35] = <SelCascade>;
        PixelShaderConstant[36] = <ShadowMats>;

        VertexShaderConstant[9]  = <WorldViewMtx>;
        VertexShaderConstant[20]  = <WorldViewProjMtx>;
        VertexShaderConstant[24]  = <ShadowMtx>;
        VertexShaderConstant[30]  = <AmbLevel>;
        VertexShaderConstant[31]  = <RangeFog>;
        VertexShaderConstant[32]  = <CameraPos>;
        VertexShaderConstant[33]  = <WorldOffset>;
        VertexShaderConstant[34]  = <TexMat1>;
        VertexShaderConstant[36]  = <TexMat2>;
        VertexShaderConstant[38]  = <TexUVMod1>;
        VertexShaderConstant[39]  = <TexUVMod2>;
        VertexShaderConstant[48]  = <TerrainAmbient>;

        //FILLMODE = SOLID;
        //CULLMODE = NONE;
        //CLIPPING = FALSE;

        VertexShader = (VS_Main);
        PixelShader = (PS_Main);


Share this post

Link to post
Share on other sites

DX11 only supports loading bytecode that was compiled by the HLSL compiler. There is no longer an assembler, so your only option is to author in HLSL. HLSL also changed quite a bit since DX9, so even your shader code will likely need to be overhauled to make it compile and work.


Also, this forum supports "code" tags for posting code if you'd like to use that in the future.

Edited by MJP

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By AxeGuywithanAxe
      I wanted to see how others are currently handling descriptor heap updates and management.
      I've read a few articles and there tends to be three major strategies :
      1 ) You split up descriptor heaps per shader stage ( i.e one for vertex shader , pixel , hull, etc)
      2) You have one descriptor heap for an entire pipeline
      3) You split up descriptor heaps for update each update frequency (i.e EResourceSet_PerInstance , EResourceSet_PerPass , EResourceSet_PerMaterial, etc)
      The benefits of the first two approaches is that it makes it easier to port current code, and descriptor / resource descriptor management and updating tends to be easier to manage, but it seems to be not as efficient.
      The benefits of the third approach seems to be that it's the most efficient because you only manage and update objects when they change.
    • By evelyn4you
      until now i use typical vertexshader approach for skinning with a Constantbuffer containing the transform matrix for the bones and an the vertexbuffer containing bone index and bone weight.
      Now i have implemented realtime environment  probe cubemaping so i have to render my scene from many point of views and the time for skinning takes too long because it is recalculated for every side of the cubemap.
      For Info i am working on Win7 an therefore use one Shadermodel 5.0 not 5.x that have more options, or is there a way to use 5.x in Win 7
      My Graphic Card is Directx 12 compatible NVidia GTX 960
      the member turanszkij has posted a good for me understandable compute shader. ( for Info: in his engine he uses an optimized version of it )
      Now my questions
       is it possible to feed the compute shader with my orignial vertexbuffer or do i have to copy it in several ByteAdressBuffers as implemented in the following code ?
        the same question is about the constant buffer of the matrixes
       my more urgent question is how do i feed my normal pipeline with the result of the compute Shader which are 2 RWByteAddressBuffers that contain position an normal
      for example i could use 2 vertexbuffer bindings
      1 containing only the uv coordinates
      2.containing position and normal
      How do i copy from the RWByteAddressBuffers to the vertexbuffer ?
      (Code from turanszkij )
      Here is my shader implementation for skinning a mesh in a compute shader:
      1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 struct Bone { float4x4 pose; }; StructuredBuffer<Bone> boneBuffer;   ByteAddressBuffer vertexBuffer_POS; // T-Pose pos ByteAddressBuffer vertexBuffer_NOR; // T-Pose normal ByteAddressBuffer vertexBuffer_WEI; // bone weights ByteAddressBuffer vertexBuffer_BON; // bone indices   RWByteAddressBuffer streamoutBuffer_POS; // skinned pos RWByteAddressBuffer streamoutBuffer_NOR; // skinned normal RWByteAddressBuffer streamoutBuffer_PRE; // previous frame skinned pos   inline void Skinning(inout float4 pos, inout float4 nor, in float4 inBon, in float4 inWei) {  float4 p = 0, pp = 0;  float3 n = 0;  float4x4 m;  float3x3 m3;  float weisum = 0;   // force loop to reduce register pressure  // though this way we can not interleave TEX - ALU operations  [loop]  for (uint i = 0; ((i &lt; 4) &amp;&amp; (weisum&lt;1.0f)); ++i)  {  m = boneBuffer[(uint)inBon].pose;  m3 = (float3x3)m;   p += mul(float4(pos.xyz, 1), m)*inWei;  n += mul(nor.xyz, m3)*inWei;   weisum += inWei;  }   bool w = any(inWei);  pos.xyz = w ? p.xyz : pos.xyz;  nor.xyz = w ? n : nor.xyz; }   [numthreads(1024, 1, 1)] void main( uint3 DTid : SV_DispatchThreadID ) {  const uint fetchAddress = DTid.x * 16; // stride is 16 bytes for each vertex buffer now...   uint4 pos_u = vertexBuffer_POS.Load4(fetchAddress);  uint4 nor_u = vertexBuffer_NOR.Load4(fetchAddress);  uint4 wei_u = vertexBuffer_WEI.Load4(fetchAddress);  uint4 bon_u = vertexBuffer_BON.Load4(fetchAddress);   float4 pos = asfloat(pos_u);  float4 nor = asfloat(nor_u);  float4 wei = asfloat(wei_u);  float4 bon = asfloat(bon_u);   Skinning(pos, nor, bon, wei);   pos_u = asuint(pos);  nor_u = asuint(nor);   // copy prev frame current pos to current frame prev pos streamoutBuffer_PRE.Store4(fetchAddress, streamoutBuffer_POS.Load4(fetchAddress)); // write out skinned props:  streamoutBuffer_POS.Store4(fetchAddress, pos_u);  streamoutBuffer_NOR.Store4(fetchAddress, nor_u); }  
    • By mister345
      Hi, can someone please explain why this is giving an assertion EyePosition!=0 exception?
      _lightBufferVS->viewMatrix = DirectX::XMMatrixLookAtLH(XMLoadFloat3(&_lightBufferVS->position), XMLoadFloat3(&_lookAt), XMLoadFloat3(&up));
      It looks like DirectX doesnt want the 2nd parameter to be a zero vector in the assertion, but I passed in a zero vector with this exact same code in another program and it ran just fine. (Here is the version of the code that worked - note XMLoadFloat3(&m_lookAt) parameter value is (0,0,0) at runtime - I debugged it - but it throws no exceptions.
          m_viewMatrix = DirectX::XMMatrixLookAtLH(XMLoadFloat3(&m_position), XMLoadFloat3(&m_lookAt), XMLoadFloat3(&up)); Here is the repo for the broken code (See LightClass) https://github.com/mister51213/DirectX11Engine/blob/master/DirectX11Engine/LightClass.cpp
      and here is the repo with the alternative version of the code that is working with a value of (0,0,0) for the second parameter.
    • By mister345
      Hi, can somebody please tell me in clear simple steps how to debug and step through an hlsl shader file?
      I already did Debug > Start Graphics Debugging > then captured some frames from Visual Studio and
      double clicked on the frame to open it, but no idea where to go from there.
      I've been searching for hours and there's no information on this, not even on the Microsoft Website!
      They say "open the  Graphics Pixel History window" but there is no such window!
      Then they say, in the "Pipeline Stages choose Start Debugging"  but the Start Debugging option is nowhere to be found in the whole interface.
      Also, how do I even open the hlsl file that I want to set a break point in from inside the Graphics Debugger?
      All I want to do is set a break point in a specific hlsl file, step thru it, and see the data, but this is so unbelievably complicated
      and Microsoft's instructions are horrible! Somebody please, please help.

    • By mister345
      I finally ported Rastertek's tutorial # 42 on soft shadows and blur shading. This tutorial has a ton of really useful effects and there's no working version anywhere online.
      Unfortunately it just draws a black screen. Not sure what's causing it. I'm guessing the camera or ortho matrix transforms are wrong, light directions, or maybe texture resources not being properly initialized.  I didnt change any of the variables though, only upgraded all types and functions DirectX3DVector3 to XMFLOAT3, and used DirectXTK for texture loading. If anyone is willing to take a look at what might be causing the black screen, maybe something pops out to you, let me know, thanks.
      Also, for reference, here's tutorial #40 which has normal shadows but no blur, which I also ported, and it works perfectly.
  • Advertisement