summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-check-shader-parameter-type.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-ir-check-shader-parameter-type.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-ir-check-shader-parameter-type.cpp')
-rw-r--r--source/slang/slang-ir-check-shader-parameter-type.cpp93
1 files changed, 50 insertions, 43 deletions
diff --git a/source/slang/slang-ir-check-shader-parameter-type.cpp b/source/slang/slang-ir-check-shader-parameter-type.cpp
index 71833c838..6f3161110 100644
--- a/source/slang/slang-ir-check-shader-parameter-type.cpp
+++ b/source/slang/slang-ir-check-shader-parameter-type.cpp
@@ -1,65 +1,72 @@
#include "slang-ir-check-shader-parameter-type.h"
+
#include "slang-ir-util.h"
namespace Slang
{
- void checkForInvalidShaderParameterTypeForMetal(IRModule* module, DiagnosticSink* sink)
+void checkForInvalidShaderParameterTypeForMetal(IRModule* module, DiagnosticSink* sink)
+{
+ HashSet<IRInst*> workListSet;
+ List<IRInst*> workList;
+ for (auto inst : module->getGlobalInsts())
{
- HashSet<IRInst*> workListSet;
- List<IRInst*> workList;
- for (auto inst : module->getGlobalInsts())
+ if (inst->getOp() == kIROp_ParameterBlockType)
{
- if (inst->getOp() == kIROp_ParameterBlockType)
+ auto type = inst->getOperand(0);
+ if (workListSet.add(type))
+ workList.add(type);
+ // Diagnose an error on `ParameterBlock<ConstantBuffer<T>>`.
+ if (type->getOp() == kIROp_ConstantBufferType)
{
- auto type = inst->getOperand(0);
- if (workListSet.add(type))
- workList.add(type);
- // Diagnose an error on `ParameterBlock<ConstantBuffer<T>>`.
- if (type->getOp() == kIROp_ConstantBufferType)
+ bool foundUseSite = false;
+ for (auto use = inst->firstUse; use; use = use->nextUse)
{
- bool foundUseSite = false;
- for (auto use = inst->firstUse; use; use = use->nextUse)
+ auto user = use->getUser();
+ if (user->sourceLoc.isValid())
{
- auto user = use->getUser();
- if (user->sourceLoc.isValid())
- {
- sink->diagnose(user, Diagnostics::constantBufferInParameterBlockNotAllowedOnMetal);
- foundUseSite = true;
- break;
- }
+ sink->diagnose(
+ user,
+ Diagnostics::constantBufferInParameterBlockNotAllowedOnMetal);
+ foundUseSite = true;
+ break;
}
- if (!foundUseSite)
- sink->diagnose(inst, Diagnostics::constantBufferInParameterBlockNotAllowedOnMetal);
}
+ if (!foundUseSite)
+ sink->diagnose(
+ inst,
+ Diagnostics::constantBufferInParameterBlockNotAllowedOnMetal);
}
}
- // Diagnose an error any any struct fields whose type is `ConstantBuffer<T>` if the
- // struct is used inside a `ParameterBlock`.
- for (Index i = 0; i < workList.getCount(); i++)
+ }
+ // Diagnose an error any any struct fields whose type is `ConstantBuffer<T>` if the
+ // struct is used inside a `ParameterBlock`.
+ for (Index i = 0; i < workList.getCount(); i++)
+ {
+ auto type = workList[i];
+ if (auto structType = as<IRStructType>(type))
{
- auto type = workList[i];
- if (auto structType = as<IRStructType>(type))
+ for (auto field : structType->getFields())
{
- for (auto field : structType->getFields())
+ auto fieldType = field->getFieldType();
+ if (fieldType->getOp() == kIROp_ConstantBufferType)
{
- auto fieldType = field->getFieldType();
- if (fieldType->getOp() == kIROp_ConstantBufferType)
- {
- sink->diagnose(field->getKey(), Diagnostics::constantBufferInParameterBlockNotAllowedOnMetal);
- }
- if (workListSet.add(fieldType))
- workList.add(fieldType);
+ sink->diagnose(
+ field->getKey(),
+ Diagnostics::constantBufferInParameterBlockNotAllowedOnMetal);
}
+ if (workListSet.add(fieldType))
+ workList.add(fieldType);
}
}
}
+}
- void checkForInvalidShaderParameterType(
- TargetRequest* target,
- IRModule* module,
- DiagnosticSink* sink)
- {
- if (isMetalTarget(target))
- checkForInvalidShaderParameterTypeForMetal(module, sink);
- }
-} \ No newline at end of file
+void checkForInvalidShaderParameterType(
+ TargetRequest* target,
+ IRModule* module,
+ DiagnosticSink* sink)
+{
+ if (isMetalTarget(target))
+ checkForInvalidShaderParameterTypeForMetal(module, sink);
+}
+} // namespace Slang \ No newline at end of file