| 1 |
/* |
| 2 |
* Copyright (C) 2022 Collabora, Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "bi_builder.h" |
| 7 |
#include "bi_test.h" |
| 8 |
#include "va_compiler.h" |
| 9 |
#include "valhall_enums.h" |
| 10 |
|
| 11 |
#include <gtest/gtest.h> |
| 12 |
|
| 13 |
#define R(x) bi_register(x) |
| 14 |
#define DR(x) bi_discard(R(x)) |
| 15 |
|
| 16 |
static void |
| 17 |
strip_discard(bi_context *ctx) |
| 18 |
{ |
| 19 |
bi_foreach_instr_global(ctx, I) { |
| 20 |
bi_foreach_src(I, s) |
| 21 |
I->src[s].discard = false; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
#define CASE(test) \ |
| 26 |
do { \ |
| 27 |
void *mem_ctx = ralloc_context(NULL); \ |
| 28 |
bi_builder *A = bit_builder(mem_ctx); \ |
| 29 |
bi_builder *B = bit_builder(mem_ctx); \ |
| 30 |
{ \ |
| 31 |
UNUSED bi_builder *b = A; \ |
| 32 |
test; \ |
| 33 |
} \ |
| 34 |
strip_discard(A->shader); \ |
| 35 |
va_mark_last(A->shader); \ |
| 36 |
{ \ |
| 37 |
UNUSED bi_builder *b = B; \ |
| 38 |
test; \ |
| 39 |
} \ |
| 40 |
ASSERT_SHADER_EQUAL(A->shader, B->shader); \ |
| 41 |
ralloc_free(mem_ctx); \ |
| 42 |
} while (0) |
| 43 |
|
| 44 |
TEST(MarkLast, Simple) |
| 45 |
{ |
| 46 |
CASE(bi_fadd_f32_to(b, R(0), DR(0), DR(1))); |
| 47 |
|
| 48 |
CASE({ |
| 49 |
bi_fadd_f32_to(b, R(2), R(0), DR(1)); |
| 50 |
bi_fadd_f32_to(b, R(0), DR(0), DR(2)); |
| 51 |
}); |
| 52 |
} |
| 53 |
|
| 54 |
TEST(MarkLast, SameSourceAndDestination) |
| 55 |
{ |
| 56 |
CASE({ |
| 57 |
bi_fadd_f32_to(b, R(0), DR(0), DR(0)); |
| 58 |
bi_fadd_f32_to(b, R(0), DR(0), DR(0)); |
| 59 |
bi_fadd_f32_to(b, R(0), DR(0), DR(0)); |
| 60 |
}); |
| 61 |
} |
| 62 |
|
| 63 |
TEST(MarkLast, StagingReadBefore) |
| 64 |
{ |
| 65 |
CASE({ |
| 66 |
bi_fadd_f32_to(b, R(9), R(2), DR(7)); |
| 67 |
bi_st_tile(b, R(0), DR(4), DR(5), DR(6), BI_REGISTER_FORMAT_F32, |
| 68 |
BI_VECSIZE_V4); |
| 69 |
}); |
| 70 |
} |
| 71 |
|
| 72 |
TEST(MarkLast, StagingReadAfter) |
| 73 |
{ |
| 74 |
CASE({ |
| 75 |
bi_st_tile(b, R(0), DR(4), DR(5), DR(6), BI_REGISTER_FORMAT_F32, |
| 76 |
BI_VECSIZE_V4); |
| 77 |
bi_fadd_f32_to(b, R(9), R(2), DR(7)); |
| 78 |
}); |
| 79 |
} |
| 80 |
|
| 81 |
TEST(MarkLast, NonstagingSourceToAsync) |
| 82 |
{ |
| 83 |
CASE({ |
| 84 |
bi_st_tile(b, R(0), R(4), R(5), DR(6), BI_REGISTER_FORMAT_F32, |
| 85 |
BI_VECSIZE_V4); |
| 86 |
bi_fadd_f32_to(b, R(9), DR(4), DR(5)); |
| 87 |
}); |
| 88 |
} |
| 89 |
|
| 90 |
TEST(MarkLast, Both64) |
| 91 |
{ |
| 92 |
CASE(bi_load_i32_to(b, R(0), DR(8), DR(9), BI_SEG_NONE, 0)); |
| 93 |
} |
| 94 |
|
| 95 |
TEST(MarkLast, Neither64ThenBoth) |
| 96 |
{ |
| 97 |
CASE({ |
| 98 |
bi_load_i32_to(b, R(0), R(8), R(9), BI_SEG_NONE, 0); |
| 99 |
bi_load_i32_to(b, R(1), DR(8), DR(9), BI_SEG_NONE, 8); |
| 100 |
}); |
| 101 |
} |
| 102 |
|
| 103 |
TEST(MarkLast, Half64) |
| 104 |
{ |
| 105 |
CASE({ |
| 106 |
bi_load_i32_to(b, R(0), R(8), R(9), BI_SEG_NONE, 0); |
| 107 |
bi_fadd_f32_to(b, R(8), DR(8), DR(8)); |
| 108 |
}); |
| 109 |
|
| 110 |
CASE({ |
| 111 |
bi_load_i32_to(b, R(0), R(8), R(9), BI_SEG_NONE, 0); |
| 112 |
bi_fadd_f32_to(b, R(9), DR(9), DR(9)); |
| 113 |
}); |
| 114 |
} |
| 115 |
|
| 116 |
TEST(MarkLast, RegisterBlendDescriptor) |
| 117 |
{ |
| 118 |
CASE({ |
| 119 |
bi_blend_to(b, R(48), R(0), DR(60), DR(4), DR(5), bi_null(), |
| 120 |
BI_REGISTER_FORMAT_F32, 4, 0); |
| 121 |
}); |
| 122 |
|
| 123 |
CASE({ |
| 124 |
bi_blend_to(b, R(48), R(0), DR(60), R(4), R(5), bi_null(), |
| 125 |
BI_REGISTER_FORMAT_F32, 4, 0); |
| 126 |
bi_fadd_f32_to(b, R(4), DR(4), DR(7)); |
| 127 |
}); |
| 128 |
|
| 129 |
CASE({ |
| 130 |
bi_blend_to(b, R(48), R(0), DR(60), R(4), R(5), bi_null(), |
| 131 |
BI_REGISTER_FORMAT_F32, 4, 0); |
| 132 |
bi_fadd_f32_to(b, R(4), DR(5), DR(7)); |
| 133 |
}); |
| 134 |
} |
| 135 |
|
| 136 |
TEST(MarkLast, ControlFlowAllFeatures) |
| 137 |
{ |
| 138 |
/* A |
| 139 |
* / \ |
| 140 |
* B C |
| 141 |
*/ |
| 142 |
CASE({ |
| 143 |
bi_block *A = bi_start_block(&b->shader->blocks); |
| 144 |
bi_block *B = bit_block(b->shader); |
| 145 |
bi_block *C = bit_block(b->shader); |
| 146 |
|
| 147 |
bi_block_add_successor(A, B); |
| 148 |
bi_block_add_successor(A, C); |
| 149 |
|
| 150 |
b->cursor = bi_after_block(A); |
| 151 |
{ |
| 152 |
bi_instr *I = bi_st_tile(b, R(10), DR(14), DR(15), DR(16), |
| 153 |
BI_REGISTER_FORMAT_F32, BI_VECSIZE_V4); |
| 154 |
I->slot = 2; |
| 155 |
|
| 156 |
bi_load_i32_to(b, R(20), R(28), R(29), BI_SEG_NONE, 0); |
| 157 |
|
| 158 |
bi_fadd_f32_to(b, R(0), DR(0), R(3)); |
| 159 |
bi_fadd_f32_to(b, R(0), DR(0), R(7)); |
| 160 |
bi_fma_f32_to(b, R(2), R(0), R(1), DR(4)); |
| 161 |
} |
| 162 |
|
| 163 |
b->cursor = bi_after_block(B); |
| 164 |
{ |
| 165 |
bi_fadd_f32_to(b, R(2), DR(0), DR(2)); |
| 166 |
bi_fadd_f32_to(b, R(2), DR(2), DR(3)); |
| 167 |
bi_fadd_f32_to(b, R(2), DR(2), DR(7)); |
| 168 |
bi_fadd_f32_to(b, R(2), DR(2), DR(29)); |
| 169 |
} |
| 170 |
|
| 171 |
b->cursor = bi_after_block(C); |
| 172 |
{ |
| 173 |
bi_fadd_f32_to(b, R(2), DR(1), DR(2)); |
| 174 |
bi_fadd_f32_to(b, R(2), DR(2), DR(7)); |
| 175 |
|
| 176 |
bi_instr *I = bi_fadd_f32_to(b, R(2), DR(2), R(13)); |
| 177 |
I->flow = VA_FLOW_WAIT2; |
| 178 |
|
| 179 |
bi_fadd_f32_to(b, R(2), DR(2), DR(11)); |
| 180 |
} |
| 181 |
}); |
| 182 |
} |