spirv_cpp.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2015-2021 Arm Limited
  3. * SPDX-License-Identifier: Apache-2.0 OR MIT
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*
  18. * At your option, you may choose to accept this material under either:
  19. * 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
  20. * 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
  21. */
  22. #ifndef SPIRV_CROSS_CPP_HPP
  23. #define SPIRV_CROSS_CPP_HPP
  24. #include "spirv_glsl.hpp"
  25. #include <utility>
  26. namespace SPIRV_CROSS_NAMESPACE
  27. {
  28. class CompilerCPP : public CompilerGLSL
  29. {
  30. public:
  31. explicit CompilerCPP(std::vector<uint32_t> spirv_)
  32. : CompilerGLSL(std::move(spirv_))
  33. {
  34. }
  35. CompilerCPP(const uint32_t *ir_, size_t word_count)
  36. : CompilerGLSL(ir_, word_count)
  37. {
  38. }
  39. explicit CompilerCPP(const ParsedIR &ir_)
  40. : CompilerGLSL(ir_)
  41. {
  42. }
  43. explicit CompilerCPP(ParsedIR &&ir_)
  44. : CompilerGLSL(std::move(ir_))
  45. {
  46. }
  47. std::string compile() override;
  48. // Sets a custom symbol name that can override
  49. // spirv_cross_get_interface.
  50. //
  51. // Useful when several shader interfaces are linked
  52. // statically into the same binary.
  53. void set_interface_name(std::string name)
  54. {
  55. interface_name = std::move(name);
  56. }
  57. private:
  58. void emit_header() override;
  59. void emit_c_linkage();
  60. void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override;
  61. void emit_resources();
  62. void emit_buffer_block(const SPIRVariable &type) override;
  63. void emit_push_constant_block(const SPIRVariable &var) override;
  64. void emit_interface_block(const SPIRVariable &type);
  65. void emit_block_chain(SPIRBlock &block);
  66. void emit_uniform(const SPIRVariable &var) override;
  67. void emit_shared(const SPIRVariable &var);
  68. void emit_block_struct(SPIRType &type);
  69. std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id) override;
  70. std::string argument_decl(const SPIRFunction::Parameter &arg);
  71. SmallVector<std::string> resource_registrations;
  72. std::string impl_type;
  73. std::string resource_type;
  74. uint32_t shared_counter = 0;
  75. std::string interface_name;
  76. };
  77. } // namespace SPIRV_CROSS_NAMESPACE
  78. #endif