Reputation: 41845
I am required to allocate bitmap in video-card memory in a project in Windows. Because the project use other 2d library other than GDI, so CreateCompatibleBitmap is useless.
Then i figure out a method using DX, here is my code:
if(FAILED(g_D3DDevice->CreateVertexBuffer(10240 * 1024, 0,
D3DFVF_VERTEX, D3DPOOL_DEFAULT, &g_VertexBuffer,
NULL))) return false;
// Fill the vertex buffer.
void *ptr;
if(FAILED(g_VertexBuffer->Lock(0, 1024 * 10240,
(void**)&ptr, 0))) return false;
//do something...
//printf("ptf = %x\n", ptr);
//memcpy(ptr, objData, sizeof(objData));
g_VertexBuffer->Unlock();
It works well so far. But are there any sideeffect?
Upvotes: 1
Views: 308
Reputation: 14067
I can't imagine any legitimate reason to want to do this but in general it is not possible anyway. Windows PCs have a wide range of hardware and many do not even have a concept of separate video memory. For those that do the performance characteristics are not guaranteed which is why Direct3D has lots of ways of indicating to the driver your intended usage so that the driver can decide where best to locate resources (amongst other things, like how best to lay them out in memory) rather than providing ways for you to specify 'in video memory' and other concepts that are not consistently defined across different hardware types.
If as you say your boss asked you to do this it seems like a case study in bad project management - specifying the implementation details of what to do rather than specifying the project goals and leaving the engineer tasked with implementation to figure out how best to achieve them. Presumably the real goal here is to improve performance of some task or operation. Almost certainly what you're doing is not the best way to achieve that.
Upvotes: 2
Reputation: 4888
Sideeffect:
Aside from this sideeffect make sure to check this process went sucessfull as video card out of memory does not supply the most "user obvious"-kind of error.
As for why it would be slow: by putting it into your video card memory you will have to request access to the vertex each time you want to write/read, which is slower then actually accessing it right away in regular memory.
Upvotes: 2