• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // MARK-V is a compression format for SPIR-V binaries. It strips away
16 // non-essential information (such as result ids which can be regenerated) and
17 // uses various bit reduction techiniques to reduce the size of the binary.
18 //
19 // WIP: MARK-V codec is in early stages of development. At the moment it only
20 // can encode and decode some SPIR-V files and only if exacly the same build of
21 // software is used (is doesn't write or handle version numbers yet).
22 
23 #ifndef SPIRV_TOOLS_MARKV_H_
24 #define SPIRV_TOOLS_MARKV_H_
25 
26 #include "libspirv.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 typedef struct spv_markv_binary_t {
33   uint8_t* data;
34   size_t length;
35 } spv_markv_binary_t;
36 
37 typedef spv_markv_binary_t* spv_markv_binary;
38 typedef const spv_markv_binary_t* const_spv_markv_binary;
39 
40 typedef struct spv_markv_encoder_options_t spv_markv_encoder_options_t;
41 typedef spv_markv_encoder_options_t* spv_markv_encoder_options;
42 typedef const spv_markv_encoder_options_t* spv_const_markv_encoder_options;
43 
44 typedef struct spv_markv_decoder_options_t spv_markv_decoder_options_t;
45 typedef spv_markv_decoder_options_t* spv_markv_decoder_options;
46 typedef const spv_markv_decoder_options_t* spv_const_markv_decoder_options;
47 
48 // Creates spv_markv_encoder_options with default options. Returns a valid
49 // options object. The object remains valid until it is passed into
50 // spvMarkvEncoderOptionsDestroy.
51 spv_markv_encoder_options spvMarkvEncoderOptionsCreate();
52 
53 // Destroys the given spv_markv_encoder_options object.
54 void spvMarkvEncoderOptionsDestroy(spv_markv_encoder_options options);
55 
56 // Creates spv_markv_decoder_options with default options. Returns a valid
57 // options object. The object remains valid until it is passed into
58 // spvMarkvDecoderOptionsDestroy.
59 spv_markv_decoder_options spvMarkvDecoderOptionsCreate();
60 
61 // Destroys the given spv_markv_decoder_options object.
62 void spvMarkvDecoderOptionsDestroy(spv_markv_decoder_options options);
63 
64 // Encodes the given SPIR-V binary to MARK-V binary.
65 // If |comments| is not nullptr, it would contain a textual description of
66 // how encoding was done (with snippets of disassembly and bit sequences).
67 spv_result_t spvSpirvToMarkv(spv_const_context context,
68                              const uint32_t* spirv_words,
69                              size_t spirv_num_words,
70                              spv_const_markv_encoder_options options,
71                              spv_markv_binary* markv_binary,
72                              spv_text* comments, spv_diagnostic* diagnostic);
73 
74 // Decodes a SPIR-V binary from the given MARK-V binary.
75 // If |comments| is not nullptr, it would contain a textual description of
76 // how decoding was done (with snippets of disassembly and bit sequences).
77 spv_result_t spvMarkvToSpirv(spv_const_context context,
78                              const uint8_t* markv_data,
79                              size_t markv_size_bytes,
80                              spv_const_markv_decoder_options options,
81                              spv_binary* spirv_binary,
82                              spv_text* comments, spv_diagnostic* diagnostic);
83 
84 // Destroys MARK-V binary created by spvSpirvToMarkv().
85 void spvMarkvBinaryDestroy(spv_markv_binary binary);
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif  // SPIRV_TOOLS_MARKV_H_
92