fix shader debug printf bug

This commit is contained in:
Asuka 2022-06-12 07:41:16 +08:00
parent 1fbcff1001
commit 0b4e8f4cd6
3 changed files with 40 additions and 36 deletions

View file

@ -1856,19 +1856,19 @@ namespace sce::gcn
{
switch (sv)
{
case GcnSystemValue::SubgroupID:
case GcnSystemValue::SubgroupInvocationID:
{
if (m_common.subgroupId == 0)
if (m_common.subgroupInvocationId == 0)
{
m_common.subgroupId = emitNewBuiltinVariable({ { GcnScalarType::Uint32, 1, 0 },
spv::StorageClassInput },
spv::BuiltInSubgroupId,
"subgroup_id");
m_common.subgroupInvocationId = emitNewBuiltinVariable({ { GcnScalarType::Uint32, 1, 0 },
spv::StorageClassInput },
spv::BuiltInSubgroupLocalInvocationId,
"invocation_id");
}
GcnRegisterPointer ptr;
ptr.type = { GcnScalarType::Uint32, 1 };
ptr.id = m_common.subgroupId;
ptr.id = m_common.subgroupInvocationId;
return emitValueLoad(ptr);
}
break;
@ -1896,7 +1896,6 @@ namespace sce::gcn
case GcnSystemValue::SubgroupLeMask:
case GcnSystemValue::SubgroupLtMask:
case GcnSystemValue::SubgroupSize:
case GcnSystemValue::SubgroupInvocationID:
default:
Logger::exception(util::str::formatex(
"GcnCompiler: Unhandled Common SV input: ", (uint32_t)sv));
@ -2204,6 +2203,22 @@ namespace sce::gcn
return emitValueLoad(ptr);
}
break;
case GcnSystemValue::SubgroupID:
{
if (m_common.subgroupId == 0)
{
m_common.subgroupId = emitNewBuiltinVariable({ { GcnScalarType::Uint32, 1, 0 },
spv::StorageClassInput },
spv::BuiltInSubgroupId,
"subgroup_id");
}
GcnRegisterPointer ptr;
ptr.type = { GcnScalarType::Uint32, 1 };
ptr.id = m_common.subgroupId;
return emitValueLoad(ptr);
}
break;
default:
Logger::exception(util::str::formatex(
"GcnCompiler: Unhandled CS SV input: ", (uint32_t)sv));

View file

@ -577,6 +577,8 @@ namespace sce::gcn
// Copy vk_layer_settings.txt from Misc folder to your
// Current Working Directory or use vkconfig.exe from SDK
// to enable shader debug printf.
// Note that normally we need to specify big enough
// buffer size and limit the number of messages by conditionally using invocation ID
//
// Format for specifier is "%"precision <d, i, o, u, x, X, a, A, e, E, f, F, g, G, or ul>
// Format for vector specifier is "%"precision"v" [2, 3, or 4] [specifiers list above]
@ -584,32 +586,19 @@ namespace sce::gcn
// To conditionally print something,
// copy and edit the following code:
//
// if (m_header->key().name() == "SHDR_AF20AC1F702451D8" && m_programCounter == 0x70)
// {
// uint32_t labelBegin = m_module.allocateId();
// uint32_t labelEnd = m_module.allocateId();
// m_module.opSelectionMerge(labelEnd, spv::SelectionControlMaskNone);
// m_module.opBranchConditional(condition, labelBegin, labelEnd);
// m_module.opLabel(labelBegin);
// emitDebugPrintf("condition %d\n", condition);
// m_module.opBranch(labelEnd);
// m_module.opLabel(labelEnd);
// }
// TODO:
// There may be some bugs for current implementation
// (or bugs for validation layer, I'm not sure),
// It can not print more than one debug string,
// and even worse, the validation layer always complains
// buffer size not enough even I provide 65536 bytes.
// And crashes randomly.
// I've compared the spir-v code generated by
// this function and glslc compiler, and I see
// no difference, so I don't know why by now.
//
// This doesn't mean the function is useless,
// it's still very powerful, although the experience
// is poor.
//if (m_header->key().name() == "SHDR_AF20AC1F702451D8" && m_programCounter == 0x70)
//{
// auto invId = emitCommonSystemValueLoad(GcnSystemValue::SubgroupInvocationID, 0);
// auto condition = m_module.opIEqual(m_module.defBoolType(), invId.id, m_module.constu32(1));
// uint32_t labelBegin = m_module.allocateId();
// uint32_t labelEnd = m_module.allocateId();
// m_module.opSelectionMerge(labelEnd, spv::SelectionControlMaskNone);
// m_module.opBranchConditional(condition, labelBegin, labelEnd);
// m_module.opLabel(labelBegin);
// emitDebugPrintf("id %X\n", invId.id);
// m_module.opBranch(labelEnd);
// m_module.opLabel(labelEnd);
//}
#ifdef GCN_SHADER_DEBUG_PRINTF
const int count = sizeof...(args);

View file

@ -5,7 +5,7 @@
# =====================
# <LayerIdentifier>.debug_action
# Specifies what action is to be taken when a layer reports information
khronos_validation.debug_action =
khronos_validation.debug_action = VK_DBG_LAYER_ACTION_LOG_MSG
# Log Filename
# =====================
@ -67,7 +67,7 @@ khronos_validation.printf_verbose = false
# =====================
# <LayerIdentifier>.printf_buffer_size
# Set the size in bytes of the buffer used by debug printf
khronos_validation.printf_buffer_size = 1024
khronos_validation.printf_buffer_size = 65536
# Fine Grained Locking
# =====================