pan/mdg: Explain helper invocations dataflow theory

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5014>
This commit is contained in:
Alyssa Rosenzweig 2020-05-11 20:05:24 -04:00 committed by Marge Bot
parent 95fd950d35
commit 0da03c68ae

View file

@ -0,0 +1,63 @@
/*
* Copyright (C) 2019 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.
*
* Authors (Collabora):
* Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
*/
#include "compiler.h"
/* Midgard texture/derivative operations have a pair of bits controlling the
* behaviour of helper invocations:
*
* - Should a helper invocation terminate after executing this instruction?
* - Should a helper invocation actually execute this instruction?
*
* The terminate bit should be set on the last instruction requiring helper
* invocations. Without control flow, that's literally the last instruction;
* with control flow, there may be multiple such instructions (with ifs) or no
* such instruction (with loops).
*
* The execute bit should be set if the value of this instruction is required
* by a future instruction requiring helper invocations. Consider:
*
* 0 = texture ...
* 1 = fmul 0, #10
* 2 = dfdx 1
* store 2
*
* Since the derivative calculation 2 requires helper invocations, the value 1
* must be calculated by helper invocations, and since it depends on 0, 0 must
* be calculated by helpers. Hence the texture op has the execute bit set, and
* the derivative op has the terminate bit set.
*
* Calculating the terminate bit occurs by forward dataflow analysis to
* determine which blocks require helper invocations. A block requires
* invocations in if any of its instructions use helper invocations, or if it
* depends on a block that requires invocation. With that analysis, the
* terminate bit is set on the last instruction using invocations within any
* block that does *not* require invocations out.
*
* Likewise, calculating the execute bit requires backward dataflow analysis
* with union as the join operation and the generating set being the union of
* sources of instructions writing executed values.
*/