mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 11:48:06 +02:00
pan/bi: Unit test message preloading optimization
To make sure it is applied in the cases we expect it to be, to avoid code generation regressions. Functional regressions are expected to be caught by integration-testing, so that is not focused on here. Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9438>
This commit is contained in:
parent
eb1479bda2
commit
cd2a4cc47c
2 changed files with 179 additions and 0 deletions
|
|
@ -151,6 +151,7 @@ if with_tests
|
|||
files(
|
||||
'test/test-constant-fold.cpp',
|
||||
'test/test-dual-texture.cpp',
|
||||
'test/test-message-preload.cpp',
|
||||
'test/test-optimizer.cpp',
|
||||
'test/test-pack-formats.cpp',
|
||||
'test/test-packing.cpp',
|
||||
|
|
|
|||
178
src/panfrost/bifrost/test/test-message-preload.cpp
Normal file
178
src/panfrost/bifrost/test/test-message-preload.cpp
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* Copyright (C) 2022 Collabora, Ltd.
|
||||
*
|
||||
* 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 "compiler.h"
|
||||
#include "bi_test.h"
|
||||
#include "bi_builder.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define CASE(instr, expected) do { \
|
||||
bi_builder *A = bit_builder(mem_ctx); \
|
||||
bi_builder *B = bit_builder(mem_ctx); \
|
||||
A->shader->info.bifrost = rzalloc(mem_ctx, struct bifrost_shader_info); \
|
||||
B->shader->info.bifrost = rzalloc(mem_ctx, struct bifrost_shader_info); \
|
||||
{ \
|
||||
bi_builder *b = A; \
|
||||
bi_index u = bi_temp(b->shader); \
|
||||
UNUSED bi_index v = bi_temp(b->shader); \
|
||||
UNUSED bi_index w = bi_temp(b->shader); \
|
||||
instr; \
|
||||
} \
|
||||
{ \
|
||||
bi_builder *b = B; \
|
||||
bi_index u = bi_temp(b->shader); \
|
||||
UNUSED bi_index v = bi_temp(b->shader); \
|
||||
UNUSED bi_index w = bi_temp(b->shader); \
|
||||
expected; \
|
||||
} \
|
||||
bi_opt_message_preload(A->shader); \
|
||||
if (!bit_shader_equal(A->shader, B->shader)) { \
|
||||
ADD_FAILURE(); \
|
||||
fprintf(stderr, "Optimization produce unexpected result"); \
|
||||
fprintf(stderr, " Actual:\n"); \
|
||||
bi_print_shader(A->shader, stderr); \
|
||||
fprintf(stderr, "Expected:\n"); \
|
||||
bi_print_shader(B->shader, stderr); \
|
||||
fprintf(stderr, "\n"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define NEGCASE(instr) CASE(instr, instr)
|
||||
|
||||
class MessagePreload : public testing::Test {
|
||||
protected:
|
||||
MessagePreload() {
|
||||
mem_ctx = ralloc_context(NULL);
|
||||
|
||||
x = bi_register(16);
|
||||
y = bi_register(32);
|
||||
|
||||
}
|
||||
|
||||
~MessagePreload() {
|
||||
ralloc_free(mem_ctx);
|
||||
}
|
||||
|
||||
void *mem_ctx;
|
||||
|
||||
bi_index reg, x, y;
|
||||
|
||||
static void preload_moves(bi_builder *b, bi_index dest, int count, int idx)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
bi_mov_i32_to(b, bi_word(dest, i), bi_register(idx*4 + i));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TEST_F(MessagePreload, PreloadLdVarSample)
|
||||
{
|
||||
CASE({
|
||||
bi_ld_var_imm_to(b, u, bi_register(61), BI_REGISTER_FORMAT_F32,
|
||||
BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 0);
|
||||
}, {
|
||||
preload_moves(b, u, 4, 0);
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(MessagePreload, PreloadLdVarLdVar)
|
||||
{
|
||||
CASE({
|
||||
bi_ld_var_imm_to(b, u, bi_register(61), BI_REGISTER_FORMAT_F32,
|
||||
BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 2);
|
||||
bi_ld_var_imm_to(b, v, bi_register(61), BI_REGISTER_FORMAT_F32,
|
||||
BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 1);
|
||||
}, {
|
||||
preload_moves(b, u, 4, 0);
|
||||
preload_moves(b, v, 4, 1);
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(MessagePreload, MaxTwoMessages)
|
||||
{
|
||||
CASE({
|
||||
bi_ld_var_imm_to(b, u, bi_register(61), BI_REGISTER_FORMAT_F32,
|
||||
BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 2);
|
||||
bi_ld_var_imm_to(b, v, bi_register(61), BI_REGISTER_FORMAT_F32,
|
||||
BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 1);
|
||||
bi_ld_var_imm_to(b, w, bi_register(61), BI_REGISTER_FORMAT_F32,
|
||||
BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 0);
|
||||
},
|
||||
{
|
||||
preload_moves(b, u, 4, 0);
|
||||
preload_moves(b, v, 4, 1);
|
||||
bi_ld_var_imm_to(b, w, bi_register(61), BI_REGISTER_FORMAT_F32,
|
||||
BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 0);
|
||||
});
|
||||
|
||||
CASE({
|
||||
bi_var_tex_f32_to(b, u, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
|
||||
bi_var_tex_f16_to(b, v, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 1, 2);
|
||||
bi_var_tex_f16_to(b, w, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 3, 3);
|
||||
}, {
|
||||
preload_moves(b, u, 4, 0);
|
||||
preload_moves(b, v, 2, 1);
|
||||
bi_var_tex_f16_to(b, w, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 3, 3);
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(MessagePreload, PreloadVartexF16)
|
||||
{
|
||||
CASE({
|
||||
bi_var_tex_f16_to(b, u, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
|
||||
}, {
|
||||
preload_moves(b, u, 2, 0);
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(MessagePreload, PreloadVartexF32)
|
||||
{
|
||||
CASE({
|
||||
bi_var_tex_f32_to(b, u, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
|
||||
}, {
|
||||
preload_moves(b, u, 4, 0);
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(MessagePreload, PreloadVartexF32VartexF16)
|
||||
{
|
||||
CASE({
|
||||
bi_var_tex_f32_to(b, u, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
|
||||
bi_var_tex_f16_to(b, v, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 1, 2);
|
||||
}, {
|
||||
preload_moves(b, u, 4, 0);
|
||||
preload_moves(b, v, 2, 1);
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(MessagePreload, PreloadVartexLodModes)
|
||||
{
|
||||
CASE({
|
||||
bi_var_tex_f32_to(b, u, true, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
|
||||
bi_var_tex_f32_to(b, v, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
|
||||
}, {
|
||||
preload_moves(b, u, 4, 0);
|
||||
preload_moves(b, v, 4, 1);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue