1d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//
3d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Licensed under the Apache License, Version 2.0 (the "License");
4d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// you may not use this file except in compliance with the License.
5d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// You may obtain a copy of the License at
666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//
7d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens//    http://www.apache.org/licenses/LICENSE-2.0
866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//
9d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Unless required by applicable law or agreed to in writing, software
10d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// distributed under the License is distributed on an "AS IS" BASIS,
11d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// See the License for the specific language governing permissions and
13d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// limitations under the License.
1466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
1566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#ifndef sw_Stream_hpp
1666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#define sw_Stream_hpp
1766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
1866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "Common/Types.hpp"
1966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
2066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumannamespace sw
2166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman{
2266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	class Resource;
2366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
2485bb4135df3bcfe8dd92ecef925d48ca1b77651eNicolas Capens	enum StreamType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
2566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	{
2666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_COLOR,     // 4 normalized unsigned bytes, ZYXW order
2766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_UDEC3,     // 3 unsigned 10-bit fields
2866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_DEC3N,     // 3 normalized signed 10-bit fields
2966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_INDICES,   // 4 unsigned bytes, stored unconverted into X component
3066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_FLOAT,     // Normalization ignored
3166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_BYTE,
3266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_SBYTE,
3366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_SHORT,
3466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_USHORT,
3557722c954f2ab65726c23c268996dd053a25b139Alexis Hetu		STREAMTYPE_INT,
3657722c954f2ab65726c23c268996dd053a25b139Alexis Hetu		STREAMTYPE_UINT,
3766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_FIXED,     // Normalization ignored (16.16 format)
3866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_HALF,      // Normalization ignored
39f414da6bf30ff29ad24ffcd8d25d4cb472581e10Alexis Hetu		STREAMTYPE_2_10_10_10_INT,
40f414da6bf30ff29ad24ffcd8d25d4cb472581e10Alexis Hetu		STREAMTYPE_2_10_10_10_UINT,
4166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
4266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		STREAMTYPE_LAST = STREAMTYPE_HALF
4366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	};
4466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
4566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	struct StreamResource
4666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	{
4766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		Resource *resource;
4866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		const void *buffer;
4966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		unsigned int stride;
5066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	};
5166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
5266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	struct Stream : public StreamResource
5366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	{
5466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		Stream(Resource *resource = 0, const void *buffer = 0, unsigned int stride = 0)
5566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		{
5666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			this->resource = resource;
5766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			this->buffer = buffer;
5866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			this->stride = stride;
5966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		}
6066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
6166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		Stream &define(StreamType type, unsigned int count, bool normalized = false)
6266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		{
6366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			this->type = type;
6466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			this->count = count;
6566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			this->normalized = normalized;
6666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
6766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			return *this;
6866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		}
6966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
7066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		Stream &define(const void *buffer, StreamType type, unsigned int count, bool normalized = false)
7166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		{
7266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			this->buffer = buffer;
7366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			this->type = type;
7466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			this->count = count;
7566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			this->normalized = normalized;
7666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
7766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			return *this;
7866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		}
7966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
8066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		Stream &defaults()
8166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		{
8266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			static const float4 null = {0, 0, 0, 1};
83d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
8466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			resource = 0;
8566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			buffer = &null;
8666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			stride = 0;
8766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			type = STREAMTYPE_FLOAT;
8866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			count = 0;
8966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			normalized = false;
9066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
9166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			return *this;
9266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		}
9366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
9466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		operator bool() const   // Returns true if stream contains data
9566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		{
9666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			return count != 0;
9766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		}
9866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
9966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		StreamType type;
10066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		unsigned char count;
10166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		bool normalized;
10266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	};
10366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman}
10466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
10566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#endif   // sw_Stream_hpp
106