diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-03-21 14:18:11 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-21 14:18:11 -0400 |
| commit | 5bdc3ef07373be62363deb64dedd4163589430b6 (patch) | |
| tree | 4c55037961a80dacbac54087544e55493a272794 | |
| parent | 4e359e109d665490909ae4a1ca980b7d766c8eff (diff) | |
Hotfix/dx12 cubemap lookup (#921)
* Disable Dx12 half tests. The half-calc test runs, but is not actually doing any half maths. If the code is changed such that it is, the device fails when the shader is used. This can be seen by looking at dxil-asm.
* Fix using software driver for dx12 even when hardware is requested.
* * Refactor Dx12 _createAdapter such that it doesn't have side effects and stores desc information
* Disable half on dx12 software renderer because it crashes
* * Disable erroneous warnings from dx12
* Test for adapter creation
* Identify warp specifically
* Structured buffer test now works on dx12.
* Fix intemittent crash on dx12.
Due to if a resource was initialized with data, the actual resource constructed might be larger, for alignment issues. This led to a memcpy potentially copying from after the allocated source data and therefore a crash. Now only copies the non aligned amount of data.
* * Rename the test to use - style
* Disable TextureCube lookup in tests, as does not produce the correct result in dx12 (will fix in future PR)
* Updated hlsl.meta.slang.h that has rcp for glsl.
* * Fix bug where the SRV description was incorrect for cubemaps on dx12
* Re-enable cube map access in dx12 tests
* Slightly re-organize texture upload on dx12 to not repeatidly create and destroy upload resource for array/cube scenarios
| -rw-r--r-- | tests/compute/texture-sampling.slang | 5 | ||||
| -rw-r--r-- | tools/gfx/render-d3d12.cpp | 104 |
2 files changed, 57 insertions, 52 deletions
diff --git a/tests/compute/texture-sampling.slang b/tests/compute/texture-sampling.slang index 046b8493f..4ce316807 100644 --- a/tests/compute/texture-sampling.slang +++ b/tests/compute/texture-sampling.slang @@ -98,13 +98,8 @@ FragmentStageOutput fragmentMain(FragmentStageInput input) val += t2dArray.Sample(samplerState, float3(uv, 0.0)); - // TODO(JS): Disable for now, as doesn't work correctly on dx12 -#if 0 val += tCubeArray.Sample(samplerState, float4(uv, 0.5, 0.0)); val += tCube.Sample(samplerState, float3(uv, 0.5)); -#else - val += float4(2, 2, 2, 2); -#endif outputBuffer[0] = val.x; return output; diff --git a/tools/gfx/render-d3d12.cpp b/tools/gfx/render-d3d12.cpp index f177d112b..3c5d19c1b 100644 --- a/tools/gfx/render-d3d12.cpp +++ b/tools/gfx/render-d3d12.cpp @@ -2023,18 +2023,16 @@ Result D3D12Renderer::createTextureResource(Resource::Usage initialUsage, const // We should have this many sub resources assert(initData->numSubResources == numMipMaps * srcDesc.size.depth * arraySize); - // This is just the size for one array upload -> not for the whole texure + // NOTE! This is just the size for one array upload -> not for the whole texture UInt64 requiredSize = 0; m_device->GetCopyableFootprints(&resourceDesc, 0, numMipMaps, 0, layouts.begin(), mipNumRows.begin(), mipRowSizeInBytes.begin(), &requiredSize); // Sub resource indexing // https://msdn.microsoft.com/en-us/library/windows/desktop/dn705766(v=vs.85).aspx#subresource_indexing - - int subResourceIndex = 0; - for (int i = 0; i < arraySize; i++) { // Create the upload texture D3D12Resource uploadTexture; + { D3D12_HEAP_PROPERTIES heapProps; @@ -2062,68 +2060,71 @@ Result D3D12Renderer::createTextureResource(Resource::Usage initialUsage, const uploadTexture.setDebugName(L"TextureUpload"); } - + // Get the pointer to the upload resource ID3D12Resource* uploadResource = uploadTexture; - uint8_t* p; - uploadResource->Map(0, nullptr, reinterpret_cast<void**>(&p)); - - for (int j = 0; j < numMipMaps; ++j) + int subResourceIndex = 0; + for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { - const D3D12_PLACED_SUBRESOURCE_FOOTPRINT& layout = layouts[j]; - const D3D12_SUBRESOURCE_FOOTPRINT& footprint = layout.Footprint; + uint8_t* p; + uploadResource->Map(0, nullptr, reinterpret_cast<void**>(&p)); - const TextureResource::Size mipSize = srcDesc.size.calcMipSize(j); + for (int j = 0; j < numMipMaps; ++j) + { + const D3D12_PLACED_SUBRESOURCE_FOOTPRINT& layout = layouts[j]; + const D3D12_SUBRESOURCE_FOOTPRINT& footprint = layout.Footprint; - assert(footprint.Width == mipSize.width && footprint.Height == mipSize.height && footprint.Depth == mipSize.depth); + const TextureResource::Size mipSize = srcDesc.size.calcMipSize(j); - const ptrdiff_t dstMipRowPitch = ptrdiff_t(layouts[j].Footprint.RowPitch); - const ptrdiff_t srcMipRowPitch = ptrdiff_t(initData->mipRowStrides[j]); + assert(footprint.Width == mipSize.width && footprint.Height == mipSize.height && footprint.Depth == mipSize.depth); - assert(dstMipRowPitch >= srcMipRowPitch); + const ptrdiff_t dstMipRowPitch = ptrdiff_t(layouts[j].Footprint.RowPitch); + const ptrdiff_t srcMipRowPitch = ptrdiff_t(initData->mipRowStrides[j]); - const uint8_t* srcRow = (const uint8_t*)initData->subResources[subResourceIndex]; - uint8_t* dstRow = p + layouts[j].Offset; + assert(dstMipRowPitch >= srcMipRowPitch); - // Copy the depth each mip - for (int l = 0; l < mipSize.depth; l++) - { - // Copy rows - for (int k = 0; k < mipSize.height; ++k) + const uint8_t* srcRow = (const uint8_t*)initData->subResources[subResourceIndex]; + uint8_t* dstRow = p + layouts[j].Offset; + + // Copy the depth each mip + for (int l = 0; l < mipSize.depth; l++) { - ::memcpy(dstRow, srcRow, srcMipRowPitch); + // Copy rows + for (int k = 0; k < mipSize.height; ++k) + { + ::memcpy(dstRow, srcRow, srcMipRowPitch); - srcRow += srcMipRowPitch; - dstRow += dstMipRowPitch; + srcRow += srcMipRowPitch; + dstRow += dstMipRowPitch; + } } + + //assert(srcRow == (const uint8_t*)(srcMip.Buffer() + srcMip.Count())); } + uploadResource->Unmap(0, nullptr); - //assert(srcRow == (const uint8_t*)(srcMip.Buffer() + srcMip.Count())); - } - uploadResource->Unmap(0, nullptr); + for (int mipIndex = 0; mipIndex < numMipMaps; ++mipIndex) + { + // https://msdn.microsoft.com/en-us/library/windows/desktop/dn903862(v=vs.85).aspx - for (int mipIndex = 0; mipIndex < numMipMaps; ++mipIndex) - { - // https://msdn.microsoft.com/en-us/library/windows/desktop/dn903862(v=vs.85).aspx + D3D12_TEXTURE_COPY_LOCATION src; + src.pResource = uploadTexture; + src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; + src.PlacedFootprint = layouts[mipIndex]; - D3D12_TEXTURE_COPY_LOCATION src; - src.pResource = uploadTexture; - src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; - src.PlacedFootprint = layouts[mipIndex]; + D3D12_TEXTURE_COPY_LOCATION dst; + dst.pResource = texture->m_resource; + dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + dst.SubresourceIndex = subResourceIndex; + m_commandList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); - D3D12_TEXTURE_COPY_LOCATION dst; - dst.pResource = texture->m_resource; - dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; - dst.SubresourceIndex = subResourceIndex; - m_commandList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); + subResourceIndex++; + } - subResourceIndex++; + // Block - waiting for copy to complete (so can drop upload texture) + submitGpuWorkAndWait(); } - - // Block - waiting for copy to complete (so can drop upload texture) - submitGpuWorkAndWait(); } - { const D3D12_RESOURCE_STATES finalState = _calcResourceState(initialUsage); D3D12BarrierSubmitter submitter(m_commandList); @@ -2362,7 +2363,16 @@ Result D3D12Renderer::createTextureView(TextureResource* texture, ResourceView:: case ResourceView::Type::ShaderResource: { SLANG_RETURN_ON_FAIL(m_viewAllocator.allocate(&viewImpl->m_descriptor)); - m_device->CreateShaderResourceView(resourceImpl->m_resource, nullptr, viewImpl->m_descriptor.cpuHandle); + + // Need to construct the D3D12_SHADER_RESOURCE_VIEW_DESC because otherwise TextureCube is not accessed + // appropriately (rather than just passing nullptr to CreateShaderResourceView) + const D3D12_RESOURCE_DESC resourceDesc = resourceImpl->m_resource.getResource()->GetDesc(); + const DXGI_FORMAT pixelFormat = resourceDesc.Format; + + D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc; + _initSrvDesc(resourceImpl->getType(), resourceImpl->getDesc(), resourceDesc, pixelFormat, srvDesc); + + m_device->CreateShaderResourceView(resourceImpl->m_resource, &srvDesc, viewImpl->m_descriptor.cpuHandle); } break; } |
