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.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-07-13 00:19:44 -07:00
|
|
|
/** @file
|
2015-07-02 15:41:02 -07:00
|
|
|
*
|
|
|
|
|
* 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)) { \
|
2023-09-24 21:38:47 -07:00
|
|
|
fprintf(stderr, "ASSERT: Scalar %s validation failed!\n", \
|
2024-04-01 12:00:16 -07:00
|
|
|
_mesa_shader_stage_to_abbrev(s.stage)); \
|
2024-07-12 16:32:36 -07:00
|
|
|
brw_print_instruction(s, inst, stderr); \
|
2022-12-01 11:45:44 -08:00
|
|
|
fprintf(stderr, "%s:%d: '%s' failed\n", __FILE__, __LINE__, #assertion); \
|
|
|
|
|
abort(); \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 11:49:02 -07:00
|
|
|
#define fsv_assert_eq(A, B) \
|
2022-08-16 14:48:38 -07:00
|
|
|
{ \
|
2024-04-01 11:49:02 -07:00
|
|
|
unsigned a = (A); \
|
|
|
|
|
unsigned b = (B); \
|
|
|
|
|
if (a != b) { \
|
2023-09-24 21:38:47 -07:00
|
|
|
fprintf(stderr, "ASSERT: Scalar %s validation failed!\n", \
|
2024-04-01 12:00:16 -07:00
|
|
|
_mesa_shader_stage_to_abbrev(s.stage)); \
|
2024-07-12 16:32:36 -07:00
|
|
|
brw_print_instruction(s, inst, stderr); \
|
2022-08-16 14:48:38 -07:00
|
|
|
fprintf(stderr, "%s:%d: A == B failed\n", __FILE__, __LINE__); \
|
2024-04-01 11:49:02 -07:00
|
|
|
fprintf(stderr, " A = %s = %u\n", #A, a); \
|
|
|
|
|
fprintf(stderr, " B = %s = %u\n", #B, b); \
|
2022-08-16 14:48:38 -07:00
|
|
|
abort(); \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 11:49:02 -07:00
|
|
|
#define fsv_assert_ne(A, B) \
|
2022-12-06 12:16:12 -08:00
|
|
|
{ \
|
2024-04-01 11:49:02 -07:00
|
|
|
unsigned a = (A); \
|
|
|
|
|
unsigned b = (B); \
|
|
|
|
|
if (a == b) { \
|
2023-09-24 21:38:47 -07:00
|
|
|
fprintf(stderr, "ASSERT: Scalar %s validation failed!\n", \
|
2024-04-01 12:00:16 -07:00
|
|
|
_mesa_shader_stage_to_abbrev(s.stage)); \
|
2024-07-12 16:32:36 -07:00
|
|
|
brw_print_instruction(s, inst, stderr); \
|
2022-12-06 12:16:12 -08:00
|
|
|
fprintf(stderr, "%s:%d: A != B failed\n", __FILE__, __LINE__); \
|
2024-04-01 11:49:02 -07:00
|
|
|
fprintf(stderr, " A = %s = %u\n", #A, a); \
|
|
|
|
|
fprintf(stderr, " B = %s = %u\n", #B, b); \
|
2022-12-06 12:16:12 -08:00
|
|
|
abort(); \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 11:49:02 -07:00
|
|
|
#define fsv_assert_lte(A, B) \
|
2022-08-16 14:48:38 -07:00
|
|
|
{ \
|
2024-04-01 11:49:02 -07:00
|
|
|
unsigned a = (A); \
|
|
|
|
|
unsigned b = (B); \
|
|
|
|
|
if (a > b) { \
|
2023-09-24 21:38:47 -07:00
|
|
|
fprintf(stderr, "ASSERT: Scalar %s validation failed!\n", \
|
2024-04-01 12:00:16 -07:00
|
|
|
_mesa_shader_stage_to_abbrev(s.stage)); \
|
2024-07-12 16:32:36 -07:00
|
|
|
brw_print_instruction(s, inst, stderr); \
|
2022-08-16 14:48:38 -07:00
|
|
|
fprintf(stderr, "%s:%d: A <= B failed\n", __FILE__, __LINE__); \
|
2024-04-01 11:49:02 -07:00
|
|
|
fprintf(stderr, " A = %s = %u\n", #A, a); \
|
|
|
|
|
fprintf(stderr, " B = %s = %u\n", #B, b); \
|
2022-08-16 14:48:38 -07:00
|
|
|
abort(); \
|
|
|
|
|
} \
|
2015-07-02 15:41:02 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-22 14:36:03 -07:00
|
|
|
#ifndef NDEBUG
|
2015-07-02 15:41:02 -07:00
|
|
|
void
|
2024-04-01 12:00:16 -07:00
|
|
|
brw_fs_validate(const fs_visitor &s)
|
2015-07-02 15:41:02 -07:00
|
|
|
{
|
2024-04-01 12:00:16 -07:00
|
|
|
const intel_device_info *devinfo = s.devinfo;
|
2023-09-11 09:10:47 -07:00
|
|
|
|
2024-04-01 12:00:16 -07:00
|
|
|
s.cfg->validate(_mesa_shader_stage_to_abbrev(s.stage));
|
|
|
|
|
|
|
|
|
|
foreach_block_and_inst (block, fs_inst, inst, s.cfg) {
|
2021-11-23 12:48:27 -06:00
|
|
|
switch (inst->opcode) {
|
|
|
|
|
case SHADER_OPCODE_SEND:
|
|
|
|
|
fsv_assert(is_uniform(inst->src[0]) && is_uniform(inst->src[1]));
|
|
|
|
|
break;
|
|
|
|
|
|
2023-03-07 18:02:03 +02:00
|
|
|
case BRW_OPCODE_MOV:
|
|
|
|
|
fsv_assert(inst->sources == 1);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-11-23 12:48:27 -06:00
|
|
|
default:
|
|
|
|
|
break;
|
2022-07-12 15:32:01 -07:00
|
|
|
}
|
|
|
|
|
|
2024-04-11 15:21:26 -07:00
|
|
|
/* On Xe2, the "write the accumulator in addition to the explicit
|
|
|
|
|
* destination" bit no longer exists. Try to catch uses of this feature
|
|
|
|
|
* earlier in the process.
|
|
|
|
|
*/
|
|
|
|
|
if (devinfo->ver >= 20 && inst->writes_accumulator) {
|
|
|
|
|
fsv_assert(inst->dst.is_accumulator() ||
|
|
|
|
|
inst->opcode == BRW_OPCODE_ADDC ||
|
|
|
|
|
inst->opcode == BRW_OPCODE_MACH ||
|
|
|
|
|
inst->opcode == BRW_OPCODE_SUBB);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 12:00:16 -07:00
|
|
|
if (inst->is_3src(s.compiler)) {
|
2022-12-01 11:45:44 -08:00
|
|
|
const unsigned integer_sources =
|
2024-04-20 23:19:43 -07:00
|
|
|
brw_type_is_int(inst->src[0].type) +
|
|
|
|
|
brw_type_is_int(inst->src[1].type) +
|
|
|
|
|
brw_type_is_int(inst->src[2].type);
|
2022-12-01 11:45:44 -08:00
|
|
|
const unsigned float_sources =
|
2024-04-20 23:19:43 -07:00
|
|
|
brw_type_is_float(inst->src[0].type) +
|
|
|
|
|
brw_type_is_float(inst->src[1].type) +
|
|
|
|
|
brw_type_is_float(inst->src[2].type);
|
2022-12-01 11:45:44 -08:00
|
|
|
|
|
|
|
|
fsv_assert((integer_sources == 3 && float_sources == 0) ||
|
|
|
|
|
(integer_sources == 0 && float_sources == 3));
|
2022-12-06 12:16:12 -08:00
|
|
|
|
|
|
|
|
if (devinfo->ver >= 10) {
|
|
|
|
|
for (unsigned i = 0; i < 3; i++) {
|
|
|
|
|
if (inst->src[i].file == BRW_IMMEDIATE_VALUE)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
switch (inst->src[i].vstride) {
|
|
|
|
|
case BRW_VERTICAL_STRIDE_0:
|
|
|
|
|
case BRW_VERTICAL_STRIDE_4:
|
|
|
|
|
case BRW_VERTICAL_STRIDE_8:
|
|
|
|
|
case BRW_VERTICAL_STRIDE_16:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BRW_VERTICAL_STRIDE_1:
|
|
|
|
|
fsv_assert_lte(12, devinfo->ver);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BRW_VERTICAL_STRIDE_2:
|
|
|
|
|
fsv_assert_lte(devinfo->ver, 11);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fsv_assert(!"invalid vstride");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-01 12:00:16 -07:00
|
|
|
} else if (s.grf_used != 0) {
|
2022-12-06 12:16:12 -08:00
|
|
|
/* Only perform the pre-Gfx10 checks after register allocation has
|
|
|
|
|
* occured.
|
|
|
|
|
*
|
|
|
|
|
* Many passes (e.g., constant copy propagation) will genenerate
|
|
|
|
|
* invalid 3-source instructions with the expectation that later
|
|
|
|
|
* passes (e.g., combine constants) will fix them.
|
|
|
|
|
*/
|
|
|
|
|
for (unsigned i = 0; i < 3; i++) {
|
|
|
|
|
fsv_assert_ne(inst->src[i].file, BRW_IMMEDIATE_VALUE);
|
|
|
|
|
|
|
|
|
|
/* A stride of 1 (the usual case) or 0, with a special
|
|
|
|
|
* "repctrl" bit, is allowed. The repctrl bit doesn't work for
|
|
|
|
|
* 64-bit datatypes, so if the source type is 64-bit then only
|
|
|
|
|
* a stride of 1 is allowed. From the Broadwell PRM, Volume 7
|
|
|
|
|
* "3D Media GPGPU", page 944:
|
|
|
|
|
*
|
|
|
|
|
* This is applicable to 32b datatypes and 16b datatype. 64b
|
|
|
|
|
* datatypes cannot use the replicate control.
|
|
|
|
|
*/
|
|
|
|
|
fsv_assert_lte(inst->src[i].vstride, 1);
|
|
|
|
|
|
2024-04-21 00:57:59 -07:00
|
|
|
if (brw_type_size_bytes(inst->src[i].type) > 4)
|
2022-12-06 12:16:12 -08:00
|
|
|
fsv_assert_eq(inst->src[i].vstride, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-01 11:45:44 -08:00
|
|
|
}
|
|
|
|
|
|
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),
|
2024-04-01 12:00:16 -07:00
|
|
|
s.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),
|
2024-04-01 12:00:16 -07:00
|
|
|
s.alloc.sizes[inst->src[i].nr]);
|
2015-07-02 15:41:02 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-08 13:21:48 +02:00
|
|
|
|
|
|
|
|
/* Accumulator Registers, bspec 47251:
|
|
|
|
|
*
|
|
|
|
|
* "When destination is accumulator with offset 0, destination
|
|
|
|
|
* horizontal stride must be 1."
|
|
|
|
|
*/
|
|
|
|
|
if (intel_needs_workaround(devinfo, 14014617373) &&
|
|
|
|
|
inst->dst.is_accumulator() &&
|
2024-06-18 14:57:37 -07:00
|
|
|
phys_subnr(devinfo, inst->dst) == 0) {
|
2024-03-07 13:58:55 -08:00
|
|
|
fsv_assert_eq(inst->dst.hstride, 1);
|
2023-03-08 13:21:48 +02:00
|
|
|
}
|
2024-03-28 09:54:20 -07:00
|
|
|
|
|
|
|
|
if (inst->is_math() && intel_needs_workaround(devinfo, 22016140776)) {
|
|
|
|
|
/* Wa_22016140776:
|
|
|
|
|
*
|
|
|
|
|
* Scalar broadcast on HF math (packed or unpacked) must not be
|
|
|
|
|
* used. Compiler must use a mov instruction to expand the scalar
|
|
|
|
|
* value to a vector before using in a HF (packed or unpacked)
|
|
|
|
|
* math operation.
|
|
|
|
|
*
|
|
|
|
|
* Since copy propagation knows about this restriction, nothing
|
|
|
|
|
* should be able to generate these invalid source strides. Detect
|
|
|
|
|
* potential problems sooner rather than later.
|
|
|
|
|
*/
|
|
|
|
|
for (unsigned i = 0; i < inst->sources; i++) {
|
|
|
|
|
fsv_assert(!is_uniform(inst->src[i]) ||
|
2024-04-20 17:08:02 -07:00
|
|
|
inst->src[i].type != BRW_TYPE_HF);
|
2024-03-28 09:54:20 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-02 15:41:02 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-10-22 14:36:03 -07:00
|
|
|
#endif
|