From 4b74f994bf94217f174cf0fb02ed94abe62e9d7c Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 11 Mar 2021 13:08:21 -0800 Subject: 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 --- tools/render-test/shader-renderer-util.cpp | 44 ++++++++++++------------------ 1 file changed, 18 insertions(+), 26 deletions(-) (limited to 'tools/render-test') diff --git a/tools/render-test/shader-renderer-util.cpp b/tools/render-test/shader-renderer-util.cpp index 57187fc44..903164567 100644 --- a/tools/render-test/shader-renderer-util.cpp +++ b/tools/render-test/shader-renderer-util.cpp @@ -87,38 +87,30 @@ void BindingStateImpl::apply(ICommandEncoder* encoder, PipelineType pipelineType const int numSubResources = textureResourceDesc.calcNumSubResources(); IResource::Usage initialUsage = IResource::Usage::GenericRead; - ITextureResource::Data initData; - List mipRowStrides; - mipRowStrides.setCount(textureResourceDesc.numMipLevels); - List subResources; - subResources.setCount(numSubResources); - - // Set up the src row strides - for (int i = 0; i < textureResourceDesc.numMipLevels; i++) - { - const int mipWidth = ITextureResource::Size::calcMipSize(textureResourceDesc.size.width, i); - mipRowStrides[i] = mipWidth * sizeof(uint32_t); - } - - // Set up pointers the the data + List initSubresources; + int subResourceCounter = 0; + for( int a = 0; a < effectiveArraySize; ++a ) { - int subResourceIndex = 0; - const int numGen = int(texData.dataBuffer.getCount()); - for (int i = 0; i < numSubResources; i++) + for( int m = 0; m < textureResourceDesc.numMipLevels; ++m ) { - subResources[i] = texData.dataBuffer[subResourceIndex].getBuffer(); - // Wrap around - subResourceIndex = (subResourceIndex + 1 >= numGen) ? 0 : (subResourceIndex + 1); + int subResourceIndex = subResourceCounter++; + const int mipWidth = ITextureResource::Size::calcMipSize(textureResourceDesc.size.width, m); + const int mipHeight = ITextureResource::Size::calcMipSize(textureResourceDesc.size.width, m); + + auto strideY = mipWidth * sizeof(uint32_t); + auto strideZ = mipHeight * strideY; + + ITextureResource::SubresourceData subresourceData; + subresourceData.data = texData.dataBuffer[subResourceIndex].getBuffer(); + subresourceData.strideY = strideY; + subresourceData.strideZ = strideZ; + + initSubresources.add(subresourceData); } } - initData.mipRowStrides = mipRowStrides.getBuffer(); - initData.numMips = textureResourceDesc.numMipLevels; - initData.numSubResources = numSubResources; - initData.subResources = subResources.getBuffer(); - - textureOut = device->createTextureResource(IResource::Usage::GenericRead, textureResourceDesc, &initData); + textureOut = device->createTextureResource(IResource::Usage::GenericRead, textureResourceDesc, initSubresources.getBuffer()); return textureOut ? SLANG_OK : SLANG_FAIL; } -- cgit v1.2.3