diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2021-03-11 13:08:21 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-11 13:08:21 -0800 |
| commit | 4b74f994bf94217f174cf0fb02ed94abe62e9d7c (patch) | |
| tree | 9c6f4c771d1e962059c84047ccf96e0d891a5c80 /tools/gfx/d3d11/render-d3d11.cpp | |
| parent | a07455c175db33d8d95bc5cd83738808d74cd105 (diff) | |
Change representation of initial data for textures (#1747)
* Change representation of initial data for textures
Before this change, initial data for a texture has been provided with the `ITextureResource::Data` type, where a call to `IDevice::createTexture()` would take zero or one `Data` and, if present, use it to initialize all the subresources of a texture.
The organization of `Data` was not actually quite how its own documentation comment described it (the implementations didn't agree with the comment), and while it aggressively factored out redundancies (e.g., only storing the stride for each mip level once, instead of once per subresource for large arrays), the result was that setting up a `Data` correcty was a bit confusing.
This change makes the initial data for a texture using a `SubresourceData` type that is almost identical to what D3D11 uses, so that developers are more likely to be comfortable filling it in. All of the existing implementations were easily adapted to use the new type, so it seems like a net win.
Note: Both Vulkan and D3D11 do away with the idea of initializing a texture with data as part of allocating it, and we might eventually want to do the same given the complexity that this system entails. The main reason to preserve this detail is for better compatibility with D3D11, where immutable textures/buffers need to have their data specified at creation time. It seems good to preserve the ability to have immutable resources on target APIs where this distinction could affect performance (e.g., immutable resources do not need state/transition tracking on APIs like D3D11).
* fixup: CUDA
Diffstat (limited to 'tools/gfx/d3d11/render-d3d11.cpp')
| -rw-r--r-- | tools/gfx/d3d11/render-d3d11.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/tools/gfx/d3d11/render-d3d11.cpp b/tools/gfx/d3d11/render-d3d11.cpp index b41169df2..1310e99ae 100644 --- a/tools/gfx/d3d11/render-d3d11.cpp +++ b/tools/gfx/d3d11/render-d3d11.cpp @@ -78,7 +78,7 @@ public: virtual SLANG_NO_THROW Result SLANG_MCALL createTextureResource( IResource::Usage initialUsage, const ITextureResource::Desc& desc, - const ITextureResource::Data* initData, + const ITextureResource::SubresourceData* initData, ITextureResource** outResource) override; virtual SLANG_NO_THROW Result SLANG_MCALL createBufferResource( IResource::Usage initialUsage, @@ -1057,18 +1057,13 @@ static int _calcResourceAccessFlags(int accessFlags) } } -Result D3D11Device::createTextureResource(IResource::Usage initialUsage, const ITextureResource::Desc& descIn, const ITextureResource::Data* initData, ITextureResource** outResource) +Result D3D11Device::createTextureResource(IResource::Usage initialUsage, const ITextureResource::Desc& descIn, const ITextureResource::SubresourceData* initData, ITextureResource** outResource) { TextureResource::Desc srcDesc(descIn); srcDesc.setDefaults(initialUsage); const int effectiveArraySize = srcDesc.calcEffectiveArraySize(); - if(initData) - { - assert(initData->numSubResources == srcDesc.numMipLevels * effectiveArraySize * srcDesc.size.depth); - } - const DXGI_FORMAT format = D3DUtil::getMapFormat(srcDesc.format); if (format == DXGI_FORMAT_UNKNOWN) { @@ -1092,11 +1087,11 @@ Result D3D11Device::createTextureResource(IResource::Usage initialUsage, const I const int mipHeight = ITextureResource::Size::calcMipSize(srcDesc.size.height, j); D3D11_SUBRESOURCE_DATA& data = subRes[subResourceIndex]; + auto& srcData = initData[subResourceIndex]; - data.pSysMem = initData->subResources[subResourceIndex]; - - data.SysMemPitch = UINT(initData->mipRowStrides[j]); - data.SysMemSlicePitch = UINT(initData->mipRowStrides[j] * mipHeight); + data.pSysMem = srcData.data; + data.SysMemPitch = UINT(srcData.strideY); + data.SysMemSlicePitch = UINT(srcData.strideZ); subResourceIndex++; } |
