VPP  0.8
A high-level modern C++ API for Vulkan
vpp::Int Class Reference

Shader (GPU-side) data type for 32-bit signed integer values. More...

#include <vppLangScalarTypes.hpp>

Public Member Functions

 Int ()
 Construct a zero r-value.
 
 Int (int value)
 Construct a r-value from specified C++ value. More...
 
Int operator+ (const Int &rhs) const
 Standard addition operator.
 
Int operator- (const Int &rhs) const
 Standard subtraction operator.
 
Int operator* (const Int &rhs) const
 Standard multiplication operator.
 
Int operator/ (const Int &rhs) const
 Standard division operator.
 
Int operator% (const Int &rhs) const
 Standard remainder operator. More...
 
Int operator<< (const Int &rhs) const
 Standard left shift operator.
 
Int operator>> (const Int &rhs) const
 Standard right shift operator.
 
Int operator| (const Int &rhs) const
 Standard bitwise or operator.
 
Int operator^ (const Int &rhs) const
 Standard bitwise xor operator.
 
Int operator & (const Int &rhs) const
 Standard bitwise and operator.
 
Int operator- () const
 Standard sign reversal operator.
 
Int operator~ () const
 Standard bitwise negation operator.
 
Bool operator== (const Int &rhs) const
 Standard comparison operator (true if equal).
 
Bool operator!= (const Int &rhs) const
 Standard comparison operator (true if not equal).
 
Bool operator> (const Int &rhs) const
 Standard comparison operator (true if greater).
 
Bool operator>= (const Int &rhs) const
 Standard comparison operator (true if greater or equal).
 
Bool operator< (const Int &rhs) const
 Standard comparison operator (true if less).
 
Bool operator<= (const Int &rhs) const
 Standard comparison operator (true if less or equal).
 

Detailed Description

Shader (GPU-side) data type for 32-bit signed integer values.

Use this type inside shader code as a counterpart of CPU-side int type.

This is a r-value type. You must initialize it with value, either CPU-side one (an explicit constant), or an expression computed on GPU side. The value can not be changed.

For mutable variable type, see VInt. Beware that mutable variables can degrade performance on GPU, therefore Int is preferable, unless you really want a mutable variable (e.g. a loop counter).

Constructor & Destructor Documentation

◆ Int()

vpp::Int::Int ( int  value)

Construct a r-value from specified C++ value.

The source value can be either a C++ constant, or a variable (e.g. a parameter passed to shader specific for that shader). The constructor is called once when compiling the pipeline.

Member Function Documentation

◆ operator%()

Int vpp::Int::operator% ( const Int rhs) const

Standard remainder operator.

This operator generates a remainder computation instruction.

Caution: the behavior of integer remainder operation for negative operands on real hardware seems to be incorrect on certain GPUs (problem detected on NVIDIA GTX 960). There is also inconsistency of specifications. The SPIR-V specification requests proper remainder calculation for negative operands. It states explicitly:

Remainder: When dividing a by b, a remainder r is defined to be a value that satisfies r + q × b = a where q is a whole number and |r| < |b|.

However, GLSL specification states that remainder is undefined if any operand is negative.

The actual hardware (or at least some of it) follows the GLSL path, not SPIR-V. Therefore it is recommended to avoid supplying negative operands to this operator.

This issue can be considered a bug in Vulkan implementations. VPP does not cause this (generated instruction has been verified to be correct), so please do not report this as a bug in VPP.


The documentation for this class was generated from the following file: