MetalError.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /******************************************************************************
  2. Copyright (C) 2024 by Patrick Heyer <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. enum MetalError {
  15. enum MTLCommandQueueError: Error, CustomStringConvertible {
  16. case commandBufferCreationFailure
  17. var description: String {
  18. switch self {
  19. case .commandBufferCreationFailure:
  20. "MTLCommandQueue failed to create command buffer"
  21. }
  22. }
  23. }
  24. enum MTLDeviceError: Error, CustomStringConvertible {
  25. case commandQueueCreationFailure
  26. case displayLinkCreationFailure
  27. case bufferCreationFailure(String)
  28. case shaderCompilationFailure(String)
  29. case pipelineStateCreationFailure
  30. case depthStencilStateCreationFailure
  31. case samplerStateCreationFailure
  32. var description: String {
  33. switch self {
  34. case .commandQueueCreationFailure:
  35. "MTLDevice failed to create command queue"
  36. case .displayLinkCreationFailure:
  37. "MTLDevice failed to create CVDisplayLink for projector output"
  38. case .bufferCreationFailure(_):
  39. "MTLDevice failed to create buffer"
  40. case .shaderCompilationFailure(_):
  41. "MTLDevice failed to create shader library and function"
  42. case .pipelineStateCreationFailure:
  43. "MTLDevice failed to create render pipeline state"
  44. case .depthStencilStateCreationFailure:
  45. "MTLDevice failed to create depth stencil state"
  46. case .samplerStateCreationFailure:
  47. "MTLDevice failed to create sampler state with provided descriptor"
  48. }
  49. }
  50. }
  51. enum MTLCommandBufferError: Error, CustomStringConvertible {
  52. case encoderCreationFailure
  53. var description: String {
  54. switch self {
  55. case .encoderCreationFailure:
  56. "MTLCommandBuffer failed to create command encoder"
  57. }
  58. }
  59. }
  60. enum MetalShaderError: Error, CustomStringConvertible {
  61. case missingVertexDescriptor
  62. case missingSamplerDescriptors
  63. var description: String {
  64. switch self {
  65. case .missingVertexDescriptor:
  66. "MetalShader of type vertex requires a vertex descriptor"
  67. case .missingSamplerDescriptors:
  68. "MetalShader of type fragment requires at least a single sampler descriptor"
  69. }
  70. }
  71. }
  72. enum OBSShaderParserError: Error, CustomStringConvertible {
  73. case parseFail(String)
  74. case unsupportedType
  75. case missingNextToken
  76. case unexpectedToken
  77. case missingMainFunction
  78. var description: String {
  79. switch self {
  80. case .parseFail:
  81. "Failed to parse provided shader string"
  82. case .unsupportedType:
  83. "Provided GS type is not convertible to a Metal type"
  84. case .missingNextToken:
  85. "Required next token not found in parser token collection"
  86. case .unexpectedToken:
  87. "Required next token had unexpected type in parser token collection"
  88. case .missingMainFunction:
  89. "Shader has no main function"
  90. }
  91. }
  92. }
  93. enum OBSShaderError: Error, CustomStringConvertible {
  94. case unsupportedType
  95. case parseFail(String)
  96. case parseError(String)
  97. case transpileError(String)
  98. var description: String {
  99. switch self {
  100. case .unsupportedType:
  101. "Unsupported Metal shader type"
  102. case .parseFail(_):
  103. "OBS shader parser failed to parse effect"
  104. case .parseError(_):
  105. "OBS shader parser encountered warnings and/or errors while parsing effect"
  106. case .transpileError(_):
  107. "Transpiling OBS effects file into MSL shader failed"
  108. }
  109. }
  110. }
  111. }