• Create Account

## Few question about DirectX 11

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

13 replies to this topic

Posted 23 July 2012 - 12:06 PM

Hi. Im learning DirectX 11 and graphic programming and I want to understand everything before I go further. So I'll might ask some stupid question here and I'll be glad if you could help a noob.

1. The vertices order in a buffer for a triangle matter in any way (assuming the the mapping vertex-uv-etc is correct) excepting optimisation?
2. If I want to optimise for vertex cache I need to render front to back objects, traingles or vertices ? Assuming that I prefer rendering huge buffers (seems that improves dramtically the performance) intead of small buffers does the vertice order matter ?
If I have a SINGLE huge vertex buffer the GPU automatically cuts unseen vertices with CullFaces and I dont need any kind of optimisation ? Optimisations are for sorting separated vertex buffers ?
3. Is there any advantage using index buffer and split in more buffer, one for vertices, one for UVs, one for normals ? If yes how can I detect offline algoritmicaly on my mesh if is a fps boost ?
4. What tools is best for debugging low level GPU performance with those kind of optimisation? (Im using Visual Studio 2010, DirectX 11 SDK, SM 5.0)

Edited by Papadopol, 23 July 2012 - 12:15 PM.

### #2ZBethel  Members

Posted 23 July 2012 - 12:30 PM

1) That entirely depends on your primitive topology. http://msdn.microsof...4(v=vs.85).aspx
Assuming you're referring to an indexed triangle list, which is the most sensitive to vertex ordering (in terms of vertex cache performance), then the answer is no. As long as your indices are in the correct order, the vertex buffer can be in any order. That's why optimization is important. If you're sending in indices like (1, 1049, 2, 510, 16, 53), the vertex cache isn't going to do you much good.

2) Like I said above, the vertex cache only helps you if you're taking advantage of temporal locality with your indexing. More simply put, make sure your index buffer references specific indices as much as possible before moving on in the buffer. It doesn't matter what your object rendering order is. Although the GPU will cull triangles eventually, it's not until late in the pipeline. It's much better to use coarse-grained methods like frustum culling for entire objects.

3) According to the MSDN docs, using multiple streams is a bit slower, in the usual case, but it can be a huge advantage in certain situations. For example, if you're rendering a depth pass for a shadow map or for deferred rendering, you don't want to pass in the entire interleaved vertex to a shader that only cares about the position. Using multiple streams in this situation allows you to just bind the position stream and use that, saving tons of bandwidth.

4. I use PIX, which is ok. I haven't delved much into the vendor specific tools yet.

Edited by ZBethel, 23 July 2012 - 12:32 PM.

Posted 24 July 2012 - 09:00 AM

So in a "common" mesh rendering if separate buffers is slow I never need Index Buffers as I use vertices buffers that has UV, normal maps etc ?
I dont see a case where a vertice is identical to another by vertex position, uv map, etc.

Nevermind, I fot the idea. Indexing vertices is not for skiping identical vertices but for reusing vertices in the vertex cache.

LE:
http://fgiesen.wordp...ne-2011-part-3/

If I understand correctly, I just use batches of vertices meaning Ill reorder the vertices in groups of 32 vertices maximum but in only big buffer? I really dont understand what a batch is. Is a render call with a different buffer or a potion of vertices in a vertex buffer?

Edited by Papadopol, 24 July 2012 - 09:33 AM.

Posted 28 July 2012 - 05:44 AM

Im reading a file and I'm having some problmes reading some variables

text file is like that:


chars count=191
char id=32   x=72    y=77    width=1	 height=1	 xoffset=0	 yoffset=26    xadvance=8	 page=0  chnl=15
etc..



Code in my program:


while ( fontFile.good() ) {

getline (fontFile,line);

//search for number of characters variables
//

string toFind = "chars count="; // what sould I search in the current line
found = line.find(toFind); // where the text to fond is located

if(found != -1) {

int count = toFind.size() + found; // Where the variable starts
// So far so good, it seems it founds the correct location where the number is starting

// Here goes the problems
// I dont know hot to find out when the number is finished. I guess that should work with newline character but it doesnt
//

// Assertion failed here
// Seems it doesnt find newline as I resize line string and also gives me asserion failed
while (line[count] != '\n') {
count = count+1;

}

}


### #5SamiHuutoniemi  Members

Posted 28 July 2012 - 06:06 AM

If I were you, I'd use the extraction operator with the ifstream (>>) and something like
[source lang="cpp"]while (c != '=') { fontFile.get( c ); //Read until the last char read was the (=)-sign}//At this point "191" should be first in the ifstream bufferfontFile >> count; //Read the integer to a variable[/source]

Of course, c is of type char, and count of type int.

Hope this works!

Edited by SamiHuutoniemi, 28 July 2012 - 06:08 AM.

### #6mhagain  Members

Posted 28 July 2012 - 06:35 AM

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

Posted 28 July 2012 - 08:05 AM

Ok, going binary mode still having some problems:
Here is some binary mode documentation for Bitmap Font Generator http://bobcat-games....format.html#bin

I dont know how to read the first variable


HANDLE hFile;
hFile = CreateFile (L"media\\fonts\\binary.fnt",
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
MessageBox(NULL,L"Failed opening the binary file",L"error",NULL);
CloseHandle (hFile);
return;
}

int fontsize=0;
// I dont get the font size;

CloseHandle (hFile);


Edited by Papadopol, 28 July 2012 - 08:05 AM.

Posted 05 August 2012 - 09:39 AM

I managed to load the binary file but no matter how hard I try it seems that the font is blurry. I unchecked "Font Smoothing" from Bitmap font generator but it seems it goes to the other extreme. I exported the font in a big size (40) do I'll have more pixel information and after that I've created triangles sized by UV coordonated and it seems I'm mapping 1:1 to the quad. When I create the quads the values of UVs are multyplied woth 0.002f. Then I use a matrix multiplication for scaling again regarding my need. Also without the scaling the font is still kind of blurry.
Any sugestion for sharpening the font?

Edited by Papadopol, 05 August 2012 - 09:46 AM.

### #9SamiHuutoniemi  Members

Posted 05 August 2012 - 09:45 AM

I use D3D11_FILTER_MIN_MAG_MIP_LINEAR for Filter in the sampler state desc. Try it!

Posted 05 August 2012 - 09:49 AM

Looks the same with any filter in the sample.


D3D11_SAMPLER_DESC samplerDesc;
samplerDesc.Filter =  D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MaxAnisotropy = 0;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.BorderColor[0] = 0;
samplerDesc.BorderColor[1] = 0;
samplerDesc.BorderColor[2] = 0;
samplerDesc.BorderColor[3] = 0;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;


Edited by Papadopol, 05 August 2012 - 09:49 AM.

Posted 05 August 2012 - 09:53 AM

Also witout font smothing and Dx filtering

Edited by Papadopol, 05 August 2012 - 09:53 AM.

Posted 05 August 2012 - 10:08 AM

Also how can I display those quads in the same size even if I resize the window on change the resolution ?
Assuming I dont care about about window resizing. A monitor with a native resolution of 1024x768 will display a quad in the same ratio as I see it on my native resolution of 1920x1200 ?

Edited by Papadopol, 05 August 2012 - 11:18 AM.

### #13SamiHuutoniemi  Members

Posted 06 August 2012 - 09:14 AM

Looks the same with any filter in the sample.


D3D11_SAMPLER_DESC samplerDesc;
samplerDesc.Filter =  D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MaxAnisotropy = 0;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.BorderColor[0] = 0;
samplerDesc.BorderColor[1] = 0;
samplerDesc.BorderColor[2] = 0;
samplerDesc.BorderColor[3] = 0;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;


Ok, stupid question, but do you SET the sampler state? Almost sounds as if you do not.

Also how can I display those quads in the same size even if I resize the window on change the resolution ?
Assuming I dont care about about window resizing. A monitor with a native resolution of 1024x768 will display a quad in the same ratio as I see it on my native resolution of 1920x1200 ?

You can, but you would have to do the calculations in your program.

Posted 21 August 2012 - 12:52 AM

Yes, actually I didnt set the sampler state. Thank you for pointing that.
Another questions:
If I have a class and I want to debug to a file or to a messagebox etc is ok to do that with a define ?
For exemple:
#define DEBUG 0

//some code that makes something
//..

#if DEBUG == 1
//write debug information about the code above to a file
#endif

// other lines of code
// ....
#if DEBUG == 1
//write debug information about the code
#endif


I know that are many logical ways to do that but I wonder wich one is better and used by a programmer.

Thanks.

Edited by Papadopol, 21 August 2012 - 12:53 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.