This commit is contained in:
elwrcl committed 2026-06-06 13:25:15 +03:00
1 parent 04d4dc8b09
commit 818cab85dc
12511 files changed
+6156641

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -0,0 +1,51 @@
/*
* Copyright © 2017 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#include "intel_decoder.h"
#include "intel_decoder_private.h"
#include "compiler/elk/elk_disasm.h"
static void
ctx_disassemble_program_elk(struct intel_batch_decode_ctx *ctx,
uint32_t ksp,
const char *short_name,
const char *name)
{
uint64_t addr = ctx->instruction_base + ksp;
struct intel_batch_decode_bo bo = ctx_get_bo(ctx, true, addr);
if (!bo.map)
return;
fprintf(ctx->fp, "\nReferenced %s:\n", name);
elk_disassemble_with_errors(ctx->elk, bo.map, 0, ctx->fp);
if (ctx->shader_binary) {
int size = elk_disassemble_find_end(ctx->elk, bo.map, 0);
ctx->shader_binary(ctx->user_data, short_name, addr,
bo.map, size);
}
}
void
intel_batch_decode_ctx_init_elk(struct intel_batch_decode_ctx *ctx,
const struct elk_isa_info *isa,
const struct intel_device_info *devinfo,
FILE *fp, enum intel_batch_decode_flags flags,
const char *xml_path,
struct intel_batch_decode_bo (*get_bo)(void *,
bool,
uint64_t),
unsigned (*get_state_size)(void *, uint64_t,
uint64_t),
void *user_data)
{
intel_batch_decode_ctx_init(ctx, devinfo, fp, flags, xml_path,
get_bo, get_state_size, user_data);
ctx->elk = isa;
ctx->disassemble_program = ctx_disassemble_program_elk;
}
@@ -0,0 +1,74 @@
/*
* Copyright © 2017 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#include "intel_decoder.h"
#include "intel_decoder_private.h"
#include "compiler/gen/gen.h"
#include "util/ralloc.h"
static void
ctx_disassemble_program_gen(struct intel_batch_decode_ctx *ctx,
uint32_t ksp,
const char *short_name,
const char *name)
{
uint64_t addr = ctx->instruction_base + ksp;
struct intel_batch_decode_bo bo = ctx_get_bo(ctx, true, addr);
if (!bo.map)
return;
fprintf(ctx->fp, "\nReferenced %s:\n", name);
const int size = gen_find_shader_size(&ctx->devinfo, bo.map, 0, bo.size);
if (size > 0) {
void *tmp_ctx = ralloc_context(NULL);
gen_decode_params decode = {
.devinfo = &ctx->devinfo,
.raw_bytes = bo.map,
.raw_bytes_size = size,
.mem_ctx = tmp_ctx,
};
gen_decode(&decode);
gen_print_params print = {
.devinfo = &ctx->devinfo,
.fp = ctx->fp,
.insts = decode.insts,
.num_insts = decode.num_insts,
.errors = decode.errors,
.num_errors = decode.num_errors,
.raw_bytes = bo.map,
.raw_bytes_size = size,
};
gen_print(&print);
ralloc_free(tmp_ctx);
}
if (ctx->shader_binary) {
ctx->shader_binary(ctx->user_data, short_name, addr,
bo.map, size);
}
}
void
intel_batch_decode_ctx_init_gen(struct intel_batch_decode_ctx *ctx,
const struct intel_device_info *devinfo,
FILE *fp, enum intel_batch_decode_flags flags,
const char *xml_path,
struct intel_batch_decode_bo (*get_bo)(void *,
bool,
uint64_t),
unsigned (*get_state_size)(void *, uint64_t,
uint64_t),
void *user_data)
{
intel_batch_decode_ctx_init(ctx, devinfo, fp, flags, xml_path,
get_bo, get_state_size, user_data);
ctx->disassemble_program = ctx_disassemble_program_gen;
}
@@ -0,0 +1,89 @@
/*
* Copyright © 2021 Intel Corporation
*
* 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 "intel_decoder.h"
#include "util/log.h"
void
intel_batch_decode_ctx_init_gen(struct intel_batch_decode_ctx *ctx,
const struct intel_device_info *devinfo,
FILE *fp, enum intel_batch_decode_flags flags,
const char *xml_path,
struct intel_batch_decode_bo (*get_bo)(void *,
bool,
uint64_t),
unsigned (*get_state_size)(void *, uint64_t,
uint64_t),
void *user_data)
{
/* Clear ctx to play safe. */
memset(ctx, 0, sizeof(*ctx));
}
void
intel_batch_decode_ctx_init_elk(struct intel_batch_decode_ctx *ctx,
const struct elk_isa_info *isa,
const struct intel_device_info *devinfo,
FILE *fp, enum intel_batch_decode_flags flags,
const char *xml_path,
struct intel_batch_decode_bo (*get_bo)(void *,
bool,
uint64_t),
unsigned (*get_state_size)(void *, uint64_t,
uint64_t),
void *user_data)
{
/* Clear ctx to play safe. */
memset(ctx, 0, sizeof(*ctx));
}
void
intel_batch_decode_ctx_finish(struct intel_batch_decode_ctx *ctx)
{
}
void
intel_print_batch(struct intel_batch_decode_ctx *ctx,
const uint32_t *batch, uint32_t batch_size,
uint64_t batch_addr, bool from_ring)
{
mesa_logw("Batch logging not supported on Release drivers");
}
void
intel_batch_stats_reset(struct intel_batch_decode_ctx *ctx)
{
}
void
intel_batch_stats(struct intel_batch_decode_ctx *ctx,
const uint32_t *batch, uint32_t batch_size,
uint64_t batch_addr, bool from_ring)
{
}
void
intel_batch_print_stats(struct intel_batch_decode_ctx *ctx)
{
mesa_logw("Batch logging not supported on Release drivers");
}
File diff suppressed because it is too large. Load diff
+348
View File
@@ -0,0 +1,348 @@
/*
* Copyright © 2016 Intel Corporation
*
* 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 INTEL_DECODER_H
#define INTEL_DECODER_H
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "dev/intel_device_info.h"
#include "util/hash_table.h"
#include "util/bitset.h"
#include "common/intel_engine.h"
#ifdef __cplusplus
extern "C" {
#endif
struct intel_spec;
struct intel_group;
struct intel_field;
union intel_field_value;
#define INTEL_ENGINE_CLASS_TO_MASK(x) BITSET_BIT(x)
static inline uint32_t intel_make_gen(uint32_t major, uint32_t minor)
{
return (major << 8) | minor;
}
struct intel_group *intel_spec_find_struct(struct intel_spec *spec, const char *name);
struct intel_spec *intel_spec_load(const struct intel_device_info *devinfo);
struct intel_spec *
intel_spec_load_from_path(const struct intel_device_info *devinfo,
const char *path);
struct intel_spec *intel_spec_load_filename(const char *dir, const char *name);
void intel_spec_destroy(struct intel_spec *spec);
uint32_t intel_spec_get_gen(struct intel_spec *spec);
struct intel_group *intel_spec_find_instruction(struct intel_spec *spec,
enum intel_engine_class engine,
const uint32_t *p);
struct intel_group *intel_spec_find_register(struct intel_spec *spec, uint32_t offset);
struct intel_group *intel_spec_find_register_by_name(struct intel_spec *spec, const char *name);
struct intel_enum *intel_spec_find_enum(struct intel_spec *spec, const char *name);
int intel_group_get_length(const struct intel_group *group, const uint32_t *p);
const char *intel_group_get_name(const struct intel_group *group);
uint32_t intel_group_get_opcode(const struct intel_group *group);
struct intel_field *intel_group_find_field(struct intel_group *group, const char *name);
struct intel_enum *intel_spec_find_enum(struct intel_spec *spec, const char *name);
bool intel_field_is_header(const struct intel_field *field);
/* Only allow 5 levels of subgroup'ing
*/
#define DECODE_MAX_ARRAY_DEPTH 5
struct intel_field_iterator {
const struct intel_group *group;
char name[128];
char value[128];
uint64_t raw_value;
struct intel_group *struct_desc;
const uint32_t *p;
int p_bit; /**< bit offset into p */
const uint32_t *p_end;
int start_bit; /**< current field starts at this bit offset into p */
int end_bit; /**< current field ends at this bit offset into p */
const struct intel_field *fields[DECODE_MAX_ARRAY_DEPTH];
const struct intel_group *groups[DECODE_MAX_ARRAY_DEPTH];
int array_iter[DECODE_MAX_ARRAY_DEPTH];
int level;
const struct intel_field *field;
bool print_colors;
};
struct intel_spec {
uint32_t gen;
struct hash_table *commands;
struct hash_table *structs;
struct hash_table *registers_by_name;
struct hash_table *registers_by_offset;
struct hash_table *enums;
struct hash_table *access_cache;
};
struct intel_group {
struct intel_spec *spec;
char *name;
struct intel_field *fields; /* linked list of fields */
struct intel_field *dword_length_field; /* <instruction> specific */
uint32_t dw_length;
uint32_t engine_mask; /* <instruction> specific */
uint32_t bias; /* <instruction> specific */
uint32_t array_offset; /* <group> specific */
uint32_t array_count; /* number of elements, <group> specific */
uint32_t array_item_size; /* <group> specific */
bool variable; /* <group> specific */
bool fixed_length; /* True for <struct> & <register> */
struct intel_group *parent;
struct intel_group *next;
uint32_t opcode_mask;
uint32_t opcode;
uint32_t register_offset; /* <register> specific */
};
struct intel_value {
char *name;
uint64_t value;
};
struct intel_enum {
char *name;
int nvalues;
struct intel_value **values;
};
struct intel_type {
enum {
INTEL_TYPE_UNKNOWN,
INTEL_TYPE_INT,
INTEL_TYPE_UINT,
INTEL_TYPE_BOOL,
INTEL_TYPE_FLOAT,
INTEL_TYPE_ADDRESS,
INTEL_TYPE_OFFSET,
INTEL_TYPE_STRUCT,
INTEL_TYPE_UFIXED,
INTEL_TYPE_SFIXED,
INTEL_TYPE_MBO,
INTEL_TYPE_MBZ,
INTEL_TYPE_ENUM
} kind;
/* Struct definition for INTEL_TYPE_STRUCT */
union {
struct intel_group *intel_struct;
struct intel_enum *intel_enum;
struct {
/* Integer and fractional sizes for INTEL_TYPE_UFIXED and INTEL_TYPE_SFIXED */
int i, f;
};
};
};
union intel_field_value {
bool b32;
float f32;
uint64_t u64;
int64_t i64;
};
struct intel_field {
struct intel_group *parent;
struct intel_field *next;
struct intel_group *array;
char *name;
int start, end;
struct intel_type type;
bool has_default;
uint32_t default_value;
struct intel_enum inline_enum;
};
void intel_field_iterator_init(struct intel_field_iterator *iter,
const struct intel_group *group,
const uint32_t *p, int p_bit,
bool print_colors);
bool intel_field_iterator_next(struct intel_field_iterator *iter);
void intel_print_group_custom_spacing(FILE *outfile,
const struct intel_group *group,
uint64_t offset, const uint32_t *p,
int p_bit, bool color,
const char *spacing_reg,
const char *spacing_dword);
void intel_print_group(FILE *out,
const struct intel_group *group,
uint64_t offset, const uint32_t *p, int p_bit,
bool color);
enum intel_batch_decode_flags {
/** Print in color! */
INTEL_BATCH_DECODE_IN_COLOR = (1 << 0),
/** Print everything, not just headers */
INTEL_BATCH_DECODE_FULL = (1 << 1),
/** Print offsets along with the batch */
INTEL_BATCH_DECODE_OFFSETS = (1 << 2),
/** Guess when a value is a float and print it as such */
INTEL_BATCH_DECODE_FLOATS = (1 << 3),
/** Print surface states */
INTEL_BATCH_DECODE_SURFACES = (1 << 4),
/** Print sampler states */
INTEL_BATCH_DECODE_SAMPLERS = (1 << 5),
/** Print accumulated state
*
* Instead of printing instructions as we parse them, retain a pointer to
* each of the last instruction emitted and print it upon parsing one of
* the following instructions :
* - 3DPRIMITIVE
* - GPGPU_WALKER
* - 3DSTATE_WM_HZ_OP
* - COMPUTE_WALKER
*/
INTEL_BATCH_DECODE_ACCUMULATE = (1 << 6),
/** Print vertex buffer data */
INTEL_BATCH_DECODE_VB_DATA = (1 << 7),
};
#define INTEL_BATCH_DECODE_DEFAULT_FLAGS \
(INTEL_BATCH_DECODE_FULL | \
INTEL_BATCH_DECODE_OFFSETS | \
INTEL_BATCH_DECODE_FLOATS | \
INTEL_BATCH_DECODE_SURFACES | \
INTEL_BATCH_DECODE_SAMPLERS | \
INTEL_BATCH_DECODE_VB_DATA)
struct intel_batch_decode_bo {
uint64_t addr;
uint32_t size;
const void *map;
};
struct intel_batch_decode_ctx {
/**
* Return information about the buffer containing the given address.
*
* If the given address is inside a buffer, the map pointer should be
* offset accordingly so it points at the data corresponding to address.
*/
struct intel_batch_decode_bo (*get_bo)(void *user_data, bool ppgtt, uint64_t address);
unsigned (*get_state_size)(void *user_data,
uint64_t address,
uint64_t base_address);
void (*shader_binary)(void *user_data,
const char *short_name,
uint64_t address,
const void *data,
unsigned data_length);
void *user_data;
FILE *fp;
const struct elk_isa_info *elk;
struct intel_device_info devinfo;
struct intel_spec *spec;
enum intel_batch_decode_flags flags;
bool use_256B_binding_tables;
uint64_t surface_base;
uint64_t bt_pool_base;
uint64_t dynamic_base;
uint64_t instruction_base;
int max_vbo_decoded_lines;
enum intel_engine_class engine;
int n_batch_buffer_start;
uint64_t acthd;
struct hash_table *commands;
struct hash_table *filters;
struct hash_table *stats;
void (*disassemble_program)(struct intel_batch_decode_ctx *ctx,
uint32_t ksp,
const char *short_name,
const char *name);
};
void intel_batch_decode_ctx_init_gen(struct intel_batch_decode_ctx *ctx,
const struct intel_device_info *devinfo,
FILE *fp, enum intel_batch_decode_flags flags,
const char *xml_path,
struct intel_batch_decode_bo (*get_bo)(void *,
bool,
uint64_t),
unsigned (*get_state_size)(void *, uint64_t,
uint64_t),
void *user_data);
void intel_batch_decode_ctx_init_elk(struct intel_batch_decode_ctx *ctx,
const struct elk_isa_info *isa,
const struct intel_device_info *devinfo,
FILE *fp, enum intel_batch_decode_flags flags,
const char *xml_path,
struct intel_batch_decode_bo (*get_bo)(void *,
bool,
uint64_t),
unsigned (*get_state_size)(void *, uint64_t,
uint64_t),
void *user_data);
void intel_batch_decode_ctx_finish(struct intel_batch_decode_ctx *ctx);
void intel_print_batch(struct intel_batch_decode_ctx *ctx,
const uint32_t *batch, uint32_t batch_size,
uint64_t batch_addr, bool from_ring);
void intel_batch_stats_reset(struct intel_batch_decode_ctx *ctx);
void intel_batch_stats(struct intel_batch_decode_ctx *ctx,
const uint32_t *batch, uint32_t batch_size,
uint64_t batch_addr, bool from_ring);
void intel_batch_print_stats(struct intel_batch_decode_ctx *ctx);
#ifdef __cplusplus
}
#endif
#endif /* INTEL_DECODER_H */
+25
View File
@@ -0,0 +1,25 @@
/*
* Copyright © 2017 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#ifndef INTEL_DECODER_PRIVATE_H
#define INTEL_DECODER_PRIVATE_H
#include "intel_decoder.h"
void intel_batch_decode_ctx_init(struct intel_batch_decode_ctx *ctx,
const struct intel_device_info *devinfo,
FILE *fp, enum intel_batch_decode_flags flags,
const char *xml_path,
struct intel_batch_decode_bo (*get_bo)(void *,
bool,
uint64_t),
unsigned (*get_state_size)(void *, uint64_t,
uint64_t),
void *user_data);
struct intel_batch_decode_bo
ctx_get_bo(struct intel_batch_decode_ctx *ctx, bool ppgtt, uint64_t addr);
#endif /* INTEL_DECODER_PRIVATE_H */
+118
View File
@@ -0,0 +1,118 @@
# Copyright © 2017 Intel Corporation
# SPDX-License-Identifier: MIT
libintel_decoder_files = files(
'intel_decoder.h',
)
libintel_decoder_deps = [
idep_intel_dev
]
if not dep_expat.found()
libintel_decoder_files += files(
'intel_batch_decoder_stub.c',
)
libintel_decoder_gen_files = files()
libintel_decoder_elk_files = files()
else
libintel_decoder_deps += dep_expat
libintel_decoder_files += files(
'intel_decoder.c',
'intel_batch_decoder.c',
)
libintel_decoder_gen_files = files('intel_batch_decoder_gen.c')
libintel_decoder_elk_files = files('intel_batch_decoder_elk.c')
endif
libintel_decoder = static_library(
'intel_decoder',
[libintel_decoder_files, genX_xml_h, sha1_h],
include_directories : [inc_include, inc_src, inc_intel],
c_args : [no_override_init_args, soong_compat_c_args, sse2_args],
gnu_symbol_visibility : 'hidden',
dependencies : libintel_decoder_deps,
build_by_default : false,
)
idep_intel_decoder = declare_dependency(
link_with : [libintel_decoder],
dependencies : libintel_decoder_deps,
)
libintel_decoder_gen = static_library(
'intel_decoder_gen',
[libintel_decoder_gen_files, genX_xml_h, sha1_h],
include_directories : [inc_include, inc_src, inc_intel],
c_args : [no_override_init_args, soong_compat_c_args, sse2_args],
gnu_symbol_visibility : 'hidden',
dependencies : [idep_intel_decoder, idep_intel_compiler_gen],
build_by_default : false,
)
idep_intel_decoder_gen = declare_dependency(
link_with : [libintel_decoder_gen],
dependencies : [idep_intel_decoder, idep_intel_compiler_gen],
)
if with_intel_elk
libintel_decoder_elk = static_library(
'intel_decoder_elk',
[libintel_decoder_elk_files, genX_xml_h, sha1_h],
include_directories : [inc_include, inc_src, inc_intel],
c_args : [no_override_init_args, soong_compat_c_args, sse2_args],
gnu_symbol_visibility : 'hidden',
dependencies : idep_intel_decoder,
build_by_default : false,
)
idep_intel_decoder_elk = declare_dependency(
link_with : [libintel_decoder_elk],
dependencies : idep_intel_decoder,
)
else
idep_intel_decoder_elk = null_dep
endif
if with_tests and not with_platform_android
gentest_xml = 'tests/gentest.xml'
_name = 'gentest_pack.h'
gentest_pack = custom_target(
_name,
input : [gen_pack_header_py, gentest_xml],
output : _name,
command : [prog_python, '@INPUT@'],
capture : true,
depend_files: gen_pack_header_deps
)
genxml_path = join_paths(meson.current_source_dir(),
'@0@'.format(gentest_xml))
test(
'genxml_test',
executable(
'genxml_test',
['tests/genxml_test.c', gentest_pack],
include_directories : [
inc_include,
inc_src,
inc_intel
],
dependencies : [
idep_libintel_common,
idep_intel_decoder_gen,
idep_intel_decoder_elk,
idep_mesautil,
idep_intel_dev,
idep_genxml,
],
c_args : [
'-DGENXML_DIR="@0@"'.format(fs.parent(genxml_path)),
'-DGENXML_FILE="@0@"'.format(fs.name(genxml_path)),
],
),
args : ['-quiet'],
suite : ['intel'],
)
endif
+29
View File
@@ -0,0 +1,29 @@
<?xml version='1.0' encoding='utf-8'?>
<genxml name="SKL" gen="9">
<struct name="STRUCT_TWO_LEVELS" length="8">
<group count="4" dword="0" size="64">
<group count="8" dword="0" size="8">
<field name="byte" dword="0" bits="7:0" type="uint" />
</group>
</group>
</struct>
<struct name="TEST_DWORD_FIELDS" length="4">
<field name="value_dw0" dword="0" bits="15:0" type="uint" />
<field name="value_dw1" dword="1" bits="31:0" type="uint" />
<field name="value_dw2" dword="2" bits="23:8" type="uint" />
<field name="single_bit" dword="3" bits="5:5" type="bool" />
</struct>
<struct name="TEST_OFFSET_BITS" length="6">
<field name="header" dword="0" bits="31:0" type="uint" />
<group count="3" dword="1" offset_bits="16" size="16">
<field name="data" dword="0" bits="15:0" type="uint" />
</group>
</struct>
<struct name="TEST_STRUCT" length="2">
<field name="number1" dword="0" bits="15:0" type="uint" />
<field name="number2" dword="0" bits="31:16" type="uint" />
<group count="4" dword="1" size="8">
<field name="byte" dword="0" bits="7:0" type="uint" />
</group>
</struct>
</genxml>
+225
View File
@@ -0,0 +1,225 @@
/*
* Copyright © 2019 Intel Corporation
*
* 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.
*/
#undef NDEBUG
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "intel_decoder.h"
static bool quiet = false;
struct test_address {
uint64_t offset;
};
__attribute__((unused)) static uint64_t
_test_combine_address(void *data, void *location,
struct test_address address, uint32_t delta)
{
return address.offset + delta;
}
#define __gen_user_data void
#define __gen_combine_address _test_combine_address
#define __gen_address_type struct test_address
#include "gentest_pack.h"
static void
test_struct(struct intel_spec *spec) {
/* Fill struct fields and <group> tag */
struct GFX9_TEST_STRUCT test1 = {
.number1 = 5,
.number2 = 1234,
};
for (int i = 0; i < 4; i++) {
test1.byte[i] = i * 10 + 5;
}
/* Pack struct into a dw array */
uint32_t dw[GFX9_TEST_STRUCT_length];
GFX9_TEST_STRUCT_pack(NULL, dw, &test1);
/* Now decode the packed struct, and make sure it matches the original */
struct intel_group *group;
group = intel_spec_find_struct(spec, "TEST_STRUCT");
assert(group != NULL);
if (!quiet) {
printf("\nTEST_STRUCT:\n");
intel_print_group(stdout, group, 0, dw, 0, false);
}
struct intel_field_iterator iter;
intel_field_iterator_init(&iter, group, dw, 0, false);
while (intel_field_iterator_next(&iter)) {
int idx;
if (strcmp(iter.name, "number1") == 0) {
uint16_t number = iter.raw_value;
assert(number == test1.number1);
} else if (strcmp(iter.name, "number2") == 0) {
uint16_t number = iter.raw_value;
assert(number == test1.number2);
} else if (sscanf(iter.name, "byte[%d]", &idx) == 1) {
uint8_t number = iter.raw_value;
assert(number == test1.byte[idx]);
}
}
}
static void
test_two_levels(struct intel_spec *spec) {
struct GFX9_STRUCT_TWO_LEVELS test;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 8; j++) {
test.byte[i][j] = (i * 10 + j) % 256;
}
}
uint32_t dw[GFX9_STRUCT_TWO_LEVELS_length];
GFX9_STRUCT_TWO_LEVELS_pack(NULL, dw, &test);
struct intel_group *group;
group = intel_spec_find_struct(spec, "STRUCT_TWO_LEVELS");
assert(group != NULL);
if (!quiet) {
printf("\nSTRUCT_TWO_LEVELS\n");
intel_print_group(stdout, group, 0, dw, 0, false);
}
struct intel_field_iterator iter;
intel_field_iterator_init(&iter, group, dw, 0, false);
while (intel_field_iterator_next(&iter)) {
int i, j;
assert(sscanf(iter.name, "byte[%d][%d]", &i, &j) == 2);
uint8_t number = iter.raw_value;
assert(number == test.byte[i][j]);
}
}
static void
test_dword_fields(struct intel_spec *spec) {
struct GFX9_TEST_DWORD_FIELDS test = {
.value_dw0 = 0x1234,
.value_dw1 = 0xABCDEF00,
.value_dw2 = 0x5678,
.single_bit = true,
};
uint32_t dw[GFX9_TEST_DWORD_FIELDS_length];
GFX9_TEST_DWORD_FIELDS_pack(NULL, dw, &test);
struct intel_group *group;
group = intel_spec_find_struct(spec, "TEST_DWORD_FIELDS");
assert(group != NULL);
if (!quiet) {
printf("\nTEST_DWORD_FIELDS:\n");
intel_print_group(stdout, group, 0, dw, 0, false);
}
struct intel_field_iterator iter;
intel_field_iterator_init(&iter, group, dw, 0, false);
while (intel_field_iterator_next(&iter)) {
if (strcmp(iter.name, "value_dw0") == 0) {
uint16_t value = iter.raw_value;
assert(value == test.value_dw0);
} else if (strcmp(iter.name, "value_dw1") == 0) {
uint32_t value = iter.raw_value;
assert(value == test.value_dw1);
} else if (strcmp(iter.name, "value_dw2") == 0) {
uint16_t value = iter.raw_value;
assert(value == test.value_dw2);
} else if (strcmp(iter.name, "single_bit") == 0) {
bool value = iter.raw_value;
assert(value == test.single_bit);
}
}
}
static void
test_offset_bits(struct intel_spec *spec) {
struct GFX9_TEST_OFFSET_BITS test = {
.header = 0x12345678,
};
for (int i = 0; i < 3; i++) {
test.data[i] = 0x1000 + i;
}
uint32_t dw[GFX9_TEST_OFFSET_BITS_length];
GFX9_TEST_OFFSET_BITS_pack(NULL, dw, &test);
struct intel_group *group;
group = intel_spec_find_struct(spec, "TEST_OFFSET_BITS");
assert(group != NULL);
if (!quiet) {
printf("\nTEST_OFFSET_BITS:\n");
intel_print_group(stdout, group, 0, dw, 0, false);
}
struct intel_field_iterator iter;
intel_field_iterator_init(&iter, group, dw, 0, false);
while (intel_field_iterator_next(&iter)) {
int idx;
if (strcmp(iter.name, "header") == 0) {
uint32_t value = iter.raw_value;
assert(value == test.header);
} else if (sscanf(iter.name, "data[%d]", &idx) == 1) {
uint16_t value = iter.raw_value;
assert(value == test.data[idx]);
}
}
}
int main(int argc, char **argv)
{
struct intel_spec *spec = intel_spec_load_filename(GENXML_DIR, GENXML_FILE);
if (argc > 1 && strcmp(argv[1], "-quiet") == 0)
quiet = true;
test_struct(spec);
test_two_levels(spec);
test_dword_fields(spec);
test_offset_bits(spec);
intel_spec_destroy(spec);
return 0;
}