diff --git a/Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp b/Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp index e7e1ff6edabf..d7231562b8ee 100644 --- a/Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp +++ b/Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp @@ -481,12 +481,14 @@ void FunctionDefinitionWriter::visit(AST::CallExpression& call) void FunctionDefinitionWriter::visit(AST::UnaryExpression& unary) { switch (unary.operation()) { + case AST::UnaryOperation::Complement: + m_stringBuilder.append("~"); + break; case AST::UnaryOperation::Negate: m_stringBuilder.append("-"); break; case AST::UnaryOperation::AddressOf: - case AST::UnaryOperation::Complement: case AST::UnaryOperation::Dereference: case AST::UnaryOperation::Not: // FIXME: Implement these @@ -512,9 +514,20 @@ void FunctionDefinitionWriter::visit(AST::BinaryExpression& binary) case AST::BinaryOperation::Divide: case AST::BinaryOperation::Modulo: + // FIXME: Implement these + RELEASE_ASSERT_NOT_REACHED(); + break; + case AST::BinaryOperation::And: + m_stringBuilder.append(" & "); + break; case AST::BinaryOperation::Or: + m_stringBuilder.append(" | "); + break; case AST::BinaryOperation::Xor: + m_stringBuilder.append(" ^ "); + break; + case AST::BinaryOperation::LeftShift: case AST::BinaryOperation::RightShift: // FIXME: Implement these diff --git a/Source/WebGPU/WGSL/TypeDeclarations.rb b/Source/WebGPU/WGSL/TypeDeclarations.rb index 80ba7e9f1605..fff0523a2fcb 100644 --- a/Source/WebGPU/WGSL/TypeDeclarations.rb +++ b/Source/WebGPU/WGSL/TypeDeclarations.rb @@ -44,6 +44,19 @@ } end +# Bitwise operations +operator :~, { + [T < Integer].(T) => T, + [T < Integer, N].(Vector[T, N]) => Vector[T, N] +} + +["|", "&", "^"].each do |op| + operator :"#{op}", { + [T < Integer].(T, T) => T, + [T < Integer, N].(Vector[T, N], Vector[T, N]) => Vector[T, N] + } +end + operator :textureSample, { [].(Texture[F32, Texture1d], Sampler, F32) => Vector[F32, 4], [].(Texture[F32, Texture2d], Sampler, Vector[F32, 2]) => Vector[F32, 4], diff --git a/Source/WebGPU/WGSL/generator/main.rb b/Source/WebGPU/WGSL/generator/main.rb index 494d20768731..9a004a1c0bcb 100644 --- a/Source/WebGPU/WGSL/generator/main.rb +++ b/Source/WebGPU/WGSL/generator/main.rb @@ -288,6 +288,7 @@ def self.prologue R = Variable.new(:R, @NumericVariable) Number = Constraint.new(:Number) + Integer = Constraint.new(:Integer) Float = Constraint.new(:Float) Scalar = Constraint.new(:Scalar) ConcreteInteger = Constraint.new(:ConcreteInteger) diff --git a/Source/WebGPU/WGSL/tests/valid/overload.wgsl b/Source/WebGPU/WGSL/tests/valid/overload.wgsl index f59e81c75220..302f6d0c8b48 100644 --- a/Source/WebGPU/WGSL/tests/valid/overload.wgsl +++ b/Source/WebGPU/WGSL/tests/valid/overload.wgsl @@ -425,3 +425,30 @@ fn testComparison() { let x9 = vec2(0.0f) <= vec2(1.0f); } } + +fn testBitwise() +{ + { + let x = ~0; + let x1 = ~0i; + let x2 = ~0u; + } + + { + let x = 0 & 1; + let x1 = 0i & 1i; + let x2 = 0u & 1u; + } + + { + let x = 0 | 1; + let x1 = 0i | 1i; + let x2 = 0u | 1u; + } + + { + let x = 0 ^ 1; + let x1 = 0i ^ 1i; + let x2 = 0u ^ 1u; + } +} \ No newline at end of file