mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-11 14:41:50 +00:00
writer/msl: Output constant 0 lod for 1d texture builtins
The MSL headers have annotations that requires that the lod for 1D textures is a constexpr with value 0. This affects .get_width() and .read(). Bug: dawn:814 Change-Id: Ic21d32067061afe67a16fbbeee222ab695b53066 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/79301 Reviewed-by: Ben Clayton <bclayton@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Corentin Wallez <cwallez@chromium.org> Auto-Submit: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Tint LUCI CQ
parent
a924ffe70c
commit
b3c99ddfae
@@ -885,6 +885,10 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
||||
return true;
|
||||
};
|
||||
|
||||
// MSL requires that `lod` is a constant 0 for 1D textures.
|
||||
bool level_is_constant_zero =
|
||||
texture_type->dim() == ast::TextureDimension::k1d;
|
||||
|
||||
switch (builtin->Type()) {
|
||||
case sem::BuiltinType::kTextureDimensions: {
|
||||
std::vector<const char*> dims;
|
||||
@@ -912,9 +916,13 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
||||
return false;
|
||||
}
|
||||
out << ".get_" << name << "(";
|
||||
if (auto* level = arg(Usage::kLevel)) {
|
||||
if (!EmitExpression(out, level->Declaration())) {
|
||||
return false;
|
||||
if (level_is_constant_zero) {
|
||||
out << "0";
|
||||
} else {
|
||||
if (auto* level = arg(Usage::kLevel)) {
|
||||
if (!EmitExpression(out, level->Declaration())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
out << ")";
|
||||
@@ -1061,8 +1069,12 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
||||
if (lod_param_is_named) {
|
||||
out << "level(";
|
||||
}
|
||||
if (!EmitExpression(out, level->Declaration())) {
|
||||
return false;
|
||||
if (level_is_constant_zero) {
|
||||
out << "0";
|
||||
} else {
|
||||
if (!EmitExpression(out, level->Declaration())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (lod_param_is_named) {
|
||||
out << ")";
|
||||
|
||||
@@ -27,7 +27,7 @@ std::string expected_texture_overload(
|
||||
switch (overload) {
|
||||
case ValidTextureOverload::kDimensions1d:
|
||||
case ValidTextureOverload::kDimensionsStorageWO1d:
|
||||
return R"(int(texture.get_width()))";
|
||||
return R"(int(texture.get_width(0)))";
|
||||
case ValidTextureOverload::kDimensions2d:
|
||||
case ValidTextureOverload::kDimensions2dArray:
|
||||
case ValidTextureOverload::kDimensionsCube:
|
||||
@@ -225,11 +225,11 @@ std::string expected_texture_overload(
|
||||
case ValidTextureOverload::kSampleCompareLevelDepthCubeArrayF32:
|
||||
return R"(texture.sample_compare(sampler, float3(1.0f, 2.0f, 3.0f), 4, 5.0f))";
|
||||
case ValidTextureOverload::kLoad1dLevelF32:
|
||||
return R"(texture.read(uint(1), 3))";
|
||||
return R"(texture.read(uint(1), 0))";
|
||||
case ValidTextureOverload::kLoad1dLevelU32:
|
||||
return R"(texture.read(uint(1), 3))";
|
||||
return R"(texture.read(uint(1), 0))";
|
||||
case ValidTextureOverload::kLoad1dLevelI32:
|
||||
return R"(texture.read(uint(1), 3))";
|
||||
return R"(texture.read(uint(1), 0))";
|
||||
case ValidTextureOverload::kLoad2dLevelF32:
|
||||
return R"(texture.read(uint2(int2(1, 2)), 3))";
|
||||
case ValidTextureOverload::kLoad2dLevelU32:
|
||||
|
||||
Reference in New Issue
Block a user