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

Constant buffer mapping problem.

8 posts in this topic

RESOLVED : For the newbie's purpose, the problem was simply that i thought padding could occur anywhere (in this case at the end of the struct). But the packing has to be done every 16 bytes involving padding in the middle of the struct.

 

Hi,

 

I'm new to d3d11 so i apologies for this newbie question.

 

I'm trying to map data to several cbuffer but it seems that only the first (register(cb0)) cbuffer is actually getting correct data. I have no control what so ever on what is written in the next ones.

 

The problem appears only in the pixel shader. I've tried to add an extra cbuffer in the vertex shader and there's i no problem.

I think i have correctly aligned data to 16 bytes packing.

I use the same MatrixBuffer for both vertex shader and pixel shader.

Map() call sequence order is irrelevant and doesn't change anything.

 

EDIT : I've managed to reduce code to the following snippet. I'm using same buffer for cbuffer TestBuffer. And it works in the vertex shader but not in the pixel shader.

 

EDIT 2 : If i set TestBuffer : register(cb0) and MatrixBuffer : register(cb1) in the pixel shader i now get this strange compile error :

+        compile_error    0x001b80e8 "error X4567: maximum cbuffer exceeded. target has 14 slots, manual bind to slot 4294967295 failed\n"
 

 

 

VertexShader :


// Typedefs
//------------------------------------------------
struct VertexInputType
{
    float4 position : POSITION;
	float3 normal   : NORMAL;
};

struct PixelInputType
{
    float4 v_position : SV_POSITION;
	float3 w_normal   : NORMAL;
	float3 w_position : TEXCOORD0;
};

// Globals
//------------------------------------------------
cbuffer MatrixBuffer
{
	float4x4 world;
	float4x4 view;
	float4x4 projection;
};

cbuffer TestBuffer
{
	float4 test;
}

// Shader
//------------------------------------------------
PixelInputType SPMLVShader(VertexInputType input)
{
    PixelInputType output;
	output.v_position = input.position;
	output.w_normal = input.normal;

    // Change the position vector to be 4 units for proper matrix calculations.
	input.position.w = 1.0f;
	
	// Calculate the position of the vertex in world coordinates.
	output.w_position = mul(input.position, world);

    // Calculate the position of the vertex against the world, view, and projection matrices.
    output.v_position.xyz = output.w_position.xyz;
    output.v_position = mul(output.v_position, view);
    output.v_position = mul(output.v_position, projection);
    
    // Calculate the normal vector against the world matrix only.
    output.w_normal = mul(input.normal, (float3x3)world);
	
    // Normalize the normal vector.
    output.w_normal = normalize(output.w_normal);
	
	// CORRECT OUTPUT
	if(test.x == 222 && test.y == 223 && test.z == 224 && test.w == 225)
	{
		return output;	
	}
	
	// DO NOT DISPLAY ANYTHING
	output.v_position = float4(0, 0, 0, 0);
	return output;
}

 

PixelShader :


//	Typedefs
//------------------------------------------------
struct PixelInputType
{
    float4 v_position : SV_POSITION;
	float3 w_normal   : NORMAL;
	float3 w_position : TEXCOORD;
};

//	Globals
//--------------------------------------
cbuffer MatrixBuffer
{
	float4x4 world;
	float4x4 view;
	float4x4 projection;
};

cbuffer TestBuffer
{
	float4 test;
};

float4 SPMLPShader(PixelInputType input) : SV_TARGET
{
	if(test.x == 222 && test.y == 223 && test.z == 224 && test.w == 225)
	{
		return float4(0.0f, 1.0f, 0.0f, 1.0f);
	}
	else
	{
		return float4(1.0f, 0.0f, 0.0f, 1.0f);
	}
}
 

 

I've been searching a lot, but i have no clue yet on where it comes from.

 

Best regards.

Edited by Lumz
0

Share this post


Link to post
Share on other sites

No,

 

I did try with registers and yet it didn't worked. I even swapped first and second cbuffer to ensure that apparition order is irrelevant.

And PSSetConstantBuffers call sequence is irrelevant too.

0

Share this post


Link to post
Share on other sites

Sorry, my mistake. Constant buffers go into b0 - bsomething registers.
Therefore:

cbuffer MatrixBuffer : register(b0) { ... };
cbuffer TestBuffer : register(b1) { ... };
0

Share this post


Link to post
Share on other sites

I typically don't specify exact registers for my constant buffers.  If you remove the register declarations, and then compile the shaders using FXC.exe, you can output a text listing of the results.  This will show you precisely which registers are expected, as well as which type.  Try this out and I think you will see where the issue lies.

0

Share this post


Link to post
Share on other sites

I think i've reduced the problem to that :

It is simply not possible to use an array of custom struct types in a cbuffer. It doesn't seems to have anything to do with the register order.

 

Btw : i'd like to try the fxc.exe but i've never used it before. Could you just post the standard compile command ?

 

Thank you.

0

Share this post


Link to post
Share on other sites

It depends on the name of the file, the shader main function name, the shader model being targetted, and the output file name.  Something like this on the command line should do the trick:

 

fxc AmbientOcclusion.hlsl /T cs_4_0 /E CSMAIN /Zi /Cc /Fc AmbientOcclusion.html

 

That will produce an output html file that you can see the details of your shader from.  I normally put this command into a batch file, since retyping it over and over gets old...

 

EDIT: Where are you using an array of custom structs in your CB's?  I don't see that anywhere...

Edited by Jason Z
0

Share this post


Link to post
Share on other sites

I get this : 

error X3084: "numthreads(X, Y, Z)" attribute expected, where "X, Y, Z" are the dimensions of the thread group.

 

And yes, i've been turning around so much the shader's code that i simply forgot what i started with. After checking every single variable in several cbuffers i've noticed that only those with custom struct was unable to map correctly.

 

Btw : Thank you for your concern. I've been stuck on this for days.

Edited by Lumz
0

Share this post


Link to post
Share on other sites

That error means that you didn't declare the number of thread groups within your compute shader.  Since you aren't dealing with compute shaders, that means you probably need to change the parameters on the command line that I listed above to match the type of shader you are targetting.  For example, if it is a vertex shader, then you pass vs_5_0 instead of cs_4_0 from above.  Also be sure to update the function's entry point name as well to match what you are targetting!

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