1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#!/usr/bin/env python3
#
# Copyright (c) 2021 LunarG, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
import sys
from base_generator import BaseGenerator, write
from dx12_base_generator import Dx12BaseGenerator
from base_struct_decoders_header_generator import BaseStructDecodersHeaderGenerator
class Dx12DecoderHeaderGenerator(
Dx12BaseGenerator, BaseStructDecodersHeaderGenerator
):
"""Generates C++ functions responsible for decoding Dx12 API calls."""
def __init__(
self,
source_dict,
dx12_prefix_strings,
err_file=sys.stderr,
warn_file=sys.stderr,
diag_file=sys.stdout
):
Dx12BaseGenerator.__init__(
self, source_dict, dx12_prefix_strings, err_file, warn_file,
diag_file
)
def beginFile(self, gen_opts):
"""Methond override."""
BaseGenerator.beginFile(self, gen_opts)
self.write_include()
write('GFXRECON_BEGIN_NAMESPACE(gfxrecon)', file=self.outFile)
write('GFXRECON_BEGIN_NAMESPACE(decode)', file=self.outFile)
self.newline()
def generate_feature(self):
"""Methond override."""
Dx12BaseGenerator.generate_feature(self)
self.write_dx12_decoder_class()
def write_include(self):
"""Methond override."""
code = ("\n" "#include \"decode/dx12_decoder_base.h\"\n" "\n")
write(code, file=self.outFile)
def get_decoder_method_body(self, params):
return ';'
def get_decode_function_call_body(self):
return ';'
def get_decode_method_call_body(self):
return ';'
def get_decoder_function(
self, class_name, method_info, indent, function_class
):
object_param = ''
if class_name:
class_name = '_' + class_name
object_param = 'format::HandleId object_id, '
return (
'{}size_t {}Decode{}_{}({}const ApiCallInfo& call_info, const uint8_t* parameter_buffer, size_t buffer_size){}\n'
.format(
indent, function_class, class_name, method_info['name'],
object_param,
self.get_decoder_method_body(method_info['parameters'])
)
)
def get_decoder_class_define(self):
declaration = (
"class Dx12Decoder : public Dx12DecoderBase\n"
"{{\n"
" public:\n"
" Dx12Decoder(){{}}\n"
" virtual ~Dx12Decoder() override {{}}\n"
"\n"
" virtual void DecodeFunctionCall(format::ApiCallId call_id,\n"
" const ApiCallInfo& call_options,\n"
" const uint8_t* parameter_buffer,\n"
" size_t buffer_size) override{}\n"
"\n"
" virtual void DecodeMethodCall(format::ApiCallId call_id,\n"
" format::HandleId object_id,\n"
" const ApiCallInfo& call_options,\n"
" const uint8_t* parameter_buffer,\n"
" size_t buffer_size) override{}\n"
" private:\n".format(
self.get_decode_function_call_body(),
self.get_decode_method_call_body()
)
)
indent = ' '
function_class = ''
class_end = '};\n'
return (declaration, indent, function_class, class_end)
def write_dx12_decoder_class(self):
declaration, indent, function_class, class_end = self.get_decoder_class_define(
)
code = declaration
header_dict = self.source_dict['header_dict']
for k, v in header_dict.items():
code_length = len(code)
for m in v.functions:
if self.is_required_function_data(m) and (
not self.is_cmd_black_listed(m['name'])
):
code += self.get_decoder_function(
'', m, indent, function_class
)
for class_name, class_value in v.classes.items():
if self.is_required_class_data(class_value):
for m in class_value['methods']['public']:
if not self.is_method_black_listed(
class_name, m['name']
):
code += self.get_decoder_function(
class_name, m, indent, function_class
)
code_length2 = len(code)
if code_length2 > code_length:
code = (
code[:code_length] + '\n'
+ self.dx12_prefix_strings.format(k) + '\n'
+ code[code_length:]
)
code += class_end
write(code, file=self.outFile)
def endFile(self):
"""Methond override."""
self.newline()
write('GFXRECON_END_NAMESPACE(decode)', file=self.outFile)
write('GFXRECON_END_NAMESPACE(gfxrecon)', file=self.outFile)
# Finish processing in superclass
BaseGenerator.endFile(self)
|