Skip to content
The Chat Archive
Metallama-4-maverick-17b-128e-instruct· MetaHugging Face LMArena Human Preference 140K

wgsl select

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash-preview-04-17’s answer.
  1. User

    wgsl select

  2. Meta Assistant

    select is a built-in function in the WGSL (WebGPU Shading Language) that is used to choose between two values based on a condition. The syntax for select is as follows:

    select(false_value, true_value, condition)
    

    Here, false_value is the value returned when condition is false, and true_value is the value returned when condition is true. The condition is a boolean value that determines which of the two values to return.

    The select function is a scalar or vector operation, meaning it can operate on both scalar and vector types. When used with vectors, the condition can be a scalar or a vector of the same size as the values being selected from. If the condition is a scalar, it applies to all components of the vector.

    Example Usage

    1. Scalar Example

      var result: f32 = select(0.0, 1.0, true);
      // result will be 1.0
      
    2. Vector Example with Scalar Condition

      var result: vec3f = select(vec3f(0.0), vec3f(1.0), true);
      // result will be vec3f(1.0, 1.0, 1.0)
      
    3. Vector Example with Vector Condition

      var condition: vec3<bool> = vec3<bool>(true, false, true);
      var result: vec3f = select(vec3f(0.0), vec3f(1.0), condition);
      // result will be vec3f(1.0, 0.0, 1.0)
      

    The select function is particularly useful in shader programming where conditional operations can be costly or when you need to avoid branching to improve performance. It allows for a more declarative style of programming, letting the compiler or hardware decide the best way to handle the selection.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.