File: PersistantConfig.cpp

package info (click to toggle)
renderdoc 1.24%2Bdfsg-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 105,156 kB
  • sloc: cpp: 759,405; ansic: 309,460; python: 26,606; xml: 22,599; java: 11,365; cs: 7,181; makefile: 6,707; yacc: 5,682; ruby: 4,648; perl: 3,461; sh: 2,354; php: 2,119; lisp: 1,835; javascript: 1,524; tcl: 1,068; ml: 747
file content (808 lines) | stat: -rw-r--r-- 22,855 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/******************************************************************************
 * The MIT License (MIT)
 *
 * Copyright (c) 2019-2022 Baldur Karlsson
 *
 * 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 <QApplication>
#include <QDebug>
#include <QDir>
#include <QMutexLocker>
#include <QStandardPaths>
#include "Code/QRDUtils.h"
#include "Styles/StyleData.h"
#include "QRDInterface.h"

template <>
rdcstr DoStringise(const TimeUnit &el)
{
  BEGIN_ENUM_STRINGISE(TimeUnit)
  {
    STRINGISE_ENUM_CLASS(Seconds);
    STRINGISE_ENUM_CLASS(Milliseconds);
    STRINGISE_ENUM_CLASS(Microseconds);
    STRINGISE_ENUM_CLASS(Nanoseconds);
  }
  END_ENUM_STRINGISE();
}

#define JSON_ID "rdocConfigData"
#define JSON_VER 1

// helper templates to convert some more complex types to/from appropriate variants
template <typename variantType, typename origType>
variantType convertToVariant(const origType &val)
{
  return variantType(val);
}

template <typename variantType, typename innerType>
variantType convertToVariant(const rdcarray<innerType> &val)
{
  variantType ret;
  ret.reserve(val.count());
  for(const innerType &s : val)
    ret.push_back(s);
  return ret;
}

template <>
QVariantMap convertToVariant(const rdcstrpairs &val)
{
  QVariantMap ret;
  for(const rdcstrpair &k : val)
  {
    ret[k.first] = k.second;
  }
  return ret;
}

template <typename origType, typename variantType>
origType convertFromVariant(const variantType &val)
{
  return origType(val);
}

template <>
rdcstr convertFromVariant(const QVariant &val)
{
  return val.toString();
}

template <typename listType>
listType convertFromVariant(const QVariantList &val)
{
  listType ret;
  ret.reserve(val.count());
  for(const QVariant &s : val)
    ret.push_back(convertFromVariant<typename listType::value_type>(s));
  return ret;
}

template <>
rdcstrpairs convertFromVariant(const QVariantMap &val)
{
  rdcstrpairs ret;
  for(const QString &k : val.keys())
  {
    ret.push_back({k, val[k].toString()});
  }
  return ret;
}

bool PersistantConfig::Deserialize(const rdcstr &filename)
{
  QFile f(filename);

  m_Filename = filename;

  // silently allow missing configs
  if(!f.exists())
    return true;

  if(f.open(QIODevice::ReadOnly | QIODevice::Text))
  {
    QVariantMap values;

    bool success = LoadFromJSON(values, f, JSON_ID, JSON_VER);

    if(!success)
      return false;

    applyValues(values);

    return true;
  }

  qInfo() << "Couldn't load layout from " << QString(filename) << " " << f.errorString();

  return false;
}

bool PersistantConfig::Serialize(const rdcstr &filename)
{
  if(!filename.isEmpty())
    m_Filename = filename;

  QVariantMap values = storeValues();

  QFile f(m_Filename);
  if(f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
    return SaveToJSON(values, f, JSON_ID, JSON_VER);

  qWarning() << "Couldn't write to " << QString(m_Filename) << " " << f.errorString();

  return false;
}

struct LegacyData
{
  QString _Android_SDKPath;
  QString _Android_JDKPath;
  uint32_t _Android_MaxConnectTimeout = 30;
  bool _ExternalTool_RGPIntegration = false;
  bool _ShaderViewer_FriendlyNaming = true;
  QVariantMap _ConfigSettings;
};

static rdcarray<rdcpair<rdcstr, CustomPersistentStorage *>> &GetCustomStorage()
{
  static rdcarray<rdcpair<rdcstr, CustomPersistentStorage *>> ret;
  return ret;
}

CustomPersistentStorage::CustomPersistentStorage(rdcstr name)
{
  if(!name.empty())
    GetCustomStorage().push_back({name, this});
}

QVariantMap PersistantConfig::storeValues() const
{
  QVariantMap ret;

#undef CONFIG_SETTING_VAL
#undef CONFIG_SETTING

#define CONFIG_SETTING_VAL(access, variantType, type, name, defaultValue) \
  ret[lit(#name)] = convertToVariant<variantType>(name);
#define CONFIG_SETTING(access, variantType, type, name) \
  ret[lit(#name)] = convertToVariant<variantType>(name);

  CONFIG_SETTINGS()

  // store any legacy values even though we don't need them

  ret[lit("Android_SDKPath")] = m_Legacy->_Android_SDKPath;
  ret[lit("Android_JDKPath")] = m_Legacy->_Android_JDKPath;
  ret[lit("Android_MaxConnectTimeout")] = m_Legacy->_Android_MaxConnectTimeout;
  ret[lit("ExternalTool_RGPIntegration")] = m_Legacy->_ExternalTool_RGPIntegration;
  ret[lit("ShaderViewer_FriendlyNaming")] = m_Legacy->_ShaderViewer_FriendlyNaming;
  ret[lit("ConfigSettings")] = m_Legacy->_ConfigSettings;

  for(const rdcpair<rdcstr, CustomPersistentStorage *> &ps : GetCustomStorage())
  {
    ps.second->save(ret[QString(ps.first)]);
  }

  return ret;
}

void PersistantConfig::applyValues(const QVariantMap &values)
{
#undef CONFIG_SETTING_VAL
#undef CONFIG_SETTING

#define CONFIG_SETTING_VAL(access, variantType, type, name, defaultValue) \
  if(values.contains(lit(#name)))                                         \
    name = convertFromVariant<type>(values[lit(#name)].value<variantType>());
#define CONFIG_SETTING(access, variantType, type, name) \
  if(values.contains(lit(#name)))                       \
    name = convertFromVariant<type>(values[lit(#name)].value<variantType>());

  CONFIG_SETTINGS()

// backwards compatibility code, to apply old values.
#define RENAMED_SETTING(variantType, oldName, newName) \
  if(values.contains(lit(#oldName)))                   \
    newName = convertFromVariant<decltype(newName)>(values[lit(#oldName)].value<variantType>());

  RENAMED_SETTING(QString, LastLogPath, LastCaptureFilePath);
  RENAMED_SETTING(QVariantList, RecentLogFiles, RecentCaptureFiles);
  RENAMED_SETTING(QDateTime, DegradedLog_LastUpdate, DegradedCapture_LastUpdate);
  RENAMED_SETTING(QVariantList, SPIRVDisassemblers, ShaderProcessors);

  // apply reasonable bounds to font scale to avoid invalid values
  // 25% - 400%
  Font_GlobalScale = qBound(0.25f, Font_GlobalScale, 4.0f);

  // port old values that were saved here but are now saved in core.
  // We only want to do this once, but we want to leave these values in the config to allow for
  // people running old versions after running a new version - we don't want to remove all of their
  // settings yet.
  // So what we do is store an extra setting indicating that it's been ported - if that setting is
  // present we just store/save them blindly. This does mean they can change but we won't re-port
  // them.
  // After the new config ships in a stable release we can remove this as we don't generally support
  // forwards compatibility, only backwards compatibility, so it will be OK to drop the config
  // settings.
  bool processed = false;
  if(values.contains(lit("ConfigSettings")) &&
     values[lit("ConfigSettings")].toMap().contains(lit("modern.config.ported")))
    processed = true;

  bool saveConfig = false;

#define CORE_SETTING(variantType, oldName, newName, data)              \
  if(values.contains(lit(#oldName)))                                   \
  {                                                                    \
    m_Legacy->_##oldName = values[lit(#oldName)].value<variantType>(); \
    if(!processed)                                                     \
    {                                                                  \
      SDObject *setting = RENDERDOC_SetConfigSetting(newName);         \
      if(setting)                                                      \
        setting->data = m_Legacy->_##oldName;                          \
      saveConfig = true;                                               \
    }                                                                  \
  }

  CORE_SETTING(QString, Android_SDKPath, "Android.SDKDirPath", data.str);
  CORE_SETTING(QString, Android_JDKPath, "Android.JDKDirPath", data.str);
  CORE_SETTING(uint32_t, Android_MaxConnectTimeout, "Android.MaxConnectTimeout", data.basic.u);
  CORE_SETTING(bool, ExternalTool_RGPIntegration, "AMD.RGP.Enable", data.basic.b);
  CORE_SETTING(bool, ShaderViewer_FriendlyNaming, "DXBC.Disassembly.FriendlyNaming", data.basic.b);

  if(values.contains(lit("ConfigSettings")))
  {
    QVariantMap &settings = m_Legacy->_ConfigSettings;
    settings = values[lit("ConfigSettings")].toMap();

    if(!processed)
    {
      if(settings.contains(lit("shader.debug.searchPaths")))
      {
        QStringList searchPaths = settings[lit("shader.debug.searchPaths")].toString().split(
            QLatin1Char(';'), QString::SkipEmptyParts);

        SDObject *debug = RENDERDOC_SetConfigSetting("DXBC.Debug.SearchDirPaths");

        debug->DeleteChildren();
        debug->ReserveChildren(searchPaths.size());

        for(int i = 0; i < searchPaths.size(); i++)
          debug->AddAndOwnChild(makeSDString("$el"_lit, searchPaths[i]));
      }

      if(settings.contains(lit("d3d12ShaderDebugging")))
      {
        RENDERDOC_SetConfigSetting("D3D12_ShaderDebugging")->data.basic.b =
            settings[lit("d3d12ShaderDebugging")].toBool();
      }

      if(settings.contains(lit("vulkanShaderDebugging")))
      {
        RENDERDOC_SetConfigSetting("Vulkan_ShaderDebugging")->data.basic.b =
            settings[lit("vulkanShaderDebugging")].toBool();
      }

      saveConfig = true;
    }

    // mark the settings as ported so we don't do it again
    settings[lit("modern.config.ported")] = true;
  }

  if(saveConfig)
    RENDERDOC_SaveConfigSettings();

  for(const rdcpair<rdcstr, CustomPersistentStorage *> &ps : GetCustomStorage())
    ps.second->load(values[QString(ps.first)]);
}

static QMutex RemoteHostLock;

rdcarray<RemoteHost> PersistantConfig::GetRemoteHosts()
{
  QMutexLocker autolock(&RemoteHostLock);
  return RemoteHostList;
}

RemoteHost PersistantConfig::GetRemoteHost(const rdcstr &hostname)
{
  RemoteHost ret;

  {
    QMutexLocker autolock(&RemoteHostLock);
    for(size_t i = 0; i < RemoteHostList.size(); i++)
    {
      if(RemoteHostList[i].Hostname() == hostname)
      {
        ret = RemoteHostList[i];
        break;
      }
    }
  }

  return ret;
}

void PersistantConfig::AddRemoteHost(RemoteHost host)
{
  if(!host.IsValid())
    return;

  QMutexLocker autolock(&RemoteHostLock);

  // don't add duplicates
  for(size_t i = 0; i < RemoteHostList.size(); i++)
  {
    if(RemoteHostList[i] == host)
    {
      RemoteHostList[i] = host;
      return;
    }
  }

  RemoteHostList.push_back(host);
}

void PersistantConfig::RemoveRemoteHost(RemoteHost host)
{
  if(!host.IsValid())
    return;

  QMutexLocker autolock(&RemoteHostLock);

  for(size_t i = 0; i < RemoteHostList.size(); i++)
  {
    if(RemoteHostList[i] == host)
    {
      RemoteHostList.takeAt(i);
      break;
    }
  }
}

void PersistantConfig::UpdateEnumeratedProtocolDevices()
{
  rdcarray<RemoteHost> enumeratedDevices;

  rdcarray<rdcstr> protocols;
  RENDERDOC_GetSupportedDeviceProtocols(&protocols);

  for(const rdcstr &p : protocols)
  {
    IDeviceProtocolController *protocol = RENDERDOC_GetDeviceProtocolController(p);

    rdcarray<rdcstr> devices = protocol->GetDevices();

    for(const rdcstr &d : devices)
    {
      RemoteHost newhost(protocol->GetProtocolName() + "://" + d);
      enumeratedDevices.push_back(newhost);
    }
  }

  QMutexLocker autolock(&RemoteHostLock);

  QMap<rdcstr, RemoteHost> oldHosts;

  for(int i = RemoteHostList.count() - 1; i >= 0; i--)
  {
    if(RemoteHostList[i].Protocol())
    {
      RemoteHost host = RemoteHostList.takeAt(i);
      oldHosts[host.Hostname()] = host;
    }
  }

  for(RemoteHost host : enumeratedDevices)
  {
    // if we already had this host, use that one.
    if(oldHosts.contains(host.Hostname()))
      host = oldHosts.take(host.Hostname());

    host.SetFriendlyName(host.Protocol()->GetFriendlyName(host.Hostname()));
    // Just a command to display in the GUI and allow Launch() to be called.
    host.SetRunCommand("Automatically handled");
    RemoteHostList.push_back(host);
  }

  // delete any leftovers
  QMutableMapIterator<rdcstr, RemoteHost> i(oldHosts);
  while(i.hasNext())
  {
    i.next();
    i.value().SetShutdown();
  }
}

bool PersistantConfig::SetStyle()
{
  for(int i = 0; i < StyleData::numAvailable; i++)
  {
    if(UIStyle == rdcstr(StyleData::availStyles[i].styleID))
    {
      QStyle *style = StyleData::availStyles[i].creator();
      Formatter::setPalette(style->standardPalette());
      QApplication::setStyle(style);
      return true;
    }
  }

  if(UIStyle != "")
    qCritical() << "Unrecognised UI style" << QString(UIStyle);

  return false;
}

PersistantConfig::PersistantConfig()
{
  m_Legacy = new LegacyData;
}

PersistantConfig::~PersistantConfig()
{
  delete m_Legacy;
}

bool PersistantConfig::Load(const rdcstr &filename)
{
  bool ret = Deserialize(filename);

  RDDialog::DefaultBrowsePath = LastFileBrowsePath;

  // localhost should always be available as a remote host
  {
    QMutexLocker autolock(&RemoteHostLock);

    bool foundLocalhost = false;

    rdcarray<RemoteHost> hosts;
    hosts.swap(RemoteHostList);

    for(RemoteHost host : hosts)
    {
      // skip invalid hosts
      if(!host.IsValid())
        continue;

      // backwards compatibility - skip old adb hosts that were adb:
      if(host.Hostname().find("adb:") >= 0 && host.Protocol() == NULL)
        continue;

      RemoteHostList.push_back(host);

      if(host.IsLocalhost())
        foundLocalhost = true;
    }

    if(!foundLocalhost)
    {
      RemoteHost host;
      host.m_hostname = "localhost";
      RemoteHostList.insert(0, host);
    }
  }

  bool tools[arraydim<KnownShaderTool>()] = {};

  // see which known tools are registered
  for(const ShaderProcessingTool &dis : ShaderProcessors)
  {
    // if it's declared
    if(dis.tool != KnownShaderTool::Unknown)
      tools[(size_t)dis.tool] = true;
  }

  for(KnownShaderTool tool : values<KnownShaderTool>())
  {
    if(tool == KnownShaderTool::Unknown || tools[(size_t)tool])
      continue;

    rdcstr exe = ToolExecutable(tool);

    if(exe.isEmpty())
      continue;

    // try to find the tool in PATH
    QString path = QStandardPaths::findExecutable(exe);

    if(!path.isEmpty())
    {
      ShaderProcessingTool s;
      s.name = ToQStr(tool);
      // we store just the base name, so when we launch the process it will always find it in PATH,
      // rather than baking in the current PATH result.
      s.executable = exe;
      s.tool = tool;

      ShaderProcessors.push_back(s);

      continue;
    }

    // try to find it in our plugins folder
    QDir appDir(QApplication::applicationDirPath());

    QStringList searchPaths = {appDir.absoluteFilePath(lit("plugins/spirv/"))};

#if defined(Q_OS_WIN64)
    // windows local
    searchPaths << appDir.absoluteFilePath(lit("../../plugins-win64/spirv/"));
#elif defined(Q_OS_WIN32)
    // windows local
    searchPaths << appDir.absoluteFilePath(lit("../../plugins-win32/spirv/"));
#elif defined(Q_OS_LINUX)
    // linux installation
    searchPaths << appDir.absoluteFilePath(lit("../share/renderdoc/plugins/spirv/"));
    // linux local
    searchPaths << appDir.absoluteFilePath(lit("../../plugins-linux64/spirv/"));
#endif

    searchPaths << appDir.absoluteFilePath(lit("../../plugins/"));

    path = QStandardPaths::findExecutable(exe, searchPaths);

    if(!path.isEmpty())
    {
      ShaderProcessingTool s;
      s.name = ToQStr(tool);
      s.executable = path;
      s.tool = tool;

      ShaderProcessors.push_back(s);

      continue;
    }
  }

  // sanitisation pass, if a tool is declared as a known type ensure its inputs/outputs are correct.
  // This is mostly for backwards compatibility with configs from before the inputs/outputs were
  // added.
  for(ShaderProcessingTool &dis : ShaderProcessors)
  {
    if(dis.tool != KnownShaderTool::Unknown)
    {
      dis.name = ToQStr(dis.tool);
      dis.input = ToolInput(dis.tool);
      dis.output = ToolOutput(dis.tool);
    }
  }

  return ret;
}

bool PersistantConfig::Save()
{
  if(m_Filename.isEmpty())
    return true;

  LastFileBrowsePath = RDDialog::DefaultBrowsePath;

  // truncate the lists to a maximum of 9 items, allow more to exist in memory
  rdcarray<rdcstr> capFiles = RecentCaptureFiles;
  rdcarray<rdcstr> capSettings = RecentCaptureSettings;

  // the oldest items are first, so remove from there
  while(RecentCaptureFiles.count() >= 10)
    RecentCaptureFiles.erase(0);
  while(RecentCaptureSettings.count() >= 10)
    RecentCaptureSettings.erase(0);

  bool ret = Serialize(m_Filename);

  // restore lists
  RecentCaptureFiles = capFiles;
  RecentCaptureSettings = capSettings;

  return ret;
}

void PersistantConfig::Close()
{
  m_Filename = QString();
}

void PersistantConfig::SetupFormatting()
{
  Formatter::setParams(*this);
}

void RemoveRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file)
{
  recentList.removeOne(QDir::cleanPath(file));
}

void AddRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file)
{
  QDir dir(file);
  QString path = dir.canonicalPath();

  if(path.isEmpty())
  {
    qWarning() << "Got empty path from " << QString(file);
    return;
  }

  if(recentList.contains(path))
    recentList.removeOne(path);

  recentList.push_back(path);
}

ShaderProcessingTool::ShaderProcessingTool(const QVariant &var)
{
  QVariantMap map = var.toMap();
  if(map.contains(lit("tool")))
    tool = (KnownShaderTool)map[lit("tool")].toUInt();
  if(map.contains(lit("name")))
    name = map[lit("name")].toString();
  if(map.contains(lit("executable")))
    executable = map[lit("executable")].toString();
  if(map.contains(lit("args")))
  {
    QString a = map[lit("args")].toString();

    // backwards compatibility
    a.replace(lit("{spv_disasm}"), lit("{output_file}"));
    a.replace(lit("{spv_bin}"), lit("{input_file}"));

    args = a;
  }

  if(map.contains(lit("input")))
  {
    input = (ShaderEncoding)map[lit("input")].toUInt();
  }
  else
  {
    // backwards compatibility, it's a SPIR-V disassembler
    input = ShaderEncoding::SPIRV;
  }

  if(map.contains(lit("output")))
  {
    output = (ShaderEncoding)map[lit("output")].toUInt();
  }
  else
  {
    // backwards compatibility, we have to guess, assume GLSL as a sensible default
    output = ShaderEncoding::GLSL;
  }
}

rdcstr ShaderProcessingTool::DefaultArguments() const
{
  if(tool == KnownShaderTool::SPIRV_Cross)
    return "--vulkan-semantics --entry {entry_point} --stage {glsl_stage4}";
  else if(tool == KnownShaderTool::spirv_dis)
    return "--no-color";
  else if(tool == KnownShaderTool::glslangValidatorGLSL)
    return "-g -V -S {glsl_stage4}";
  else if(tool == KnownShaderTool::glslangValidatorHLSL)
    return "-D -g -V -S {glsl_stage4} -e {entry_point}";
  else if(tool == KnownShaderTool::spirv_as)
    return "";
  else if(tool == KnownShaderTool::dxcSPIRV)
    return "-T {hlsl_stage2}_6_0 -E {entry_point} -spirv";
  else if(tool == KnownShaderTool::dxcDXIL)
    return "-T {hlsl_stage2}_6_0 -E {entry_point}";
  else if(tool == KnownShaderTool::fxc)
    return "/T {hlsl_stage2}_5_0 /E {entry_point}";

  return args;
}

rdcstr ShaderProcessingTool::IOArguments() const
{
  if(tool == KnownShaderTool::SPIRV_Cross)
    return "--output {output_file} {input_file}";
  else if(tool == KnownShaderTool::spirv_dis)
    return "-o {output_file} {input_file}";
  else if(tool == KnownShaderTool::glslangValidatorGLSL)
    return "-o {output_file} {input_file}";
  else if(tool == KnownShaderTool::glslangValidatorHLSL)
    return "-o {output_file} {input_file}";
  else if(tool == KnownShaderTool::spirv_as)
    return "-o {output_file} {input_file}";
  else if(tool == KnownShaderTool::dxcSPIRV)
    return "-Fo {output_file} {input_file}";
  else if(tool == KnownShaderTool::dxcDXIL)
    return "-Fo {output_file} {input_file}";
  else if(tool == KnownShaderTool::fxc)
    return "/Fo {output_file} {input_file}";

  return rdcstr();
}

ShaderProcessingTool::operator QVariant() const
{
  QVariantMap map;

  map[lit("tool")] = (uint32_t)tool;
  map[lit("name")] = name;
  map[lit("executable")] = executable;
  map[lit("args")] = args;
  map[lit("input")] = (uint32_t)input;
  map[lit("output")] = (uint32_t)output;

  return map;
}

BugReport::BugReport(const QVariant &var)
{
  QVariantMap map = var.toMap();
  if(map.contains(lit("reportId")))
    reportId = map[lit("reportId")].toString();
  if(map.contains(lit("submitDate")))
    submitDate = map[lit("submitDate")].toDateTime();
  if(map.contains(lit("checkDate")))
    checkDate = map[lit("checkDate")].toDateTime();
  if(map.contains(lit("unreadUpdates")))
    unreadUpdates = map[lit("unreadUpdates")].toBool();
}

rdcstr BugReport::URL() const
{
  return lit(BUGREPORT_URL "/report/%1").arg(QString(reportId));
}

BugReport::operator QVariant() const
{
  QVariantMap map;

  map[lit("reportId")] = reportId;
  map[lit("submitDate")] = submitDate;
  map[lit("checkDate")] = checkDate;
  map[lit("unreadUpdates")] = unreadUpdates;

  return map;
}

ReplayOptions::ReplayOptions(const QVariant &var)
{
  QVariantMap map = var.toMap();

  if(map.contains(lit("apiValidation")))
    apiValidation = map[lit("apiValidation")].toBool();
  if(map.contains(lit("forceGPUVendor")))
    forceGPUVendor = (GPUVendor)map[lit("forceGPUVendor")].toUInt();
  if(map.contains(lit("forceGPUDeviceID")))
    forceGPUDeviceID = map[lit("forceGPUDeviceID")].toUInt();
  if(map.contains(lit("forceGPUDriverName")))
    forceGPUDriverName = map[lit("forceGPUDriverName")].toString();
  if(map.contains(lit("optimisation")))
    optimisation = (ReplayOptimisationLevel)map[lit("optimisation")].toUInt();
}

ReplayOptions::operator QVariant() const
{
  QVariantMap map;

  map[lit("apiValidation")] = apiValidation;
  map[lit("forceGPUVendor")] = (uint32_t)forceGPUVendor;
  map[lit("forceGPUDeviceID")] = forceGPUDeviceID;
  map[lit("forceGPUDriverName")] = forceGPUDriverName;
  map[lit("optimisation")] = (uint32_t)optimisation;

  return map;
}