Skip to content

Commit

Permalink
dx12 codegen: Run yapf on all files changed
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkY-LunarG committed Oct 24, 2024
1 parent edc3ef2 commit d931ce6
Show file tree
Hide file tree
Showing 23 changed files with 293 additions and 163 deletions.
9 changes: 6 additions & 3 deletions framework/generated/dx12_generators/dx12_CppHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,14 @@ def preprocess_file(self, lines):

if 'DEFINE_ENUM_FLAG_OPERATORS(' in line:
continue

if interface_scope == 0:
source += line
enum_scope = line.startswith('typedef enum ')
if (line.startswith('#if') and ('!defined(CINTERFACE)' in line)) or enum_scope:
if (
line.startswith('#if') and
('!defined(CINTERFACE)' in line)
) or enum_scope:
interface_scope = 1
else:
if enum_scope:
Expand All @@ -131,7 +134,7 @@ def preprocess_file(self, lines):
else:
if line.startswith('#if'):
interface_scope += 1

if 'defined(_MSC_VER) || !defined(_WIN32)' in line:
retval_param = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def get_encode_struct(self, value, is_generating_struct, is_result):
return ''

def get_encode_value(
self, value, caller_values, function_name, function_value, is_generating_struct,
is_result
self, value, caller_values, function_name, function_value,
is_generating_struct, is_result
):
"""Method override."""
write_parameter_value = ''
Expand All @@ -174,7 +174,9 @@ def get_encode_value(
# This is a void** pointer to a memory allocation with a size defined by value.array_length,
# not a void* array. For this case, we will encode the content of the memory allocation, and
# need to dereference the void** pointer.
dereference_expr = '({prefix}{param} != nullptr) ? *{prefix}{param} : nullptr'.format(prefix=write_parameter_value, param=value.name)
dereference_expr = '({prefix}{param} != nullptr) ? *{prefix}{param} : nullptr'.format(
prefix=write_parameter_value, param=value.name
)
return 'encoder->Encode{}Array({}, {}{});'.format(
function_name, dereference_expr,
self.get_encode_str_array_length(
Expand All @@ -183,9 +185,12 @@ def get_encode_value(
)
elif value.pointer_count == 2:
method_call = 'Encode{}Array2D'.format(function_name)
make_array_2d = ', '.join(self.make_array2d_length_expression(value, caller_values))
make_array_2d = ', '.join(
self.make_array2d_length_expression(value, caller_values)
)
return 'encoder->{}({}{}, {});'.format(
method_call, write_parameter_value, value.name, make_array_2d
method_call, write_parameter_value, value.name,
make_array_2d
)
else:
return 'encoder->Encode{}Array({}{}, {}{});'.format(
Expand Down Expand Up @@ -235,7 +240,9 @@ def get_encode_value(
)
return ''

def get_encode_parameter(self, value, caller_values, is_generating_struct, is_result):
def get_encode_parameter(
self, value, caller_values, is_generating_struct, is_result
):
rtn = ''
omit_output_data = ''
if is_result and self.is_output(value):
Expand Down Expand Up @@ -301,8 +308,8 @@ def get_encode_parameter(self, value, caller_values, is_generating_struct, is_re

if encode_type:
rtn = self.get_encode_value(
value, caller_values, encode_type, function_value, is_generating_struct,
is_result
value, caller_values, encode_type, function_value,
is_generating_struct, is_result
)

if not rtn:
Expand Down Expand Up @@ -449,7 +456,9 @@ def get_encode_function_body(self, class_name, method_info, is_result):
' }\n'

for value in param_values:
encode = self.get_encode_parameter(value, param_values, False, is_result)
encode = self.get_encode_parameter(
value, param_values, False, is_result
)
body += ' {}\n'.format(encode)

rtn_type = method_info['rtnType']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def make_decode_invocation(self, value):
body += ' bytes_read += ValueDecoder::DecodeHandleIdValue({}, &{});\n'.format(
buffer_args, value.name
)
elif self.has_basetype(type_name) :
elif self.has_basetype(type_name):
base_type = self.get_basetype(type_name)
body += ' bytes_read += ValueDecoder::Decode{}Value({}, &{});\n'.format(
self.encode_types[base_type], buffer_args, value.name
Expand Down
83 changes: 49 additions & 34 deletions framework/generated/dx12_generators/dx12_base_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

import json,os,re,shutil,sys,tempfile
import json, os, re, shutil, sys, tempfile

from collections import OrderedDict

Expand All @@ -32,12 +32,14 @@
# For limited python 2 compat as used by some Vulkan consumers
from pathlib2 import Path # type: ignore


def write(*args, **kwargs):
file = kwargs.pop('file', sys.stdout)
end = kwargs.pop('end', '\n')
file.write(' '.join(str(arg) for arg in args))
file.write(end)


def make_re_string(list, default=None):
"""Turn a list of strings into a regexp string matching exactly those strings.
Pulled from Khronos genvk.py
Expand All @@ -47,13 +49,15 @@ def make_re_string(list, default=None):
else:
return default


def remove_suffix(self: str, suffix: str, /) -> str:
# suffix='' should not call self[:-0].
if suffix and self.endswith(suffix):
return self[:-len(suffix)]
else:
return self[:]


def noneStr(s):
"""Return string argument, or "" if argument is None.
Expand Down Expand Up @@ -143,6 +147,7 @@ def __init__(
self.is_const = is_const
self.is_com_outptr = is_com_outptr


class Dx12GeneratorOptions():
"""Options for generating C++ function declarations for Dx12 API.
Expand Down Expand Up @@ -306,8 +311,7 @@ class Dx12BaseGenerator():

# ID3D23CommandList is top parent class for all ID3D12GraphicsCommandList[n]
FAMILY_CLASSES_EXECPTION = {
'ID3D12GraphicsCommandList':
'ID3D12CommandList'
'ID3D12GraphicsCommandList': 'ID3D12CommandList'
}

ADD_RV_ANNOTATION_METHODS = [
Expand All @@ -317,19 +321,21 @@ class Dx12BaseGenerator():
]

REMOVE_RV_ANNOTATION_TYPES = {
'D3D12_GPU_VIRTUAL_ADDRESS':'',
'D3D12_GPU_DESCRIPTOR_HANDLE':'',
'D3D12_INDEX_BUFFER_VIEW':'',
'D3D12_VERTEX_BUFFER_VIEW':'',
'D3D12_STREAM_OUTPUT_BUFFER_VIEW':'',
'D3D12_CONSTANT_BUFFER_VIEW_DESC':'',
'D3D12_SHADER_RESOURCE_VIEW_DESC':'',
'D3D12_WRITEBUFFERIMMEDIATE_PARAMETER':'',
'D3D12_DISPATCH_RAYS_DESC':'',
'D3D12_RAYTRACING_GEOMETRY_DESC':'',
'D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC':'D3D12_RAYTRACING_GEOMETRY_DESC[]',
'D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS':'D3D12_RAYTRACING_GEOMETRY_DESC[]',
'D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC':'',
'D3D12_GPU_VIRTUAL_ADDRESS': '',
'D3D12_GPU_DESCRIPTOR_HANDLE': '',
'D3D12_INDEX_BUFFER_VIEW': '',
'D3D12_VERTEX_BUFFER_VIEW': '',
'D3D12_STREAM_OUTPUT_BUFFER_VIEW': '',
'D3D12_CONSTANT_BUFFER_VIEW_DESC': '',
'D3D12_SHADER_RESOURCE_VIEW_DESC': '',
'D3D12_WRITEBUFFERIMMEDIATE_PARAMETER': '',
'D3D12_DISPATCH_RAYS_DESC': '',
'D3D12_RAYTRACING_GEOMETRY_DESC': '',
'D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC':
'D3D12_RAYTRACING_GEOMETRY_DESC[]',
'D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS':
'D3D12_RAYTRACING_GEOMETRY_DESC[]',
'D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC': '',
}

def __init__(
Expand Down Expand Up @@ -471,7 +477,9 @@ def beginFile(self, gen_opts):

# Open a temporary file for accumulating output.
if self.genOpts.filename is not None:
self.outFile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8', newline='\n', delete=False)
self.outFile = tempfile.NamedTemporaryFile(
mode='w', encoding='utf-8', newline='\n', delete=False
)
else:
self.outFile = sys.stdout

Expand All @@ -491,7 +499,9 @@ def beginFile(self, gen_opts):

# Multiple inclusion protection & C++ wrappers.
if (gen_opts.protect_file and self.genOpts.filename):
header_sym = 'GFXRECON_' + os.path.basename(self.genOpts.filename).replace('.h', '_H').upper()
header_sym = 'GFXRECON_' + os.path.basename(
self.genOpts.filename
).replace('.h', '_H').upper()
write('#ifndef ', header_sym, file=self.outFile)
write('#define ', header_sym, file=self.outFile)
self.newline()
Expand Down Expand Up @@ -523,7 +533,9 @@ def endFile(self):
if sys.platform == 'win32':
if not Path.exists(directory):
os.makedirs(directory)
shutil.copy(self.outFile.name, directory / self.genOpts.filename)
shutil.copy(
self.outFile.name, directory / self.genOpts.filename
)
os.remove(self.outFile.name)
self.genOpts = None

Expand Down Expand Up @@ -943,9 +955,7 @@ def make_consumer_func_decl(

if return_type != 'void':
method_name = name[name.find('::Process_') + 10:]
return_value = self.get_return_value_info(
return_type, method_name
)
return_value = self.get_return_value_info(return_type, method_name)
rtn_type1 = self.make_decoded_param_type(return_value)
if rtn_type1.find('Decoder') != -1:
rtn_type1 += '*'
Expand Down Expand Up @@ -1012,7 +1022,9 @@ def make_dump_resources_func_decl(
if count == 1:
param_type = type_name[2:] + 'Info*'
else:
param_type = 'HandlePointerDecoder<{}*>'.format(type_name)
param_type = 'HandlePointerDecoder<{}*>'.format(
type_name
)
else:
param_type = 'const ' + type_name + '*'
else:
Expand Down Expand Up @@ -1047,7 +1059,9 @@ def get_wrapper_prefix_from_type(self):
return 'object_wrappers'

def is_resource_dump_class(self):
return True if ('ReplayDumpResources' in self.__class__.__name__) else False
return True if (
'ReplayDumpResources' in self.__class__.__name__
) else False

def is_dump_resources_api_call(self, call_name):
return False
Expand Down Expand Up @@ -1203,7 +1217,8 @@ def get_array_len(self, param):
if 'null-terminated' in len:
if len == 'null-terminated':
paramname = param.find('name')
if (paramname.tail is not None) and ('[' in paramname.tail):
if (paramname.tail
is not None) and ('[' in paramname.tail):
paramenumsizes = param.findall('enum')
for paramenumsize in paramenumsizes:
result = paramenumsize.text
Expand Down Expand Up @@ -1235,7 +1250,7 @@ def get_array_len(self, param):
first = False
result = paramenumsize.text
else:
result +=', '
result += ', '
result += paramenumsize.text
else:
paramsizes = paramname.tail[1:-1].split('][')
Expand Down Expand Up @@ -1548,8 +1563,7 @@ def make_invocation_type_name(self, base_type):
elif type.endswith('_t'):
if type[0] == 'u':
# For unsigned types, capitalize the first two characters.
return type[0].upper() + type[1].upper(
) + type[2:-2]
return type[0].upper() + type[1].upper() + type[2:-2]
else:
return type[:-2].title()
elif type[0].islower():
Expand All @@ -1576,9 +1590,8 @@ def is_required_struct_data(self, struct_type, struct_source_data):
if struct_source_data['declaration_method'] == 'struct' and (
not self.check_blacklist
or not struct_source_data['name'] in self.STRUCT_BLACKLIST
) and struct_type[-4:] != 'Vtbl' and struct_type.find(
"::<anon-union-"
) == -1:
) and struct_type[
-4:] != 'Vtbl' and struct_type.find("::<anon-union-") == -1:
return True
return False

Expand Down Expand Up @@ -1615,8 +1628,8 @@ def collect_struct_with_objects(self, header_dict):
return structs_with_objects

def is_output(self, value):
if (value.full_type.find('_Out') !=
-1) or (value.full_type.find('_Inout') != -1):
if (value.full_type.find('_Out')
!= -1) or (value.full_type.find('_Inout') != -1):
return True
return False

Expand Down Expand Up @@ -1656,6 +1669,8 @@ def make_array2d_length_expression(self, value, values, prefix=''):
return lengths
else:
# XML does not provide lengths for all dimensions, instantiate a specialization of ArraySize2D to fetch the sizes
type_list = ', '.join([self.clean_type_define(v.full_type) for v in values])
type_list = ', '.join(
[self.clean_type_define(v.full_type) for v in values]
)
arg_list = ', '.join([v.name for v in values])
return ['ArraySize2D<{}>({})'.format(type_list, arg_list)]
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def generate_feature(self):
first = True
for cmd in self.get_filtered_cmd_names():

if self.is_resource_dump_class() and self.is_dump_resources_api_call(cmd) == False:
if self.is_resource_dump_class(
) and self.is_dump_resources_api_call(cmd) == False:
continue

info = self.feature_cmd_params[cmd]
Expand All @@ -45,8 +46,8 @@ def generate_feature(self):
if self.is_resource_dump_class():
cmddef += self.make_dump_resources_func_decl(
return_type,
'{}ReplayDumpResources::Process_'.format(platform_type) + cmd,
values, cmd in self.DUMP_RESOURCES_OVERRIDES
'{}ReplayDumpResources::Process_'.format(platform_type)
+ cmd, values, cmd in self.DUMP_RESOURCES_OVERRIDES
) + '\n'
else:
cmddef += self.make_consumer_func_decl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def make_decode_invocation(self, name, value):

if is_static_array:
array_dimension = ''
# dx12 treats 2d array as 1d array. EX: [8][2] -> [16], so dx12's 2d array needs *.
# dx12 treats 2d array as 1d array. EX: [8][2] -> [16], so dx12's 2d array needs *.
# But vk keeps 2d array.
if value.array_dimension and value.array_dimension > 0:
array_dimension = '*'
Expand Down
Loading

0 comments on commit d931ce6

Please sign in to comment.