File: custom_dx12_struct_object_mappers.cpp

package info (click to toggle)
gfxreconstruct 0.9.18%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 24,636 kB
  • sloc: cpp: 328,961; ansic: 25,454; python: 18,156; xml: 255; sh: 128; makefile: 6
file content (325 lines) | stat: -rw-r--r-- 13,244 bytes parent folder | download
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
** Copyright (c) 2021 LunarG, Inc.
**
** 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 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.
*/

#include "decode/custom_dx12_struct_object_mappers.h"

#include "decode/custom_dx12_struct_decoders.h"
#include "generated/generated_dx12_struct_object_mappers.h"
#include "util/defines.h"

GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(decode)

template <typename Handle, typename Function>
void MapDescriptorStructObjects(Handle*                       wrapper,
                                const Dx12ObjectInfoTable&    object_info_table,
                                const graphics::Dx12GpuVaMap& gpu_va_map,
                                Function                      get_begin_addr)
{
    if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
    {
        auto entry = object_info_table.find(wrapper->heap_id);
        if (entry != object_info_table.end())
        {
            auto  index     = wrapper->index;
            auto  value     = wrapper->decoded_value;
            auto& info      = entry->second;
            auto  heap_info = reinterpret_cast<D3D12DescriptorHeapInfo*>(info.extra_info.get());
            assert(heap_info->extra_info_type == DxObjectInfoType::kID3D12DescriptorHeapInfo);

            value->ptr = get_begin_addr(heap_info);
            if (index > 0)
            {
                auto offset = (*heap_info->replay_increments)[heap_info->descriptor_type] * index;
                value->ptr += offset;
            }
        }
    }
}

void MapStructObjects(Decoded_D3D12_CPU_DESCRIPTOR_HANDLE* wrapper,
                      const Dx12ObjectInfoTable&           object_info_table,
                      const graphics::Dx12GpuVaMap&        gpu_va_map)
{
    MapDescriptorStructObjects(wrapper, object_info_table, gpu_va_map, [](const D3D12DescriptorHeapInfo* info) {
        return info->replay_cpu_addr_begin;
    });
}

void MapStructObjects(Decoded_D3D12_RESOURCE_BARRIER* wrapper,
                      const Dx12ObjectInfoTable&      object_info_table,
                      const graphics::Dx12GpuVaMap&   gpu_va_map)
{
    if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
    {
        auto value = wrapper->decoded_value;

        switch (value->Type)
        {
            case D3D12_RESOURCE_BARRIER_TYPE_TRANSITION:
                MapStructObjects(wrapper->Transition, object_info_table, gpu_va_map);
                break;
            case D3D12_RESOURCE_BARRIER_TYPE_ALIASING:
                MapStructObjects(wrapper->Aliasing, object_info_table, gpu_va_map);
                break;
            case D3D12_RESOURCE_BARRIER_TYPE_UAV:
                MapStructObjects(wrapper->UAV, object_info_table, gpu_va_map);
                break;
            default:
                break;
        }
    }
}

void MapStructObjects(Decoded_D3D12_TEXTURE_COPY_LOCATION* wrapper,
                      const Dx12ObjectInfoTable&           object_info_table,
                      const graphics::Dx12GpuVaMap&        gpu_va_map)
{
    if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
    {
        auto value = wrapper->decoded_value;

        value->pResource = object_mapping::MapObject<ID3D12Resource>(wrapper->pResource, object_info_table);
    }
}

void MapStructObjects(Decoded_D3D12_RAYTRACING_GEOMETRY_DESC* wrapper,
                      const Dx12ObjectInfoTable&              object_info_table,
                      const graphics::Dx12GpuVaMap&           gpu_va_map)
{
    if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
    {
        auto value = wrapper->decoded_value;

        switch (value->Type)
        {
            case D3D12_RAYTRACING_GEOMETRY_TYPE_TRIANGLES:
                MapStructObjects(wrapper->Triangles, object_info_table, gpu_va_map);
                break;
            case D3D12_RAYTRACING_GEOMETRY_TYPE_PROCEDURAL_PRIMITIVE_AABBS:
                MapStructObjects(wrapper->AABBs, object_info_table, gpu_va_map);
                break;
            default:
                break;
        }
    }
}

void MapStructObjects(Decoded_D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS* wrapper,
                      const Dx12ObjectInfoTable&                                    object_info_table,
                      const graphics::Dx12GpuVaMap&                                 gpu_va_map)
{
    if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
    {
        auto value = wrapper->decoded_value;

        switch (value->Type)
        {
            case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL:
                object_mapping::MapGpuVirtualAddress(value->InstanceDescs, gpu_va_map);
                break;
            case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL:
                switch (value->DescsLayout)
                {
                    case D3D12_ELEMENTS_LAYOUT_ARRAY:
                        MapStructArrayObjects(wrapper->pGeometryDescs->GetMetaStructPointer(),
                                              wrapper->pGeometryDescs->GetLength(),
                                              object_info_table,
                                              gpu_va_map);
                        break;
                    case D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS:
                    {
                        auto descs     = wrapper->ppGeometryDescs->GetMetaStructPointer();
                        auto num_descs = wrapper->ppGeometryDescs->GetLength();

                        for (size_t i = 0; i < num_descs; ++i)
                        {
                            MapStructObjects(descs[i], object_info_table, gpu_va_map);
                        }

                        break;
                    }
                    default:
                        break;
                }
                break;
            default:
                break;
        }
    }
}

void MapStructObjects(Decoded_D3D12_RENDER_PASS_ENDING_ACCESS* wrapper,
                      const Dx12ObjectInfoTable&               object_info_table,
                      const graphics::Dx12GpuVaMap&            gpu_va_map)
{
    if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
    {
        auto value = wrapper->decoded_value;

        switch (value->Type)
        {
            case D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE:
                MapStructObjects(wrapper->Resolve, object_info_table, gpu_va_map);
                break;
            default:
                break;
        }
    }
}

void MapStructObjects(Decoded_D3D12_PIPELINE_STATE_STREAM_DESC* wrapper,
                      const Dx12ObjectInfoTable&                object_info_table,
                      const graphics::Dx12GpuVaMap&             gpu_va_map)
{
    if ((wrapper != nullptr) && (wrapper->root_signature_ptr != nullptr))
    {
        (*wrapper->root_signature_ptr) =
            object_mapping::MapObject<ID3D12RootSignature>(wrapper->root_signature, object_info_table);
    }
}

void MapStructObjects(Decoded_D3D12_STATE_OBJECT_DESC* wrapper,
                      const Dx12ObjectInfoTable&       object_info_table,
                      const graphics::Dx12GpuVaMap&    gpu_va_map)
{
    if (wrapper != nullptr)
    {
        auto length   = wrapper->subobjects->GetLength();
        auto wrappers = wrapper->subobjects->GetMetaStructPointer();

        for (size_t i = 0; i < length; ++i)
        {
            MapStructObjects(
                &wrappers[i], wrapper->subobjects, wrapper->subobject_stride, object_info_table, gpu_va_map);
        }
    }
}

void MapStructObjects(Decoded_D3D12_STATE_SUBOBJECT*                       wrapper,
                      StructPointerDecoder<Decoded_D3D12_STATE_SUBOBJECT>* subobjects,
                      size_t                                               subobject_stride,
                      const Dx12ObjectInfoTable&                           object_info_table,
                      const graphics::Dx12GpuVaMap&                        gpu_va_map)
{
    if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
    {
        auto value = wrapper->decoded_value;

        switch (value->Type)
        {
            case D3D12_STATE_SUBOBJECT_TYPE_GLOBAL_ROOT_SIGNATURE:
                MapStructObjects(wrapper->global_root_signature->GetMetaStructPointer(), object_info_table, gpu_va_map);
                break;
            case D3D12_STATE_SUBOBJECT_TYPE_LOCAL_ROOT_SIGNATURE:
                MapStructObjects(wrapper->local_root_signature->GetMetaStructPointer(), object_info_table, gpu_va_map);
                break;
            case D3D12_STATE_SUBOBJECT_TYPE_EXISTING_COLLECTION:
                MapStructObjects(
                    wrapper->existing_collection_desc->GetMetaStructPointer(), object_info_table, gpu_va_map);
                break;
            case D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION:
                MapStructObjects(wrapper->subobject_to_exports_association->GetMetaStructPointer(),
                                 subobjects,
                                 subobject_stride,
                                 object_info_table,
                                 gpu_va_map);
                break;
            default:
                break;
        }
    }
}

void MapStructObjects(Decoded_D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION*      wrapper,
                      StructPointerDecoder<Decoded_D3D12_STATE_SUBOBJECT>* subobjects,
                      size_t                                               subobject_stride,
                      const Dx12ObjectInfoTable&                           object_info_table,
                      const graphics::Dx12GpuVaMap&                        gpu_va_map)
{
    if (wrapper != nullptr)
    {
        assert(wrapper->pSubobjectToAssociate->HasAddress() && (subobjects != nullptr) && subobjects->HasAddress());

        // This may be a pointer to an existing subobject structure.
        auto subobject_address = wrapper->pSubobjectToAssociate->GetAddress();
        auto subobject_array   = subobjects->GetPointer();
        auto base_address      = subobjects->GetAddress();
        auto num_subobjects    = subobjects->GetLength();

        for (UINT i = 0; i < num_subobjects; ++i)
        {
            if (subobject_address == (base_address + (subobject_stride * i)))
            {
                // Point to the existing struct value.
                auto value                   = wrapper->decoded_value;
                value->pSubobjectToAssociate = &subobject_array[i];
                return;
            }
        }

        // The subobject was not found in the list of existing subobjects, so fall back on standard object mapping.
        MapStructObjects(wrapper->pSubobjectToAssociate->GetMetaStructPointer(),
                         subobjects,
                         subobject_stride,
                         object_info_table,
                         gpu_va_map);
    }
}

void MapStructObjects(Decoded_D3D12_SHADER_RESOURCE_VIEW_DESC* wrapper,
                      const Dx12ObjectInfoTable&               object_info_table,
                      const graphics::Dx12GpuVaMap&            gpu_va_map)
{
    if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
    {
        auto value = wrapper->decoded_value;

        switch (value->ViewDimension)
        {
            case D3D12_SRV_DIMENSION_RAYTRACING_ACCELERATION_STRUCTURE:
                MapStructObjects(wrapper->RaytracingAccelerationStructure, object_info_table, gpu_va_map);
                break;
            default:
                break;
        }
    }
}

void MapStructObjects(Decoded_D3D12_BARRIER_GROUP*  wrapper,
                      const Dx12ObjectInfoTable&    object_info_table,
                      const graphics::Dx12GpuVaMap& gpu_va_map)
{
    if (wrapper != nullptr)
    {
        auto length   = wrapper->texture_barriers->GetLength();
        auto wrappers = wrapper->texture_barriers->GetMetaStructPointer();

        for (size_t i = 0; i < length; ++i)
        {
            MapStructObjects(&wrappers[i], object_info_table, gpu_va_map);
        }
    }
}

GFXRECON_END_NAMESPACE(encode)
GFXRECON_END_NAMESPACE(gfxrecon)