• 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 #include "tools/comp/markv_model_shader.h"
16 
17 #include <algorithm>
18 #include <map>
19 #include <memory>
20 #include <unordered_map>
21 #include <unordered_set>
22 #include <vector>
23 
24 #include "source/util/make_unique.h"
25 
26 namespace spvtools {
27 namespace comp {
28 namespace {
29 
30 // Signals that the value is not in the coding scheme and a fallback method
31 // needs to be used.
32 const uint64_t kMarkvNoneOfTheAbove = MarkvModel::GetMarkvNoneOfTheAbove();
33 
CombineOpcodeAndNumOperands(uint32_t opcode,uint32_t num_operands)34 inline uint32_t CombineOpcodeAndNumOperands(uint32_t opcode,
35                                             uint32_t num_operands) {
36   return opcode | (num_operands << 16);
37 }
38 
39 #include "tools/comp/markv_model_shader_default_autogen.inc"
40 
41 }  // namespace
42 
MarkvModelShaderLite()43 MarkvModelShaderLite::MarkvModelShaderLite() {
44   const uint16_t kVersionNumber = 1;
45   SetModelVersion(kVersionNumber);
46 
47   opcode_and_num_operands_huffman_codec_ =
48       MakeUnique<HuffmanCodec<uint64_t>>(GetOpcodeAndNumOperandsHist());
49 
50   id_fallback_strategy_ = IdFallbackStrategy::kShortDescriptor;
51 }
52 
MarkvModelShaderMid()53 MarkvModelShaderMid::MarkvModelShaderMid() {
54   const uint16_t kVersionNumber = 1;
55   SetModelVersion(kVersionNumber);
56 
57   opcode_and_num_operands_huffman_codec_ =
58       MakeUnique<HuffmanCodec<uint64_t>>(GetOpcodeAndNumOperandsHist());
59   non_id_word_huffman_codecs_ = GetNonIdWordHuffmanCodecs();
60   id_descriptor_huffman_codecs_ = GetIdDescriptorHuffmanCodecs();
61   descriptors_with_coding_scheme_ = GetDescriptorsWithCodingScheme();
62   literal_string_huffman_codecs_ = GetLiteralStringHuffmanCodecs();
63 
64   id_fallback_strategy_ = IdFallbackStrategy::kShortDescriptor;
65 }
66 
MarkvModelShaderMax()67 MarkvModelShaderMax::MarkvModelShaderMax() {
68   const uint16_t kVersionNumber = 1;
69   SetModelVersion(kVersionNumber);
70 
71   opcode_and_num_operands_huffman_codec_ =
72       MakeUnique<HuffmanCodec<uint64_t>>(GetOpcodeAndNumOperandsHist());
73   opcode_and_num_operands_markov_huffman_codecs_ =
74       GetOpcodeAndNumOperandsMarkovHuffmanCodecs();
75   non_id_word_huffman_codecs_ = GetNonIdWordHuffmanCodecs();
76   id_descriptor_huffman_codecs_ = GetIdDescriptorHuffmanCodecs();
77   descriptors_with_coding_scheme_ = GetDescriptorsWithCodingScheme();
78   literal_string_huffman_codecs_ = GetLiteralStringHuffmanCodecs();
79 
80   id_fallback_strategy_ = IdFallbackStrategy::kRuleBased;
81 }
82 
83 }  // namespace comp
84 }  // namespace spvtools
85