def gen_vertex_map_switch_case(angle_fmt, actual_angle_fmt, angle_to_mtl_map, override_packed_map): mtl_format = angle_to_mtl_map[actual_angle_fmt] copy_function = angle_format.get_vertex_copy_function( angle_fmt, actual_angle_fmt) if actual_angle_fmt in override_packed_map: # This format has an override when used in tightly packed buffer, # Return if else block angle_fmt_packed = override_packed_map[actual_angle_fmt] mtl_format_packed = angle_to_mtl_map[angle_fmt_packed] copy_function_packed = angle_format.get_vertex_copy_function( angle_fmt, angle_fmt_packed) return case_vertex_format_template2.format( angle_format=angle_fmt, mtl_format_packed=mtl_format_packed, actual_angle_format_packed=angle_fmt_packed, vertex_copy_function_packed=copy_function_packed, mtl_format=mtl_format, actual_angle_format=actual_angle_fmt, vertex_copy_function=copy_function) else: # This format has no packed buffer's override, return ordinary block. return case_vertex_format_template1.format( angle_format=angle_fmt, mtl_format=mtl_format, actual_angle_format=actual_angle_fmt, vertex_copy_function=copy_function)
def gen_format_case(angle, internal_format, vk_json_data): vk_map = vk_json_data["map"] vk_overrides = vk_json_data["overrides"] vk_fallbacks = vk_json_data["fallbacks"] args = {"format_id": angle} if ((angle not in vk_map) and (angle not in vk_overrides) and (angle not in vk_fallbacks)) or angle == 'NONE': return empty_format_entry_template.format(**args) def get_formats_and_template(format, type, basic_template, fallback_template): format = vk_overrides.get(format, {}).get(type, format) fallback = vk_fallbacks.get(format, {}).get(type, "NONE") if format not in vk_map: format = "NONE" template = "" elif fallback == "NONE": template = basic_template else: template = fallback_template return format, fallback, template texture_format, texture_fallback, texture_template = get_formats_and_template( angle, "texture", texture_basic_template, texture_fallback_template) buffer_format, buffer_fallback, buffer_template = get_formats_and_template( angle, "buffer", buffer_basic_template, buffer_fallback_template) args.update( internal_format=internal_format, texture_template=texture_template, texture=texture_format, vk_texture_format=vk_map[texture_format], texture_initializer=angle_format.get_internal_format_initializer( internal_format, texture_format), texture_fallback=texture_fallback, vk_texture_format_fallback=vk_map[texture_fallback], texture_initializer_fallback=angle_format. get_internal_format_initializer(internal_format, texture_fallback), buffer_template=buffer_template, buffer=buffer_format, vk_buffer_format=vk_map[buffer_format], vertex_load_function=angle_format.get_vertex_copy_function( angle, buffer_format), vertex_load_converts='false' if angle == buffer_format else 'true', buffer_fallback=buffer_fallback, vk_buffer_format_fallback=vk_map[buffer_fallback], vertex_load_function_fallback=angle_format.get_vertex_copy_function( angle, buffer_fallback), ) return format_entry_template.format(**args).format(**args)
def buffer_args(format): return dict( buffer="angle::FormatID::" + format, vk_buffer_format=vk_map[format], vk_buffer_format_is_packed=is_packed(vk_map[format]), vertex_load_function=angle_format.get_vertex_copy_function(angle, format), vertex_load_converts='false' if angle == format else 'true', )
def get_vertex_copy_function(src_format, dst_format, vk_format): if "_PACK" in vk_format: pack_bits = int(re.search(r'_PACK(\d+)', vk_format).group(1)) base_type = None if pack_bits == 8: base_type = 'byte' elif pack_bits == 16: base_type = 'short' elif pack_bits == 32: base_type = 'int' else: return 'nullptr' return 'CopyNativeVertexData<GLu%s, 1, 1, 0>' % base_type return angle_format.get_vertex_copy_function(src_format, dst_format)
def get_vertex_copy_function_and_default_alpha(src_format, dst_format): if dst_format == "NONE": return "nullptr", 0, "false" num_channel = len(angle_format_utils.get_channel_tokens(src_format)) if num_channel < 1 or num_channel > 4: return "nullptr", 0, "false" src_gl_type = angle_format_utils.get_format_gl_type(src_format) dst_gl_type = angle_format_utils.get_format_gl_type(dst_format) if src_gl_type == dst_gl_type: if src_format.startswith('R10G10B10A2'): return 'CopyNativeVertexData<GLuint, 1, 1, 0>', 0, "true" if src_gl_type == None: return 'nullptr', 0, "true" dst_num_channel = len( angle_format_utils.get_channel_tokens(dst_format)) default_alpha = '1' if num_channel == dst_num_channel or dst_num_channel < 4: default_alpha = '0' elif 'A16_FLOAT' in dst_format: default_alpha = 'gl::Float16One' elif 'A32_FLOAT' in dst_format: default_alpha = 'gl::Float32One' elif 'NORM' in dst_format: default_alpha = 'std::numeric_limits<%s>::max()' % (src_gl_type) return 'CopyNativeVertexData<%s, %d, %d, %s>' % ( src_gl_type, num_channel, dst_num_channel, default_alpha), default_alpha, "true" if src_format.startswith('R10G10B10A2'): assert 'FLOAT' in dst_format, ( 'get_vertex_copy_function: can only convert to float,' + ' not to ' + dst_format) is_signed = 'true' if 'SINT' in src_format or 'SNORM' in src_format or 'SSCALED' in src_format else 'false' is_normal = 'true' if 'NORM' in src_format else 'false' return 'CopyXYZ10W2ToXYZWFloatVertexData<%s, %s, true, false>' % ( is_signed, is_normal), 0, "false" return angle_format_utils.get_vertex_copy_function(src_format, dst_format), 0, "false"
def get_vertex_copy_function(src_format, dst_format, vk_format): if "_PACK" in vk_format: pack_bits = int(re.search(r'_PACK(\d+)', vk_format).group(1)) base_type = None if pack_bits == 8: base_type = 'byte' elif pack_bits == 16: base_type = 'short' elif pack_bits == 32: base_type = 'int' else: return 'nullptr' return 'CopyNativeVertexData<GLu%s, 1, 1, 0>' % base_type if 'R10G10B10A2' in src_format: # When the R10G10B10A2 type can't be used by the vertex buffer, # it needs to be converted to the type which can be used by it. is_signed = 'false' if 'UINT' in src_format or 'UNORM' in src_format or 'USCALED' in src_format else 'true' normalized = 'true' if 'NORM' in src_format else 'false' to_float = 'false' if 'INT' in src_format else 'true' return 'CopyXYZ10W2ToXYZW32FVertexData<%s, %s, %s>' % ( is_signed, normalized, to_float) return angle_format.get_vertex_copy_function(src_format, dst_format)