| 188 | } |
| 189 | |
| 190 | bool GPUBuffer::Init(const GPUBufferDescription& desc) |
| 191 | { |
| 192 | PROFILE_CPU(); |
| 193 | PROFILE_MEM(GraphicsBuffers); |
| 194 | |
| 195 | // Validate description |
| 196 | #if !BUILD_RELEASE |
| 197 | #define GET_NAME() GetName() |
| 198 | #else |
| 199 | #define GET_NAME() TEXT("") |
| 200 | #endif |
| 201 | if (Math::IsNotInRange<uint32>(desc.Size, 1, MAX_int32)) |
| 202 | { |
| 203 | LOG(Warning, "Cannot create buffer '{}'. Incorrect size {}.", GET_NAME(), desc.Size); |
| 204 | return true; |
| 205 | } |
| 206 | if (Math::IsNotInRange<uint32>(desc.Stride, 0, 1024)) |
| 207 | { |
| 208 | LOG(Warning, "Cannot create buffer '{}'. Incorrect stride {}.", GET_NAME(), desc.Stride); |
| 209 | return true; |
| 210 | } |
| 211 | if (EnumHasAnyFlags(desc.Flags, GPUBufferFlags::Structured)) |
| 212 | { |
| 213 | if (desc.Stride <= 0) |
| 214 | { |
| 215 | LOG(Warning, "Cannot create buffer '{}'. Element size cannot be less or equal 0 for structured buffer.", GET_NAME()); |
| 216 | return true; |
| 217 | } |
| 218 | } |
| 219 | if (EnumHasAnyFlags(desc.Flags, GPUBufferFlags::RawBuffer)) |
| 220 | { |
| 221 | if (desc.Format != PixelFormat::R32_Typeless) |
| 222 | { |
| 223 | LOG(Warning, "Cannot create buffer '{}'. Raw buffers must use format R32_Typeless.", GET_NAME()); |
| 224 | return true; |
| 225 | } |
| 226 | } |
| 227 | if (EnumHasAnyFlags(desc.Flags, GPUBufferFlags::VertexBuffer)) |
| 228 | { |
| 229 | if (desc.VertexLayout == nullptr) |
| 230 | { |
| 231 | // [Deprecated in v1.10] Change this into an error as VertexLayout becomes a requirement when layout is no longer set in a vertex shader |
| 232 | LOG(Warning, "Missing Vertex Layout in buffer '{}'. Vertex Buffers should provide layout information about contained vertex elements.", GET_NAME()); |
| 233 | } |
| 234 | } |
| 235 | #undef GET_NAME |
| 236 | |
| 237 | // Release previous data |
| 238 | ReleaseGPU(); |
| 239 | |
| 240 | // Initialize |
| 241 | _desc = desc; |
| 242 | if (OnInit()) |
| 243 | { |
| 244 | ReleaseGPU(); |
| 245 | LOG(Warning, "Cannot initialize buffer. Description: {0}", desc.ToString()); |
| 246 | return true; |
| 247 | } |
no test coverage detected