From patchwork Sun Sep 20 11:44:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 'Timothy Arceri' via Patchwork Forward X-Patchwork-Id: 53954 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id AE0BD22B04 for ; Sun, 20 Sep 2015 11:44:32 +0000 (UTC) Received: by lamp12 with SMTP id p12sf31683791lam.2 for ; Sun, 20 Sep 2015 04:44:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :reply-to; bh=UCzFhm0zbZH8vz4o4idjwe4wXCKtt9j8PQqVhvuAL/Y=; b=DrGBC1QiCWWbPSFtivo6bKmOLE+9gS7tCVWkc31wmoojLE6r3MfMlrWNZ7WMtdyr30 lukrpuFLQ4PXia4JWitD09pf/B6hLadMXRf8namGkzMX9V4620And6Uk0dqWVMwcd5Ox L9bPcLTW75xcM5DMuUvje2ElgrabITqc2Ywf7aPkYX/33Vlh/bJNVXR1lOVCJh+wk1JJ QJcRH/NQ9uy4UzuvWobqL9zOMoDY0fgL1Rw5asJ2lFaRH1SFpL0LFeItZBjWBYMeroqJ nFwbwgYW72/0i0zu6/yzdzcbAT3r6aRnusvx3JAFL44c9cJVBU6bo83wWSv1WUn3lrhw 7O1A== X-Gm-Message-State: ALoCoQkfrH7EIBaymZqipWIqj9Lgto2ATANLib+dqU2vEdv2ena5XaBSpV8h+plBVi1iGgDbJtpr X-Received: by 10.180.188.211 with SMTP id gc19mr1175437wic.6.1442749471620; Sun, 20 Sep 2015 04:44:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.138 with SMTP id lc10ls405210lab.90.gmail; Sun, 20 Sep 2015 04:44:31 -0700 (PDT) X-Received: by 10.112.205.69 with SMTP id le5mr5885746lbc.89.1442749471491; Sun, 20 Sep 2015 04:44:31 -0700 (PDT) Received: from mail-la0-x229.google.com (mail-la0-x229.google.com. [2a00:1450:4010:c03::229]) by mx.google.com with ESMTPS id y9si12655910lad.86.2015.09.20.04.44.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Sep 2015 04:44:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::229 as permitted sender) client-ip=2a00:1450:4010:c03::229; Received: by lanb10 with SMTP id b10so53286440lan.3 for ; Sun, 20 Sep 2015 04:44:31 -0700 (PDT) X-Received: by 10.25.207.82 with SMTP id f79mr848986lfg.73.1442749471236; Sun, 20 Sep 2015 04:44:31 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1227938lbq; Sun, 20 Sep 2015 04:44:30 -0700 (PDT) X-Received: by 10.107.149.129 with SMTP id x123mr20458481iod.68.1442749469935; Sun, 20 Sep 2015 04:44:29 -0700 (PDT) Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTP id 72si13678320iot.191.2015.09.20.04.44.29; Sun, 20 Sep 2015 04:44:29 -0700 (PDT) Received-SPF: pass (google.com: domain of piglit-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1C2A46E0FF; Sun, 20 Sep 2015 04:44:29 -0700 (PDT) X-Original-To: piglit@lists.freedesktop.org Delivered-To: piglit@lists.freedesktop.org Received: from nm21-vm10.bullet.mail.gq1.yahoo.com (nm21-vm10.bullet.mail.gq1.yahoo.com [98.136.217.57]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7DE826E0FF for ; Sun, 20 Sep 2015 04:44:27 -0700 (PDT) Received: from [216.39.60.182] by nm21.bullet.mail.gq1.yahoo.com with NNFMP; 20 Sep 2015 11:44:25 -0000 Received: from [208.71.42.205] by tm18.bullet.mail.gq1.yahoo.com with NNFMP; 20 Sep 2015 11:44:25 -0000 Received: from [127.0.0.1] by smtp216.mail.gq1.yahoo.com with NNFMP; 20 Sep 2015 11:44:25 -0000 X-Yahoo-Newman-Id: 896303.1690.bm@smtp216.mail.gq1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 7BMHicQVM1lpFuDRsGm6GZ9lgHIIJqfk36zEaA_ny.Lgqs5 LFrLpIXBsHFgA8yn21jHhpNqsF.ju7XONl2z8cmsGtfs_NFaw5Hrf6j3TnsZ ZteIxI3t6oIt.rlKzsFwKIla_KhYjDWLuF_ezL.s2sZGf4JOoUSKsTAswlbB WQwM7yvYTRnHPao3VRYZqW0EBeZX6SbNTva3URpjfSU1jxXb0LOBoRjskyrS IUdRJb0io4YhAaGF4Cm6QaZ1XjMApiiHwWmQ1ZX1RDYmsp74E3501yZVMGYm G932bkkOGSvrI2pEvI1D9At5veV0b9HUOX8Yk7akOcf59tj5M6cG35dGt1_z __MEuavvNzPddLfQMkgtl4Qs7yxhrz3KCmEOxMWonitmsAKJh84spa37x_G4 6Z.kWEPZJ4vaNfecl_8fYWfvdyJPIu9eyqG.httLRMacW18emWXBqHYdur.S 70hm.bSk1Ql9_HJK6afhJ0kciSLIBfakpdlvYLKnqmgMIixlYI15IIItXDfC mjHi3E6ueV1bQFfUiv9LnVoJdTg5hE2_oFrY- X-Yahoo-SMTP: 9BNlx.aswBAkr0D8mG_whiOP1dyU From: "'Timothy Arceri' via Patchwork Forward" To: piglit@lists.freedesktop.org Date: Sun, 20 Sep 2015 21:44:10 +1000 Message-Id: <1442749451-22117-1-git-send-email-t_arceri@yahoo.com.au> X-Mailer: git-send-email 2.4.3 Cc: Ian Romanick Subject: [Piglit] [PATCH 1/2] arb_uniform_buffer_object: Add AoA support to random test generation script X-BeenThere: piglit@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: piglit-bounces@lists.freedesktop.org Sender: "Piglit" X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::229 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@yahoo.com.au; dmarc=fail (p=NONE dis=NONE) header.from=yahoo.com.au Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 X-Original-From: Timothy Arceri Reply-To: Timothy Arceri Cc: Ian Romanick --- Hi Ian, I know these scripts haven't yet been committed to piglit yet but didn't know what else to do with it. I thought sending it here would at least reduce the chance of me losing it. Tim .../random_ubo-arb_uniform_buffer_object.py | 7 +- generated_tests/random_ubo.py | 225 +++++++++++++-------- 2 files changed, 147 insertions(+), 85 deletions(-) diff --git a/generated_tests/random_ubo-arb_uniform_buffer_object.py b/generated_tests/random_ubo-arb_uniform_buffer_object.py index 915963f..d9cdb5d 100644 --- a/generated_tests/random_ubo-arb_uniform_buffer_object.py +++ b/generated_tests/random_ubo-arb_uniform_buffer_object.py @@ -64,7 +64,7 @@ def do_test(requirements, packing): blocks, packing, 130, - ["GL_ARB_uniform_buffer_object"])) + ["GL_ARB_uniform_buffer_object","GL_ARB_arrays_of_arrays"])) file.close() @@ -115,6 +115,11 @@ all_requirements.append([["struct", "array", "struct"]]) all_requirements.append([["array", "struct", "struct"]]) all_requirements.append([["array", "struct", "array", "struct"]]) +all_requirements.append([["struct", "array", "array", "struct"]]) +all_requirements.append([["struct", "array", "array", "array", "struct"]]) +all_requirements.append([["array", "array", "struct", "array"]]) +all_requirements.append([["struct", "array", "array", "array"]]) + for p in all_packing: for r in all_requirements: do_test(r, p) diff --git a/generated_tests/random_ubo.py b/generated_tests/random_ubo.py index 33359f6..f6952d3 100644 --- a/generated_tests/random_ubo.py +++ b/generated_tests/random_ubo.py @@ -141,7 +141,6 @@ def array_elements(type): # Is there a better way to do this? return int(type.split("[")[1].split("]")[0]) - def basic_machine_units(type): """Return the size in 'basic machine units' of a scalar type.""" if type in ["float", "bool", "int", "uint"]: @@ -158,9 +157,27 @@ def array_base_type(type): if not isarray(type): raise Exception("Non-array type {}".format(type)) - # XXX This will need changes for arrays-of-arrays. + return type[:type.index("[")] + type[type.index("]")+1:] + +def without_array(type): + """Return the type of an element with all arrays removed.""" + if not isarray(type): + raise Exception("Non-array type {}".format(type)) + return type.split("[")[0] +def arrays_of_arrays_size(type): + """Return the total number of elements in an array of arrays.""" + if not isarray(type): + raise Exception("Non-array type {}".format(type)) + + size = 1 + base_type = type + while (isarray(base_type)): + size = size * array_elements(base_type) + base_type = array_base_type(base_type) + + return size def vector_base_type(type): """Return the type of an element from a vector.""" @@ -188,7 +205,7 @@ def iterate_structures(fields, types_seen=[], types_yielded=[]): """ for (type, name) in fields: if isarray(type): - type = array_base_type(type) + type = without_array(type) if not isstructure(type): continue @@ -351,7 +368,7 @@ def generate_layouts(fields, required_layouts, allow_row_major_structure): layouts = [] for ((type, name), lay) in zip(fields, required_layouts): if isarray(type): - type = array_base_type(type) + type = without_array(type) if lay: layouts.append(lay) @@ -407,6 +424,60 @@ def fields_to_glsl_struct(type): return structure_template.render(struct_name=type, fields=struct_types[type]) +def iterate_struct_array_recursive(field_type, + name_from_API, + name_from_shader, + packing, + offset, + row_major, + field_row_major, + explicit_layout): + + astride = packing.array_stride(field_type, field_row_major) + array_member_align = packing.base_alignment(field_type, field_row_major) + + element_t = array_base_type(field_type) + + for i in xrange(array_elements(field_type)): + name_from_API_with_index = "{}[{}]".format(name_from_API, i) + name_from_shader_with_index = "{}[{}]".format(name_from_shader, i) + + if isarray(element_t): + inner_aoa_size = arrays_of_arrays_size(element_t) + o = align(offset, array_member_align) + (astride * i * inner_aoa_size) + + for x in iterate_struct_array_recursive(element_t, + name_from_API_with_index, + name_from_shader_with_index, + packing, + o, + row_major, + field_row_major, + explicit_layout): + yield x + + a = packing.base_alignment(x.GLSL_type, row_major) + o = align(o, a) + packing.size(x.GLSL_type, row_major) + else: + o = align(offset, array_member_align) + (astride * i) + yield block_member( + name_from_shader_with_index, + name_from_API_with_index, + element_t, + explicit_layout, + o, + field_row_major) + for x in iterate_all_recursive(struct_types[element_t], + None, + name_from_API_with_index, + name_from_shader_with_index, + packing, + o, + field_row_major): + yield x + + a = packing.base_alignment(x.GLSL_type, row_major) + o = align(o, a) + packing.size(x.GLSL_type, row_major) def iterate_all_recursive(fields, field_layouts, @@ -483,7 +554,7 @@ def iterate_all_recursive(fields, field_row_major = row_major if isarray(field_type): - base_type = array_base_type(field_type) + base_type = without_array(field_type) if isstructure(base_type): yield block_member( @@ -494,40 +565,15 @@ def iterate_all_recursive(fields, offset, field_row_major) - astride = packing.array_stride(field_type, field_row_major) - array_member_align = packing.base_alignment( - field_type, - field_row_major) - - for i in xrange(array_elements(field_type)): - name_from_API_with_index = "{}[{}]".format( - name_from_API, - i) - name_from_shader_with_index = "{}[{}]".format( - name_from_shader, - i) - - o = align(offset, array_member_align) + (astride * i) - - yield block_member( - name_from_shader_with_index, - name_from_API_with_index, - base_type, - explicit_layout, - o, - field_row_major) - - for x in iterate_all_recursive(struct_types[base_type], - None, - name_from_API_with_index, - name_from_shader_with_index, - packing, - o, - field_row_major): - yield x - - a = packing.base_alignment(x.GLSL_type, row_major) - o = align(o, a) + packing.size(x.GLSL_type, row_major) + for x in iterate_struct_array_recursive(field_type, + name_from_API, + name_from_shader, + packing, + offset, + row_major, + field_row_major, + explicit_layout): + yield x elif ismatrix(base_type): yield block_member( @@ -709,19 +755,25 @@ def generate_test_vectors(fields, a = packing.base_alignment(m.GLSL_type, m.row_major) if isarray(m.GLSL_type): + size = array_elements(m.GLSL_type) base_type = array_base_type(m.GLSL_type) astride = packing.array_stride(m.GLSL_type, m.row_major) name = m.API_name + "[0]" + while(isarray(base_type)): + size = array_elements(base_type) + base_type = array_base_type(base_type) + name = name + "[0]" else: base_type = m.GLSL_type astride = 0 name = m.API_name + size = m.size if ismatrix(base_type): test_vectors.append(( name, m.API_type, - m.size, + size, align(m.offset, a), astride, packing.matrix_stride(base_type, m.row_major), @@ -730,7 +782,7 @@ def generate_test_vectors(fields, test_vectors.append(( name, m.API_type, - m.size, + size, align(m.offset, a), astride, 0, @@ -862,6 +914,44 @@ def bit_exact_data(raw_data, type): else: return raw_data +def generate_array_data_pairs(name, api_name, element_type, row_major, offset, packing, setters, checkers): + base_type = array_base_type(element_type) + + astride = packing.array_stride(element_type, row_major) + + for i in xrange(array_elements(element_type)): + + name_with_index = "{}[{}]".format(name, i) + api_name_with_index = "{}[{}]".format(api_name, i) + + if isarray(base_type): + offset = offset + (i * arrays_of_arrays_size(base_type) * astride) + generate_array_data_pairs(name_with_index, api_name_with_index, base_type, row_major, offset, packing, setters, checkers) + else: + offset = offset + (i * astride) + raw_data = random_data(base_type, name_with_index, offset) + setters.append( + (fudge_type_for_setter(base_type), + api_name_with_index, + bit_exact_data(raw_data, base_type))) + + data = raw_data.split(" ") + + if isscalar(base_type): + checkers.append(scalar_derp(base_type, + name_with_index, + offset, + data[0])) + elif isvector(base_type): + checkers.extend(vector_derp(base_type, + name_with_index, + offset, + data)) + elif ismatrix(base_type): + checkers.extend(matrix_derp(base_type, + name_with_index, + offset, + data)) def generate_data_pairs(uniform_blocks, packing): """Return GLSL code to test values and shader_runner code to set them. @@ -893,38 +983,7 @@ def generate_data_pairs(uniform_blocks, packing): if m.API_type: if isarray(m.GLSL_type): - base_type = array_base_type(m.GLSL_type) - - astride = packing.array_stride(m.GLSL_type, m.row_major) - - for i in xrange(array_elements(m.GLSL_type)): - - name = "{}[{}]".format(m.GLSL_name, i) - offset = m.offset + (i * astride) - - raw_data = random_data(base_type, m.GLSL_name, offset) - setters.append( - (fudge_type_for_setter(base_type), - "{}[{}]".format(m.API_name, i), - bit_exact_data(raw_data, base_type))) - - data = raw_data.split(" ") - - if isscalar(base_type): - checkers.append(scalar_derp(base_type, - name, - offset, - data[0])) - elif isvector(base_type): - checkers.extend(vector_derp(base_type, - name, - offset, - data)) - elif ismatrix(base_type): - checkers.extend(matrix_derp(base_type, - name, - offset, - data)) + generate_array_data_pairs(m.GLSL_name, m.API_name, m.GLSL_type, m.row_major, m.offset, packing, setters, checkers) else: raw_data = random_data(m.GLSL_type, m.GLSL_name, m.offset) setters.append((fudge_type_for_setter(m.GLSL_type), @@ -969,7 +1028,7 @@ def pretty_format_type_data(packing, type, offset, row_major): if isarray(type): astride = packing.array_stride(type, row_major) - base_type = array_base_type(type) + base_type = without_array(type) if ismatrix(base_type) and row_major: if row_major: row_major_str = "yes" @@ -1009,13 +1068,12 @@ def pretty_format_member(m, packing): # If the name ends in an array subscript, emit a special line to note that # the following fields are the contents of an element of an array of # structures. - if m.GLSL_name[-1] == "]": n = m.struct_nesting() + 1 indent = "// " + (" " * n) - return "{indent}[{index}".format(indent=indent, - index=m.GLSL_name.split("[")[-1]) + return "{indent}{index}".format(indent=indent, + index=m.GLSL_name[m.GLSL_name.index("["):]) # Strip off everything before the last period. name = m.GLSL_name.split(".")[-1] @@ -1337,8 +1395,8 @@ class packing_rules(object): size, in bytes, of the entire data type. This will include padded after the data element as required by the GLSL specification. """ - if "[" in type: - return self.array_stride(type, row_major) * array_elements(type) + if isarray(type): + return self.array_stride(type, row_major) * arrays_of_arrays_size(type) if type in ["float", "bool", "int", "uint"]: return 4 @@ -1484,7 +1542,7 @@ class std140_packing_rules(packing_rules): return max(16, self.base_alignment("vec{}".format(c), False)) def array_stride(self, type, row_major): - base_type = array_base_type(type) + base_type = without_array(type) if not isstructure(base_type): # (4) If the member is an array of scalars or vectors, the base @@ -1547,7 +1605,7 @@ class unique_name_dict: form. All other type names are unmodified. """ if isarray(type): - t = array_base_type(type) + t = without_array(type) else: t = type @@ -1577,7 +1635,7 @@ class unique_name_dict: (indexed by "type") of (base_name, 1). """ if isarray(type): - t = array_base_type(type) + t = without_array(type) else: t = type @@ -1690,8 +1748,7 @@ class block_member(object): self.row_major = row_major if isarray(GLSL_type): - base_type = array_base_type(GLSL_type) - + base_type = without_array(GLSL_type) if isstructure(base_type): self.API_type = None else: