Convert SPIRV-Cross type to Vulkan vertex attribute format.
503{
504 using BaseType = spirv_cross::SPIRType::BaseType;
505
506 if (type.columns > 1) {
508 "Matrix types are not valid vertex attributes (columns={})",
509 type.columns);
510 return vk::Format::eUndefined;
511 }
512
513 if (type.width != 32) {
515 "Unsupported SPIR-V vertex attribute width {} (only 32-bit supported)",
516 type.width);
517 return vk::Format::eUndefined;
518 }
519
520 const uint32_t vec_size = type.vecsize;
521 if (type.basetype == BaseType::Float) {
522 switch (vec_size) {
523 case 1:
524 return vk::Format::eR32Sfloat;
525 case 2:
526 return vk::Format::eR32G32Sfloat;
527 case 3:
528 return vk::Format::eR32G32B32Sfloat;
529 case 4:
530 return vk::Format::eR32G32B32A32Sfloat;
531 }
532 } else if (type.basetype == BaseType::Int) {
533 switch (vec_size) {
534 case 1:
535 return vk::Format::eR32Sint;
536 case 2:
537 return vk::Format::eR32G32Sint;
538 case 3:
539 return vk::Format::eR32G32B32Sint;
540 case 4:
541 return vk::Format::eR32G32B32A32Sint;
542 }
543 } else if (type.basetype == BaseType::UInt) {
544 switch (vec_size) {
545 case 1:
546 return vk::Format::eR32Uint;
547 case 2:
548 return vk::Format::eR32G32Uint;
549 case 3:
550 return vk::Format::eR32G32B32Uint;
551 case 4:
552 return vk::Format::eR32G32B32A32Uint;
553 }
554 }
555
557 "Unsupported SPIR-V vertex attribute type (basetype={}, vecsize={})",
558 static_cast<int>(type.basetype), vec_size);
559
560 return vk::Format::eUndefined;
561}
#define MF_WARN(comp, ctx,...)
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.