wgsl select
- User
wgsl select
Assistant
selectis a built-in function in the WGSL (WebGPU Shading Language) that is used to choose between two values based on a condition. The syntax forselectis as follows:select(false_value, true_value, condition)Here,
false_valueis the value returned whenconditionis false, andtrue_valueis the value returned whenconditionis true. Theconditionis a boolean value that determines which of the two values to return.The
selectfunction 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
-
Scalar Example
var result: f32 = select(0.0, 1.0, true); // result will be 1.0 -
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) -
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
selectfunction 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.-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
deepseek-r1-0528Compare side by side →
claude-3-7-sonnet-20250219-thinking-32kCompare side by side →
mistral-medium-2505Compare side by side →
gemini-2.5-pro-preview-05-06Compare side by side →
gemini-2.5-proCompare side by side →
claude-3-7-sonnet-20250219-thinking-32kCompare side by side →
gemini-2.5-flash-preview-04-17Compare side by side →
llama-4-maverick-03-26-experimentalCompare side by side →
claude-3-7-sonnet-20250219Compare side by side →