Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!

We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

Jason Z

Member Since 04 Feb 2004
Offline Last Active Nov 22 2014 02:18 PM

#5194161 Best way to Create a Grid

Posted by Jason Z on 22 November 2014 - 02:22 PM

Who needs buffers anyway ? wink.png

cbuffer Parameters
	uint Rows;
	matrix WorldViewProjection;

void LineGridVS(uint vid: SV_VertexID,
	out float4 color: COLOR,
	out float4 position: SV_Position)
    // which row ?
    uint n = vid / 2;	
    // line start or end (column coordinate)
    position.x = (vid % 2) * Rows;	
    // row coordinate (modulo needed for later flip to work)	
    position.z = n % (Rows + 1);
    position.y = 0;
    position.w = 1;
    // center around origin
    position.xz -= (Rows / 2);		
    color = float4(1,0,0,1);
    // rows or columns ? flip x and z (and also give a different color)
    if(n > Rows)
        position.xz = position.zx;
        color = float4(0,1,0,1);
    position = mul(position, WorldViewProjection);		
Don't bind neither vertex nor index buffer nor input layout. Call with context->Draw((rows + 1) * 4, 0); (Edit: Line list topology). Anything else (centering around camera and snapping) can be done with the transformation, as pointed out.

Nice weekend y'all!

Edit2: Minor corrections.



That's a easy way to get a grid on the screen, but it may take more GPU effort than is really needed.  It is usually sufficient just to make a grid and store it in some vertex/index buffers, and then you can easily transform the vertices and simply rasterize the geometry.  It will eliminate the vertex work being done to generate the lines, at the cost of a little bit of bandwidth.

#5192196 D3D11 Graphics Debugging under VS2012 (Missing Call)

Posted by Jason Z on 10 November 2014 - 07:43 PM

That's pretty strange...  for some reason I can't open the log file - it hangs the graphics debugger as soon as I try to open it :(


Even without it though - if you see that the vertex buffer is being set to null, can you check it on your CPU call to see if the buffer is null?  The argument should be directly mirrored with what you see in the log file, so what you are passing to the API should be a null as well.  Perhaps the buffer variable is being overwritten somewhere in between?

#5191724 D3D11 Graphics Debugging under VS2012 (Missing Call)

Posted by Jason Z on 07 November 2014 - 02:19 PM

I can send you the vsglog but if some of my API calls are not even showing up, how will that help you?

You are probably not capturing the first frame where the creation of the buffer takes place.  If you have the vsglog, you can see exactly why a primitive isn't showing up - it could be your input assembler configuration (if your buffer doesn't exist for some reason), it could be your VS transformations, it could be clipping/culling, it could vertex order, it could be depth/stencil buffer issues, it could be alpha blending state misconfigured, or it could even be the output merger state isn't right.  With a vsglog you can clearly identify why a particular draw call ends up the way it does.

#5191668 Resource management

Posted by Jason Z on 07 November 2014 - 08:29 AM

As described, used a raw pointer or reference (to the resource or to the shared_ptr) if the resource is guaranteed to outlive the pointer/reference. There's no way to check whether the resource is still valid, you can only assume.

This method is actually a very valid way to go, since you usually will bundle up the resources to be used in a particular 'level' together.  You can unload the resources when the level is finished (or whatever other logical construct you want to use) and in between you can utilize the naked pointer to your hearts content.  That provides a very lightweight system, and as long as your non-managing code doesn't delete a resource, it would be viable.


Personally I would rather utilize (and do utilize) a proxy in between the resource and its users.  This has many benefits, including the fact that the object that the client code has (the proxy in this case) does not have any ownership at all.  The reference only points to an object, but doesn't have the ability to keep it alive.  When you try to use it, the proxy is used to look up the reference and can check if the resource is still alive.  This lets you assert that there isn't any calls to a resource that was unloaded.


I found that an oldish post on the bitsquid blog was a pretty good reference for this type of discussion: http://bitsquid.blogspot.com/2011/09/managing-decoupling-part-4-id-lookup.html

#5191354 D3D11 Graphics Debugging under VS2012 (Missing Call)

Posted by Jason Z on 05 November 2014 - 11:11 AM

Yes, it looks like you are correctly enabling the debug device, so it should be good. Your log file only shows the closing part of the log though - it doesn't show anything from the startup.  Normally you will see messages about loading dlls and some other things related to the driver.  Did you truncate the log?


Regarding the full stream, I haven't actually done it with the graphics debugger.  Instead, you used to be able to do this with PIX, and I thought the graphics debugger has feature parity (although I may be wrong).  However, it doesn't matter since you proved that the buffers are correctly created with the description calls.


If you take a frame snapshot and save it to file (vsglog) then I can take a quick look to see what is happening there.  I suspect that the buffers are not the issue, but rather the transformations that are used or perhaps a viewport that is not properly set.  You can check the input assembler state to see if it has the buffers bound to it as you expected through the vsglog file.

#5191124 D3D11 Graphics Debugging under VS2012 (Missing Call)

Posted by Jason Z on 04 November 2014 - 09:33 AM

Are you capturing a full stream, or only a frame?  You could try to verify that the buffers were properly created by calling the GetDesc member function and verifying that the object allows you to actually access its data.  That way if your graphics tools are not catching the second buffer creation then you can still rule the creation part out.


Do you also have the debug runtime enabled?  If you enable it, then any obvious misconfigurations (like a potentially missing buffer) will get printed to the output console.

#5189213 Need some help, can't figure out what's wrong

Posted by Jason Z on 26 October 2014 - 06:56 AM

Ok I am trying to fix it but what does this mean "16 byte aligned boundaries" I don't even know what that is. And why do they have to be 16 byte aligned?

If you go to the link in my original answer, you will have a decent description of what the alignment of an object is, and why it matters in the case of the XMM registers.  I would also like to say, that you have received a number of good answers (and admittedly a few not so good ones too...) which should be more than enough for you to continue on debugging and experimenting on your own.  If someone points you towards alignment issues and you don't know about alignment, start to research it.  If you type in "C++ memory alignment Visual Studio" in Google, I'm 99% sure there is a full explanation waiting for you.  You should be willing to take the second step on your own, instead of waiting for someone to fully explain a basic concept to you.


Regarding the declaration syntax for aligned variables, you could do something similar and look up the documentation about the declspec keyword, where you are sure to find answers.  Take the initiative, and you will make much faster progress.

#5188357 [Solved] Stretching bug in Parallax Occlusion Mapping

Posted by Jason Z on 21 October 2014 - 12:45 PM

For case #2, I think that is an authoring problem.  If you assign texture coordinates in such a way that the texture itself is stretched more in one direction, then that is something you need to correct when you create your geometry - it isn't a problem to be solved in your shader!


I think the non-uniform scaling is also a very special case type of problem.  Do you really need non-uniform scaling on a cube?  I would say you should simply apply the texture coordinates to the geometry with the appropriate scaling that you want, and then just use uniform scaling and forget about it the issue!

#5188228 [Solved] Stretching bug in Parallax Occlusion Mapping

Posted by Jason Z on 20 October 2014 - 08:18 PM

It is hard to say what the issue is, but I would guess that either your input data incorrect (i.e. your normal space is not correctly defined at each vertex) or perhaps your matrices are not being passed correctly.  I recall seeing this type of error quite a few times during my own work with POM, so it isn't unusual.  My bet is that the matrices are incorrect, but of course that is just a guess...

#5187862 Help! GS StreamOutput..

Posted by Jason Z on 18 October 2014 - 12:36 PM

You can actually stream output and rasterize at the same time, you just use multiple stream outputs in your geometry shader.  You would append the single float4 to your stream output stream, and then just send your other geometry out another stream to be rasterized.  Have you tried that out yet?  Perhaps if you could show your steam output declaration entries, it might help to understand what you are currently set up for.

#5187822 A stable portable threading implementation

Posted by Jason Z on 18 October 2014 - 06:08 AM

Being able to start threads is like 0.5% of the work of doing useful parallelism.

I recommend Intel Threaded Building Blocks or Microsoft Parallel Programming Library (which _is_ portable!) as they help you solve the actually hard stuff.

I think this is a pretty insightful comment - the machinery of making threads is one thing, but being able to make good use of them is of course much harder.  Under the assumption that you are aware of the myriad issues with multithreaded program design, the higher level libraries that Sean mentions here will help you considerably in safely utilizing more of your available parallelism.  It is at least worth checking the docs on those libraries to see how they handle certain situations, and then use that to inform your own design if you go that route.

#5187560 Why not use UE4?

Posted by Jason Z on 16 October 2014 - 08:15 PM

Another point that I find attractive about both Unity and Unreal 4 is the built in cross platform capabilities.  I don't know anyone that enjoys resolving cross platform issues, so having a system designed to minimize that pain is a good thing all the way around.  That wasn't such a big deal a couple of years ago, but nowadays there are lots of platforms to target...


I can also agree with Phantom's statement about the 5% not being such a big deal for your first game project.  If your game makes enough money for that 5% to become significant, then you are pretty successful and won't mind that royalty.

#5187544 Should I try to optimise the World matrix build like this?

Posted by Jason Z on 16 October 2014 - 07:37 PM

Why not have different methods for each case - if you know an object is only going to be using translation and rotation, then don't include the other calculations.  The other thing you can do is to decompose those matrix multiplies into a direct calculation for each element of the end result matrix.  That lets you factor out common calculations and reduce the overall number of multiplies to perform.

#5187262 Why not use UE4?

Posted by Jason Z on 15 October 2014 - 05:20 PM

For me, it is quite similar to a few others' arguments.  My engine was actually the vehicle that I used to learn about graphics programming (and general programming too), and I wouldn't trade that for anything.  Once you get attached to your own engine, it is pretty hard to make the decision to dump it and go with something else, no matter how awesome it looks.


If you are just in it for business reasons, then one of the low cost engines is probably an attractive way to go.  But if you are trying to understand and learn, then starting from zilch is still the best way to understand what you need to do.

#5186484 Multiple windows and views - help me understand Direct3D11 a little better?

Posted by Jason Z on 12 October 2014 - 09:04 AM

If you want to check out a sample program that demonstrates using multiple windows, you can check out the 'ViewFromTheWindow' sample in Hieroglyph 3.  It renders the scene to a single off screen render target, then renders sub areas of the window to each swap chain of many Win32 windows.  If you have any questions about how something is done in particular, I would be happy to answer them!