• Advertisement
Sign in to follow this  

Maximum Size Of Vertex Buffer

This topic is 644 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys,

 

Is there a way to determine the maximum size of a vertex buffer that a GFX can handle?

 

I have found on some lesser cards that CreateBuffer() is throwing an exception but the actual call to CreateBuffer() does not return a fail code. I have narrowed it down to the size of the buffer I am allocating. Small buffers are ok, massive no good.

 

Is there some way to query the cards capabilities for this?

 

Thanks in advance. :)

Share this post


Link to post
Share on other sites
Advertisement

How big of a buffer are you trying to create?

You should always get a fail code unless you've passed completely invalid parameters to the function! :o 

Are you making use of the pInitialData parameter when you get these crashes?

Can you post your code here?

Share this post


Link to post
Share on other sites

Hi Hodgman,
 
This is the entire function here.
 
 

HRESULT geometry_dynamic_create()
{
        HRESULT result;

        struct float5
        {
                float x;
                float y;
                float z;
                float u;
                float v;
        };
 
        // Make some geometry
        int nVerts = 6;
 
        float5* vertex_data = new float5[nVerts];
        vertex_data[0] = { -0.0f, -1.0f, 0.0f, 0.0f ,1.0f };
        vertex_data[1] = { -0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
        vertex_data[2] = { 1.0f, -1.0f, 0.0f, 0.5f, 1.0f };
        vertex_data[3] = { 1.0f, -1.0f, 0.0f, 0.5f ,1.0f };
        vertex_data[4] = { -0.0f, 0.0f, 0.0f, 0.0f ,0.0f };
        vertex_data[5] = { 1.0f, 0.0f, 0.0f, 0.5f ,0.0f };
 
        D3D11_BUFFER_DESC vertexDesc;
 
        ZeroMemory(&vertexDesc, sizeof(vertexDesc));-
        vertexDesc.Usage = D3D11_USAGE_DYNAMIC;
        vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
        vertexDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
        vertexDesc.ByteWidth = 900000;       //900000 seems to max this out
  
        D3D11_SUBRESOURCE_DATA resourceData;
        ZeroMemory(&resourceData, sizeof(resourceData));
        resourceData.pSysMem = vertex_data;
        result = d3dDevice->CreateBuffer(&vertexDesc, &resourceData, &vBufferDynamic);
 
        if (FAILED(result))
                return E_FAIL;
        
        return S_OK;
}

The value of 900,000 is a 'reservation' as I am merging geometry in a later area of my program. This was roughly the largest value I could find without crashing the application.

 

But is seems like a 'one size fits all' isn't a good option as I have a ~30% fail rate on different cards. New cards seem happy but some older cards are reporting "This program is not responding".

 

My whole application has error handling on every call possible but this one still slips by.

Share this post


Link to post
Share on other sites

Just found this in the debugger if I make the value larger, like 100000000.

 

 


result 0x00000008 : Not enough storage is available to process this command.  HRESULT

 

Which is more or less what I was suspecting. But why doesn't fail detect code catch this?
 

Should I be ditching HRESULT in favour of 'try/catch'?

Edited by DarkRonin

Share this post


Link to post
Share on other sites

You're passing vertex_data which is only 120 bytes of size and telling D3D11 to read 900.000 bytes of it. Naturally, it will crash.

 

True.

 

Shouldn't that result in a garbage filled buffer?

 

BTW 900,000 works (1000,000 crashes it).

Share this post


Link to post
Share on other sites

 

You're passing vertex_data which is only 120 bytes of size and telling D3D11 to read 900.000 bytes of it. Naturally, it will crash.

 

True.

 

Shouldn't that result in a garbage filled buffer?

 

BTW 900,000 works (1000,000 crashes it).

 

If the pages that follow your 120 byte allocation are mapped by the OS as readable, then yes.

But there's no guarantee that those addresses are valid to read from - and in your case, it seems they are not.

 

1,000,000 is just shy of one megabyte, which is an entirely reasonable size for a buffer, and should be expected to succeed.

Edited by Hodgman

Share this post


Link to post
Share on other sites

Thanks guys for the help! This has got me back on track.

 

@Hodgman - I didn't even think of the 'readable' part of memory thing. I guess it was pure luck that it ran properly on as many systems as it did.

Share this post


Link to post
Share on other sites

https://msdn.microsoft.com/en-us/library/windows/desktop/ff819065(v=vs.85).aspx

D3D11 only guarentees a buffer size of 128 MB that is usuable, on hardware that supports more it will allow the allocation to happen but since this wil fail on other hardware its better to not do this. But if you have a 128MB vertex buffer I dont think your performance will be super anyway.

Edited by NightCreature83

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement