Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
| 15 | #ifndef sw_Stream_hpp |
| 16 | #define sw_Stream_hpp |
| 17 | |
| 18 | #include "Common/Types.hpp" |
| 19 | |
| 20 | namespace sw |
| 21 | { |
| 22 | class Resource; |
| 23 | |
Nicolas Capens | 28d5a26 | 2017-03-09 15:32:31 -0500 | [diff] [blame] | 24 | enum StreamType ENUM_UNDERLYING_TYPE_UNSIGNED_INT |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 25 | { |
| 26 | STREAMTYPE_COLOR, // 4 normalized unsigned bytes, ZYXW order |
| 27 | STREAMTYPE_UDEC3, // 3 unsigned 10-bit fields |
| 28 | STREAMTYPE_DEC3N, // 3 normalized signed 10-bit fields |
| 29 | STREAMTYPE_INDICES, // 4 unsigned bytes, stored unconverted into X component |
| 30 | STREAMTYPE_FLOAT, // Normalization ignored |
| 31 | STREAMTYPE_BYTE, |
| 32 | STREAMTYPE_SBYTE, |
| 33 | STREAMTYPE_SHORT, |
| 34 | STREAMTYPE_USHORT, |
Alexis Hetu | 25639ea | 2016-03-18 15:00:09 -0400 | [diff] [blame] | 35 | STREAMTYPE_INT, |
| 36 | STREAMTYPE_UINT, |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 37 | STREAMTYPE_FIXED, // Normalization ignored (16.16 format) |
| 38 | STREAMTYPE_HALF, // Normalization ignored |
Alexis Hetu | 70085ba | 2016-05-13 22:40:02 -0400 | [diff] [blame] | 39 | STREAMTYPE_2_10_10_10_INT, |
| 40 | STREAMTYPE_2_10_10_10_UINT, |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 41 | |
Nicolas Capens | 7308297 | 2017-10-27 14:36:36 -0400 | [diff] [blame] | 42 | STREAMTYPE_LAST = STREAMTYPE_2_10_10_10_UINT |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | struct StreamResource |
| 46 | { |
| 47 | Resource *resource; |
| 48 | const void *buffer; |
| 49 | unsigned int stride; |
| 50 | }; |
| 51 | |
| 52 | struct Stream : public StreamResource |
| 53 | { |
| 54 | Stream(Resource *resource = 0, const void *buffer = 0, unsigned int stride = 0) |
| 55 | { |
| 56 | this->resource = resource; |
| 57 | this->buffer = buffer; |
| 58 | this->stride = stride; |
| 59 | } |
| 60 | |
| 61 | Stream &define(StreamType type, unsigned int count, bool normalized = false) |
| 62 | { |
| 63 | this->type = type; |
| 64 | this->count = count; |
| 65 | this->normalized = normalized; |
| 66 | |
| 67 | return *this; |
| 68 | } |
| 69 | |
| 70 | Stream &define(const void *buffer, StreamType type, unsigned int count, bool normalized = false) |
| 71 | { |
| 72 | this->buffer = buffer; |
| 73 | this->type = type; |
| 74 | this->count = count; |
| 75 | this->normalized = normalized; |
| 76 | |
| 77 | return *this; |
| 78 | } |
| 79 | |
| 80 | Stream &defaults() |
| 81 | { |
| 82 | static const float4 null = {0, 0, 0, 1}; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 83 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 84 | resource = 0; |
| 85 | buffer = &null; |
| 86 | stride = 0; |
| 87 | type = STREAMTYPE_FLOAT; |
| 88 | count = 0; |
| 89 | normalized = false; |
| 90 | |
| 91 | return *this; |
| 92 | } |
| 93 | |
| 94 | operator bool() const // Returns true if stream contains data |
| 95 | { |
| 96 | return count != 0; |
| 97 | } |
| 98 | |
| 99 | StreamType type; |
| 100 | unsigned char count; |
| 101 | bool normalized; |
| 102 | }; |
| 103 | } |
| 104 | |
| 105 | #endif // sw_Stream_hpp |