D3D11_MAPPED_SUBRESOURCE

Discussions related to graphics (2D and 3D), animation and games programming
Ric
Posts: 208
Joined: Tue 17 Apr 2018, 21:03

D3D11_MAPPED_SUBRESOURCE

Post by Ric »

The code from DirectXTutorials is this

Code: Select all

  D3D11_BUFFER_DESC bd;
    ZeroMemory(&bd, sizeof(bd));

    bd.Usage = D3D11_USAGE_DYNAMIC;                // write access access by CPU and GPU
    bd.ByteWidth = sizeof(VERTEX) * 3;             // size is the VERTEX struct * 3
    bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;       // use as a vertex buffer
    bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;    // allow CPU to write in buffer

    dev->CreateBuffer(&bd, NULL, &pVBuffer);       // create the buffer


    // copy the vertices into the buffer
    D3D11_MAPPED_SUBRESOURCE ms;
    devcon->Map(pVBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);    // map the buffer
    memcpy(ms.pData, OurVertices, sizeof(OurVertices));                 // copy the data
    devcon->Unmap(pVBuffer, NULL);                                      // unmap the buffer
I have changed it to BASIC but can not get it to work, can anyone help?
Here is the code i have produced.

Code: Select all

      DIM bd{} = D3D11_BUFFER_DESC{}
      bd.Usage% = D3D11_USAGE_DYNAMIC
      bd.ByteWidth% = DIM(VERTEX{}) * 3
      bd.BindFlags% = D3D11_BIND_VERTEX_BUFFER
      bd.CPUAccessFlags% = D3D11_CPU_ACCESS_WRITE

      SYS Dev.CreateBuffer%, Dev%, bd{}, NULL, ^pVBuffer% TO hRESULT%
      IF hRESULT% <> 0 OR pVBuffer% = 0 ERROR 100, "Dev::CreateBuffer failed: "+STR$~hRESULT%

      DIM ms{} = D3D11_MAPPED_SUBRESOURCE{}
      SYS DevCon.Map%, DevCon%, pVBuffer%, NULL, D3D11_MAP_WRITE_DISCARD, NULL, ms{}
      SYS"RtlMoveMemory", ms.pData%, OurVertices{(0)},  DIM(VERTEX{}) * 3
      SYS DevCon.Unmap%, DevCon%, pVBuffer%, NULL
Kind regards Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
DDRM

Re: D3D11_MAPPED_SUBRESOURCE

Post by DDRM »

Hi Ric,

Richard did quite a bit of work on D3D11, and produced a library and some tutorials - my copies are dated August 2015. Would they be a useful starting point? They are discussed on the wiki (with links) here:

http://www.bbcbasic.co.uk/wiki/doku.php ... 0tutorials

Best wishes,

D
Ric
Posts: 208
Joined: Tue 17 Apr 2018, 21:03

Re: D3D11_MAPPED_SUBRESOURCE

Post by Ric »

Thanks D,
I have been through the tutorials and decided to have a go on my own, I always feel this is the best way to learn.
The problem is that in Richards example

Code: Select all

    
      DIM bd{} = D3D11_BUFFER_DESC{}
      bd.Usage% = D3D11_USAGE_DEFAULT
      bd.ByteWidth% = DIM(SimpleVertex{}) * (DIM(vertices{()},1)+1)
      bd.BindFlags% = D3D11_BIND_VERTEX_BUFFER
      bd.CPUAccessFlags% = 0

      DIM InitData{} = D3D11_SUBRESOURCE_DATA{}
      InitData.pSysMem% = vertices{(0)}
      SYS ID3D11Device.CreateBuffer%, pd3dDevice%, bd{}, InitData{}, ^pVertexBuffer% TO hr%
      IF hr% <> 0 OR pVertexBuffer% = 0 ERROR 100, "ID3D11Device::CreateBuffer (vertices) failed: "+STR$~hr%
He inserts the vertices when he creates the buffer, this is ok for the examples but not good for changing the buffers on the fly during a game.
It is this effect i am trying to achieve.
Hence the differing code. I have translated the code from DirectXTutorial but without the desired effect, actually nothing happens, I am not familiar enough with moving blocks of memory around or what are pointers and what are not to work out what is wrong.
If it is not up your street either could you please ask Richard to have a look?

Kindest Regards

Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
DDRM

Re: D3D11_MAPPED_SUBRESOURCE

Post by DDRM »

Hi Ric,

I never got to grips with D3D11 - I was worried it would confuse my (also rather lapsed!) understanding of D3D9....

Richard isn't monitoring this forum (he says), and certainly isn't posting to it: why don't you post a query on the groups.io site (preferable, since then I'd see the answer!), or email him directly?

Best wishes,

D
Ric
Posts: 208
Joined: Tue 17 Apr 2018, 21:03

Re: D3D11_MAPPED_SUBRESOURCE

Post by Ric »

My apologies to anyone who has read this thread and scratched their heads, the code works, i had misspelled the name of a pointer a little later in the code. Ho Hum!!!

Regards Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
DDRM

Re: D3D11_MAPPED_SUBRESOURCE

Post by DDRM »

...and I'm sorry for the outcome of you following my advice and posting on groups.io...

:-(

D
Ric
Posts: 208
Joined: Tue 17 Apr 2018, 21:03

Re: D3D11_MAPPED_SUBRESOURCE

Post by Ric »

Ho hum D,

Nothing ventured nothing gained.
I don't like the format of the group.io anyway.😆
If you are in contact with Richard, please give my apologies, my frustration was aimed at the high horse who got involved.
On a lighter note, no pun intended, I am up to lighting in D3D11 and it's not that brutal, when I get to the end of the tutorials I will post a demo of what I have learned.

Kind regards Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023