spirv_cpp.hpp 2.3 KB

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