• 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
BClarenbach

16 Byte Alignment on Value Types

10 posts in this topic

Hi,

I need a 16 byte alignment on certain value types to accurately mirror value classes we pass into our interface. I've tried overloading the memory allocator but that does not seem to work, I still get unaligned addresses for value types created by AngelScript.
I noticed there is an 8 byte alignment flag, but that does not seem to do anything at all.

Could you point me to where I can modify this and turn the 8byte into a functional 16 byte alignment flag?

Thanks!
0

Share this post


Link to post
Share on other sites
So far the only way to guarantee memory alignment is with scoped reference types.

I have plans to add support for per-type memory alignment with registered types, but it is not an easy thing to do, and is quite low on my priorities.
1

Share this post


Link to post
Share on other sites
I've run into a problem with the scoped reference type. :)

I have the following registration call:
[source lang="cpp"]

r = _engine->RegisterObjectMethod("vector", "vector &opAdd(const vector &in) const",
asMETHODPR(Vector, operator+, (const Vector &) const, Vector), asCALL_THISCALL);

[/source]
and this binds to a class method of class Vector that is declared like this:
[source lang="cpp"]

Vector operator+( const Vector& _rhs ) const;

[/source]
There seems to be no way to declare the method in a working fashion. If I leave the reference out in the angelscript type, I cannot register the method. If I remove the reference on the c++ side, I hit a road block because it is 16 bytes aligned and value parameters do not work with alignment restrictions.

If I use both the way they are, I get a 0-pointer on the _rhs parameter.

Any ideas on how to work around this?

Thanks!

ps.: I dug up the old post so you knew the troubles I had with declaring vector a scoped reference and why I did it. Edited by BClarenbach
0

Share this post


Link to post
Share on other sites
The problem appears to be amazingly similar to http://www.gamedev.net/topic/507813-operator-addsubmultiplydivide-with-scoped-types/ :)
0

Share this post


Link to post
Share on other sites
Unfortunately you can only register this method through a wrapper, as AngelScript requires that the scoped type is allocated on the heap where the application controls the alignment.

Here's an example wrapper:

[code]
Vector *wrapper_VectorAdd(const Vector &_lhs, const Vector &_rhs)
{
return new Vector(_lhs + _rhs);
}

// Registered as...
r = _engine->RegisterObjectMethod("vector", "vector @opAdd(const vector &in) const",
asFUNCTION(wrapper_VectorAdd), asCALL_CDECL_OBJFIRST);
[/code]

Despite the scoped type not normally supporting handles, it should still be used in this case to let AngelScript know you're returning a new instance, rather than a reference to an existing instance. This will allow AngelScript to free the object after using the returned instance.


I have plans to implement support for memory aligned value types. However, this is unfortunately a very complex subject, where the alignment needs to be guaranteed everywhere, local variables on the stack, as members of a class, when returned from an application function, etc. And most importantly since this needs to be guaranteed in the platform independent bytecode too where the alignment requirements can be different on different platforms. Edited by Andreas Jonsson
1

Share this post


Link to post
Share on other sites
With modern SIMD architectures, we're looking mostly at 4 and 16 byte alignments. If AS would provide those two, my guesstimate is that almost everyone is happy.

If your class needs 8 bytes alignment, you are probably happy with 16 byte alignments, too.
If your class needs alignments over 16 bytes, you are most likely ok to allocate the memory in a different location and wrap the access. (e.g. 4k pages etc.)

If an align16 object flag is reasonably easy to implement, that would be fabulous. Right now, I had to switch to unaligned reads for my simd types which makes the bridge between native and scripted code somewhat cumbersome. No, I am not going to do performance relevant math operations in scripts :) but passing values in and out of registered functions that use an equivalent math class like we have in the native code makes it easier to read and maintain.
0

Share this post


Link to post
Share on other sites
Doing 8 or 16 byte alignments, or both, is about the same complexity. The complexity doesn't come from size of the alignment, but rather from the restriction that there is an alignment that needs to be guaranteed, and that this alignment can be different on different platforms.

For now I would suggest continuing to use scoped reference types, and wrap only those functions/methods that take or return the Vector by value. This is in my opinion much less work than to use two completely different types to represent the memory aligned and non-memory aligned Vector type.
0

Share this post


Link to post
Share on other sites
Hi,

I tried to implement your wrapper idea but it seems that the type registration does not allow @ modifiers when using scoped types.
[source lang="bash"]Object handle is not supported for this type
Failed in call to function 'RegisterObjectMethod' with 'vector' and 'vector @opAdd(const vector &in) const' (Code: -10)[/source]

Any ideas? The signature of the wrapper is like you mentioned in your post.

Thanks for the help! Edited by BClarenbach
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