Skip to content

Commit

Permalink
Vulkan shader view (debug): Add a simple textural representation (inc…
Browse files Browse the repository at this point in the history
…omplete) of pipelines
  • Loading branch information
hrydgard committed Nov 13, 2017
1 parent 5c7f7c1 commit 4788221
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 5 deletions.
126 changes: 121 additions & 5 deletions GPU/Vulkan/PipelineManagerVulkan.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -342,22 +342,138 @@ std::vector<std::string> PipelineManagerVulkan::DebugGetObjectIDs(DebugShaderTyp
return ids; return ids;
} }


static const char *const topologies[8] = {
"POINTLIST",
"LINELIST",
"LINESTRIP",
"TRILIST",
"TRISTRIP",
"TRIFAN",
};

static const char *const blendOps[8] = {
"ADD",
"SUB",
"REVSUB",
"MIN",
"MAX",
};

static const char *const compareOps[8] = {
"NEVER",
"<",
"==",
"<=",
">",
">=",
"!=",
"ALWAYS",
};

static const char *const stencilOps[8] = {
"KEEP",
"ZERO",
"REPLACE",
"INC_CLAMP",
"DEC_CLAMP",
"INVERT",
"INC_WRAP",
"DEC_WRAP",
};

static const char *const blendFactors[19] = {
"ZERO",
"ONE",
"SRC_COLOR",
"ONE_MINUS_SRC_COLOR",
"DST_COLOR",
"ONE_MINUS_DST_COLOR",
"SRC_ALPHA",
"ONE_MINUS_SRC_ALPHA",
"DST_ALPHA",
"ONE_MINUS_DST_ALPHA",
"CONSTANT_COLOR",
"ONE_MINUS_CONSTANT_COLOR",
"CONSTANT_ALPHA",
"ONE_MINUS_CONSTANT_ALPHA",
"SRC_ALPHA_SATURATE",
"SRC1_COLOR",
"ONE_MINUS_SRC1_COLOR",
"SRC1_ALPHA",
"ONE_MINUS_SRC1_ALPHA",
};

std::string PipelineManagerVulkan::DebugGetObjectString(std::string id, DebugShaderType type, DebugShaderStringType stringType) { std::string PipelineManagerVulkan::DebugGetObjectString(std::string id, DebugShaderType type, DebugShaderStringType stringType) {
if (type != SHADER_TYPE_PIPELINE) if (type != SHADER_TYPE_PIPELINE)
return "N/A"; return "N/A";


VulkanPipelineKey shaderId; VulkanPipelineKey pipelineKey;
shaderId.FromString(id); pipelineKey.FromString(id);


VulkanPipeline *iter = pipelines_.Get(shaderId); VulkanPipeline *iter = pipelines_.Get(pipelineKey);
if (!iter) { if (!iter) {
return ""; return "";
} }


switch (stringType) { switch (stringType) {
case SHADER_STRING_SHORT_DESC: case SHADER_STRING_SHORT_DESC:
{ {
return StringFromFormat("%p", iter); std::stringstream str;
str << topologies[pipelineKey.raster.topology] << " ";
if (pipelineKey.raster.blendEnable) {
str << "Blend(";
str << "C:" << blendOps[pipelineKey.raster.blendOpColor] << "/"
<< blendFactors[pipelineKey.raster.srcColor] << ":" << blendFactors[pipelineKey.raster.destColor] << " ";
if (pipelineKey.raster.blendOpAlpha != VK_BLEND_OP_ADD ||
pipelineKey.raster.srcAlpha != VK_BLEND_FACTOR_ONE ||
pipelineKey.raster.destAlpha != VK_BLEND_FACTOR_ZERO) {
str << "A:" << blendOps[pipelineKey.raster.blendOpAlpha] << "/"
<< blendFactors[pipelineKey.raster.srcColor] << ":" << blendFactors[pipelineKey.raster.destColor] << " ";
}
str << ") ";
}
if (pipelineKey.raster.colorWriteMask != 0xF) {
str << "Mask(";
for (int i = 0; i < 4; i++) {
if (pipelineKey.raster.colorWriteMask & (1 << i)) {
str << "RGBA"[i];
} else {
str << "_";
}
}
str << ") ";
}
if (pipelineKey.raster.depthTestEnable) {
str << "Depth(";
if (pipelineKey.raster.depthWriteEnable)
str << "W, ";
if (pipelineKey.raster.depthCompareOp)
str << compareOps[pipelineKey.raster.depthCompareOp & 7];
str << ") ";
}
if (pipelineKey.raster.stencilTestEnable) {
str << "Stencil(";
str << compareOps[pipelineKey.raster.stencilCompareOp & 7] << " ";
str << stencilOps[pipelineKey.raster.stencilPassOp & 7] << "/";
str << stencilOps[pipelineKey.raster.stencilFailOp & 7] << "/";
str << stencilOps[pipelineKey.raster.stencilDepthFailOp& 7];
str << ") ";
}
if (pipelineKey.raster.logicOpEnable) {
str << "Logic(";
str << ") ";
}
if (pipelineKey.useHWTransform) {
str << "HWX ";
}
if (pipelineKey.vtxDecId) {
str << "V(";
str << StringFromFormat("%08x", pipelineKey.vtxDecId); // TODO: Format nicer.
str << ") ";
} else {
str << "SWX ";
}
return StringFromFormat("%p: %s", iter, str.str().c_str());
} }


case SHADER_STRING_SOURCE_CODE: case SHADER_STRING_SOURCE_CODE:
Expand All @@ -382,4 +498,4 @@ void PipelineManagerVulkan::SetLineWidth(float lineWidth) {
pipelines_.Remove(key); pipelines_.Remove(key);
} }
}); });
} }
2 changes: 2 additions & 0 deletions UI/DevScreens.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ void SystemInfoScreen::CreateViews() {
deviceSpecs->Add(new ItemHeader("OS Information")); deviceSpecs->Add(new ItemHeader("OS Information"));
deviceSpecs->Add(new InfoItem("Memory Page Size", StringFromFormat("%d bytes", GetMemoryProtectPageSize()))); deviceSpecs->Add(new InfoItem("Memory Page Size", StringFromFormat("%d bytes", GetMemoryProtectPageSize())));
deviceSpecs->Add(new InfoItem("RW/RX exclusive: ", PlatformIsWXExclusive() ? "Yes" : "No")); deviceSpecs->Add(new InfoItem("RW/RX exclusive: ", PlatformIsWXExclusive() ? "Yes" : "No"));
#ifdef ANDROID
deviceSpecs->Add(new InfoItem("Sustained perf mode: ", System_GetPropertyBool(SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE) ? "Yes" : "No")); deviceSpecs->Add(new InfoItem("Sustained perf mode: ", System_GetPropertyBool(SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE) ? "Yes" : "No"));
#endif


const char *build = "Release"; const char *build = "Release";
#ifdef _DEBUG #ifdef _DEBUG
Expand Down

0 comments on commit 4788221

Please sign in to comment.