summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.h
blob: 9c4c6672184a9d22855d01fedea70db6c35d4fa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/****************************************************************************
 * Copyright (C) 2014-2015 Intel Corporation.   All Rights Reserved.
 *
 * 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 fetch_jit.h
 *
 * @brief Definition of the fetch jitter
 *
 * Notes:
 *
 ******************************************************************************/
#pragma once

#include "common/formats.h"
#include "core/state.h"

//////////////////////////////////////////////////////////////////////////
/// INPUT_ELEMENT_DESC
//////////////////////////////////////////////////////////////////////////
struct INPUT_ELEMENT_DESC
{
    union
    {
        struct
        {
            uint32_t AlignedByteOffset : 12;
            uint32_t Format : 10;
            uint32_t StreamIndex : 6;
            uint32_t InstanceEnable : 1;
            uint32_t InstanceStrideEnable : 1;
            uint32_t ComponentControl0 : 4;
            uint32_t ComponentControl1 : 4;
            uint32_t ComponentControl2 : 4;
            uint32_t ComponentControl3 : 4;
            uint32_t ComponentPacking : 4;
            uint32_t _reserved : 14;
        };
        uint64_t bits;
    };
    uint32_t InstanceAdvancementState;
};

// used to set ComponentPacking
enum ComponentEnable
{
    NONE = 0x0,
    X    = 0x1,
    Y    = 0x2,
    XY   = 0x3,
    Z    = 0x4,
    XZ   = 0x5,
    YZ   = 0x6,
    XYZ  = 0x7,
    W    = 0x8,
    XW   = 0x9,
    YW   = 0xA,
    XYW  = 0xB,
    ZW   = 0xC,
    XZW  = 0xD,
    YZW  = 0xE,
    XYZW = 0xF,
};

enum ComponentControl
{
    NoStore         = 0,
    StoreSrc        = 1,
    Store0          = 2,
    Store1Fp        = 3,
    Store1Int       = 4,
    StoreVertexId   = 5,
    StoreInstanceId = 6,
};

//////////////////////////////////////////////////////////////////////////
/// State required for fetch shader jit compile.
//////////////////////////////////////////////////////////////////////////
struct FETCH_COMPILE_STATE
{
    uint32_t           numAttribs{0};
    INPUT_ELEMENT_DESC layout[SWR_VTX_NUM_SLOTS];
    SWR_FORMAT         indexType;
    uint32_t           cutIndex{0xffffffff};

    // Options that effect the JIT'd code
    bool bDisableIndexOOBCheck;        // If enabled, FetchJit will exclude index OOB check
    bool bEnableCutIndex{false};       // Compares indices with the cut index and returns a cut mask
    bool bVertexIDOffsetEnable{false}; // Offset vertexID by StartVertex for non-indexed draws or
                                       // BaseVertex for indexed draws
    bool bPartialVertexBuffer{
        false}; // for indexed draws, map illegal indices to a known resident vertex

    bool bForceSequentialAccessEnable{false};
    bool bInstanceIDOffsetEnable{false};

    FETCH_COMPILE_STATE(bool disableIndexOOBCheck = false) :
        bDisableIndexOOBCheck(disableIndexOOBCheck){};

    bool operator==(const FETCH_COMPILE_STATE& other) const
    {
        if (numAttribs != other.numAttribs)
            return false;
        if (indexType != other.indexType)
            return false;
        if (bDisableIndexOOBCheck != other.bDisableIndexOOBCheck)
            return false;
        if (bEnableCutIndex != other.bEnableCutIndex)
            return false;
        if (cutIndex != other.cutIndex)
            return false;
        if (bVertexIDOffsetEnable != other.bVertexIDOffsetEnable)
            return false;
        if (bPartialVertexBuffer != other.bPartialVertexBuffer)
            return false;
        if (bForceSequentialAccessEnable != other.bForceSequentialAccessEnable)
            return false;
        if (bInstanceIDOffsetEnable != other.bInstanceIDOffsetEnable)
            return false;

        for (uint32_t i = 0; i < numAttribs; ++i)
        {
            if ((layout[i].bits != other.layout[i].bits) ||
                (((layout[i].InstanceEnable == 1) || (layout[i].InstanceStrideEnable == 1)) &&
                 (layout[i].InstanceAdvancementState != other.layout[i].InstanceAdvancementState)))
            {
                return false;
            }
        }

        return true;
    }
};