Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Port HLSL to x86 Assembly


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 fs1   Members   -  Reputation: 363

Like
0Likes
Like

Posted 18 February 2014 - 11:59 AM

Is there a tutorial/literature on how to port HLSL to Assembly? Is this possible?

 

Thanks!

 



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 9491

Like
0Likes
Like

Posted 18 February 2014 - 12:17 PM

Could you talk a little about why you want to do this.  HLSL code you write doesn't run on the CPU to begin with, so this doesn't seem to make much sense,


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 Chris_F   Members   -  Reputation: 2685

Like
3Likes
Like

Posted 18 February 2014 - 12:23 PM

I'm not aware of any HLSL compiler that will output x86 assembly.

 

What you could maybe do is use the Microsoft HLSL compiler to output HLSL IR and then use this to convert the HLSL IR -> GLSL, and then use MESA to convert GLSL -> LLVM IR, then finally use LLVM to get x86 assembly.



#4 fs1   Members   -  Reputation: 363

Like
0Likes
Like

Posted 18 February 2014 - 12:34 PM

Could you talk a little about why you want to do this.  HLSL code you write doesn't run on the CPU to begin with, so this doesn't seem to make much sense,

 

I need to recreate in the CPU, some of the calculations done in the GPU.

 

So, taking advantage I am familiar with x86 wanted to port HLSL to Assembly.

 

I'm not aware of any HLSL compiler that will output x86 assembly.

 

What you could maybe do is use the Microsoft HLSL compiler to output HLSL IR and then use this to convert the HLSL IR -> GLSL, and then use MESA to convert GLSL -> LLVM IR, then finally use LLVM to get x86 assembly.

 

Thanks! I will take a look.



#5 Ravyne   GDNet+   -  Reputation: 10629

Like
2Likes
Like

Posted 18 February 2014 - 01:13 PM

It depends somewhat on what kinds of operations you're using, but a fair number of HLSL instructions map fairly directly to different flavors of SSE -- If you can use SSE, that will be your highest-performing option. Otherwise, you need a scalar fall-back using normal x86 instructions. You can use intrinsic functions for the former.

 

Now, that said -- you don't need to port the HLSL to assembly language. What you need to do is understand what the HLSL is accomplishing and then write a version of teh same algorithm in whatever language you choose. It doesn't have to be x86 or SSE assembly/intrinsic functions.

 

How much HLSL is it? Can you post the code?


throw table_exception("(ノ ゜Д゜)ノ ︵ ┻━┻");


#6 fs1   Members   -  Reputation: 363

Like
0Likes
Like

Posted 18 February 2014 - 06:33 PM

It depends somewhat on what kinds of operations you're using, but a fair number of HLSL instructions map fairly directly to different flavors of SSE -- If you can use SSE, that will be your highest-performing option. Otherwise, you need a scalar fall-back using normal x86 instructions. You can use intrinsic functions for the former.
 
Now, that said -- you don't need to port the HLSL to assembly language. What you need to do is understand what the HLSL is accomplishing and then write a version of teh same algorithm in whatever language you choose. It doesn't have to be x86 or SSE assembly/intrinsic functions.
 
How much HLSL is it? Can you post the code?

It makes sense, but there is a lot of code so that's why wanted to port it. Maybe have to replace specific HLSL math functions but may be there is already a Lib out there?

#7 MJP   Moderators   -  Reputation: 13648

Like
1Likes
Like

Posted 18 February 2014 - 07:32 PM

You may want to check out SlimShader.



#8 Ryan_001   Prime Members   -  Reputation: 1752

Like
3Likes
Like

Posted 18 February 2014 - 07:55 PM

AFAIK Direct3D11 has the option to create a software WARP device http://msdn.microsoft.com/en-us/library/windows/desktop/gg615082(v=vs.85).aspx.  That way shader could would be run on the CPU.  I've never used it so I don't how well it runs though...



#9 pcmaster   Members   -  Reputation: 723

Like
1Likes
Like

Posted 19 February 2014 - 03:31 AM

DX11 WARP runs very well (and slow but that's not the problem, right?), however that's not quite just what OP asked, I guess..


Edited by pcmaster, 19 February 2014 - 03:31 AM.


#10 Ryan_001   Prime Members   -  Reputation: 1752

Like
2Likes
Like

Posted 19 February 2014 - 04:09 AM

DX11 WARP runs very well (and slow but that's not the problem, right?), however that's not quite just what OP asked, I guess..

Well... he said "I need to recreate in the CPU, some of the calculations done in the GPU." which... I'm not sure exactly what he has in mind TBH.  I just thought I'd mention it as an option, but you are correct in that it is not a HLSL to x86 assembly converted in the sense that the assembly could then be extracted and used elsewhere, though I imagine somewhere deep inside is a hlsl bytecode to assembly converter.  So... ummm ya, without more info from the OP I'm not really sure TBH.

#11 fs1   Members   -  Reputation: 363

Like
0Likes
Like

Posted 19 February 2014 - 07:45 AM

Thanks to all.

 

 

DX11 WARP runs very well (and slow but that's not the problem, right?), however that's not quite just what OP asked, I guess..

Well... he said "I need to recreate in the CPU, some of the calculations done in the GPU." which... I'm not sure exactly what he has in mind TBH.  I just thought I'd mention it as an option, but you are correct in that it is not a HLSL to x86 assembly converted in the sense that the assembly could then be extracted and used elsewhere, though I imagine somewhere deep inside is a hlsl bytecode to assembly converter.  So... ummm ya, without more info from the OP I'm not really sure TBH.

 

 

I need to recreate all shader instructions in the CPU. My idea was porting all opcodes generated by the shader to x86. And run it in the CPU to replicate it.

 

HLSL Bytecode and x86 seem very similar, I am not familiar with HLSL but I code in ASM, that's why I was thinking of porting it.



#12 phil_t   Crossbones+   -  Reputation: 5652

Like
0Likes
Like

Posted 19 February 2014 - 11:04 AM

HLSL isn't too far syntactically from c++. If it's just some calculations you need you could probably put that code in a separate file, and #include it into both your HLSL and c++ code files. You might need a bit of macro magic to make everything work.



#13 pcmaster   Members   -  Reputation: 723

Like
0Likes
Like

Posted 20 February 2014 - 08:42 AM

There are sampling instructions which do various kinds of texture filtering and then there are vector instructions, fences and many things, which you'd have to emulate in SW.

 

HLSL compiles to D3D bytecode, which still isn't really "assembly" and that gets compiled (JIT) to real HW ASM. Do you want to emulate this in SW or what is the reason? I don't understand how the fact that you code in ASM helps you, since you'll have to get familiar with HLSL (which is C++ "like") anyway.



#14 fs1   Members   -  Reputation: 363

Like
0Likes
Like

Posted 20 February 2014 - 07:07 PM

There are sampling instructions which do various kinds of texture filtering and then there are vector instructions, fences and many things, which you'd have to emulate in SW.
 
HLSL compiles to D3D bytecode, which still isn't really "assembly" and that gets compiled (JIT) to real HW ASM. Do you want to emulate this in SW or what is the reason? I don't understand how the fact that you code in ASM helps you, since you'll have to get familiar with HLSL (which is C++ "like") anyway.

I am dissasembling the shader code, and that's why they seem very similar. I will follow your advices

#15 TheChubu   Crossbones+   -  Reputation: 6452

Like
0Likes
Like

Posted 20 February 2014 - 07:52 PM

I read the thread title as "Port HTML to x86 assembly", that would be quite the experience :D


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS