2015-07-02 15:41:02 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2015 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** @file brw_fs_validate.cpp
|
|
|
|
|
*
|
|
|
|
|
* Implements a pass that validates various invariants of the IR. The current
|
|
|
|
|
* pass only validates that GRF's uses are sane. More can be added later.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "brw_fs.h"
|
|
|
|
|
#include "brw_cfg.h"
|
|
|
|
|
|
2022-12-01 11:45:44 -08:00
|
|
|
#define fsv_assert(assertion) \
|
|
|
|
|
{ \
|
|
|
|
|
if (!(assertion)) { \
|
|
|
|
|
fprintf(stderr, "ASSERT: Scalar %s validation failed!\n", stage_abbrev); \
|
|
|
|
|
dump_instruction(inst, stderr); \
|
|
|
|
|
fprintf(stderr, "%s:%d: '%s' failed\n", __FILE__, __LINE__, #assertion); \
|
|
|
|
|
abort(); \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 14:48:38 -07:00
|
|
|
#define fsv_assert_eq(first, second) \
|
|
|
|
|
{ \
|
|
|
|
|
unsigned f = (first); \
|
|
|
|
|
unsigned s = (second); \
|
|
|
|
|
if (f != s) { \
|
|
|
|
|
fprintf(stderr, "ASSERT: Scalar %s validation failed!\n", stage_abbrev); \
|
|
|
|
|
dump_instruction(inst, stderr); \
|
|
|
|
|
fprintf(stderr, "%s:%d: A == B failed\n", __FILE__, __LINE__); \
|
|
|
|
|
fprintf(stderr, " A = %s = %u\n", #first, f); \
|
|
|
|
|
fprintf(stderr, " B = %s = %u\n", #second, s); \
|
|
|
|
|
abort(); \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define fsv_assert_lte(first, second) \
|
|
|
|
|
{ \
|
|
|
|
|
unsigned f = (first); \
|
|
|
|
|
unsigned s = (second); \
|
|
|
|
|
if (f > s) { \
|
|
|
|
|
fprintf(stderr, "ASSERT: Scalar %s validation failed!\n", stage_abbrev); \
|
|
|
|
|
dump_instruction(inst, stderr); \
|
|
|
|
|
fprintf(stderr, "%s:%d: A <= B failed\n", __FILE__, __LINE__); \
|
|
|
|
|
fprintf(stderr, " A = %s = %u\n", #first, f); \
|
|
|
|
|
fprintf(stderr, " B = %s = %u\n", #second, s); \
|
|
|
|
|
abort(); \
|
|
|
|
|
} \
|
2015-07-02 15:41:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fs_visitor::validate()
|
|
|
|
|
{
|
2018-08-19 10:15:12 -07:00
|
|
|
#ifndef NDEBUG
|
2015-07-02 15:41:02 -07:00
|
|
|
foreach_block_and_inst (block, fs_inst, inst, cfg) {
|
2022-07-12 15:32:01 -07:00
|
|
|
if (inst->opcode == SHADER_OPCODE_URB_WRITE_LOGICAL) {
|
|
|
|
|
const unsigned header_size = 1 +
|
|
|
|
|
unsigned(inst->src[URB_LOGICAL_SRC_PER_SLOT_OFFSETS].file != BAD_FILE) +
|
|
|
|
|
unsigned(inst->src[URB_LOGICAL_SRC_CHANNEL_MASK].file != BAD_FILE);
|
|
|
|
|
|
|
|
|
|
unsigned data_size = 0;
|
|
|
|
|
for (unsigned i = header_size, j = 0; i < inst->mlen; i++, j++) {
|
2022-08-16 14:48:38 -07:00
|
|
|
fsv_assert_eq(type_sz(offset(inst->src[URB_LOGICAL_SRC_DATA], bld, j).type), 4);
|
2022-07-12 15:32:01 -07:00
|
|
|
data_size++;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 14:48:38 -07:00
|
|
|
fsv_assert_eq(header_size + data_size, inst->mlen);
|
2022-07-12 15:32:01 -07:00
|
|
|
}
|
|
|
|
|
|
2022-12-01 11:45:44 -08:00
|
|
|
if (inst->is_3src(compiler)) {
|
|
|
|
|
const unsigned integer_sources =
|
|
|
|
|
brw_reg_type_is_integer(inst->src[0].type) +
|
|
|
|
|
brw_reg_type_is_integer(inst->src[1].type) +
|
|
|
|
|
brw_reg_type_is_integer(inst->src[2].type);
|
|
|
|
|
const unsigned float_sources =
|
|
|
|
|
brw_reg_type_is_floating_point(inst->src[0].type) +
|
|
|
|
|
brw_reg_type_is_floating_point(inst->src[1].type) +
|
|
|
|
|
brw_reg_type_is_floating_point(inst->src[2].type);
|
|
|
|
|
|
|
|
|
|
fsv_assert((integer_sources == 3 && float_sources == 0) ||
|
|
|
|
|
(integer_sources == 0 && float_sources == 3));
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 17:09:25 -07:00
|
|
|
if (inst->dst.file == VGRF) {
|
2022-08-16 14:48:38 -07:00
|
|
|
fsv_assert_lte(inst->dst.offset / REG_SIZE + regs_written(inst),
|
|
|
|
|
alloc.sizes[inst->dst.nr]);
|
2015-07-02 15:41:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < inst->sources; i++) {
|
2015-10-26 17:09:25 -07:00
|
|
|
if (inst->src[i].file == VGRF) {
|
2022-08-16 14:48:38 -07:00
|
|
|
fsv_assert_lte(inst->src[i].offset / REG_SIZE + regs_read(inst, i),
|
|
|
|
|
alloc.sizes[inst->src[i].nr]);
|
2015-07-02 15:41:02 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-19 10:15:12 -07:00
|
|
|
#endif
|
2015-07-02 15:41:02 -07:00
|
|
|
}
|