| 50 | |
| 51 | template<typename T> |
| 52 | static void GetTextureData(ID3D11Device* device, ID3D11ShaderResourceView* textureSRV, |
| 53 | DXGI_FORMAT outFormat, TextureData<T>& texData) |
| 54 | { |
| 55 | static ComputeShaderPtr decodeTextureCS; |
| 56 | static ComputeShaderPtr decodeTextureArrayCS; |
| 57 | |
| 58 | static const uint32 TGSize = 16; |
| 59 | |
| 60 | if(decodeTextureCS.Valid() == false) |
| 61 | { |
| 62 | CompileOptions opts; |
| 63 | opts.Add("TGSize_", TGSize); |
| 64 | const std::wstring shaderPath = SampleFrameworkDir() + L"Shaders\\DecodeTextureCS.hlsl"; |
| 65 | decodeTextureCS = CompileCSFromFile(device, shaderPath.c_str(), "DecodeTextureCS", "cs_5_0", opts); |
| 66 | |
| 67 | decodeTextureArrayCS = CompileCSFromFile(device, shaderPath.c_str(), "DecodeTextureArrayCS", "cs_5_0", opts); |
| 68 | } |
| 69 | |
| 70 | ID3D11Texture2DPtr texture; |
| 71 | textureSRV->GetResource(reinterpret_cast<ID3D11Resource**>(&texture)); |
| 72 | |
| 73 | D3D11_TEXTURE2D_DESC texDesc; |
| 74 | texture->GetDesc(&texDesc); |
| 75 | |
| 76 | D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; |
| 77 | textureSRV->GetDesc(&srvDesc); |
| 78 | |
| 79 | ID3D11ShaderResourceViewPtr sourceSRV = textureSRV; |
| 80 | uint32 arraySize = texDesc.ArraySize; |
| 81 | if(srvDesc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE |
| 82 | || srvDesc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY) |
| 83 | { |
| 84 | srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; |
| 85 | srvDesc.Texture2DArray.ArraySize = arraySize; |
| 86 | srvDesc.Texture2DArray.FirstArraySlice = 0; |
| 87 | srvDesc.Texture2DArray.MostDetailedMip = 0; |
| 88 | srvDesc.Texture2DArray.MipLevels = -1; |
| 89 | DXCall(device->CreateShaderResourceView(texture, &srvDesc, &sourceSRV)); |
| 90 | } |
| 91 | |
| 92 | D3D11_TEXTURE2D_DESC decodeTextureDesc; |
| 93 | decodeTextureDesc.Width = texDesc.Width; |
| 94 | decodeTextureDesc.Height = texDesc.Height; |
| 95 | decodeTextureDesc.ArraySize = arraySize; |
| 96 | decodeTextureDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS; |
| 97 | decodeTextureDesc.Format = outFormat; |
| 98 | decodeTextureDesc.MipLevels = 1; |
| 99 | decodeTextureDesc.MiscFlags = 0; |
| 100 | decodeTextureDesc.SampleDesc.Count = 1; |
| 101 | decodeTextureDesc.SampleDesc.Quality = 0; |
| 102 | decodeTextureDesc.Usage = D3D11_USAGE_DEFAULT; |
| 103 | decodeTextureDesc.CPUAccessFlags = 0; |
| 104 | |
| 105 | ID3D11Texture2DPtr decodeTexture; |
| 106 | DXCall(device->CreateTexture2D(&decodeTextureDesc, nullptr, &decodeTexture)); |
| 107 | |
| 108 | ID3D11UnorderedAccessViewPtr decodeTextureUAV; |
| 109 | DXCall(device->CreateUnorderedAccessView(decodeTexture, nullptr, &decodeTextureUAV)); |
no test coverage detected