spirv_reflect.hpp 2.5 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. using namespace SPIRV_CROSS_SPV_HEADER_NAMESPACE;
  33. class CompilerReflection : public CompilerGLSL
  34. {
  35. using Parent = CompilerGLSL;
  36. public:
  37. explicit CompilerReflection(std::vector<uint32_t> spirv_)
  38. : Parent(std::move(spirv_))
  39. {
  40. options.vulkan_semantics = true;
  41. }
  42. CompilerReflection(const uint32_t *ir_, size_t word_count)
  43. : Parent(ir_, word_count)
  44. {
  45. options.vulkan_semantics = true;
  46. }
  47. explicit CompilerReflection(const ParsedIR &ir_)
  48. : CompilerGLSL(ir_)
  49. {
  50. options.vulkan_semantics = true;
  51. }
  52. explicit CompilerReflection(ParsedIR &&ir_)
  53. : CompilerGLSL(std::move(ir_))
  54. {
  55. options.vulkan_semantics = true;
  56. }
  57. void set_format(const std::string &format);
  58. std::string compile() override;
  59. private:
  60. static std::string execution_model_to_str(ExecutionModel model);
  61. void emit_entry_points();
  62. void emit_types();
  63. void emit_resources();
  64. void emit_specialization_constants();
  65. void emit_type(uint32_t type_id, bool &emitted_open_tag);
  66. void emit_type_member(const SPIRType &type, uint32_t index);
  67. void emit_type_member_qualifiers(const SPIRType &type, uint32_t index);
  68. void emit_type_array(const SPIRType &type);
  69. void emit_resources(const char *tag, const SmallVector<Resource> &resources);
  70. bool type_is_reference(const SPIRType &type) const;
  71. std::string to_member_name(const SPIRType &type, uint32_t index) const;
  72. std::shared_ptr<simple_json::Stream> json_stream;
  73. };
  74. } // namespace SPIRV_CROSS_NAMESPACE
  75. #endif