| 160 | } |
| 161 | |
| 162 | bool ParticleBuffer::AllocateSortBuffer() |
| 163 | { |
| 164 | ASSERT(Emitter && GPU.SortedIndices == nullptr && GPU.SortingKeys == nullptr); |
| 165 | if (Emitter->Graph.SortModules.IsEmpty()) |
| 166 | return false; |
| 167 | const int32 sortedIndicesCount = Capacity * Emitter->Graph.SortModules.Count(); |
| 168 | uint32 indexSize = sizeof(uint32); |
| 169 | PixelFormat indexFormat = PixelFormat::R32_UInt; |
| 170 | auto r16Support = GPUDevice::Instance->GetFormatFeatures(PixelFormat::R16_UInt).Support; |
| 171 | auto indexFormatRequirements = FormatSupport::Buffer | FormatSupport::UnorderedAccessReadOnly; |
| 172 | if (Mode == ParticlesSimulationMode::GPU) |
| 173 | indexFormatRequirements |= FormatSupport::UnorderedAccess; |
| 174 | if (Capacity <= MAX_uint16 && EnumHasAllFlags(r16Support, indexFormatRequirements)) |
| 175 | { |
| 176 | // 16-bit indices |
| 177 | indexSize = sizeof(uint16); |
| 178 | indexFormat = PixelFormat::R16_UInt; |
| 179 | } |
| 180 | |
| 181 | switch (Mode) |
| 182 | { |
| 183 | case ParticlesSimulationMode::CPU: |
| 184 | { |
| 185 | GPU.SortedIndices = GPUDevice::Instance->CreateBuffer(TEXT("ParticleSortedIndices")); |
| 186 | if (GPU.SortedIndices->Init(GPUBufferDescription::Buffer(sortedIndicesCount * indexSize, GPUBufferFlags::ShaderResource, indexFormat, nullptr, indexSize, GPUResourceUsage::Dynamic))) |
| 187 | return true; |
| 188 | break; |
| 189 | } |
| 190 | #if COMPILE_WITH_GPU_PARTICLES |
| 191 | case ParticlesSimulationMode::GPU: |
| 192 | { |
| 193 | GPU.SortingKeys = GPUDevice::Instance->CreateBuffer(TEXT("ParticleSortingKeys")); |
| 194 | if (GPU.SortingKeys->Init(GPUBufferDescription::Buffer(sortedIndicesCount * sizeof(float), GPUBufferFlags::ShaderResource | GPUBufferFlags::UnorderedAccess, PixelFormat::R32_Float, nullptr, sizeof(float)))) |
| 195 | return true; |
| 196 | GPU.SortedIndices = GPUDevice::Instance->CreateBuffer(TEXT("ParticleSortedIndices")); |
| 197 | if (GPU.SortedIndices->Init(GPUBufferDescription::Buffer(sortedIndicesCount * indexSize, GPUBufferFlags::ShaderResource | GPUBufferFlags::UnorderedAccess, indexFormat, nullptr, indexSize))) |
| 198 | return true; |
| 199 | break; |
| 200 | } |
| 201 | #endif |
| 202 | default: |
| 203 | CRASH; |
| 204 | return true; |
| 205 | } |
| 206 | |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | void ParticleBuffer::Clear() |
| 211 | { |
no test coverage detected