spirv-reader: generalize skip reasons

Bug: tint:412
Change-Id: Ie9dd230361019ec929f4d36215e7058a893bbe0d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35860
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
David Neto 2020-12-16 20:42:10 +00:00 committed by Commit Bot service account
parent 99688918e1
commit e9b90f755b
2 changed files with 39 additions and 13 deletions

View File

@ -2859,7 +2859,7 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
// Handle combinatorial instructions.
const auto* def_info = GetDefInfo(result_id);
if (def_info) {
if (def_info->skip_generation) {
if (def_info->skip != SkipReason::kDontSkip) {
return true;
}
auto combinatorial_expr = MaybeEmitCombinatorialValue(inst);
@ -3532,13 +3532,13 @@ bool FunctionEmitter::RegisterLocallyDefinedValues() {
<< inst.PrettyPrint();
}
if (info->storage_class == ast::StorageClass::kUniformConstant) {
info->skip_generation = true;
info->skip = SkipReason::kOpaqueObject;
}
}
if (type->AsSampler() || type->AsImage() || type->AsSampledImage()) {
// Defer code generation until the instruction that actually acts on
// the image.
info->skip_generation = true;
info->skip = SkipReason::kOpaqueObject;
}
}
}

View File

@ -195,6 +195,31 @@ inline std::ostream& operator<<(std::ostream& o, const BlockInfo& bi) {
return o;
}
/// Reasons for avoiding generating an intermediate value.
enum class SkipReason {
/// `kDontSkip`: The value should be generated. Used for most values.
kDontSkip,
/// For remaining cases, the value is not generated.
/// `kOpaqueObject`: used for any intermediate value which is an sampler,
/// image,
/// or sampled image, or any pointer to such object. Code is generated
/// for those objects only when emitting the image instructions that access
/// the image (read, write, sample, gather, fetch, or query). For example,
/// when encountering an OpImageSampleExplicitLod, a call to the
/// textureSampleLevel builtin function will be emitted, and the call will
/// directly reference the underlying texture and sampler (variable or
/// function parameter).
kOpaqueObject,
/// `kPointSizeBuiltin`: the value is a pointer to the Position builtin
/// variable. Don't generate its address. Avoid generating stores to
/// this pointer. When loading from the pointer, yield the value 1,
/// the only supported value for PointSize.
kPointSizeBuiltin
};
/// Bookkeeping info for a SPIR-V ID defined in the function.
/// This will be valid for result IDs for:
/// - instructions that are not OpLabel, and not OpFunctionParameter
@ -262,16 +287,7 @@ struct DefInfo {
/// This is kNone for non-pointers.
ast::StorageClass storage_class = ast::StorageClass::kNone;
/// Should this instruction be skipped when generating code?
/// This is true for any intermediate value which is an sampler, image,
/// or sampled image, or any pointer to such object. Code is generated
/// for those objects only when emitting the image instructions that access
/// the image (read, write, sample, gather, fetch, or query). For example,
/// when encountering an OpImageSampleExplicitLod, a call to the
/// textureSampleLevel builtin function will be emitted, and the call will
/// directly reference the underlying texture and sampler (variable or
/// function parameter).
bool skip_generation = false;
SkipReason skip = SkipReason::kDontSkip;
};
inline std::ostream& operator<<(std::ostream& o, const DefInfo& di) {
@ -285,6 +301,16 @@ inline std::ostream& operator<<(std::ostream& o, const DefInfo& di) {
if (di.storage_class != ast::StorageClass::kNone) {
o << " sc:" << int(di.storage_class);
}
switch (di.skip) {
case SkipReason::kDontSkip:
break;
case SkipReason::kOpaqueObject:
o << " skip:opaque";
break;
case SkipReason::kPointSizeBuiltin:
o << " skip:pointsize";
break;
}
o << "}";
return o;
}