Skip to content

Commit

Permalink
[WGSL] Add code generation for textureSampleCompare
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=262386
rdar://116247210

Reviewed by Mike Wyrzykowski.

Add the Metal generator that converts `textureSampleCompare(t, ...)` into `t.sample_compare(...)`

* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
(WGSL::Metal::emitTextureSampleCompare):
* Source/WebGPU/WGSL/tests/valid/overload.wgsl:

Canonical link: https://commits.webkit.org/268719@main
  • Loading branch information
tadeuzagallo committed Oct 2, 2023
1 parent 1539889 commit d65248a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,11 @@ void FunctionDefinitionWriter::visit(const Type* type)
case Types::Primitive::Void:
case Types::Primitive::Bool:
case Types::Primitive::Sampler:
case Types::Primitive::SamplerComparison:
m_stringBuilder.append(*type);
break;
case Types::Primitive::SamplerComparison:
m_stringBuilder.append("sampler");
break;
case Types::Primitive::TextureExternal:
m_stringBuilder.append("texture_external");
break;
Expand Down Expand Up @@ -963,6 +965,15 @@ static void emitTextureSample(FunctionDefinitionWriter* writer, AST::CallExpress
visitArguments(writer, call, 1);
}

static void emitTextureSampleCompare(FunctionDefinitionWriter* writer, AST::CallExpression& call)
{
ASSERT(call.arguments().size() > 1);
writer->visit(call.arguments()[0]);
writer->stringBuilder().append(".sample_compare");
visitArguments(writer, call, 1);
}


static void emitTextureSampleLevel(FunctionDefinitionWriter* writer, AST::CallExpression& call)
{
bool isArray = false;
Expand Down Expand Up @@ -1162,6 +1173,7 @@ void FunctionDefinitionWriter::visit(const Type* type, AST::CallExpression& call
{ "textureNumLevels", emitTextureNumLevels },
{ "textureSample", emitTextureSample },
{ "textureSampleBaseClampToEdge", emitTextureSampleClampToEdge },
{ "textureSampleCompare", emitTextureSampleCompare },
{ "textureSampleLevel", emitTextureSampleLevel },
{ "textureStore", emitTextureStore },
{ "workgroupBarrier", emitWorkgroupBarrier },
Expand Down
2 changes: 2 additions & 0 deletions Source/WebGPU/WGSL/tests/valid/overload.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,8 @@ fn testTextureSampleBias()
}

// 16.7.10
// RUN: %metal-compile testTextureSampleCompare
@compute @workgroup_size(1)
fn testTextureSampleCompare()
{
// [].(texture_depth_2d, sampler_comparison, vec2[f32], f32) => f32,
Expand Down

0 comments on commit d65248a

Please sign in to comment.