| 21 | */ |
| 22 | |
| 23 | bool ShaderProgram::ValidateShaderComposition(Shader* const * shaders, std::size_t numShaders) |
| 24 | { |
| 25 | enum ShaderTypeBits |
| 26 | { |
| 27 | BitVert = (1 << static_cast<int>( ShaderType::Vertex )), |
| 28 | BitTesc = (1 << static_cast<int>( ShaderType::TessControl )), |
| 29 | BitTese = (1 << static_cast<int>( ShaderType::TessEvaluation )), |
| 30 | BitGeom = (1 << static_cast<int>( ShaderType::Geometry )), |
| 31 | BitFrag = (1 << static_cast<int>( ShaderType::Fragment )), |
| 32 | BitComp = (1 << static_cast<int>( ShaderType::Compute )), |
| 33 | }; |
| 34 | |
| 35 | /* Determine which shader types are attached */ |
| 36 | bool hasPostTessVertexShader = false; |
| 37 | int bitmask = 0; |
| 38 | |
| 39 | for (std::size_t i = 0; i < numShaders; ++i) |
| 40 | { |
| 41 | if (auto shader = shaders[i]) |
| 42 | { |
| 43 | /* Check if bit was already set */ |
| 44 | auto bit = (1 << static_cast<int>(shader->GetType())); |
| 45 | |
| 46 | if ((bitmask & bit) != 0) |
| 47 | return false; |
| 48 | |
| 49 | bitmask |= bit; |
| 50 | |
| 51 | /* Check if a post-tessellation vertex shader is used to enable validation with Metal semantics */ |
| 52 | if (shader->IsPostTessellationVertex()) |
| 53 | hasPostTessVertexShader = true; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /* Validate composition of attached shaders */ |
| 58 | if (hasPostTessVertexShader) |
| 59 | { |
| 60 | switch (bitmask) |
| 61 | { |
| 62 | case ( BitVert ): |
| 63 | case ( BitVert | BitFrag): |
| 64 | case (BitComp ): |
| 65 | case (BitComp | BitVert ): |
| 66 | case (BitComp | BitVert | BitFrag): |
| 67 | return true; |
| 68 | } |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | switch (bitmask) |
| 73 | { |
| 74 | case (BitVert ): |
| 75 | case (BitVert | BitGeom ): |
| 76 | case (BitVert | BitTesc | BitTese ): |
| 77 | case (BitVert | BitTesc | BitTese | BitGeom ): |
| 78 | case (BitVert | BitFrag): |
| 79 | case (BitVert | BitGeom | BitFrag): |
| 80 | case (BitVert | BitTesc | BitTese | BitFrag): |
nothing calls this directly
no test coverage detected