freedreno/ir3: refactor out helper to compile shader from asm
Deduplicate a bit of hand-building of ir3_shader/_variant from computerator and delay test. This also removes the need for external things to depend on generated ir3_parser header. Signed-off-by: Rob Clark <robdclark@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5508>
This commit is contained in:
@@ -22,6 +22,8 @@ ir3_SOURCES := \
|
||||
ir3/ir3.c \
|
||||
ir3/ir3_a4xx.c \
|
||||
ir3/ir3_a6xx.c \
|
||||
ir3/ir3_assembler.c \
|
||||
ir3/ir3_assembler.h \
|
||||
ir3/ir3_compiler.c \
|
||||
ir3/ir3_compiler.h \
|
||||
ir3/ir3_compiler_nir.c \
|
||||
|
@@ -21,8 +21,8 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "ir3/ir3_assembler.h"
|
||||
#include "ir3/ir3_compiler.h"
|
||||
#include "ir3/ir3_parser.h"
|
||||
|
||||
#include "ir3_asm.h"
|
||||
|
||||
@@ -30,32 +30,18 @@ struct ir3_kernel *
|
||||
ir3_asm_assemble(struct ir3_compiler *c, FILE *in)
|
||||
{
|
||||
struct ir3_kernel *kernel = calloc(1, sizeof(*kernel));
|
||||
struct ir3_shader *shader = ir3_parse_asm(c, &kernel->info, in);
|
||||
struct ir3_shader_variant *v = shader->variants;
|
||||
|
||||
struct ir3_shader *shader = calloc(1, sizeof(*shader));
|
||||
shader->compiler = c;
|
||||
shader->type = MESA_SHADER_COMPUTE;
|
||||
|
||||
struct ir3_shader_variant *v = calloc(1, sizeof(*v));
|
||||
v->type = MESA_SHADER_COMPUTE;
|
||||
v->shader = shader;
|
||||
v->mergedregs = true;
|
||||
|
||||
kernel->v = v;
|
||||
|
||||
kernel->info.numwg = INVALID_REG;
|
||||
|
||||
v->ir = ir3_parse(v, &kernel->info, in);
|
||||
if (!v->ir)
|
||||
errx(-1, "parse failed");
|
||||
|
||||
ir3_debug_print(v->ir, "AFTER PARSING");
|
||||
kernel->bin = v->bin;
|
||||
|
||||
memcpy(kernel->base.local_size, kernel->info.local_size, sizeof(kernel->base.local_size));
|
||||
kernel->base.num_bufs = kernel->info.num_bufs;
|
||||
memcpy(kernel->base.buf_sizes, kernel->info.buf_sizes, sizeof(kernel->base.buf_sizes));
|
||||
|
||||
kernel->bin = ir3_shader_assemble(v);
|
||||
|
||||
unsigned sz = v->info.sizedwords * 4;
|
||||
|
||||
v->bo = fd_bo_new(c->dev, sz,
|
||||
|
@@ -23,7 +23,6 @@ computerator_files = [
|
||||
'ir3_asm.c',
|
||||
'main.c',
|
||||
freedreno_xml_header_files,
|
||||
ir3_parser,
|
||||
]
|
||||
|
||||
computerator = executable(
|
||||
|
62
src/freedreno/ir3/ir3_assembler.c
Normal file
62
src/freedreno/ir3/ir3_assembler.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright © 2020 Google, 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 (including the next
|
||||
* paragraph) 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.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
|
||||
#include "ir3_assembler.h"
|
||||
#include "ir3_compiler.h"
|
||||
#include "ir3_parser.h"
|
||||
|
||||
/**
|
||||
* A helper to go from ir3 assembly to assembled shader. The shader has a
|
||||
* single variant.
|
||||
*/
|
||||
struct ir3_shader *
|
||||
ir3_parse_asm(struct ir3_compiler *c, struct ir3_kernel_info *info, FILE *in)
|
||||
{
|
||||
struct ir3_shader *shader = calloc(1, sizeof(*shader));
|
||||
shader->compiler = c;
|
||||
shader->type = MESA_SHADER_COMPUTE;
|
||||
mtx_init(&shader->variants_lock, mtx_plain);
|
||||
|
||||
struct ir3_shader_variant *v = calloc(1, sizeof(*v));
|
||||
v->type = MESA_SHADER_COMPUTE;
|
||||
v->shader = shader;
|
||||
|
||||
shader->variants = v;
|
||||
shader->variant_count = 1;
|
||||
|
||||
info->numwg = INVALID_REG;
|
||||
|
||||
v->ir = ir3_parse(v, info, in);
|
||||
if (!v->ir)
|
||||
errx(-1, "parse failed");
|
||||
|
||||
ir3_debug_print(v->ir, "AFTER PARSING");
|
||||
|
||||
v->bin = ir3_shader_assemble(v);
|
||||
if (!v->bin)
|
||||
errx(-1, "assembler failed");
|
||||
|
||||
return shader;
|
||||
}
|
46
src/freedreno/ir3/ir3_assembler.h
Normal file
46
src/freedreno/ir3/ir3_assembler.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright © 2020 Google, 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 (including the next
|
||||
* paragraph) 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.
|
||||
*/
|
||||
|
||||
#ifndef __IR3_ASSEMBLER_H__
|
||||
#define __IR3_ASSEMBLER_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_BUFS 4
|
||||
|
||||
struct ir3_kernel_info {
|
||||
uint32_t local_size[3];
|
||||
uint32_t num_bufs;
|
||||
uint32_t buf_sizes[MAX_BUFS]; /* size in dwords */
|
||||
|
||||
/* driver-param uniforms: */
|
||||
unsigned numwg;
|
||||
};
|
||||
|
||||
struct ir3_shader;
|
||||
struct ir3_compiler;
|
||||
|
||||
struct ir3_shader * ir3_parse_asm(struct ir3_compiler *c, struct ir3_kernel_info *info, FILE *in);
|
||||
|
||||
#endif /* __IR3_ASSEMBLER_H__ */
|
@@ -22,17 +22,7 @@
|
||||
*/
|
||||
|
||||
%code requires {
|
||||
|
||||
#define MAX_BUFS 4
|
||||
|
||||
struct ir3_kernel_info {
|
||||
uint32_t local_size[3];
|
||||
uint32_t num_bufs;
|
||||
uint32_t buf_sizes[MAX_BUFS]; /* size in dwords */
|
||||
|
||||
/* driver-param uniforms: */
|
||||
unsigned numwg;
|
||||
};
|
||||
#include "ir3/ir3_assembler.h"
|
||||
|
||||
struct ir3 * ir3_parse(struct ir3_shader_variant *v,
|
||||
struct ir3_kernel_info *k, FILE *f);
|
||||
|
@@ -66,6 +66,8 @@ libfreedreno_ir3_files = files(
|
||||
'ir3.c',
|
||||
'ir3_a4xx.c',
|
||||
'ir3_a6xx.c',
|
||||
'ir3_assembler.c',
|
||||
'ir3_assembler.h',
|
||||
'ir3_compiler_nir.c',
|
||||
'ir3_compiler.c',
|
||||
'ir3_compiler.h',
|
||||
@@ -126,9 +128,9 @@ test('ir3_disasm',
|
||||
test('ir3_delay_test',
|
||||
executable(
|
||||
'ir3_delay_test',
|
||||
['tests/delay.c', ir3_parser],
|
||||
'tests/delay.c',
|
||||
link_with: libfreedreno_ir3,
|
||||
dependencies: [idep_mesautil, idep_nir_headers],
|
||||
dependencies: [idep_mesautil, idep_nir],
|
||||
include_directories: [inc_freedreno, inc_include, inc_src, inc_mesa, inc_gallium],
|
||||
),
|
||||
suite: ['freedreno'],
|
||||
|
@@ -24,8 +24,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ir3.h"
|
||||
#include "ir3_assembler.h"
|
||||
#include "ir3_compiler.h"
|
||||
#include "ir3_parser.h"
|
||||
|
||||
/*
|
||||
* A test for delay-slot calculation. Each test specifies ir3 assembly
|
||||
@@ -85,25 +85,16 @@ static const struct test {
|
||||
),
|
||||
};
|
||||
|
||||
static struct ir3 *
|
||||
static struct ir3_shader *
|
||||
parse_asm(struct ir3_compiler *c, const char *asmstr)
|
||||
{
|
||||
struct ir3_shader shader = {
|
||||
.type = MESA_SHADER_COMPUTE,
|
||||
.compiler = c,
|
||||
};
|
||||
struct ir3_shader_variant v = {
|
||||
.type = shader.type,
|
||||
.shader = &shader,
|
||||
};
|
||||
struct ir3_kernel_info info = {};
|
||||
FILE *in = fmemopen((void *)asmstr, strlen(asmstr), "r");
|
||||
|
||||
struct ir3 *ir = ir3_parse(&v, &info, in);
|
||||
struct ir3_shader *shader = ir3_parse_asm(c, &info, in);
|
||||
|
||||
fclose(in);
|
||||
|
||||
return ir;
|
||||
return shader;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
@@ -190,9 +181,8 @@ main(int argc, char **argv)
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(tests); i++) {
|
||||
const struct test *test = &tests[i];
|
||||
struct ir3 *ir = parse_asm(c, test->asmstr);
|
||||
|
||||
ir3_debug_print(ir, "AFTER PARSING");
|
||||
struct ir3_shader *shader = parse_asm(c, test->asmstr);
|
||||
struct ir3 *ir = shader->variants->ir;
|
||||
|
||||
regs_to_ssa(ir);
|
||||
|
||||
@@ -224,6 +214,8 @@ main(int argc, char **argv)
|
||||
} else {
|
||||
printf("%d: PASS\n", i);
|
||||
}
|
||||
|
||||
ir3_shader_destroy(shader);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user