render: D3D9 doesn't need to check for stream offset support anymore. SDL-ryan-batching-renderer
authorRyan C. Gordon <icculus@icculus.org>
Mon, 01 Oct 2018 13:41:15 -0400
branchSDL-ryan-batching-renderer
changeset 12281838c5562d05f
parent 12280 412a6f2078d4
child 12282 2395434a074d
render: D3D9 doesn't need to check for stream offset support anymore.

We don't use offsets at all now. Too slow.
src/render/direct3d/SDL_render_d3d.c
     1.1 --- a/src/render/direct3d/SDL_render_d3d.c	Mon Oct 01 11:32:08 2018 -0400
     1.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Mon Oct 01 13:41:15 2018 -0400
     1.3 @@ -70,7 +70,6 @@
     1.4      SDL_bool updateSize;
     1.5      SDL_bool beginScene;
     1.6      SDL_bool enableSeparateAlphaBlend;
     1.7 -    SDL_bool supportsStreamOffset;
     1.8      D3DTEXTUREFILTERTYPE scaleMode[8];
     1.9      IDirect3DSurface9 *defaultRenderTarget;
    1.10      IDirect3DSurface9 *currentRenderTarget;
    1.11 @@ -1199,44 +1198,40 @@
    1.12      }
    1.13  
    1.14      /* upload the new VBO data for this set of commands. */
    1.15 -    if (data->supportsStreamOffset) {
    1.16 -        vbo = data->vertexBuffers[vboidx];
    1.17 -        if (!vbo || (data->vertexBufferSize[vboidx] < vertsize)) {
    1.18 -            const DWORD usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY;
    1.19 -            const DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
    1.20 -            if (vbo) {
    1.21 -                IDirect3DVertexBuffer9_Release(vbo);
    1.22 -            }
    1.23 -
    1.24 -            if (FAILED(IDirect3DDevice9_CreateVertexBuffer(data->device, vertsize, usage, fvf, D3DPOOL_DEFAULT, &vbo, NULL))) {
    1.25 -                vbo = NULL;
    1.26 -            }
    1.27 -            data->vertexBuffers[vboidx] = vbo;
    1.28 -            data->vertexBufferSize[vboidx] = vbo ? vertsize : 0;
    1.29 +    vbo = data->vertexBuffers[vboidx];
    1.30 +    if (!vbo || (data->vertexBufferSize[vboidx] < vertsize)) {
    1.31 +        const DWORD usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY;
    1.32 +        const DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
    1.33 +        if (vbo) {
    1.34 +            IDirect3DVertexBuffer9_Release(vbo);
    1.35          }
    1.36  
    1.37 -        if (vbo) {
    1.38 -            void *ptr;
    1.39 -            if (FAILED(IDirect3DVertexBuffer9_Lock(vbo, 0, vertsize, &ptr, D3DLOCK_DISCARD))) {
    1.40 +        if (FAILED(IDirect3DDevice9_CreateVertexBuffer(data->device, vertsize, usage, fvf, D3DPOOL_DEFAULT, &vbo, NULL))) {
    1.41 +            vbo = NULL;
    1.42 +        }
    1.43 +        data->vertexBuffers[vboidx] = vbo;
    1.44 +        data->vertexBufferSize[vboidx] = vbo ? vertsize : 0;
    1.45 +    }
    1.46 +
    1.47 +    if (vbo) {
    1.48 +        void *ptr;
    1.49 +        if (FAILED(IDirect3DVertexBuffer9_Lock(vbo, 0, vertsize, &ptr, D3DLOCK_DISCARD))) {
    1.50 +            vbo = NULL;  /* oh well, we'll do immediate mode drawing.  :(  */
    1.51 +        } else {
    1.52 +            SDL_memcpy(ptr, vertices, vertsize);
    1.53 +            if (FAILED(IDirect3DVertexBuffer9_Unlock(vbo))) {
    1.54                  vbo = NULL;  /* oh well, we'll do immediate mode drawing.  :(  */
    1.55 -            } else {
    1.56 -                SDL_memcpy(ptr, vertices, vertsize);
    1.57 -                if (FAILED(IDirect3DVertexBuffer9_Unlock(vbo))) {
    1.58 -                    vbo = NULL;  /* oh well, we'll do immediate mode drawing.  :(  */
    1.59 -                }
    1.60 -            }
    1.61 -        }
    1.62 -
    1.63 -        /* cycle through a few VBOs so D3D has some time with the data before we replace it. */
    1.64 -        if (vbo) {
    1.65 -            data->currentVertexBuffer++;
    1.66 -            if (data->currentVertexBuffer >= SDL_arraysize(data->vertexBuffers)) {
    1.67 -                data->currentVertexBuffer = 0;
    1.68              }
    1.69          }
    1.70      }
    1.71  
    1.72 -    if (!vbo && !data->reportedVboProblem) {
    1.73 +    /* cycle through a few VBOs so D3D has some time with the data before we replace it. */
    1.74 +    if (vbo) {
    1.75 +        data->currentVertexBuffer++;
    1.76 +        if (data->currentVertexBuffer >= SDL_arraysize(data->vertexBuffers)) {
    1.77 +            data->currentVertexBuffer = 0;
    1.78 +        }
    1.79 +    } else if (!data->reportedVboProblem) {
    1.80          SDL_LogError(SDL_LOG_CATEGORY_RENDER, "SDL failed to get a vertex buffer for this Direct3D 9 rendering batch!");
    1.81          SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Dropping back to a slower method.");
    1.82          SDL_LogError(SDL_LOG_CATEGORY_RENDER, "This might be a brief hiccup, but if performance is bad, this is probably why.");
    1.83 @@ -1709,8 +1704,6 @@
    1.84          device_flags |= D3DCREATE_MULTITHREADED;
    1.85      }
    1.86  
    1.87 -    data->supportsStreamOffset = ((caps.DevCaps2 & D3DDEVCAPS2_STREAMOFFSET) == D3DDEVCAPS2_STREAMOFFSET);
    1.88 -
    1.89      result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
    1.90                                       D3DDEVTYPE_HAL,
    1.91                                       pparams.hDeviceWindow,