XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

MaxVertexIndex - ambiguity

Last post 08-18-2008 2:58 PM by ArchangelWaR. 7 replies.
  • 08-15-2008 2:06 PM

    MaxVertexIndex - ambiguity

    Hi there.

     As you probably now - there is one entry among DeviceCaps called MaxVertexIndex. As the name implies, it is supposed to indicate the maximum possible INDEX of a vertex in a vertex buffer. Since in C++/C# we index arrays starting with 0, one can guess that maximum index being (x) means the maximal size is (x + 1).

    Now, I am testing my MDX application on a a 945GM chipset, and MaxVertexIndex is 65534, so I guess that the maximal size is 65535, which seems perfectly ok, since this is all one can get from a 16-bit register (2^16 - 1). [edit: actually: MaxVertexIndex = 65535 and therefore maximal buffer size = 65536 would be all one can get from a 16-bit reg.]

    I need to create a mesh out of vertex and index buffer, simple. Having loaded these two appropriately, I call mesh constructor. The thing is that when I try to construct the mesh specifying vertex number of 65535, the constructor throws the almighty "Error in the application"; specifying vertex number 65534 goes without any problems.

     The question is - why? I could just hard-code it to work, but the twisted logic is quite irritating and I cannot be guaranteed that some other chipset will demand vertex number of (MaxVertexIndex - 3) or so in the mesh ctor. How can one create anything usable on many machines :/.

     Any ideas? Is mesh constructor subject to some additional limitations apart  from the MaxVertexIndex or am I missing something?

  • 08-16-2008 9:50 AM In reply to

    Re: MaxVertexIndex - ambiguity

    Okay, I did some further checking, and this is what I got:

     I cross-checked this issue using two different radeon-based machines; they both have MaxVertexIndex cap of 16777215 (2^24 - 1) and both perform exactly the same as 945GM laptop (i.e. create meshes with 65534 vertices max).

    I do not set 32-bit registers usage in any way (I guess it is done globally somehow), so I am not surprised 16-bit ones are used by default. What makes me wonder is the fact, that 16-bit limits vertex count to 65534 and not 65535, no matter the device caps.

    Is this a rule of sorts? I guess MaxVertexIndex meaning could be interpreted by different vendors in slightly different fashions, but it does not explain this "65534/65535 with 16-bit regs." thing.

     Please, help me solve this ;).

     

  • 08-16-2008 4:00 PM In reply to

    Re: MaxVertexIndex - ambiguity

    Sounds like a potential graphics driver bug. You could try updating the driver, though of course this won't prevent the issue reoccurring for users in the wild.

    Difficult to come up with a hard and fast rule. I suppose you could shave 5% or 10% off the number for safety. It's a little hacky, but off by one errors and the like do seem common in drivers, depending on the vendor, card and how "seasoned" the drivers themselves are.


    --formerly Genstein
  • 08-16-2008 5:45 PM In reply to

    Re: MaxVertexIndex - ambiguity

    You don't need to shave 5% off. Just treat the value as "MaxNumberOfVertices."

    Also, when you create a mesh, make sure you specify 32 bit indices if you want to use values higher than 65535.


    Jon Watte, Direct3D MVP kW X-port 3ds Max .X exporter kW Animation source code
  • 08-16-2008 6:17 PM In reply to

    Re: MaxVertexIndex - ambiguity

    Thanks for your replies!

    Ego:
    I suppose you could shave 5% or 10% off the number for safety.

    I thought of it, but as a last resort really.

    jwatte:
    treat the value as "MaxNumberOfVertices"

    Okay, fair enough, but do you know why the cards with MaxVertexIndex/Number way over 65535 still crack (these radeons), when I set 65535 as the vertices number (using 16-bit indexing) ? Is it NOT what you get from your cards?  (As for 32-bit indexing - I do not want to use it, I divide the mesh into several smaller ones in case of so many verts.)

    I can reproduce this problem easily, can you? (code below):

    try 
       mesh = new Mesh(100, 65535, MeshFlags.Managed, CustomVertex.PositionNormalColored.Format, _device); 
    catch(Exception e) 
       MessageBox.Show("Oops!"); 

    ...and I mean the two cards with MaxVertexIndex = 2^24 - 1.

     

  • 08-16-2008 7:40 PM In reply to

    Re: MaxVertexIndex - ambiguity

    It's probably the case that 65534 is the most you can get out of a 16-bit index, because 65535 is used as a magic marker of some sort (say, for restarting primitives?). Thus, if you want an index value greater than 65534, you need 32-bit indices.
    Jon Watte, Direct3D MVP kW X-port 3ds Max .X exporter kW Animation source code
  • 08-17-2008 12:52 PM In reply to

    Re: MaxVertexIndex - ambiguity

    Hm, pity you cannot learn such things directly from Microsoft, this kind of guesswork makes me feel anxious.

    If I come up with anything worth mentioning, I will post it here.

    By the bye, jwatte, how do you enable 32-bit indices on a per-mesh basis? Can this be done?

  • 08-18-2008 2:58 PM In reply to

    Re: MaxVertexIndex - ambiguity

    nietakt:
    Hm, pity you cannot learn such things directly from Microsoft, this kind of guesswork makes me feel anxious.

    If I come up with anything worth mentioning, I will post it here.

    By the bye, jwatte, how do you enable 32-bit indices on a per-mesh basis? Can this be done?

    Microsoft is not responsible for the design of video cards, which is where this number is set. It just gives you the option of 16 bit or 32 bit indices. The MaxVertexIndex number comes directly from the card/drivers.

Page 1 of 1 (8 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG