VPP  0.7
A high-level modern C++ API for Vulkan
vppLangScalarTypes.hpp
1 /*
2  Copyright 2016-2018 SOFT-ERG, Przemek Kuczmierczyk (www.softerg.com)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification,
6  are permitted provided that the following conditions are met:
7 
8  1. Redistributions of source code must retain the above copyright notice,
9  this list of conditions and the following disclaimer.
10 
11  2. Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 // -----------------------------------------------------------------------------
28 namespace vpp {
29 // -----------------------------------------------------------------------------
30 
45 class Bool
46 {
47 public:
54  Bool ( bool value );
55 
57  Bool operator|| ( const Bool& rhs ) const;
58 
60  Bool operator&& ( const Bool& rhs ) const;
61 
63  Bool operator!() const;
64 
66  Bool operator== ( const Bool& rhs ) const;
67 
69  Bool operator!= ( const Bool& rhs ) const;
70 };
71 
72 // -----------------------------------------------------------------------------
84 class VBool
85 {
86 public:
87  VBool();
88  VBool ( const Bool& rvalue );
89 
90  const VBool& operator= ( const Bool& rhs );
91  operator Bool() const;
92 
93  Bool operator|| ( const Bool& rhs ) const;
94  Bool operator&& ( const Bool& rhs ) const;
95  Bool operator!() const;
96 
97  Bool operator== ( const Bool& rhs ) const;
98  Bool operator!= ( const Bool& rhs ) const;
99 };
100 
101 // -----------------------------------------------------------------------------
111 class Void
112 {
113 public:
114 };
115 
116 // -----------------------------------------------------------------------------
117 /*
118 template< typename ScalarT >
119 class TLValue : public KValue
120 {
121 public:
122  TLValue();
123  TLValue ( const TRValue< ScalarT >& rvalue );
124 
125  operator rvalue_type() const;
126  const TLValue< ScalarT >& operator= ( const TRValue< ScalarT >& rhs );
127 
128  VPP_DEFINE_SCALAR_OPERATORS;
129  VPP_DEFINE_MUTATING_SCALAR_OPERATORS;
130 
131  inline rvalue_type operator* ( const rvalue_type& rhs ) const
132  {
133  rvalue_type lhs = *this;
134  return lhs * rhs;
135  }
136 
137  template< typename RightT >
138  inline auto operator* ( const RightT& rhs ) const
139  {
140  typedef typename detail::TGetRV< RightT >::type rhs_type;
141  const rvalue_type rValue1 = *this;
142  const rhs_type rValue2 = rhs;
143  return rValue1 * rValue2;
144  }
145 
146  rvalue_type operator++();
147  rvalue_type operator++ ( int );
148  rvalue_type operator--();
149  rvalue_type operator-- ( int );
150 };
151 */
152 // -----------------------------------------------------------------------------
167 class Int
168 {
169 public:
176  Int ( int value );
177 
179  Int operator+ ( const Int& rhs ) const;
180 
182  Int operator- ( const Int& rhs ) const;
183 
185  Int operator* ( const Int& rhs ) const;
186 
188  Int operator/ ( const Int& rhs ) const;
189 
191  Int operator% ( const Int& rhs ) const;
192 
194  Int operator<< ( const Int& rhs ) const;
195 
197  Int operator>> ( const Int& rhs ) const;
198 
200  Int operator| ( const Int& rhs ) const;
201 
203  Int operator^ ( const Int& rhs ) const;
204 
206  Int operator& ( const Int& rhs ) const;
207 
209  Int operator-() const;
210 
212  Int operator~() const;
213 
215  Bool operator== ( const Int& rhs ) const;
216 
218  Bool operator!= ( const Int& rhs ) const;
219 
221  Bool operator> ( const Int& rhs ) const;
222 
224  Bool operator>= ( const Int& rhs ) const;
225 
227  Bool operator< ( const Int& rhs ) const;
228 
230  Bool operator<= ( const Int& rhs ) const;
231 };
232 
233 // -----------------------------------------------------------------------------
234 
249 class UInt
250 {
251 public:
258  UInt ( unsigned int value );
259 
261  UInt operator+ ( const UInt& rhs ) const;
262 
264  UInt operator- ( const UInt& rhs ) const;
265 
267  UInt operator* ( const UInt& rhs ) const;
268 
270  UInt operator/ ( const UInt& rhs ) const;
271 
273  UInt operator% ( const UInt& rhs ) const;
274 
276  UInt operator<< ( const UInt& rhs ) const;
277 
279  UInt operator>> ( const UInt& rhs ) const;
280 
282  UInt operator| ( const UInt& rhs ) const;
283 
285  UInt operator^ ( const UInt& rhs ) const;
286 
288  UInt operator& ( const UInt& rhs ) const;
289 
291  UInt operator-() const;
292 
294  UInt operator~() const;
295 
297  Bool operator== ( const UInt& rhs ) const;
298 
300  Bool operator!= ( const UInt& rhs ) const;
301 
303  Bool operator> ( const UInt& rhs ) const;
304 
306  Bool operator>= ( const UInt& rhs ) const;
307 
309  Bool operator< ( const UInt& rhs ) const;
310 
312  Bool operator<= ( const UInt& rhs ) const;
313 };
314 
315 // -----------------------------------------------------------------------------
330 class Float
331 {
332 public:
339  Float ( float value );
340 
342  Float operator+ ( const Float& rhs ) const;
343 
345  Float operator- ( const Float& rhs ) const;
346 
348  Float operator* ( const Float& rhs ) const;
349 
351  Float operator/ ( const Float& rhs ) const;
352 
354  Float operator% ( const Float& rhs ) const;
355 
357  Float operator-() const;
358 
360  Bool operator== ( const Float& rhs ) const;
361 
363  Bool operator!= ( const Float& rhs ) const;
364 
366  Bool operator> ( const Float& rhs ) const;
367 
369  Bool operator>= ( const Float& rhs ) const;
370 
372  Bool operator< ( const Float& rhs ) const;
373 
375  Bool operator<= ( const Float& rhs ) const;
376 };
377 
378 // -----------------------------------------------------------------------------
393 class Double
394 {
395 public:
402  Double ( double value );
403 
405  Double operator+ ( const Double& rhs ) const;
406 
408  Double operator- ( const Double& rhs ) const;
409 
411  Double operator* ( const Double& rhs ) const;
412 
414  Double operator/ ( const Double& rhs ) const;
415 
417  Double operator% ( const Double& rhs ) const;
418 
420  Double operator-() const;
421 
423  Bool operator== ( const Double& rhs ) const;
424 
426  Bool operator!= ( const Double& rhs ) const;
427 
429  Bool operator> ( const Double& rhs ) const;
430 
432  Bool operator>= ( const Double& rhs ) const;
433 
435  Bool operator< ( const Double& rhs ) const;
436 
438  Bool operator<= ( const Double& rhs ) const;
439 };
440 
441 // -----------------------------------------------------------------------------
453 class VInt
454 {
456  VInt();
457 
459  VInt ( const Int& rvalue );
460 
462  operator Int() const;
463 
465  const VInt& operator= ( const Int& rhs );
466 
468  Int operator+= ( const Int& rhs );
469 
471  Int operator-= ( const Int& rhs );
472 
474  Int operator*= ( const Int& rhs );
475 
477  Int operator/= ( const Int& rhs );
478 
480  Int operator%= ( const Int& rhs );
481 
483  Int operator<<= ( const Int& rhs );
484 
486  Int operator>>= ( const Int& rhs );
487 
489  Int operator&= ( const Int& rhs );
490 
492  Int operator|= ( const Int& rhs );
493 
495  Int operator^= ( const Int& rhs );
496 
498  Int operator++();
499 
501  Int operator++ ( int );
502 
504  Int operator--();
505 
507  Int operator-- ( int );
508 };
509 
510 // -----------------------------------------------------------------------------
522 class VUInt
523 {
525  VUInt();
526 
528  VUInt ( const UInt& rvalue );
529 
531  operator UInt() const;
532 
534  const VUInt& operator= ( const UInt& rhs );
535 
537  UInt operator+= ( const UInt& rhs );
538 
540  UInt operator-= ( const UInt& rhs );
541 
543  UInt operator*= ( const UInt& rhs );
544 
546  UInt operator/= ( const UInt& rhs );
547 
549  UInt operator%= ( const UInt& rhs );
550 
552  UInt operator<<= ( const UInt& rhs );
553 
555  UInt operator>>= ( const UInt& rhs );
556 
558  UInt operator&= ( const UInt& rhs );
559 
561  UInt operator|= ( const UInt& rhs );
562 
564  UInt operator^= ( const UInt& rhs );
565 
567  UInt operator++();
568 
570  UInt operator++ ( int );
571 
573  UInt operator--();
574 
576  UInt operator-- ( int );
577 };
578 
579 // -----------------------------------------------------------------------------
591 class VFloat
592 {
593 };
594 
595 // -----------------------------------------------------------------------------
607 class VDouble
608 {
609 };
610 
611 // -----------------------------------------------------------------------------
641 template< class ScalarT >
642 class Pointer
643 {
644 public:
648  ScalarT Load() const;
649 
653  void Store ( const ScalarT& value ) const;
654 
659  ScalarT Exchange ( const ScalarT& value ) const;
660 
666  ScalarT CompareExchange (
667  const ScalarT& newValue,
668  const ScalarT& oldValue ) const;
669 
675  ScalarT CompareExchangeWeak (
676  const ScalarT& newValue,
677  const ScalarT& oldValue ) const;
678 
682  ScalarT Increment() const;
683 
687  ScalarT Decrement() const;
688 
693  ScalarT Add ( const ScalarT& value ) const;
694 
699  ScalarT Sub ( const ScalarT& value ) const;
700 
705  ScalarT Min ( const ScalarT& value ) const;
706 
711  ScalarT Max ( const ScalarT& value ) const;
712 
717  ScalarT And ( const ScalarT& value ) const;
718 
723  ScalarT Or ( const ScalarT& value ) const;
724 
729  ScalarT Xor ( const ScalarT& value ) const;
730 };
731 
732 // -----------------------------------------------------------------------------
733 } // namespace vpp
734 // -----------------------------------------------------------------------------
Int operator%(const Int &rhs) const
Standard remainder operator. Result sign is taken from the first operand.
Bool operator>(const UInt &rhs) const
Standard comparison operator (true if greater).
Bool operator>(const Float &rhs) const
Standard comparison operator (true if greater).
Bool operator!=(const Float &rhs) const
Standard comparison operator (true if not equal).
Float operator*(const Float &rhs) const
Standard multiplication operator.
Shader (GPU-side) data type for mutable variables of boolean type.
Definition: vppLangScalarTypes.hpp:84
Int operator-() const
Standard sign reversal operator.
UInt(unsigned int value)
Construct a r-value from specified C++ value.
Bool(bool value)
Construct a r-value from specified C++ value.
Bool operator>=(const Int &rhs) const
Standard comparison operator (true if greater or equal).
Bool operator==(const UInt &rhs) const
Standard comparison operator (true if equal).
Shader (GPU-side) data type for 32-bit unsigned integer values.
Definition: vppLangScalarTypes.hpp:249
UInt operator/(const UInt &rhs) const
Standard division operator.
Bool operator<=(const Int &rhs) const
Standard comparison operator (true if less or equal).
Int operator~() const
Standard bitwise negation operator.
The VPP namespace.
Definition: main.hpp:1
ScalarT Load() const
Reads the target variable.
Bool operator==(const Float &rhs) const
Standard comparison operator (true if equal).
Int operator*(const Int &rhs) const
Standard multiplication operator.
Bool operator<=(const Float &rhs) const
Standard comparison operator (true if less or equal).
UInt operator &(const UInt &rhs) const
Standard bitwise and operator.
Int operator<<(const Int &rhs) const
Standard left shift operator.
UInt operator%(const UInt &rhs) const
Standard remainder operator.
Int operator/(const Int &rhs) const
Standard division operator.
Bool operator||(const Bool &rhs) const
Standard logical or operator.
ScalarT Add(const ScalarT &value) const
Atomically adds specified value to the target variable. Returns previous value.
Bool operator<=(const Double &rhs) const
Standard comparison operator (true if less or equal).
Bool operator!=(const Double &rhs) const
Standard comparison operator (true if not equal).
ScalarT Xor(const ScalarT &value) const
Atomically computes bitwise XOR of specified value and the target variable and stores it to the targe...
Bool operator>(const Int &rhs) const
Standard comparison operator (true if greater).
Float operator%(const Float &rhs) const
Standard remainder operator. Result sign is taken from the first operand.
Double(double value)
Construct a r-value from specified C++ value.
UInt operator-() const
Standard sign reversal operator.
Double operator-() const
Standard sign reversal operator.
void Store(const ScalarT &value) const
Stores specified value to the target variable.
Int operator^(const Int &rhs) const
Standard bitwise xor operator.
Int operator>>(const Int &rhs) const
Standard right shift operator.
Bool operator!=(const UInt &rhs) const
Standard comparison operator (true if not equal).
UInt operator>>(const UInt &rhs) const
Standard right shift operator.
Bool operator>=(const Double &rhs) const
Standard comparison operator (true if greater or equal).
Bool operator!() const
Standard logical not operator.
Float operator+(const Float &rhs) const
Standard addition operator.
UInt operator<<(const UInt &rhs) const
Standard left shift operator.
Bool operator==(const Double &rhs) const
Standard comparison operator (true if equal).
Shader (GPU-side) data type for mutable variables of 32-bit floating point type.
Definition: vppLangScalarTypes.hpp:591
Bool operator!=(const Bool &rhs) const
Standard comparison operator (true if not equal).
Shader (GPU-side) data type for pointers to mutable variables.
Definition: vppLangScalarTypes.hpp:642
Int(int value)
Construct a r-value from specified C++ value.
Int operator &(const Int &rhs) const
Standard bitwise and operator.
Bool operator &&(const Bool &rhs) const
Standard logical and operator.
Double operator*(const Double &rhs) const
Standard multiplication operator.
Bool operator<=(const UInt &rhs) const
Standard comparison operator (true if less or equal).
Bool operator<(const Int &rhs) const
Standard comparison operator (true if less).
Bool operator<(const Float &rhs) const
Standard comparison operator (true if less).
UInt operator~() const
Standard bitwise negation operator.
UInt operator+(const UInt &rhs) const
Standard addition operator.
Int operator|(const Int &rhs) const
Standard bitwise or operator.
Shader (GPU-side) data type for 32-bit floating point values.
Definition: vppLangScalarTypes.hpp:330
ScalarT Exchange(const ScalarT &value) const
Atomically exchanges specified value with the target variable. Returns previous value.
Bool operator!=(const Int &rhs) const
Standard comparison operator (true if not equal).
Shader (GPU-side) data type for mutable variables of 32-bit unsigned integer type.
Definition: vppLangScalarTypes.hpp:522
ScalarT Increment() const
Atomically increments the target variable.
Bool operator==(const Int &rhs) const
Standard comparison operator (true if equal).
Int operator+(const Int &rhs) const
Standard addition operator.
Bool operator>(const Double &rhs) const
Standard comparison operator (true if greater).
ScalarT Decrement() const
Atomically decrements the target variable.
Shader (GPU-side) data type for mutable variables of 32-bit signed integer type.
Definition: vppLangScalarTypes.hpp:453
UInt operator^(const UInt &rhs) const
Standard bitwise xor operator.
Float operator/(const Float &rhs) const
Standard division operator.
Bool operator==(const Bool &rhs) const
Standard comparison operator (true if equal).
Shader (GPU-side) void data type.
Definition: vppLangScalarTypes.hpp:111
Bool operator>=(const Float &rhs) const
Standard comparison operator (true if greater or equal).
Shader (GPU-side) data type for 32-bit signed integer values.
Definition: vppLangScalarTypes.hpp:167
Shader (GPU-side) data type for 64-bit floating point values.
Definition: vppLangScalarTypes.hpp:393
UInt operator*(const UInt &rhs) const
Standard multiplication operator.
ScalarT CompareExchangeWeak(const ScalarT &newValue, const ScalarT &oldValue) const
Atomically exchanges specified value with the target variable, but only if current value is equal to ...
ScalarT Or(const ScalarT &value) const
Atomically computes bitwise OR of specified value and the target variable and stores it to the target...
Bool operator<(const UInt &rhs) const
Standard comparison operator (true if less).
ScalarT CompareExchange(const ScalarT &newValue, const ScalarT &oldValue) const
Atomically exchanges specified value with the target variable, but only if current value is equal to ...
ScalarT And(const ScalarT &value) const
Atomically computes bitwise AND of specified value and the target variable and stores it to the targe...
ScalarT Max(const ScalarT &value) const
Atomically computes maximum of specified value and the target variable and stores it to the target va...
Bool operator<(const Double &rhs) const
Standard comparison operator (true if less).
Double operator+(const Double &rhs) const
Standard addition operator.
Shader (GPU-side) data type for boolean values.
Definition: vppLangScalarTypes.hpp:45
UInt operator|(const UInt &rhs) const
Standard bitwise or operator.
Double operator%(const Double &rhs) const
Standard remainder operator. Result sign is taken from the first operand.
ScalarT Sub(const ScalarT &value) const
Atomically subtracts specified value from the target variable. Returns previous value.
Float(float value)
Construct a r-value from specified C++ value.
Float operator-() const
Standard sign reversal operator.
Shader (GPU-side) data type for mutable variables of 64-bit floating point type.
Definition: vppLangScalarTypes.hpp:607
Bool operator>=(const UInt &rhs) const
Standard comparison operator (true if greater or equal).
Double operator/(const Double &rhs) const
Standard division operator.
ScalarT Min(const ScalarT &value) const
Atomically computes minimum of specified value and the target variable and stores it to the target va...