• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
fs1

Port HLSL to x86 Assembly

14 posts in this topic

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

 

Thanks!

 

0

Share this post


Link to post
Share on other sites

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,

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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?

2

Share this post


Link to post
Share on other sites

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?
0

Share this post


Link to post
Share on other sites

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
1

Share this post


Link to post
Share on other sites

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.
2

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0