writer/spirv: Refactor IntrinsicTextureTest.OutsideFunction_IsError

Use the same builder helpers as IntrinsicTextureTest.Call, significantly reducing boilerplate

Change-Id: Idb37a1704b9ed76c3872d14003ff279b2955d18b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37443
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton 2021-01-12 20:09:42 +00:00 committed by Commit Bot service account
parent 559f4e66d5
commit 50c5fa1100
2 changed files with 9 additions and 47 deletions

View File

@ -168,10 +168,12 @@ ast::Variable* TextureOverloadCase::buildTextureVariable(
b->create<ast::type::MultisampledTexture>(texture_dimension, b->create<ast::type::MultisampledTexture>(texture_dimension,
datatype)); datatype));
case ast::intrinsic::test::TextureKind::kStorage: case ast::intrinsic::test::TextureKind::kStorage: {
return b->Var("texture", ast::StorageClass::kNone, auto* st = b->create<ast::type::StorageTexture>(
b->create<ast::type::StorageTexture>( texture_dimension, access_control, image_format);
texture_dimension, access_control, image_format)); st->set_type(datatype);
return b->Var("texture", ast::StorageClass::kNone, st);
}
} }
assert(false /* unreachable */); assert(false /* unreachable */);

View File

@ -3734,50 +3734,10 @@ TEST_P(IntrinsicTextureTest, OutsideFunction_IsError) {
// The point of this test is to try to generate the texture // The point of this test is to try to generate the texture
// intrinsic call outside a function. // intrinsic call outside a function.
ast::type::Type* datatype = nullptr; auto* texture = param.buildTextureVariable(this);
switch (param.texture_data_type) { auto* sampler = param.buildSamplerVariable(this);
case ast::intrinsic::test::TextureDataType::kF32:
datatype = ty.f32;
break;
case ast::intrinsic::test::TextureDataType::kU32:
datatype = ty.u32;
break;
case ast::intrinsic::test::TextureDataType::kI32:
datatype = ty.i32;
break;
}
ast::type::Sampler sampler_type{param.sampler_kind}; ASSERT_TRUE(b.GenerateGlobalVariable(texture)) << b.error();
ast::Variable* tex = nullptr;
switch (param.texture_kind) {
case ast::intrinsic::test::TextureKind::kRegular:
tex = Var("texture", ast::StorageClass::kNone,
mod->create<ast::type::SampledTexture>(param.texture_dimension,
datatype));
break;
case ast::intrinsic::test::TextureKind::kDepth:
tex = Var("texture", ast::StorageClass::kNone,
mod->create<ast::type::DepthTexture>(param.texture_dimension));
break;
case ast::intrinsic::test::TextureKind::kMultisampled:
tex = Var("texture", ast::StorageClass::kNone,
mod->create<ast::type::MultisampledTexture>(
param.texture_dimension, datatype));
break;
case ast::intrinsic::test::TextureKind::kStorage: {
auto* st = mod->create<ast::type::StorageTexture>(
param.texture_dimension, param.access_control, param.image_format);
st->set_type(datatype);
tex = Var("texture", ast::StorageClass::kNone, st);
} break;
}
auto* sampler = Var("sampler", ast::StorageClass::kNone, &sampler_type);
ASSERT_TRUE(b.GenerateGlobalVariable(tex)) << b.error();
ASSERT_TRUE(b.GenerateGlobalVariable(sampler)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(sampler)) << b.error();
auto* call = auto* call =