• 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

Resources for writing a JIT compiler for my own markup graph system (with focus on x86 and Android)

1 post in this topic

I'm working on my own markup system, which is graph based (a la Kismet). It can currently output GLSL code and it wouldn't be overly complex to extend it to make use of a scripting language such as Lua. I'm limited to the the same instruction set supported by modern shaders, although things like bitwise operations wouldn't make it into the initial set.

I'm trying to come up with a contingency solution for when the relevant shader profile isn't available or isn't desired, and emulate the same functionality in software. As mentioned, it wouldn't be too difficult to do this through LUA or make use of Dalvik directly on Android, but since I'm curious and somewhat stubborn, I'd like to at least try and write my own native code compiler - for starters for x86. With a limited instruction set, no planned code-generation optimizations or code parsing (since the input is a graph system), this should be a simple matter of stacking CPU instructions on top of each other.

There is a lot of material on the web on compiler programming, but I have a feeling I don't really need to delve into most of this. Can anyone suggest good webpages to get the kind of information I need or would I be better off just taking a reverse engineering approach, implementing all of the required functionality in a higher level language and working it out from the disassembly?

Note that I really am trying to jump the gun here by avoiding getting knee-deep in a field that has decades of experience and literature to show for it. However, I feel that in view of my modest requirements and no interest in focusing too heavily on the topic, the time required to parse through hundreds of resources could be more effectively spent elsewhere while still achieving what I need. If I'm being naive in my assumptions, don't be shy to just say so - this is something I'd like to try to do myself, not something I absolutely need. Edited by irreversible

Share this post

Link to post
Share on other sites
To get decent performance I'd suggest an offline process that goes something like this (I'm assuming generating hlsl as well as glsl won't be too hard as they are very similar):

1. Run fxc.exe on the hlsl to turn it into assembly instructions and optimize it.
2. Generate a list of variables. To simplify swizzling ("foo.zwx") I'd treat each component as a separate variable.
3. Convert each variable declaration and assembly instruction into C/C++ code. It might be simplest to write a function for each instruction, and then just generate a bunch of function calls, which the compiler should inline.
4. Compile the generated code in your favourite compiler on the target platforms.

If you really want to generate machine code directly you need to replace steps 3 and 4. The new step 3/4 would be something like:

3. Allocate some memory to hold the variables, keeping track of where each one is. Then for each instruction in the program, translate that into a block of code, patching in the correct address for each variable and branch target. If the instruction is the start of a loop you'll also need to keep track of it's address so you can branch to it at the end of the loop.
4. Generate a single ret instruction at the end so you can call it via a function pointer from your C/C++ code. Parameter passing can be done by writing to those variables.

To create the block of machine code for each instruction you have a couple of options:
1. Use a C/C++ compiler to generate a function for each instruction as above. You then just need to generate a bunch of function calls passing the right parameters in machine code. This obviously adds a bunch of function calling overhead, but the functions themselves can be optimized, and you'll only have to generate a few different instructions (push address_of_variable; call address_of_function; test eax,eax; jnz start_of_loop_address).
2. Use a C/C++ compiler to generate code, and look at the assembly to work out where the addresses of the variables / branch targets go. This isn't as easy as you might think as the compiler may optimize things into registers, and use forms of instructions which take a [url="http://stackoverflow.com/questions/1546141/jmp-to-absolute-address-op-codes"]relative offset[/url] instead of a complete address. So you'll have some work to do to get the instructions you need.

All of those options will require you to be comfortable with reading disassembly on your target platforms.

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