Decode a texture into 32-bit floats and copies it to the CPU
| 168 | |
| 169 | // Decode a texture into 32-bit floats and copies it to the CPU |
| 170 | void GetTextureData(ID3D11Device* device, ID3D11ShaderResourceView* textureSRV, |
| 171 | std::vector<Float4>& textureData) |
| 172 | { |
| 173 | static ComputeShaderPtr decodeTextureCS; |
| 174 | static ComputeShaderPtr decodeTextureArrayCS; |
| 175 | |
| 176 | static const uint32 TGSize = 16; |
| 177 | |
| 178 | if(decodeTextureCS.Valid() == false) |
| 179 | { |
| 180 | CompileOptions opts; |
| 181 | opts.Add("TGSize_", TGSize); |
| 182 | decodeTextureCS = CompileCSFromFile(device, L"SampleFramework11\\Shaders\\DecodeTextureCS.hlsl", |
| 183 | "DecodeTextureCS", "cs_5_0", opts); |
| 184 | |
| 185 | decodeTextureArrayCS = CompileCSFromFile(device, L"SampleFramework11\\Shaders\\DecodeTextureCS.hlsl", |
| 186 | "DecodeTextureArrayCS", "cs_5_0", opts); |
| 187 | } |
| 188 | |
| 189 | ID3D11Texture2DPtr texture; |
| 190 | textureSRV->GetResource(reinterpret_cast<ID3D11Resource**>(&texture)); |
| 191 | |
| 192 | D3D11_TEXTURE2D_DESC texDesc; |
| 193 | texture->GetDesc(&texDesc); |
| 194 | |
| 195 | D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; |
| 196 | textureSRV->GetDesc(&srvDesc); |
| 197 | |
| 198 | ID3D11ShaderResourceViewPtr sourceSRV = textureSRV; |
| 199 | uint32 arraySize = texDesc.ArraySize; |
| 200 | if(srvDesc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE |
| 201 | || srvDesc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY) |
| 202 | { |
| 203 | arraySize *= 6; |
| 204 | |
| 205 | srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; |
| 206 | srvDesc.Texture2DArray.ArraySize = arraySize; |
| 207 | srvDesc.Texture2DArray.FirstArraySlice = 0; |
| 208 | srvDesc.Texture2DArray.MostDetailedMip = 0; |
| 209 | srvDesc.Texture2DArray.MipLevels = -1; |
| 210 | DXCall(device->CreateShaderResourceView(texture, &srvDesc, &sourceSRV)); |
| 211 | } |
| 212 | |
| 213 | D3D11_TEXTURE2D_DESC decodeTextureDesc; |
| 214 | decodeTextureDesc.Width = texDesc.Width; |
| 215 | decodeTextureDesc.Height = texDesc.Height; |
| 216 | decodeTextureDesc.ArraySize = arraySize; |
| 217 | decodeTextureDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS; |
| 218 | decodeTextureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; |
| 219 | decodeTextureDesc.MipLevels = 1; |
| 220 | decodeTextureDesc.MiscFlags = 0; |
| 221 | decodeTextureDesc.SampleDesc.Count = 1; |
| 222 | decodeTextureDesc.SampleDesc.Quality = 0; |
| 223 | decodeTextureDesc.Usage = D3D11_USAGE_DEFAULT; |
| 224 | decodeTextureDesc.CPUAccessFlags = 0; |
| 225 | |
| 226 | ID3D11Texture2DPtr decodeTexture; |
| 227 | DXCall(device->CreateTexture2D(&decodeTextureDesc, nullptr, &decodeTexture)); |
nothing calls this directly
no test coverage detected