aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets_shared.h
blob: f6e75cda89d23eab1613b90ab8ab314ffb43076b (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/****************************************************************************
* 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 rdtsc_buckets.h
* 
* @brief declaration for rdtsc buckets.
* 
* Notes:
* 
******************************************************************************/
#pragma once

#include <vector>
#include <cassert>

struct BUCKET
{
    uint32_t id{ 0 };
    uint64_t start{ 0 };
    uint64_t elapsed{ 0 };
    uint32_t count{ 0 };

    BUCKET* pParent{ nullptr };
    std::vector<BUCKET> children;
};

struct BUCKET_DESC
{
    // name of bucket, used in reports
    std::string name;

    // description of bucket, used in threadviz
    std::string description;

    // enable for threadviz dumping
    bool enableThreadViz;

    // threadviz color of bucket, in RGBA8_UNORM format
    uint32_t color;
};


struct BUCKET_THREAD
{
    // name of thread, used in reports
    std::string name;

    // id for this thread, assigned by the thread manager
    uint32_t id{ 0 };

    // root of the bucket hierarchy for this thread
    BUCKET root;

    // currently executing bucket somewhere in the hierarchy
    BUCKET* pCurrent{ nullptr };

    // currently executing hierarchy level
    uint32_t level{ 0 };

    // threadviz file object
    FILE* vizFile{ nullptr };


    BUCKET_THREAD() {}
    BUCKET_THREAD(const BUCKET_THREAD& that)
    {
        name = that.name;
        id = that.id;
        root = that.root;
        pCurrent = &root;
        vizFile = that.vizFile;
    }
};

enum VIZ_TYPE
{
    VIZ_START = 0,
    VIZ_STOP  = 1,
    VIZ_DATA  = 2
};

struct VIZ_START_DATA
{
    uint8_t type;
    uint32_t bucketId;
    uint64_t timestamp;
};

struct VIZ_STOP_DATA
{
    uint8_t type;
    uint64_t timestamp;
};

inline void Serialize(FILE* f, const VIZ_START_DATA& data)
{
    fwrite(&data, sizeof(VIZ_START_DATA), 1, f);
}

inline void Deserialize(FILE* f, VIZ_START_DATA& data)
{
    fread(&data, sizeof(VIZ_START_DATA), 1, f);
    assert(data.type == VIZ_START);
}

inline void Serialize(FILE* f, const VIZ_STOP_DATA& data)
{
    fwrite(&data, sizeof(VIZ_STOP_DATA), 1, f);
}

inline void Deserialize(FILE* f, VIZ_STOP_DATA& data)
{
    fread(&data, sizeof(VIZ_STOP_DATA), 1, f);
    assert(data.type == VIZ_STOP);
}

inline void Serialize(FILE* f, const std::string& string)
{
    assert(string.size() <= 256);

    uint8_t length = (uint8_t)string.size();
    fwrite(&length, sizeof(length), 1, f);
    fwrite(string.c_str(), string.size(), 1, f);
}

inline void Deserialize(FILE* f, std::string& string)
{
    char cstr[256];
    uint8_t length;
    fread(&length, sizeof(length), 1, f);
    fread(cstr, length, 1, f);
    cstr[length] = 0;
    string.assign(cstr);
}

inline void Serialize(FILE* f, const BUCKET_DESC& desc)
{
    Serialize(f, desc.name);
    Serialize(f, desc.description);
    fwrite(&desc.enableThreadViz, sizeof(desc.enableThreadViz), 1, f);
    fwrite(&desc.color, sizeof(desc.color), 1, f);
}

inline void Deserialize(FILE* f, BUCKET_DESC& desc)
{
    Deserialize(f, desc.name);
    Deserialize(f, desc.description);
    fread(&desc.enableThreadViz, sizeof(desc.enableThreadViz), 1, f);
    fread(&desc.color, sizeof(desc.color), 1, f);
}