Skip to content

Commit 346419f

Browse files
committed
Change compile flags from uint32_t to string key/value pairs
* For D3D this is overkill as we just stuff the uint32_t flags into a string. However for SPIR-V this will let us store the parameters from an OpModuleProcessed.
1 parent a25de03 commit 346419f

28 files changed

+161
-81
lines changed

qrenderdoc/Windows/PipelineState/PipelineStateViewer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ void PipelineStateViewer::EditShader(ShaderStage shaderType, ResourceId id,
826826
viewer](IReplayController *r) {
827827
rdctype::str errs;
828828

829-
uint flags = shaderDetails->DebugInfo.compileFlags;
829+
const ShaderCompileFlags &flags = shaderDetails->DebugInfo.compileFlags;
830830

831831
ResourceId from = id;
832832
ResourceId to;

qrenderdoc/Windows/TextureViewer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,8 +3600,8 @@ void TextureViewer::reloadCustomShaders(const QString &filter)
36003600
rdctype::str errors;
36013601

36023602
ResourceId id;
3603-
std::tie(id, errors) =
3604-
r->BuildCustomShader("main", source.toUtf8().data(), 0, ShaderStage::Pixel);
3603+
std::tie(id, errors) = r->BuildCustomShader("main", source.toUtf8().data(),
3604+
ShaderCompileFlags(), ShaderStage::Pixel);
36053605

36063606
if(m_CustomShaderEditor.contains(key))
36073607
{

renderdoc/api/replay/basic_types.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ struct str : public rdctype::array<char>
269269

270270
operator std::string() const { return std::string(elems, elems + count); }
271271
const char *c_str() const { return elems ? elems : ""; }
272+
bool operator==(const char *const o) const
273+
{
274+
if(!elems)
275+
return o == NULL;
276+
return !strcmp(elems, o);
277+
}
278+
bool operator==(const std::string &o) const { return o == elems; }
279+
bool operator==(const str &o) const { return *this == (const char *const)o.elems; }
280+
bool operator!=(const char *const o) const { return !(*this == o); }
281+
bool operator!=(const std::string &o) const { return !(*this == o); }
282+
bool operator!=(const str &o) const { return !(*this == o); }
272283
};
273284

274285
inline str &str::operator=(const std::string &in)

renderdoc/api/replay/renderdoc_replay.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,9 @@ See :data:`TextureDisplay.CustomShader`.
580580
:meth:`ResourceId.Null` otherwise, and a ``str`` with any warnings/errors from compilation.
581581
:rtype: ``tuple`` of :class:`ResourceId` and ``str``.
582582
)");
583-
virtual rdctype::pair<ResourceId, rdctype::str> BuildCustomShader(const char *entry,
584-
const char *source,
585-
const uint32_t compileFlags,
586-
ShaderStage type) = 0;
583+
virtual rdctype::pair<ResourceId, rdctype::str> BuildCustomShader(
584+
const char *entry, const char *source, const ShaderCompileFlags &compileFlags,
585+
ShaderStage type) = 0;
587586

588587
DOCUMENT(R"(Free a previously created custom shader.
589588
@@ -599,15 +598,15 @@ The language used is native to the API's renderer - HLSL for D3D based renderers
599598
600599
:param str entry: The entry point to use when compiling.
601600
:param str source: The source file.
602-
:param int compileFlags: API-specific compilation flags.
601+
:param ShaderCompileFlags compileFlags: API-specific compilation flags.
603602
:param ShaderStage type: The stage that this shader will be executed at.
604603
:return: A ``tuple`` with the id of the new shader if compilation was successful,
605604
:meth:`ResourceId.Null` otherwise, and a ``str`` with any warnings/errors from compilation.
606605
:rtype: ``tuple`` of :class:`ResourceId` and ``str``.
607606
)");
608607
virtual rdctype::pair<ResourceId, rdctype::str> BuildTargetShader(const char *entry,
609608
const char *source,
610-
const uint32_t compileFlags,
609+
const ShaderCompileFlags &flags,
611610
ShaderStage type) = 0;
612611

613612
DOCUMENT(R"(Replace one resource with another for subsequent replay and analysis work.

renderdoc/api/replay/shader_types.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,16 +441,26 @@ able to be read from and written to arbitrarily.
441441

442442
DECLARE_REFLECTION_STRUCT(ShaderResource);
443443

444+
DOCUMENT("Contains the information about the compilation environment of a shader");
445+
struct ShaderCompileFlags
446+
{
447+
DOCUMENT(R"(A list of tuples, where each tuple is a pair of flagName, flagValue.
448+
449+
Each entry is an API or compiler specific flag used to compile this shader originally.
450+
)");
451+
rdctype::array<rdctype::pair<rdctype::str, rdctype::str> > flags;
452+
};
453+
444454
DOCUMENT(R"(Contains the information about a shader contained within API-specific debugging
445455
information attached to the shader.
446456

447457
Primarily this means the embedded original source files.
448458
)");
449459
struct ShaderDebugChunk
450460
{
451-
ShaderDebugChunk() : compileFlags(0) {}
452-
DOCUMENT("An API or compiler specific set of flags used to compile this shader originally.");
453-
uint32_t compileFlags;
461+
ShaderDebugChunk() {}
462+
DOCUMENT("A :class:`ShaderCompileFlags` containing the flags used to compile this shader.");
463+
ShaderCompileFlags compileFlags;
454464

455465
DOCUMENT(R"(A list of tuples, where each tuple is a pair of filename, source code.
456466

renderdoc/core/image_viewer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ class ImageViewer : public IReplayDriver
124124
{
125125
return m_Proxy->PickVertex(eventID, cfg, x, y);
126126
}
127-
void BuildCustomShader(string source, string entry, const uint32_t compileFlags, ShaderStage type,
128-
ResourceId *id, string *errors)
127+
void BuildCustomShader(string source, string entry, const ShaderCompileFlags &compileFlags,
128+
ShaderStage type, ResourceId *id, string *errors)
129129
{
130130
m_Proxy->BuildCustomShader(source, entry, compileFlags, type, id, errors);
131131
}
@@ -231,8 +231,8 @@ class ImageViewer : public IReplayDriver
231231
RDCEraseEl(ret);
232232
return ret;
233233
}
234-
void BuildTargetShader(string source, string entry, const uint32_t compileFlags, ShaderStage type,
235-
ResourceId *id, string *errors)
234+
void BuildTargetShader(string source, string entry, const ShaderCompileFlags &compileFlags,
235+
ShaderStage type, ResourceId *id, string *errors)
236236
{
237237
}
238238
void ReplaceResource(ResourceId from, ResourceId to) {}

renderdoc/core/replay_proxy.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,30 @@ void Serialiser::Serialise(const char *name, ShaderResource &el)
207207
SIZE_CHECK(80);
208208
}
209209

210+
template <>
211+
void Serialiser::Serialise(const char *name, ShaderCompileFlags &el)
212+
{
213+
Serialise("", el.flags);
214+
215+
SIZE_CHECK(16);
216+
}
217+
218+
template <>
219+
void Serialiser::Serialise(const char *name, ShaderDebugChunk &el)
220+
{
221+
Serialise("", el.compileFlags);
222+
Serialise("", el.files);
223+
224+
SIZE_CHECK(32);
225+
}
226+
210227
template <>
211228
void Serialiser::Serialise(const char *name, ShaderReflection &el)
212229
{
213230
Serialise("", el.ID);
214231
Serialise("", el.EntryPoint);
215232

216-
Serialise("", el.DebugInfo.compileFlags);
217-
Serialise("", el.DebugInfo.files);
233+
Serialise("", el.DebugInfo);
218234

219235
SerialisePODArray<3>("", el.DispatchThreadsDimension);
220236

@@ -230,7 +246,7 @@ void Serialiser::Serialise(const char *name, ShaderReflection &el)
230246

231247
Serialise("", el.Interfaces);
232248

233-
SIZE_CHECK(176);
249+
SIZE_CHECK(184);
234250
}
235251

236252
template <>
@@ -2247,7 +2263,7 @@ bool ReplayProxy::Tick(int type, Serialiser *incomingPacket)
22472263
}
22482264
case eReplayProxy_GetPostVS: GetPostVSBuffers(0, 0, MeshDataStage::Unknown); break;
22492265
case eReplayProxy_BuildTargetShader:
2250-
BuildTargetShader("", "", 0, ShaderStage::Vertex, NULL, NULL);
2266+
BuildTargetShader("", "", ShaderCompileFlags(), ShaderStage::Vertex, NULL, NULL);
22512267
break;
22522268
case eReplayProxy_ReplaceResource: ReplaceResource(ResourceId(), ResourceId()); break;
22532269
case eReplayProxy_RemoveReplacement: RemoveReplacement(ResourceId()); break;
@@ -3072,10 +3088,11 @@ Callstack::AddressDetails ReplayProxy::GetAddr(uint64_t addr)
30723088
return ret;
30733089
}
30743090

3075-
void ReplayProxy::BuildTargetShader(string source, string entry, const uint32_t compileFlags,
3076-
ShaderStage type, ResourceId *id, string *errors)
3091+
void ReplayProxy::BuildTargetShader(string source, string entry,
3092+
const ShaderCompileFlags &compileFlags, ShaderStage type,
3093+
ResourceId *id, string *errors)
30773094
{
3078-
uint32_t flags = compileFlags;
3095+
ShaderCompileFlags flags = compileFlags;
30793096
m_ToReplaySerialiser->Serialise("", source);
30803097
m_ToReplaySerialiser->Serialise("", entry);
30813098
m_ToReplaySerialiser->Serialise("", flags);

renderdoc/core/replay_proxy.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ class ReplayProxy : public IReplayDriver, Callstack::StackResolver
347347
return ~0U;
348348
}
349349

350-
void BuildCustomShader(string source, string entry, const uint32_t compileFlags, ShaderStage type,
351-
ResourceId *id, string *errors)
350+
void BuildCustomShader(string source, string entry, const ShaderCompileFlags &compileFlags,
351+
ShaderStage type, ResourceId *id, string *errors)
352352
{
353353
if(m_Proxy)
354354
{
@@ -457,8 +457,8 @@ class ReplayProxy : public IReplayDriver, Callstack::StackResolver
457457
ShaderDebugTrace DebugThread(uint32_t eventID, const uint32_t groupid[3],
458458
const uint32_t threadid[3]);
459459

460-
void BuildTargetShader(string source, string entry, const uint32_t compileFlags, ShaderStage type,
461-
ResourceId *id, string *errors);
460+
void BuildTargetShader(string source, string entry, const ShaderCompileFlags &compileFlags,
461+
ShaderStage type, ResourceId *id, string *errors);
462462
void ReplaceResource(ResourceId from, ResourceId to);
463463
void RemoveReplacement(ResourceId id);
464464

renderdoc/driver/d3d11/d3d11_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ ShaderReflection *MakeShaderReflection(DXBC::DXBCFile *dxbc)
808808

809809
if(dxbc->m_DebugInfo)
810810
{
811-
ret->DebugInfo.compileFlags = dxbc->m_DebugInfo->GetShaderCompileFlags();
811+
ret->DebugInfo.compileFlags = DXBC::EncodeFlags(dxbc->m_DebugInfo);
812812

813813
create_array_uninit(ret->DebugInfo.files, dxbc->m_DebugInfo->Files.size());
814814
for(size_t i = 0; i < dxbc->m_DebugInfo->Files.size(); i++)

renderdoc/driver/d3d11/d3d11_debug.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,12 @@ ID3D11ComputeShader *D3D11DebugManager::MakeCShader(const char *source, const ch
442442
return cs;
443443
}
444444

445-
void D3D11DebugManager::BuildShader(string source, string entry, const uint32_t compileFlags,
446-
ShaderStage type, ResourceId *id, string *errors)
445+
void D3D11DebugManager::BuildShader(string source, string entry,
446+
const ShaderCompileFlags &compileFlags, ShaderStage type,
447+
ResourceId *id, string *errors)
447448
{
449+
uint32_t flags = DXBC::DecodeFlags(compileFlags);
450+
448451
if(id == NULL || errors == NULL)
449452
{
450453
if(id)
@@ -469,7 +472,7 @@ void D3D11DebugManager::BuildShader(string source, string entry, const uint32_t
469472
}
470473

471474
ID3DBlob *blob = NULL;
472-
*errors = GetShaderBlob(source.c_str(), entry.c_str(), compileFlags, profile, &blob);
475+
*errors = GetShaderBlob(source.c_str(), entry.c_str(), flags, profile, &blob);
473476

474477
if(blob == NULL)
475478
{

renderdoc/driver/d3d11/d3d11_debug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ class D3D11DebugManager
176176
ID3D11PixelShader *MakePShader(const char *source, const char *entry, const char *profile);
177177
ID3D11ComputeShader *MakeCShader(const char *source, const char *entry, const char *profile);
178178

179-
void BuildShader(string source, string entry, const uint32_t compileFlags, ShaderStage type,
180-
ResourceId *id, string *errors);
179+
void BuildShader(string source, string entry, const ShaderCompileFlags &compileFlags,
180+
ShaderStage type, ResourceId *id, string *errors);
181181

182182
ID3D11Buffer *MakeCBuffer(UINT size);
183183

renderdoc/driver/d3d11/d3d11_replay.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,15 +1524,19 @@ void D3D11Replay::RenderMesh(uint32_t eventID, const vector<MeshFormat> &seconda
15241524
return m_pDevice->GetDebugManager()->RenderMesh(eventID, secondaryDraws, cfg);
15251525
}
15261526

1527-
void D3D11Replay::BuildTargetShader(string source, string entry, const uint32_t compileFlags,
1528-
ShaderStage type, ResourceId *id, string *errors)
1527+
void D3D11Replay::BuildTargetShader(string source, string entry,
1528+
const ShaderCompileFlags &compileFlags, ShaderStage type,
1529+
ResourceId *id, string *errors)
15291530
{
1530-
m_pDevice->GetDebugManager()->BuildShader(source, entry, D3DCOMPILE_DEBUG | compileFlags, type,
1531-
id, errors);
1531+
ShaderCompileFlags debugCompileFlags =
1532+
DXBC::EncodeFlags(DXBC::DecodeFlags(compileFlags) | D3DCOMPILE_DEBUG);
1533+
1534+
m_pDevice->GetDebugManager()->BuildShader(source, entry, debugCompileFlags, type, id, errors);
15321535
}
15331536

1534-
void D3D11Replay::BuildCustomShader(string source, string entry, const uint32_t compileFlags,
1535-
ShaderStage type, ResourceId *id, string *errors)
1537+
void D3D11Replay::BuildCustomShader(string source, string entry,
1538+
const ShaderCompileFlags &compileFlags, ShaderStage type,
1539+
ResourceId *id, string *errors)
15361540
{
15371541
m_pDevice->GetDebugManager()->BuildShader(source, entry, compileFlags, type, id, errors);
15381542
}

renderdoc/driver/d3d11/d3d11_replay.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ class D3D11Replay : public IReplayDriver
112112
byte *GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip,
113113
const GetTextureDataParams &params, size_t &dataSize);
114114

115-
void BuildTargetShader(string source, string entry, const uint32_t compileFlags, ShaderStage type,
116-
ResourceId *id, string *errors);
115+
void BuildTargetShader(string source, string entry, const ShaderCompileFlags &compileFlags,
116+
ShaderStage type, ResourceId *id, string *errors);
117117
void ReplaceResource(ResourceId from, ResourceId to);
118118
void RemoveReplacement(ResourceId id);
119119

@@ -157,8 +157,8 @@ class D3D11Replay : public IReplayDriver
157157
ResourceId RenderOverlay(ResourceId texid, CompType typeHint, DebugOverlay overlay,
158158
uint32_t eventID, const vector<uint32_t> &passEvents);
159159

160-
void BuildCustomShader(string source, string entry, const uint32_t compileFlags, ShaderStage type,
161-
ResourceId *id, string *errors);
160+
void BuildCustomShader(string source, string entry, const ShaderCompileFlags &compileFlags,
161+
ShaderStage type, ResourceId *id, string *errors);
162162
ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, uint32_t arrayIdx,
163163
uint32_t sampleIdx, CompType typeHint);
164164

renderdoc/driver/d3d12/d3d12_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ void MakeShaderReflection(DXBC::DXBCFile *dxbc, ShaderReflection *refl,
451451

452452
if(dxbc->m_DebugInfo)
453453
{
454-
refl->DebugInfo.compileFlags = dxbc->m_DebugInfo->GetShaderCompileFlags();
454+
refl->DebugInfo.compileFlags = DXBC::EncodeFlags(dxbc->m_DebugInfo);
455455

456456
create_array_uninit(refl->DebugInfo.files, dxbc->m_DebugInfo->Files.size());
457457
for(size_t i = 0; i < dxbc->m_DebugInfo->Files.size(); i++)

renderdoc/driver/d3d12/d3d12_debug.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,9 +3166,12 @@ void D3D12DebugManager::FillCBufferVariables(const vector<DXBC::CBufferVariable>
31663166
outvars.push_back(v[i]);
31673167
}
31683168

3169-
void D3D12DebugManager::BuildShader(string source, string entry, const uint32_t compileFlags,
3170-
ShaderStage type, ResourceId *id, string *errors)
3169+
void D3D12DebugManager::BuildShader(string source, string entry,
3170+
const ShaderCompileFlags &compileFlags, ShaderStage type,
3171+
ResourceId *id, string *errors)
31713172
{
3173+
uint32_t flags = DXBC::DecodeFlags(compileFlags);
3174+
31723175
if(id == NULL || errors == NULL)
31733176
{
31743177
if(id)
@@ -3193,7 +3196,7 @@ void D3D12DebugManager::BuildShader(string source, string entry, const uint32_t
31933196
}
31943197

31953198
ID3DBlob *blob = NULL;
3196-
*errors = GetShaderBlob(source.c_str(), entry.c_str(), compileFlags, profile, &blob);
3199+
*errors = GetShaderBlob(source.c_str(), entry.c_str(), flags, profile, &blob);
31973200

31983201
if(blob == NULL)
31993202
{

renderdoc/driver/d3d12/d3d12_debug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ class D3D12DebugManager
107107
byte *GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip,
108108
const GetTextureDataParams &params, size_t &dataSize);
109109

110-
void BuildShader(string source, string entry, const uint32_t compileFlags, ShaderStage type,
111-
ResourceId *id, string *errors);
110+
void BuildShader(string source, string entry, const ShaderCompileFlags &compileFlags,
111+
ShaderStage type, ResourceId *id, string *errors);
112112

113113
D3D12_CPU_DESCRIPTOR_HANDLE AllocRTV();
114114
void FreeRTV(D3D12_CPU_DESCRIPTOR_HANDLE handle);

renderdoc/driver/d3d12/d3d12_replay.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,11 +1574,14 @@ vector<DebugMessage> D3D12Replay::GetDebugMessages()
15741574
return m_pDevice->GetDebugMessages();
15751575
}
15761576

1577-
void D3D12Replay::BuildTargetShader(string source, string entry, const uint32_t compileFlags,
1578-
ShaderStage type, ResourceId *id, string *errors)
1577+
void D3D12Replay::BuildTargetShader(string source, string entry,
1578+
const ShaderCompileFlags &compileFlags, ShaderStage type,
1579+
ResourceId *id, string *errors)
15791580
{
1580-
m_pDevice->GetDebugManager()->BuildShader(source, entry, D3DCOMPILE_DEBUG | compileFlags, type,
1581-
id, errors);
1581+
ShaderCompileFlags debugCompileFlags =
1582+
DXBC::EncodeFlags(DXBC::DecodeFlags(compileFlags) | D3DCOMPILE_DEBUG);
1583+
1584+
m_pDevice->GetDebugManager()->BuildShader(source, entry, debugCompileFlags, type, id, errors);
15821585
}
15831586

15841587
void D3D12Replay::ReplaceResource(ResourceId from, ResourceId to)
@@ -1681,8 +1684,9 @@ byte *D3D12Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mi
16811684
return m_pDevice->GetDebugManager()->GetTextureData(tex, arrayIdx, mip, params, dataSize);
16821685
}
16831686

1684-
void D3D12Replay::BuildCustomShader(string source, string entry, const uint32_t compileFlags,
1685-
ShaderStage type, ResourceId *id, string *errors)
1687+
void D3D12Replay::BuildCustomShader(string source, string entry,
1688+
const ShaderCompileFlags &compileFlags, ShaderStage type,
1689+
ResourceId *id, string *errors)
16861690
{
16871691
m_pDevice->GetDebugManager()->BuildShader(source, entry, compileFlags, type, id, errors);
16881692
}

renderdoc/driver/d3d12/d3d12_replay.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class D3D12Replay : public IReplayDriver
110110
byte *GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip,
111111
const GetTextureDataParams &params, size_t &dataSize);
112112

113-
void BuildTargetShader(string source, string entry, const uint32_t compileFlags, ShaderStage type,
114-
ResourceId *id, string *errors);
113+
void BuildTargetShader(string source, string entry, const ShaderCompileFlags &compileFlags,
114+
ShaderStage type, ResourceId *id, string *errors);
115115
void ReplaceResource(ResourceId from, ResourceId to);
116116
void RemoveReplacement(ResourceId id);
117117

@@ -155,8 +155,8 @@ class D3D12Replay : public IReplayDriver
155155
ResourceId RenderOverlay(ResourceId texid, CompType typeHint, DebugOverlay overlay,
156156
uint32_t eventID, const vector<uint32_t> &passEvents);
157157

158-
void BuildCustomShader(string source, string entry, const uint32_t compileFlags, ShaderStage type,
159-
ResourceId *id, string *errors);
158+
void BuildCustomShader(string source, string entry, const ShaderCompileFlags &compileFlags,
159+
ShaderStage type, ResourceId *id, string *errors);
160160
ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, uint32_t arrayIdx,
161161
uint32_t sampleIdx, CompType typeHint);
162162

0 commit comments

Comments
 (0)