• 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
Tim Coolman

Understanding Buffer, Texture, and Sampler "registers"

9 posts in this topic

Good questions Tim, and ones I would like to know the answers to too.

Have you tried defining 2 constant buffers with the same register on the HLSL side?
My guess would be that you can, and then so long as you only set one of them from the C++ side and then only use one of them on your shader side you should be fine.

For example, imagine your game is a car racing game. In your code you might draw the roads first and then the cars in a separate Draw call.

So, when you draw the roads you could have a RoadParams specific constant buffer assigned to B0 and then set the appropriate Pixel Shader etc.

Once complete you could then assign a completely different CarParams constant buffer to B0, and set a different Pixel Shader (One that uses these params and draws car pixels instead of road pixels).

I'd imagine that should work fine, but I've not tried it.

Thanks
Ben
1

Share this post


Link to post
Share on other sites
[quote name='BenS1' timestamp='1352298391' post='4998415']
Have you tried defining 2 constant buffers with the same register on the HLSL side?
[/quote]

I have not tried this. I thought I read on another forum post that for registers to be reused they have to be "compatible" in some way. But I understand what you mean. If you have two different constant buffers defined with the same register slot in HLSL, maybe it is okay to use one or the other from a given shader as long as that slot has been provided with appropriate data from C++ first.

Anyone else know the answer? I won't know for sure until I have time to set up an experiment.

Thanks,
Tim
0

Share this post


Link to post
Share on other sites
You can bind up to 14 constant buffers per pipeline stage (and up to 128 texture buffers per pipeline stage). See the remarks here: [url="http://msdn.microsoft.com/en-us/library/bb509581(VS.85).aspx"]http://msdn.microsoft.com/en-us/library/bb509581(VS.85).aspx[/url] .
0

Share this post


Link to post
Share on other sites
[quote name='MikeBMcL' timestamp='1352339241' post='4998687']
You can bind up to 14 constant buffers per pipeline stage (and up to 128 texture buffers per pipeline stage).
[/quote]

I understand that. The thing I'm still unsure about is whether you can use the same register number for multiple [i]cbuffer[/i] structures in the same HLSL file, as long as you don't use more than one of those in a given pipeline stage.

For example, can you do this...
[source lang="cpp"]cbuffer BufferForVertexShader : register(b0)
{
float variable1;
float variable2;
uint variable3;
};

cbuffer BufferForPixelShader : register(b0)
{
float4x4 variable1;
float4 variable2;
int variable3;
int variable4;
};[/source]
... as long as you only access one cbuffer from either pipeline stage and have the proper buffer bound to slot 0 for each shader? Or does this cause compilation problems within the same HLSL file and require you to separate them out into different files?

Thanks.
0

Share this post


Link to post
Share on other sites
You can, yes, though it's probably better to just use an include file for common structs and define the shader-specific buffers in each shader's HLSL file. Or are you planning to put all of the shaders into one file?

(Note: By "you can" I mean that I tested compiling a vertex and pixel shader with two cbuffers both assigned to register(b0) where only one of those cbuffers is used and that I received no compile errors using the built-in shader compilation with VS 2012 and the Windows 8 SDK; you might have different results if you compile using an older version of fxc even though it should in theory work fine. It's not super hard to test so if you are using an older fxc, just try it and see what happens.).
2

Share this post


Link to post
Share on other sites
Thanks for the clarification MJP, that's what I was trying to say in my post above.
0

Share this post


Link to post
Share on other sites
Thanks to both MikeBMcL and MJP for your input. This really helps clarify things for me. Always helps to understand a little bit better how things work, even the things that happen "behind the scenes".
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