spirv_reflect.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2018-2021 Bradley Austin Davis
  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_REFLECT_HPP
  23. #define SPIRV_CROSS_REFLECT_HPP
  24. #include "spirv_glsl.hpp"
  25. #include <utility>
  26. namespace simple_json
  27. {
  28. class Stream;
  29. }
  30. namespace SPIRV_CROSS_NAMESPACE
  31. {
  32. class CompilerReflection : public CompilerGLSL
  33. {
  34. using Parent = CompilerGLSL;
  35. public:
  36. explicit CompilerReflection(std::vector<uint32_t> spirv_)
  37. : Parent(std::move(spirv_))
  38. {
  39. options.vulkan_semantics = true;
  40. }
  41. CompilerReflection(const uint32_t *ir_, size_t word_count)
  42. : Parent(ir_, word_count)
  43. {
  44. options.vulkan_semantics = true;
  45. }
  46. explicit CompilerReflection(const ParsedIR &ir_)
  47. : CompilerGLSL(ir_)
  48. {
  49. options.vulkan_semantics = true;
  50. }
  51. explicit CompilerReflection(ParsedIR &&ir_)
  52. : CompilerGLSL(std::move(ir_))
  53. {
  54. options.vulkan_semantics = true;
  55. }
  56. void set_format(const std::string &format);
  57. std::string compile() override;
  58. private:
  59. static std::string execution_model_to_str(spv::ExecutionModel model);
  60. void emit_entry_points();
  61. void emit_types();
  62. void emit_resources();
  63. void emit_specialization_constants();
  64. void emit_type(uint32_t type_id, bool &emitted_open_tag);
  65. void emit_type_member(const SPIRType &type, uint32_t index);
  66. void emit_type_member_qualifiers(const SPIRType &type, uint32_t index);
  67. void emit_type_array(const SPIRType &type);
  68. void emit_resources(const char *tag, const SmallVector<Resource> &resources);
  69. bool type_is_reference(const SPIRType &type) const;
  70. std::string to_member_name(const SPIRType &type, uint32_t index) const;
  71. std::shared_ptr<simple_json::Stream> json_stream;
  72. };
  73. } // namespace SPIRV_CROSS_NAMESPACE
  74. #endif