This commit is contained in:
ouczbs 2024-09-21 17:19:22 +08:00
parent 1eee0be937
commit 3ab7bb46f6
23 changed files with 11777 additions and 78 deletions

View File

@ -2,7 +2,7 @@ static_component("core","engine")
add_rules("c++.codegen",{
files = {"include/module/module.h"}
})
add_includedirs("include/3rdparty", {public = true})
add_includedirs("3rdparty", {public = true})
add_headerfiles("include/**.h","include/**.inl", "impl/*.inl")
add_files("src/**.cpp")
add_deps("zlib")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,523 @@
// Auto generated by formatgen on Sep 21 2019
#pragma once
#if !defined(TINYIMAGEFORMAT_BASE_H_) && !defined(TINYIMAGEFORMAT_IMAGEFORMAT_H)
#define TINYIMAGEFORMAT_BASE_H_ 1
/* TinyImageFormat is a library about the encodings of pixels typically
* encountered in real time graphics.
*
* Like modern graphics API it is enumeration based but it also provides an API
* for reasoning about that enumeration programmatically.
*
* Additionally it provide ways of accessing pixels encoded in the specified
* format for most pixel formats. The hope is eventually to get decode to 100%
* but not there yet (119 out of 193 currently).
* This allows you to effectively read/write a large amount of image data.
*
* To assist with working with graphics APIs converters to and from Vulkan,
* D3D12 and Metal. These are self contained and do not require the actual APIs.
*
* Available as either a single header or a version made of 6 headers split into
* functional groups. Use one style or the other but they don't mix.
*
* These files are large due to unrolling and large switches. Functions are
* inlined, allowing the compiler to eliminate and collapse when possible,
* however particularly the Encode/Decode functions aren't near as fast as they
* could be if heavily optimised for specific formats/layouts.
*
* Whilst not optimal due to number of formats it supports, it intends to be
* fast enough that in many cases it will be fine.
*
* Internally every format has a descriptor packed into a 64 bit code word.
* This code word is used to generate the header and it isn't used by the API
* itself, as its been 'burnt' out by the code generator but it can be used at
* runtime if desired and in future its intended to be used for exotic packed
* formats that don't get there own enumeration value but can be expressed
* via a descriptor.
*
* Where possible for C++ users functions are constexpr.
*
* It is MIT licensed and borrows/builds on code/specs including but not
* limited to
* Microsoft's Chris Walbourn DXTextureTool
* Rygerous public domain Half to float (and vice versa) code
* Khronos DFD specifications
* Khronos Vulkan Specification
* Microsoft D3D11/D3D12 Specifications
* Apple Metal documentation
* DDS Loaders from various sources (Humus, Confetti FX, DXTextureTool)
*
* TODO
* ----
* Test CLUT formats and add encode clause
* Add shared component i.e. G8R8G8B8 4:2:x formats
* Add Multi plane formats
* Add compressed format decoders
* Add Block copy (for updating compressed formats)
* Add functions that work on descriptor codes directly
* Add UFLOAT 6 and 7 bit support
* Optional SIMD decode/encode functions
* More tests
*
* Definitions
* -----------
*
* Pixel
* We define a pixel as upto 4 channels representing a single 'colour'
* Its may not be addressable directly but as blocks of related pixels.
* When decode/encoding pixels are presented to the API as 4 floats or doubles.
*
* Logical Channels (TinyImageFormat_LogicalChannel)
* Logical channel are the usual way you would ask for a particular channel,
* so asking about LC_Red while get you data for the red channel, however its
* actually physically encoded in the data.
*
* Physical Channels (TinyImageFormat_PhysicalChannel)
* Physical channels are the inverse of logical channels, that have no meaning
* beyond the position in the data itself.
*
* Both Logical and Physical channels support returning constant 0 or 1
*
* Blocks
* A block is the smallest addressable element this format refers to. Blocks
* have up to 3 dimensions (though no format currently uses the 3rd).
* Blocks are always at least byte aligned.
* For single pixel formats this will be 1x1x1. For something like R1 it would
* be 8x1x1 (8 single bits for 8 pixels).
* For block compressed format a common value is 4x4x1.
* A block for shared channels or very tightly packed this is how many pixels
* are combined into one addressable unit.
*
* API
* ---
* The primary enumeration is simply TinyImageFormat, everything else supports
* this enum.
* All functions, enums etc. are prefixed with TinyImageFormat_, All functions
* also take the format as first parameter. These are often removed in the api
* docs to save space.
*
* Defines
* -------
* TinyImageFormat_Count - how many formats in total
* TinyImageFormat_MaxPixelCountOfBlock - maximum number of pixels in a block
* - for any format (for static decode buffer allocation)
*
* Enums
* -----
* TinyImageFormat - Count entries, one for each format supported
* LogicalChannel - values for logical channel or constants
* - LC_Red - Red channel is specified
* - LC_Green - Green channel is specified
* - LC_Blue - Blue channel is specified
* - LC_Alpha - Alpha channel is specified
* - LC_Depth - Depth channel is specified
* - LC_Stencil - Stencil channel is specified
* - LC_1 - constant 1 will be returned
* - LC_0 - constant 0 will be return
* PhysicalChannel - values for physical channel or constants
* - PC_0 - Leftmost channel
* - PC_1 - 2nd channel
* - PC_2 - 3rd channel
* - PC_3 - 4th channel
* - PC_CONST_1 - constant 1 will be returned
* - PC_CONST_0 - constant 0 will be return
*
* Structs
* -------
* TinyImageFormat_DecodeInput
* - pixel or pixelPlane0 - pixel data ptr or pixel data ptr for plane 0
* - lut or pixelPlane1 - Look Up Table ptr for CLUT formats or pixel plane 1
* - pixelPlane2 to pixelPlane 9 - 7 more planes ptrs
* TinyImageFormat_EncodeOutput
* - pixel or pixelPlane0 - pixel data ptr or pixel data ptr for plane 0
* - pixelPlane2 to pixelPlane 9 - 8 more planes ptrs
* Query Functions
* -----------
* Code - uint64_t with the internal descriptor code
* Name - Human C string with the name of this fmt
* FromName - lookup the format given the name as a C String (fast)
* IsDepthOnly - true if just a depth channel
* IsStencilOnly - true if just a stencil channel
* IsDepthAndStencil - if has both depth and stencil channel
* IsCompressed - true if its a compressed format (aka block)
* IsCLUT - true if data is index into a CLUT (Colour Look Up Table)
* IsFloat - is the data in floating point
* IsNormalised - return true if data will be within 0 to 1 or -1 to 1
* IsSigned - does the data include negatives
* IsSRGB - is the data encoded using sRGB non linear encoding
* IsHomogenous - is the encoding the same for every channel
* WidthOfBlock - How many pixels in the x dimension for a block
* HeightOfBlock - How many pixels in the y dimension for a block
* DepthOfBlock - How many pixels in the z dimension for a block
* PixelCountOfBlock - How many pixels in total for a block
* BitSizeOfBlock - How big in bits is a single block.
* ChannelCount - How many channels are actually encoded
*
* Logical Channel Functions
* -------------------------
* ChannelBitWidth( logical channel ) - how wide in bits is the channel
* Min( logical channel ) - minimum possible value for the channel
* Max( logical channel ) - maximum possible value for the channel
* LogicalChannelToPhysical( logical channel )
* - what physical channel is the logical channel stored in
* - or constant 0 or 1 if its not physically stored
*
* Pixel Decoder Functions (X = F or D version, use F if possible as its faster)
* -----------------------
* CanDecodeLogicalPixelsX - Can DecodeLogicalPixelsX work with this format?
* DecodeLogicalPixelsX( width in blocks, FetchInput, out pixels)
* - pixels should be a pointer to 4 * PixelCounfOfBlack float/doubles
* - does full decode and remapping into logical channels include constants.
* - Returned result can be used directly as RGBA floating point data
* - Input pointers are updated are used, so can be passed back in for
* - next set of pixel decoding if desired.
* - For CLUT formats in.pixel should be the packed pixel data and in.lut is
* - the lookuptable in R8G8B8A8 format of 2^Pbits entries
* - For all others in.pixel should be the packed pixel data
* Pixel Decoder Helper Functions
* -----------------------
* UFloat6AsUintToFloat - returns the value stored as a 6 bit UFloat
* UFloat7AsUintToFloat - returns the value stored as a 7 bit UFloat
* UFloat10AsUintToFloat - returns the value stored as a 10 bit UFloat
* UFloat11AsUintToFloat - returns the value stored as a 11 bit UFloat
* SharedE5B9G9R9UFloatToFloats - return the pixel stored in shared
* - shared 5 bit exponent, 9 bit mantissa for RGB
* HalfAsUintToFloat - returns the value stored as a 16 bit SFloat
* BFloatAsUintToFloat - returns the value stored as a 16 bit BFloat
* LookupSRGB - returns the value for an 8 bit sRGB encoded value
*
* Pixel Encoder Functions (X = F or D version, use F if possible as its faster)
* -----------------------
* CanEncodeLogicalPixelsX - Can EncodeLogicalPixelsX work with this format?
* EncodeLogicalPixelsX( width in blocks, in pixels, PutOutput)
* - pixels should be a pointer to 4 * PixelCounfOfBlack float/doubles
* - does full encode and remapping into logical channels
* - Output pointers are updated are used, so can be passed back in for
* - next set of pixel encoding if desired.
* - out.pixel is where colour information should be stored
*
* Pixel Encoder Helper Functions
* -----------------------
* FloatToUFloat6AsUint - Encodes float into a 6 bit UFloat
* FloatToUFloat7AsUint - Encodes float into a 7 bit UFloat
* FloatToUFloat10AsUint - Encodes float into a 10 bit UFloat
* FloatToUFloat11AsUint - Encodes float into 11 bit UFloat
* FloatRGBToRGB9E5AsUint32 - Encodes a float RGB into RGB9E5
* FloatToHalfAsUint - Encodes a float into a 16 bit SFloat
* FloatToBFloatAsUint - Encodes a float into a 16 bit BFloat
* FloatToSRGB - encodes a float to sRGB assuming input is 0-1
*
* Physical Channel Functions (in general use the Logical Channels)
* ------------------
* ChannelBitWidthAtPhysical( phys channel ) - how wide in bits for this channel
* MinAtPhysical( phys channel ) - min possible value for this channel
* MaxAtPhysical( phys channel ) - max possible value for this channel
* PhysicalChannelToLogical(phys channel)
* - what logical channel does a physical channel map to.
* - Or a constant 0 or 1
*
* Graphics API Functions
* ------------------
* FromVkFormat( VkFormat ) - converts from or UNDEFINED if not possible
* ToVkFormat - converts to or VK_FORMAT_UNDEFINED if not possible
* FromDXGI_FORMAT( DXGI_FORMAT) converts from or UNDEFINED if not possible
* ToDXGI_FORMAT - converts to or DXGI_FORMAT_UNKNOWN if not possible
* DXGI_FORMATToTypeless - returns the DXGI typeless format if possible
* FromMetal( MTLPixelFormat ) - converts from or UNDEFINED if not possible
* ToMetal - converts to or MTLPixelFormatInvalid if not possible
*
*
*/
typedef enum TinyImageFormat {
TinyImageFormat_UNDEFINED = 0,
TinyImageFormat_R1_UNORM = 1,
TinyImageFormat_R2_UNORM = 2,
TinyImageFormat_R4_UNORM = 3,
TinyImageFormat_R4G4_UNORM = 4,
TinyImageFormat_G4R4_UNORM = 5,
TinyImageFormat_A8_UNORM = 6,
TinyImageFormat_R8_UNORM = 7,
TinyImageFormat_R8_SNORM = 8,
TinyImageFormat_R8_UINT = 9,
TinyImageFormat_R8_SINT = 10,
TinyImageFormat_R8_SRGB = 11,
TinyImageFormat_B2G3R3_UNORM = 12,
TinyImageFormat_R4G4B4A4_UNORM = 13,
TinyImageFormat_R4G4B4X4_UNORM = 14,
TinyImageFormat_B4G4R4A4_UNORM = 15,
TinyImageFormat_B4G4R4X4_UNORM = 16,
TinyImageFormat_A4R4G4B4_UNORM = 17,
TinyImageFormat_X4R4G4B4_UNORM = 18,
TinyImageFormat_A4B4G4R4_UNORM = 19,
TinyImageFormat_X4B4G4R4_UNORM = 20,
TinyImageFormat_R5G6B5_UNORM = 21,
TinyImageFormat_B5G6R5_UNORM = 22,
TinyImageFormat_R5G5B5A1_UNORM = 23,
TinyImageFormat_B5G5R5A1_UNORM = 24,
TinyImageFormat_A1B5G5R5_UNORM = 25,
TinyImageFormat_A1R5G5B5_UNORM = 26,
TinyImageFormat_R5G5B5X1_UNORM = 27,
TinyImageFormat_B5G5R5X1_UNORM = 28,
TinyImageFormat_X1R5G5B5_UNORM = 29,
TinyImageFormat_X1B5G5R5_UNORM = 30,
TinyImageFormat_B2G3R3A8_UNORM = 31,
TinyImageFormat_R8G8_UNORM = 32,
TinyImageFormat_R8G8_SNORM = 33,
TinyImageFormat_G8R8_UNORM = 34,
TinyImageFormat_G8R8_SNORM = 35,
TinyImageFormat_R8G8_UINT = 36,
TinyImageFormat_R8G8_SINT = 37,
TinyImageFormat_R8G8_SRGB = 38,
TinyImageFormat_R16_UNORM = 39,
TinyImageFormat_R16_SNORM = 40,
TinyImageFormat_R16_UINT = 41,
TinyImageFormat_R16_SINT = 42,
TinyImageFormat_R16_SFLOAT = 43,
TinyImageFormat_R16_SBFLOAT = 44,
TinyImageFormat_R8G8B8_UNORM = 45,
TinyImageFormat_R8G8B8_SNORM = 46,
TinyImageFormat_R8G8B8_UINT = 47,
TinyImageFormat_R8G8B8_SINT = 48,
TinyImageFormat_R8G8B8_SRGB = 49,
TinyImageFormat_B8G8R8_UNORM = 50,
TinyImageFormat_B8G8R8_SNORM = 51,
TinyImageFormat_B8G8R8_UINT = 52,
TinyImageFormat_B8G8R8_SINT = 53,
TinyImageFormat_B8G8R8_SRGB = 54,
TinyImageFormat_R8G8B8A8_UNORM = 55,
TinyImageFormat_R8G8B8A8_SNORM = 56,
TinyImageFormat_R8G8B8A8_UINT = 57,
TinyImageFormat_R8G8B8A8_SINT = 58,
TinyImageFormat_R8G8B8A8_SRGB = 59,
TinyImageFormat_B8G8R8A8_UNORM = 60,
TinyImageFormat_B8G8R8A8_SNORM = 61,
TinyImageFormat_B8G8R8A8_UINT = 62,
TinyImageFormat_B8G8R8A8_SINT = 63,
TinyImageFormat_B8G8R8A8_SRGB = 64,
TinyImageFormat_R8G8B8X8_UNORM = 65,
TinyImageFormat_B8G8R8X8_UNORM = 66,
TinyImageFormat_R16G16_UNORM = 67,
TinyImageFormat_G16R16_UNORM = 68,
TinyImageFormat_R16G16_SNORM = 69,
TinyImageFormat_G16R16_SNORM = 70,
TinyImageFormat_R16G16_UINT = 71,
TinyImageFormat_R16G16_SINT = 72,
TinyImageFormat_R16G16_SFLOAT = 73,
TinyImageFormat_R16G16_SBFLOAT = 74,
TinyImageFormat_R32_UINT = 75,
TinyImageFormat_R32_SINT = 76,
TinyImageFormat_R32_SFLOAT = 77,
TinyImageFormat_A2R10G10B10_UNORM = 78,
TinyImageFormat_A2R10G10B10_UINT = 79,
TinyImageFormat_A2R10G10B10_SNORM = 80,
TinyImageFormat_A2R10G10B10_SINT = 81,
TinyImageFormat_A2B10G10R10_UNORM = 82,
TinyImageFormat_A2B10G10R10_UINT = 83,
TinyImageFormat_A2B10G10R10_SNORM = 84,
TinyImageFormat_A2B10G10R10_SINT = 85,
TinyImageFormat_R10G10B10A2_UNORM = 86,
TinyImageFormat_R10G10B10A2_UINT = 87,
TinyImageFormat_R10G10B10A2_SNORM = 88,
TinyImageFormat_R10G10B10A2_SINT = 89,
TinyImageFormat_B10G10R10A2_UNORM = 90,
TinyImageFormat_B10G10R10A2_UINT = 91,
TinyImageFormat_B10G10R10A2_SNORM = 92,
TinyImageFormat_B10G10R10A2_SINT = 93,
TinyImageFormat_B10G11R11_UFLOAT = 94,
TinyImageFormat_E5B9G9R9_UFLOAT = 95,
TinyImageFormat_R16G16B16_UNORM = 96,
TinyImageFormat_R16G16B16_SNORM = 97,
TinyImageFormat_R16G16B16_UINT = 98,
TinyImageFormat_R16G16B16_SINT = 99,
TinyImageFormat_R16G16B16_SFLOAT = 100,
TinyImageFormat_R16G16B16_SBFLOAT = 101,
TinyImageFormat_R16G16B16A16_UNORM = 102,
TinyImageFormat_R16G16B16A16_SNORM = 103,
TinyImageFormat_R16G16B16A16_UINT = 104,
TinyImageFormat_R16G16B16A16_SINT = 105,
TinyImageFormat_R16G16B16A16_SFLOAT = 106,
TinyImageFormat_R16G16B16A16_SBFLOAT = 107,
TinyImageFormat_R32G32_UINT = 108,
TinyImageFormat_R32G32_SINT = 109,
TinyImageFormat_R32G32_SFLOAT = 110,
TinyImageFormat_R32G32B32_UINT = 111,
TinyImageFormat_R32G32B32_SINT = 112,
TinyImageFormat_R32G32B32_SFLOAT = 113,
TinyImageFormat_R32G32B32A32_UINT = 114,
TinyImageFormat_R32G32B32A32_SINT = 115,
TinyImageFormat_R32G32B32A32_SFLOAT = 116,
TinyImageFormat_R64_UINT = 117,
TinyImageFormat_R64_SINT = 118,
TinyImageFormat_R64_SFLOAT = 119,
TinyImageFormat_R64G64_UINT = 120,
TinyImageFormat_R64G64_SINT = 121,
TinyImageFormat_R64G64_SFLOAT = 122,
TinyImageFormat_R64G64B64_UINT = 123,
TinyImageFormat_R64G64B64_SINT = 124,
TinyImageFormat_R64G64B64_SFLOAT = 125,
TinyImageFormat_R64G64B64A64_UINT = 126,
TinyImageFormat_R64G64B64A64_SINT = 127,
TinyImageFormat_R64G64B64A64_SFLOAT = 128,
TinyImageFormat_D16_UNORM = 129,
TinyImageFormat_X8_D24_UNORM = 130,
TinyImageFormat_D32_SFLOAT = 131,
TinyImageFormat_S8_UINT = 132,
TinyImageFormat_D16_UNORM_S8_UINT = 133,
TinyImageFormat_D24_UNORM_S8_UINT = 134,
TinyImageFormat_D32_SFLOAT_S8_UINT = 135,
TinyImageFormat_DXBC1_RGB_UNORM = 136,
TinyImageFormat_DXBC1_RGB_SRGB = 137,
TinyImageFormat_DXBC1_RGBA_UNORM = 138,
TinyImageFormat_DXBC1_RGBA_SRGB = 139,
TinyImageFormat_DXBC2_UNORM = 140,
TinyImageFormat_DXBC2_SRGB = 141,
TinyImageFormat_DXBC3_UNORM = 142,
TinyImageFormat_DXBC3_SRGB = 143,
TinyImageFormat_DXBC4_UNORM = 144,
TinyImageFormat_DXBC4_SNORM = 145,
TinyImageFormat_DXBC5_UNORM = 146,
TinyImageFormat_DXBC5_SNORM = 147,
TinyImageFormat_DXBC6H_UFLOAT = 148,
TinyImageFormat_DXBC6H_SFLOAT = 149,
TinyImageFormat_DXBC7_UNORM = 150,
TinyImageFormat_DXBC7_SRGB = 151,
TinyImageFormat_PVRTC1_2BPP_UNORM = 152,
TinyImageFormat_PVRTC1_4BPP_UNORM = 153,
TinyImageFormat_PVRTC2_2BPP_UNORM = 154,
TinyImageFormat_PVRTC2_4BPP_UNORM = 155,
TinyImageFormat_PVRTC1_2BPP_SRGB = 156,
TinyImageFormat_PVRTC1_4BPP_SRGB = 157,
TinyImageFormat_PVRTC2_2BPP_SRGB = 158,
TinyImageFormat_PVRTC2_4BPP_SRGB = 159,
TinyImageFormat_ETC2_R8G8B8_UNORM = 160,
TinyImageFormat_ETC2_R8G8B8_SRGB = 161,
TinyImageFormat_ETC2_R8G8B8A1_UNORM = 162,
TinyImageFormat_ETC2_R8G8B8A1_SRGB = 163,
TinyImageFormat_ETC2_R8G8B8A8_UNORM = 164,
TinyImageFormat_ETC2_R8G8B8A8_SRGB = 165,
TinyImageFormat_ETC2_EAC_R11_UNORM = 166,
TinyImageFormat_ETC2_EAC_R11_SNORM = 167,
TinyImageFormat_ETC2_EAC_R11G11_UNORM = 168,
TinyImageFormat_ETC2_EAC_R11G11_SNORM = 169,
TinyImageFormat_ASTC_4x4_UNORM = 170,
TinyImageFormat_ASTC_4x4_SRGB = 171,
TinyImageFormat_ASTC_5x4_UNORM = 172,
TinyImageFormat_ASTC_5x4_SRGB = 173,
TinyImageFormat_ASTC_5x5_UNORM = 174,
TinyImageFormat_ASTC_5x5_SRGB = 175,
TinyImageFormat_ASTC_6x5_UNORM = 176,
TinyImageFormat_ASTC_6x5_SRGB = 177,
TinyImageFormat_ASTC_6x6_UNORM = 178,
TinyImageFormat_ASTC_6x6_SRGB = 179,
TinyImageFormat_ASTC_8x5_UNORM = 180,
TinyImageFormat_ASTC_8x5_SRGB = 181,
TinyImageFormat_ASTC_8x6_UNORM = 182,
TinyImageFormat_ASTC_8x6_SRGB = 183,
TinyImageFormat_ASTC_8x8_UNORM = 184,
TinyImageFormat_ASTC_8x8_SRGB = 185,
TinyImageFormat_ASTC_10x5_UNORM = 186,
TinyImageFormat_ASTC_10x5_SRGB = 187,
TinyImageFormat_ASTC_10x6_UNORM = 188,
TinyImageFormat_ASTC_10x6_SRGB = 189,
TinyImageFormat_ASTC_10x8_UNORM = 190,
TinyImageFormat_ASTC_10x8_SRGB = 191,
TinyImageFormat_ASTC_10x10_UNORM = 192,
TinyImageFormat_ASTC_10x10_SRGB = 193,
TinyImageFormat_ASTC_12x10_UNORM = 194,
TinyImageFormat_ASTC_12x10_SRGB = 195,
TinyImageFormat_ASTC_12x12_UNORM = 196,
TinyImageFormat_ASTC_12x12_SRGB = 197,
TinyImageFormat_CLUT_P4 = 198,
TinyImageFormat_CLUT_P4A4 = 199,
TinyImageFormat_CLUT_P8 = 200,
TinyImageFormat_CLUT_P8A8 = 201,
TinyImageFormat_R4G4B4A4_UNORM_PACK16 = 202,
TinyImageFormat_B4G4R4A4_UNORM_PACK16 = 203,
TinyImageFormat_R5G6B5_UNORM_PACK16 = 204,
TinyImageFormat_B5G6R5_UNORM_PACK16 = 205,
TinyImageFormat_R5G5B5A1_UNORM_PACK16 = 206,
TinyImageFormat_B5G5R5A1_UNORM_PACK16 = 207,
TinyImageFormat_A1R5G5B5_UNORM_PACK16 = 208,
TinyImageFormat_G16B16G16R16_422_UNORM = 209,
TinyImageFormat_B16G16R16G16_422_UNORM = 210,
TinyImageFormat_R12X4G12X4B12X4A12X4_UNORM_4PACK16 = 211,
TinyImageFormat_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16 = 212,
TinyImageFormat_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16 = 213,
TinyImageFormat_R10X6G10X6B10X6A10X6_UNORM_4PACK16 = 214,
TinyImageFormat_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16 = 215,
TinyImageFormat_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16 = 216,
TinyImageFormat_G8B8G8R8_422_UNORM = 217,
TinyImageFormat_B8G8R8G8_422_UNORM = 218,
TinyImageFormat_G8_B8_R8_3PLANE_420_UNORM = 219,
TinyImageFormat_G8_B8R8_2PLANE_420_UNORM = 220,
TinyImageFormat_G8_B8_R8_3PLANE_422_UNORM = 221,
TinyImageFormat_G8_B8R8_2PLANE_422_UNORM = 222,
TinyImageFormat_G8_B8_R8_3PLANE_444_UNORM = 223,
TinyImageFormat_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 = 224,
TinyImageFormat_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16 = 225,
TinyImageFormat_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16 = 226,
TinyImageFormat_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 = 227,
TinyImageFormat_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16 = 228,
TinyImageFormat_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16 = 229,
TinyImageFormat_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16 = 230,
TinyImageFormat_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16 = 231,
TinyImageFormat_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16 = 232,
TinyImageFormat_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16 = 233,
TinyImageFormat_G16_B16_R16_3PLANE_420_UNORM = 234,
TinyImageFormat_G16_B16_R16_3PLANE_422_UNORM = 235,
TinyImageFormat_G16_B16_R16_3PLANE_444_UNORM = 236,
TinyImageFormat_G16_B16R16_2PLANE_420_UNORM = 237,
TinyImageFormat_G16_B16R16_2PLANE_422_UNORM = 238,
} TinyImageFormat;
typedef enum TinyImageFormat_LogicalChannel {
TinyImageFormat_LC_Red = 0,
TinyImageFormat_LC_Green = 1,
TinyImageFormat_LC_Blue = 2,
TinyImageFormat_LC_Alpha = 3,
TinyImageFormat_LC_Depth = 0,
TinyImageFormat_LC_Stencil = 1,
TinyImageFormat_LC_0 = -1,
TinyImageFormat_LC_1 = -2,
} TinyImageFormat_LogicalChannel;
typedef enum TinyImageFormat_PhysicalChannel {
TinyImageFormat_PC_0 = 0,
TinyImageFormat_PC_1 = 1,
TinyImageFormat_PC_2 = 2,
TinyImageFormat_PC_3 = 3,
TinyImageFormat_PC_CONST_0 = -1,
TinyImageFormat_PC_CONST_1 = -2,
} TinyImageFormat_PhysicalChannel;
#define TinyImageFormat_Count 239U
typedef struct TinyImageFormat_DecodeInput {
union { void const* pixel; void const* pixelPlane0; };
union { void const* lut; void const* pixelPlane1; };
void const* pixelPlane2;
void const* pixelPlane3;
void const* pixelPlane4;
void const* pixelPlane5;
void const* pixelPlane6;
void const* pixelPlane7;
void const* pixelPlane8;
void const* pixelPlane9;
} TinyImageFormat_FetchInput;
typedef struct TinyImageFormat_EncodeOutput {
union { void const* pixel; void const* pixelPlane0; };
void const* pixelPlane1;
void const* pixelPlane2;
void const* pixelPlane3;
void const* pixelPlane4;
void const* pixelPlane5;
void const* pixelPlane6;
void const* pixelPlane7;
void const* pixelPlane8;
void const* pixelPlane9;
} TinyImageFormat_PutOutput;
#endif // TINYIMAGEFORMAT_BASE_H_

View File

@ -0,0 +1,281 @@
#pragma once
typedef enum TinyImageFormat_Namespace {
TinyImageFormat_NAMESPACE_PACK = 0ULL,
TinyImageFormat_NAMESPACE_DEPTH_STENCIL = 1ULL,
TinyImageFormat_NAMESPACE_DXTC = 2ULL,
TinyImageFormat_NAMESPACE_PVRTC = 3ULL,
TinyImageFormat_NAMESPACE_ETC = 4ULL,
TinyImageFormat_NAMESPACE_ASTC = 5ULL,
TinyImageFormat_NAMESPACE_CLUT = 6ULL,
} TinyImageFormat_Namespace;
typedef enum TinyImageFormat_Pack_Special {
TinyImageFormat_PACK_SPECIAL_NONE = 0ULL,
TinyImageFormat_PACK_SPECIAL_PACK = 1ULL,
TinyImageFormat_PACK_SPECIAL_MULTI2 = 2ULL,
TinyImageFormat_PACK_SPECIAL_MULTI4 = 3ULL,
TinyImageFormat_PACK_SPECIAL_MULTI8 = 4ULL,
} TinyImageFormat_Pack_Special;
typedef enum TinyImageFormat_Pack_Bits {
TinyImageFormat_PACK_BITS_0 = 0ULL,
TinyImageFormat_PACK_BITS_1 = 1ULL,
TinyImageFormat_PACK_BITS_2 = 2ULL,
TinyImageFormat_PACK_BITS_3 = 3ULL,
TinyImageFormat_PACK_BITS_4 = 4ULL,
TinyImageFormat_PACK_BITS_5 = 5ULL,
TinyImageFormat_PACK_BITS_6 = 6ULL,
TinyImageFormat_PACK_BITS_7 = 7ULL,
TinyImageFormat_PACK_BITS_8 = 8ULL,
TinyImageFormat_PACK_BITS_9 = 9ULL,
TinyImageFormat_PACK_BITS_10 = 10ULL,
TinyImageFormat_PACK_BITS_11 = 11ULL,
TinyImageFormat_PACK_BITS_12 = 12ULL,
TinyImageFormat_PACK_BITS_16 = 13ULL,
TinyImageFormat_PACK_BITS_24 = 14ULL,
TinyImageFormat_PACK_BITS_32 = 15ULL,
TinyImageFormat_PACK_BITS_64 = 16ULL,
} TinyImageFormat_Pack_Bits;
typedef enum TinyImageFormat_Pack_Swizzle {
TinyImageFormat_PACK_SWIZZLE_R = 0ULL,
TinyImageFormat_PACK_SWIZZLE_G = 1ULL,
TinyImageFormat_PACK_SWIZZLE_B = 2ULL,
TinyImageFormat_PACK_SWIZZLE_A = 3ULL,
TinyImageFormat_PACK_SWIZZLE_0 = 4ULL,
TinyImageFormat_PACK_SWIZZLE_1 = 5ULL,
} TinyImageFormat_Pack_Swizzle;
typedef enum TinyImageFormat_Pack_Type {
TinyImageFormat_PACK_TYPE_NONE = 0ULL,
TinyImageFormat_PACK_TYPE_UNORM = 1ULL,
TinyImageFormat_PACK_TYPE_SNORM = 2ULL,
TinyImageFormat_PACK_TYPE_UINT = 3ULL,
TinyImageFormat_PACK_TYPE_SINT = 4ULL,
TinyImageFormat_PACK_TYPE_UFLOAT = 5ULL,
TinyImageFormat_PACK_TYPE_SFLOAT = 6ULL,
TinyImageFormat_PACK_TYPE_SRGB = 7ULL,
TinyImageFormat_PACK_TYPE_SBFLOAT = 8ULL,
} TinyImageFormat_Pack_Type;
typedef enum TinyImageFormat_DepthStencil_Total_Size {
TinyImageFormat_DEPTH_STENCIL_TOTAL_SIZE_8 = 0ULL,
TinyImageFormat_DEPTH_STENCIL_TOTAL_SIZE_16 = 1ULL,
TinyImageFormat_DEPTH_STENCIL_TOTAL_SIZE_32 = 2ULL,
TinyImageFormat_DEPTH_STENCIL_TOTAL_SIZE_64 = 3ULL,
} TinyImageFormat_DepthStencil_Total_Size;
typedef enum TinyImageFormat_DepthStencil_Bits {
TinyImageFormat_DEPTH_STENCIL_BITS_0 = 0ULL,
TinyImageFormat_DEPTH_STENCIL_BITS_8 = 1ULL,
TinyImageFormat_DEPTH_STENCIL_BITS_16 = 2ULL,
TinyImageFormat_DEPTH_STENCIL_BITS_24 = 3ULL,
TinyImageFormat_DEPTH_STENCIL_BITS_32 = 4ULL,
} TinyImageFormat_DepthStencil_Bits;
typedef enum TinyImageFormat_DepthStencil_Swizzle {
TinyImageFormat_DEPTH_STENCIL_SWIZZLE_D = 0ULL,
TinyImageFormat_DEPTH_STENCIL_SWIZZLE_S = 1ULL,
TinyImageFormat_DEPTH_STENCIL_SWIZZLE_0 = 2ULL,
} TinyImageFormat_DepthStencil_Swizzle;
typedef enum TinyImageFormat_DepthStencil_Type {
TinyImageFormat_DEPTH_STENCIL_TYPE_NONE = 0ULL,
TinyImageFormat_DEPTH_STENCIL_TYPE_UNORM = 1ULL,
TinyImageFormat_DEPTH_STENCIL_TYPE_UINT = 2ULL,
TinyImageFormat_DEPTH_STENCIL_TYPE_SFLOAT = 3ULL,
} TinyImageFormat_DepthStencil_Type;
typedef enum TinyImageFormat_DXTC_Alpha {
TinyImageFormat_DXTC_ALPHA_NONE = 0ULL,
TinyImageFormat_DXTC_ALPHA_PUNCHTHROUGH = 1ULL,
TinyImageFormat_DXTC_ALPHA_BLOCK = 2ULL,
TinyImageFormat_DXTC_ALPHA_FULL = 3ULL,
} TinyImageFormat_DXTC_Alpha;
typedef enum TinyImageFormat_DXTC_Type {
TinyImageFormat_DXTC_TYPE_UNORM = 0ULL,
TinyImageFormat_DXTC_TYPE_SNORM = 1ULL,
TinyImageFormat_DXTC_TYPE_SRGB = 2ULL,
TinyImageFormat_DXTC_TYPE_SFLOAT = 3ULL,
TinyImageFormat_DXTC_TYPE_UFLOAT = 4ULL,
} TinyImageFormat_DXTC_Type;
typedef enum TinyImageFormat_DXTC_BlockBytes {
TinyImageFormat_DXTC_BLOCKBYTES_8 = 0ULL,
TinyImageFormat_DXTC_BLOCKBYTES_16 = 1ULL,
} TinyImageFormat_DXTC_BlockBytes;
typedef enum TinyImageFormat_DXTC_ChannelCount {
TinyImageFormat_DXTC_CHANNELCOUNT_1 = 0ULL,
TinyImageFormat_DXTC_CHANNELCOUNT_2 = 1ULL,
TinyImageFormat_DXTC_CHANNELCOUNT_3 = 2ULL,
TinyImageFormat_DXTC_CHANNELCOUNT_4 = 3ULL,
} TinyImageFormat_DXTC_ChannelCount;
typedef enum TinyImageFormat_DXTC_ModeCount {
TinyImageFormat_DXTC_MODECOUNT_1 = 0ULL,
TinyImageFormat_DXTC_MODECOUNT_8 = 1ULL,
TinyImageFormat_DXTC_MODECOUNT_14 = 2ULL,
} TinyImageFormat_DXTC_ModeCount;
typedef enum TinyImageFormat_PVRTC_Version {
TinyImageFormat_PVRTC_VERSION_V1 = 0ULL,
TinyImageFormat_PVRTC_VERSION_V2 = 1ULL,
} TinyImageFormat_PVRTC_Version;
typedef enum TinyImageFormat_PVRTC_Bits {
TinyImageFormat_PVRTC_BITS_2 = 0ULL,
TinyImageFormat_PVRTC_BITS_4 = 1ULL,
} TinyImageFormat_PVRTC_Bits;
typedef enum TinyImageFormat_PVRTC_Type {
TinyImageFormat_PVRTC_TYPE_UNORM = 0ULL,
TinyImageFormat_PVRTC_TYPE_SRGB = 1ULL,
} TinyImageFormat_PVRTC_Type;
typedef enum TinyImageFormat_ETC_Bits {
TinyImageFormat_ETC_BITS_8 = 0ULL,
TinyImageFormat_ETC_BITS_11 = 1ULL,
} TinyImageFormat_ETC_Bits;
typedef enum TinyImageFormat_ETC_Alpha {
TinyImageFormat_ETC_ALPHA_NONE = 0ULL,
TinyImageFormat_ETC_ALPHA_PUNCHTHROUGH = 1ULL,
TinyImageFormat_ETC_ALPHA_BLOCK = 2ULL,
} TinyImageFormat_ETC_Alpha;
typedef enum TinyImageFormat_ETC_Type {
TinyImageFormat_ETC_TYPE_UNORM = 0ULL,
TinyImageFormat_ETC_TYPE_SNORM = 1ULL,
TinyImageFormat_ETC_TYPE_SRGB = 2ULL,
} TinyImageFormat_ETC_Type;
typedef enum TinyImageFormat_ETC_ChannelCount {
TinyImageFormat_ETC_CHANNELCOUNT_1 = 0ULL,
TinyImageFormat_ETC_CHANNELCOUNT_2 = 1ULL,
TinyImageFormat_ETC_CHANNELCOUNT_3 = 2ULL,
TinyImageFormat_ETC_CHANNELCOUNT_4 = 3ULL,
} TinyImageFormat_ETC_ChannelCount;
typedef enum TinyImageFormat_ASTC_Size {
TinyImageFormat_ASTC_SIZE_1 = 0ULL,
TinyImageFormat_ASTC_SIZE_4 = 2ULL,
TinyImageFormat_ASTC_SIZE_5 = 3ULL,
TinyImageFormat_ASTC_SIZE_6 = 4ULL,
TinyImageFormat_ASTC_SIZE_8 = 5ULL,
TinyImageFormat_ASTC_SIZE_10 = 6ULL,
TinyImageFormat_ASTC_SIZE_12 = 7ULL,
} TinyImageFormat_ASTC_Size;
typedef enum TinyImageFormat_ASTC_Type {
TinyImageFormat_ASTC_TYPE_UNORM = 0ULL,
TinyImageFormat_ASTC_TYPE_SRGB = 1ULL,
} TinyImageFormat_ASTC_Type;
typedef enum TinyImageFormat_CLUT_BlockSize {
TinyImageFormat_CLUT_BLOCKSIZE_1 = 0ULL,
TinyImageFormat_CLUT_BLOCKSIZE_2 = 1ULL,
TinyImageFormat_CLUT_BLOCKSIZE_4 = 2ULL,
TinyImageFormat_CLUT_BLOCKSIZE_8 = 3ULL,
} TinyImageFormat_CLUT_BlockSize;
typedef enum TinyImageFormat_CLUT_Bits {
TinyImageFormat_CLUT_BITS_0 = 0ULL,
TinyImageFormat_CLUT_BITS_1 = 1ULL,
TinyImageFormat_CLUT_BITS_2 = 2ULL,
TinyImageFormat_CLUT_BITS_4 = 3ULL,
TinyImageFormat_CLUT_BITS_8 = 4ULL,
} TinyImageFormat_CLUT_Bits;
typedef enum TinyImageFormat_CLUT_Type {
TinyImageFormat_CLUT_TYPE_NONE = 0ULL,
TinyImageFormat_CLUT_TYPE_RGB = 1ULL,
TinyImageFormat_CLUT_TYPE_SINGLE = 2ULL,
TinyImageFormat_CLUT_TYPE_EXPLICIT_ALPHA = 3ULL,
} TinyImageFormat_CLUT_Type;
typedef enum TinyImageFormat_Bits {
TinyImageFormat_NAMESPACE_REQUIRED_BITS = 12ULL,
TinyImageFormat_NAMESPACE_MASK = (1 << TinyImageFormat_NAMESPACE_REQUIRED_BITS) - 1,
TinyImageFormat_PACK_SPECIAL_REQUIRED_BITS = 3ULL,
TinyImageFormat_PACK_BITS_REQUIRED_BITS = 5ULL,
TinyImageFormat_PACK_SWIZZLE_REQUIRED_BITS = 3ULL,
TinyImageFormat_PACK_TYPE_REQUIRED_BITS = 4ULL,
TinyImageFormat_PACK_NUM_CHANNELS = 4ULL,
TinyImageFormat_PACK_SPECIAL_SHIFT = (TinyImageFormat_NAMESPACE_REQUIRED_BITS),
TinyImageFormat_PACK_BITS_SHIFT = (TinyImageFormat_PACK_SPECIAL_REQUIRED_BITS + TinyImageFormat_PACK_SPECIAL_SHIFT),
TinyImageFormat_PACK_SWIZZLE_SHIFT =
((TinyImageFormat_PACK_BITS_REQUIRED_BITS * TinyImageFormat_PACK_NUM_CHANNELS) + TinyImageFormat_PACK_BITS_SHIFT),
TinyImageFormat_PACK_TYPE_SHIFT = ((TinyImageFormat_PACK_SWIZZLE_REQUIRED_BITS * TinyImageFormat_PACK_NUM_CHANNELS)
+ TinyImageFormat_PACK_SWIZZLE_SHIFT),
TinyImageFormat_DEPTH_STENCIL_TOTAL_SIZE_REQUIRED_BITS = 2ULL,
TinyImageFormat_DEPTH_STENCIL_BITS_REQUIRED_BITS = 3ULL,
TinyImageFormat_DEPTH_STENCIL_SWIZZLE_REQUIRED_BITS = 2ULL,
TinyImageFormat_DEPTH_STENCIL_TYPE_REQUIRED_BITS = 2ULL,
TinyImageFormat_DEPTH_STENCIL_NUM_CHANNELS = 2ULL,
TinyImageFormat_DEPTH_STENCIL_TOTAL_SIZE_SHIFT = (TinyImageFormat_NAMESPACE_REQUIRED_BITS),
TinyImageFormat_DEPTH_STENCIL_BITS_SHIFT =
((TinyImageFormat_DEPTH_STENCIL_TOTAL_SIZE_REQUIRED_BITS) + TinyImageFormat_DEPTH_STENCIL_TOTAL_SIZE_SHIFT),
TinyImageFormat_DEPTH_STENCIL_SWIZZLE_SHIFT =
((TinyImageFormat_DEPTH_STENCIL_BITS_REQUIRED_BITS * TinyImageFormat_DEPTH_STENCIL_NUM_CHANNELS)
+ TinyImageFormat_DEPTH_STENCIL_BITS_SHIFT),
TinyImageFormat_DEPTH_STENCIL_TYPE_SHIFT =
((TinyImageFormat_DEPTH_STENCIL_SWIZZLE_REQUIRED_BITS * TinyImageFormat_DEPTH_STENCIL_NUM_CHANNELS)
+ TinyImageFormat_DEPTH_STENCIL_SWIZZLE_SHIFT),
TinyImageFormat_DXTC_ALPHA_REQUIRED_BITS = 2ULL,
TinyImageFormat_DXTC_TYPE_REQUIRED_BITS = 3ULL,
TinyImageFormat_DXTC_BLOCKBYTES_REQUIRED_BITS = 2ULL,
TinyImageFormat_DXTC_CHANNELCOUNT_REQUIRED_BITS = 2ULL,
TinyImageFormat_DXTC_MODECOUNT_REQUIRED_BITS = 3ULL,
TinyImageFormat_DXTC_ALPHA_SHIFT = (TinyImageFormat_NAMESPACE_REQUIRED_BITS),
TinyImageFormat_DXTC_TYPE_SHIFT = (TinyImageFormat_DXTC_ALPHA_REQUIRED_BITS + TinyImageFormat_DXTC_ALPHA_SHIFT),
TinyImageFormat_DXTC_BLOCKBYTES_SHIFT = (TinyImageFormat_DXTC_TYPE_REQUIRED_BITS + TinyImageFormat_DXTC_TYPE_SHIFT),
TinyImageFormat_DXTC_CHANNELCOUNT_SHIFT =
(TinyImageFormat_DXTC_BLOCKBYTES_REQUIRED_BITS + TinyImageFormat_DXTC_BLOCKBYTES_SHIFT),
TinyImageFormat_DXTC_MODECOUNT_SHIFT =
(TinyImageFormat_DXTC_CHANNELCOUNT_REQUIRED_BITS + TinyImageFormat_DXTC_CHANNELCOUNT_SHIFT),
TinyImageFormat_PVRTC_VERSION_REQUIRED_BITS = 2ULL,
TinyImageFormat_PVRTC_BITS_REQUIRED_BITS = 2ULL,
TinyImageFormat_PVRTC_TYPE_REQUIRED_BITS = 2ULL,
TinyImageFormat_PVRTC_VERSION_SHIFT = (TinyImageFormat_NAMESPACE_REQUIRED_BITS),
TinyImageFormat_PVRTC_BITS_SHIFT =
(TinyImageFormat_PVRTC_VERSION_REQUIRED_BITS + TinyImageFormat_PVRTC_VERSION_SHIFT),
TinyImageFormat_PVRTC_TYPE_SHIFT = (TinyImageFormat_PVRTC_BITS_REQUIRED_BITS + TinyImageFormat_PVRTC_BITS_SHIFT),
TinyImageFormat_ETC_BITS_REQUIRED_BITS = 2ULL,
TinyImageFormat_ETC_ALPHA_REQUIRED_BITS = 2ULL,
TinyImageFormat_ETC_TYPE_REQUIRED_BITS = 2ULL,
TinyImageFormat_ETC_CHANNELCOUNT_REQUIRED_BITS = 2ULL,
TinyImageFormat_ETC_BITS_SHIFT = (TinyImageFormat_NAMESPACE_REQUIRED_BITS),
TinyImageFormat_ETC_ALPHA_SHIFT = (TinyImageFormat_ETC_BITS_REQUIRED_BITS + TinyImageFormat_ETC_BITS_SHIFT),
TinyImageFormat_ETC_TYPE_SHIFT = (TinyImageFormat_ETC_ALPHA_REQUIRED_BITS + TinyImageFormat_ETC_ALPHA_SHIFT),
TinyImageFormat_ETC_CHANNELCOUNT_SHIFT = (TinyImageFormat_ETC_TYPE_REQUIRED_BITS + TinyImageFormat_ETC_TYPE_SHIFT),
TinyImageFormat_ASTC_SIZE_REQUIRED_BITS = 3,
TinyImageFormat_ASTC_TYPE_REQUIRED_BITS = 2ULL,
TinyImageFormat_ASTC_NUM_DIMS = 3,
TinyImageFormat_ASTC_SIZE_SHIFT = (TinyImageFormat_NAMESPACE_REQUIRED_BITS),
TinyImageFormat_ASTC_TYPE_SHIFT =
((TinyImageFormat_ASTC_SIZE_REQUIRED_BITS * TinyImageFormat_ASTC_NUM_DIMS) + TinyImageFormat_ASTC_SIZE_SHIFT),
TinyImageFormat_CLUT_BLOCKSIZE_REQUIRED_BITS = 2,
TinyImageFormat_CLUT_BITS_REQUIRED_BITS = 3,
TinyImageFormat_CLUT_TYPE_REQUIRED_BITS = 2,
TinyImageFormat_CLUT_NUM_CHANNELS = 2,
TinyImageFormat_CLUT_BLOCKSIZE_SHIFT = TinyImageFormat_NAMESPACE_REQUIRED_BITS,
TinyImageFormat_CLUT_BITS_SHIFT = TinyImageFormat_CLUT_BLOCKSIZE_REQUIRED_BITS + TinyImageFormat_CLUT_BLOCKSIZE_SHIFT,
TinyImageFormat_CLUT_TYPE_SHIFT =
((TinyImageFormat_CLUT_BITS_REQUIRED_BITS * TinyImageFormat_CLUT_NUM_CHANNELS) + TinyImageFormat_CLUT_BITS_SHIFT),
} TinyImageFormat_Bits;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -35,5 +35,7 @@ namespace api {
void ExecutePresentPass(RenderPassNode* node, FRenderView& view);
void ExecuteComputePass(RenderPassNode* node, FRenderView& view);
void ExecuteCopyPass(RenderPassNode* node, FRenderView& view);
void ExecuteResourceBarriers(RenderPassNode* node, RenderPassEdgeIterFn fn);
};
}

View File

@ -35,36 +35,36 @@ namespace api {
return node;
}
};
struct FrameTextureResource {
TextureDesc texture;
AttachmentDesc attach;
};
struct FrameResource {
using Resource = std::variant<FrameTextureResource, void*>;
using Resource = std::variant<TextureDesc, BufferDesc, AttachmentDesc>;
Name name;
ResourceState sourceState;
Resource resource;
FrameGraphNodePtr source;
pmr::vector<FrameGraphNodePtr> targets{ FramePool() };
template<typename T>
T CastTo() {
T& CastTo() {
return std::get<T>(resource);
}
bool IsAttachment() {
return std::holds_alternative<AttachmentDesc>(resource);
}
bool IsTexture() {
return std::holds_alternative<TextureDesc>(resource);
}
bool IsBuffer() {
return std::holds_alternative<BufferDesc>(resource);
}
};
struct FrameGraphEdgePtr {
enum EdgeType : uint8_t {
Import,
Input,
Output
};
EdgeType type{ EdgeType::Import };
uint8_t isImport : 1;
ResourceState targetState;
FrameResource* resource;
FrameGraphEdgePtr() : resource(nullptr) {};
FrameGraphEdgePtr(FrameResource* resource, EdgeType type = EdgeType::Import)
: resource(resource), type(type) {}
FrameGraphEdgePtr(EdgeType type) : type(type){
FrameGraphEdgePtr() = default;
FrameResource* Make() {
resource = new (FramePool()) FrameResource();
return resource;
}
bool IsImport() const { return type == EdgeType::Import; }
operator bool() const{
return resource;
}
@ -72,15 +72,34 @@ namespace api {
return resource;
}
};
using RenderPassEdgeIterFn = std::function<void(FrameResource*, FrameGraphEdgePtr)>;
struct RenderPassNode {
Name name;
RenderPass* pass;
const void* pass;
RenderPassNodeExecuteFn executor;
pmr::vector<FrameGraphEdgePtr> edges{ FramePool() };//read -> write, 顺序固定
FrameGraphEdgePtr GetInput(int i);
FrameGraphEdgePtr GetOutput(int i);
FrameGraphEdgePtr FindInput(Name name);
FrameGraphEdgePtr FindOutput(Name name);
pmr::vector<FrameGraphEdgePtr> inEdges{ FramePool() };
pmr::vector<FrameGraphEdgePtr> outEdges{ FramePool() };
void ForeachEdge(RenderPassEdgeIterFn fn);
FrameGraphEdgePtr GetInput(int i) { return inEdges[i]; };
FrameGraphEdgePtr GetOutput(int i) { return outEdges[i]; };
FrameGraphEdgePtr FindInput(Name name)
{
for (auto edge : inEdges) {
if (edge.resource->name == name) {
return edge;
}
}
return {};
}
FrameGraphEdgePtr FindOutput(Name name)
{
for (auto edge : outEdges) {
if (edge.resource->name == name) {
return edge;
}
}
return {};
}
};
inline FrameGraphNodePtr::FrameGraphNodePtr(GraphNodeRef ref, const RenderPassNodeExecuteFn& executor, NodeType type)
: ref(ref), type(type)

View File

@ -6,6 +6,7 @@
namespace api {
class Mesh;
class Shader;
class RenderPassNode;
class RENDER_API RenderAPI : public Singleton<RenderAPI>
{
public:
@ -30,6 +31,9 @@ namespace api {
virtual void BeginFrame() = 0;
virtual void EndFrame() = 0;
virtual void RenderView(FRenderView& view);
virtual void BeginRenderPass(RenderPassNode* node) = 0;
virtual void EndRenderPass(RenderPassNode* node) = 0;
virtual void ExecuteResourceBarriers(const ResourceBarrierDesc& desc) = 0;
void Render();
};
}

View File

@ -1,4 +1,5 @@
#pragma once
#include "tinyimageformat/tinyimageformat_base.h"
#include <cstdint>
namespace api {
enum class GraphicsAPI
@ -7,12 +8,18 @@ namespace api {
Vulkan,
D3D12
};
struct BufferDesc {
static BufferDesc Make() {
return {};
}
};
struct TextureDesc {
static TextureDesc Make() {
return {};
}
};
struct AttachmentDesc {
TinyImageFormat colorFormat;
static AttachmentDesc Make() {
return {};
}
@ -76,4 +83,18 @@ namespace api {
uint8_t mMipLevel : 7;
uint16_t mArrayLayer;
};
typedef struct BufferBarrier
{
//Buffer* pBuffer;
ResourceState mSrcState;
ResourceState mDstState;
uint8_t mBeginOnly : 1;
uint8_t mEndOnly : 1;
} BufferBarrier;
struct ResourceBarrierDesc {
const BufferBarrier* pBufferBarriers;
uint32_t bufferBarriersCount;
const TextureBarrier* pTextureBarriers;
uint32_t textureBarriersCount;
};
}

View File

@ -12,7 +12,8 @@ namespace api {
}
FrameGraphEdgePtr FrameGraph::CreateTexture(const TextureSetupFunction& setup)
{
FrameGraphEdgePtr edge{ FrameGraphEdgePtr::Import };
FrameGraphEdgePtr edge{};
edge.Make();
TextureBuilder builder(this, edge);
setup(*this, builder);
return edge;
@ -36,7 +37,7 @@ namespace api {
ExecuteRenderPass(node.node, view);
break;
case FrameGraphNodePtr::Present:
ExecuteRenderPass(node.node, view);
ExecutePresentPass(node.node, view);
break;
case FrameGraphNodePtr::Compute:
ExecuteComputePass(node.node, view);
@ -51,16 +52,13 @@ namespace api {
{
mGraph.clear();
mNodes.clear();
}
void BeginRenderPass() {
}
void FrameGraph::ExecuteRenderPass(RenderPassNode* node, FRenderView& view)
{
BeginRenderPass();
//RenderAPI::Ptr()->BeginRenderPass();
RenderAPI::Ptr()->BeginRenderPass(node);
RenderPassContext context{};
std::get<RenderPassExecuteFunction>(node->executor)(*this, context);
RenderAPI::Ptr()->EndRenderPass(node);
}
void FrameGraph::ExecutePresentPass(RenderPassNode* node, FRenderView& view)
{
@ -77,42 +75,43 @@ namespace api {
CopyPassContext context{};
std::get<CopyPassExecuteFunction>(node->executor)(*this, context);
}
FrameGraphEdgePtr RenderPassNode::GetInput(int i)
void FrameGraph::ExecuteResourceBarriers(RenderPassNode* node, RenderPassEdgeIterFn fn)
{
int count = 0;
for (auto edge : edges) {
if (edge.type != FrameGraphEdgePtr::Output && count++ == i) {
return edge;
pmr::vector<BufferBarrier> bufferBarrier{FramePool()};
pmr::vector<TextureBarrier> textureBarrier{ FramePool() };
node->ForeachEdge([&](FrameResource* resource, FrameGraphEdgePtr edge) {
if (!edge || edge.targetState == resource->sourceState) {
return;
}
if (resource->IsBuffer()) {
BufferBarrier barrier{};
barrier.mSrcState = resource->sourceState;
barrier.mDstState = edge.targetState;
bufferBarrier.push_back(barrier);
}
return nullptr;
else {
TextureBarrier barrier{};
barrier.mSrcState = resource->sourceState;
barrier.mDstState = edge.targetState;
textureBarrier.push_back(barrier);
}
FrameGraphEdgePtr RenderPassNode::GetOutput(int i)
{
int count = 0;
for (auto edge : edges) {
if (edge.type == FrameGraphEdgePtr::Output && count++ == i) {
return edge;
});
if (bufferBarrier.empty() && textureBarrier.empty()) {
return;
}
ResourceBarrierDesc desc{};
desc.bufferBarriersCount = bufferBarrier.size();
desc.pBufferBarriers = bufferBarrier.data();
desc.textureBarriersCount = textureBarrier.size();
desc.pTextureBarriers = textureBarrier.data();
}
return nullptr;
void RenderPassNode::ForeachEdge(RenderPassEdgeIterFn fn) {
for (auto& edge : inEdges) {
fn(edge.resource, edge);
}
FrameGraphEdgePtr RenderPassNode::FindInput(Name name)
{
for (auto edge : edges) {
if (edge.resource->name == name && edge.type != FrameGraphEdgePtr::Output) {
return edge;
for (auto& edge : outEdges) {
fn(edge.resource, edge);
}
}
return nullptr;
}
FrameGraphEdgePtr RenderPassNode::FindOutput(Name name)
{
for (auto edge : edges) {
if (edge.resource->name == name && edge.type == FrameGraphEdgePtr::Output) {
return edge;
}
}
return nullptr;
}
}

View File

@ -14,29 +14,28 @@ namespace api {
FrameGraph::RenderPassBuilder& FrameGraph::RenderPassBuilder::Read(TextureDesc desc)
{
FrameGraphEdgePtr edge{ FrameGraphEdgePtr::Input };
resource = edge.resource;
FrameGraphEdgePtr edge{};
resource = edge.Make();
resource->source = node;
resource->resource = FrameTextureResource{desc};
node->edges.push_back(edge);
resource->resource = desc;
node->inEdges.push_back(edge);
return *this;
}
FrameGraph::RenderPassBuilder& FrameGraph::RenderPassBuilder::Write(TextureDesc desc)
{
FrameGraphEdgePtr edge{ FrameGraphEdgePtr::Output };
resource = edge.resource;
FrameGraphEdgePtr edge{};
resource = edge.Make();
resource->source = node;
resource->resource = FrameTextureResource{ desc };
node->edges.push_back(edge);
resource->resource = desc;
node->outEdges.push_back(edge);
return *this;
}
FrameGraph::RenderPassBuilder& FrameGraph::RenderPassBuilder::Attach(AttachmentDesc desc)
{
if (resource) {
auto& text_resource = std::get<FrameTextureResource>(resource->resource);
text_resource.attach = desc;
resource->resource = desc;
}
return *this;
}
@ -44,7 +43,7 @@ namespace api {
FrameGraph::RenderPassBuilder& FrameGraph::RenderPassBuilder::Read(const FrameGraphEdgePtr& edge)
{
if (!edge) { return *this; }
node->edges.emplace_back(edge.resource, edge.IsImport() ? FrameGraphEdgePtr::Import : FrameGraphEdgePtr::Input);
node->inEdges.emplace_back(edge);
edge->targets.emplace_back(node);
if(edge->source)
graph.mGraph.addEdge(edge->source.ref, node.ref);
@ -57,7 +56,7 @@ namespace api {
}
FrameGraph::TextureBuilder& FrameGraph::TextureBuilder::Import(RscHandle<Texture> handle)
{
edge.type = FrameGraphEdgePtr::Import;
edge.isImport = true;
return *this;
}
}

View File

@ -1,4 +1,5 @@
static_component("render","engine")
add_includedirs("3rdparty", {public = true})
add_headerfiles("include/**.h", "impl/*.inl")
add_files("src/**.cpp")
add_deps("asset", "zlib", "core")

View File

@ -11,6 +11,8 @@ namespace vkn {
using api::Guid;
using api::Mesh;
using api::Shader;
using api::RenderPassNode;
using api::ResourceBarrierDesc;
struct VulkanContext : public api::RenderContext {
VkSemaphore surfaceSemaphore;
VkSemaphore presentSemaphore;
@ -34,8 +36,12 @@ namespace vkn {
void BeginFrame()override;
void EndFrame()override;
void BeginRenderPass(RenderPassNode* node) override;
void EndRenderPass(RenderPassNode* node) override;
void ExecuteResourceBarriers(const ResourceBarrierDesc& desc) override;
VkPipeline GetPipeline();
VkRenderPass GetRenderPass(RenderPassKey config);
VkRenderPass GetRenderPass(RenderPassKey& config);
Backend& GetBackend() {
return backend;

View File

@ -0,0 +1,4 @@
#include "type.h"
namespace vkn {
}

View File

@ -6,6 +6,7 @@
#include "vkn/thread/command_worker.h"
#include "render/asset/mesh.h"
#include "meta/enum.h"
#include "tinyimageformat/tinyimageformat_apis.h"
namespace vkn {
inline bool operator==(const RenderPassKey& k1, const RenderPassKey& k2) {
if (k1.initialColorLayoutMask != k2.initialColorLayoutMask) return false;
@ -72,7 +73,36 @@ namespace vkn {
{
window.Present(*(VulkanContext*)&context);
}
VkRenderPass VulkanAPI::GetRenderPass(RenderPassKey config) {
void VulkanAPI::ExecuteResourceBarriers(const ResourceBarrierDesc& desc) {
VkCommandBuffer cmd;
pmr::vector<VkBufferMemoryBarrier> bufferBarriers{ FramePool() };
bufferBarriers.reserve(desc.bufferBarriersCount);
pmr::vector<VkImageMemoryBarrier> imageBarriers{ FramePool() };
imageBarriers.reserve(desc.textureBarriersCount);
using api::ResourceState;
for (uint32_t i = 0; i < desc.textureBarriersCount; i++)
{
auto& barrier = desc.pTextureBarriers[i];
}
}
void VulkanAPI::BeginRenderPass(RenderPassNode* node)
{
RenderPassKey config{};
int i = 0;
for (auto& it : node->outEdges) {
if (it->IsAttachment()) {
auto& desc = it->CastTo<api::AttachmentDesc>();
config.colorFormat[i] = (VkFormat)TinyImageFormat_ToVkFormat(desc.colorFormat);
i++;
}
}
node->pass = GetRenderPass(config);
}
void VulkanAPI::EndRenderPass(RenderPassNode* node)
{
}
VkRenderPass VulkanAPI::GetRenderPass(RenderPassKey& config) {
auto it = RenderPassCache.find(config);
if (it != RenderPassCache.end()) {
return it->second;

View File

@ -0,0 +1,103 @@
#include <tuple>
#include "vkn/vulkan_api_help.h"
namespace vkn {
using api::ResourceState;
inline std::tuple<VkAccessFlags, VkAccessFlags, VkPipelineStageFlags, VkPipelineStageFlags,
VkImageLayout, VkImageLayout>
getVkTransition(const api::TextureBarrier& barrier) {
VkAccessFlags srcAccessMask, dstAccessMask;
VkPipelineStageFlags srcStage, dstStage;
switch (barrier.mSrcState) {
case ResourceState::UNDEFINED:
srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
srcStage = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;
break;
case ResourceState::COLOR_ATTACHMENT:
srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT |
VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
srcStage = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
break;
case ResourceState::READ_WRITE:
srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
srcStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
break;
case ResourceState::READ_ONLY:
srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
srcStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
break;
case ResourceState::TRANSFER_SRC:
srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
break;
case ResourceState::TRANSFER_DST:
srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
break;
case ResourceState::DEPTH_ATTACHMENT:
srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
srcStage = VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
break;
case ResourceState::DEPTH_SAMPLER:
srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
srcStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
break;
case ResourceState::COLOR_ATTACHMENT_RESOLVE:
srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
break;
case ResourceState::PRESENT:
srcAccessMask = VK_ACCESS_NONE;
srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
break;
}
switch (barrier.mDstState) {
case ResourceState::COLOR_ATTACHMENT:
dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT
| VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
| VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dstStage = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
| VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
break;
case ResourceState::READ_WRITE:
dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
dstStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
break;
case ResourceState::READ_ONLY:
dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
dstStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;
break;
case ResourceState::TRANSFER_SRC:
dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
break;
case ResourceState::TRANSFER_DST:
dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
break;
case ResourceState::DEPTH_ATTACHMENT:
dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
| VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
dstStage = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
break;
case ResourceState::DEPTH_SAMPLER:
dstAccessMask =
VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
dstStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
break;
case ResourceState::PRESENT:
case ResourceState::COLOR_ATTACHMENT_RESOLVE:
case ResourceState::UNDEFINED:
dstAccessMask = 0;
dstStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
break;
}
return std::make_tuple(srcAccessMask, dstAccessMask, srcStage, dstStage,
getVkLayout(transition.oldLayout), getVkLayout(transition.newLayout));
}
}

View File

@ -5,11 +5,12 @@
#include "render/pass/demo_pass.h"
#include <iostream>
using namespace api;
RenderAPI* API;
void ZWorldModule::OnLoad(int argc, char** argv)
{
// 创建窗口
auto window = new vkn::VulkanWindow(&SDL_CreateWindow, { "zengine" , SDL_WINDOW_VULKAN }, 1080, 720);
RenderAPI* API = new vkn::VulkanAPI();
API = new vkn::VulkanAPI();
auto args = vkn::VulkanWindowArgs::Default();
args.frames = 3;
if (!window->CreateRender(&SDL_Vulkan_CreateSurface, args)) {
@ -24,7 +25,6 @@ void ZWorldModule::OnUnload()
void ZWorldModule::MainLoop()
{
RenderAPI* API = RenderAPI::Ptr();
bool running = true;
SDL_Event event_;
while (running) {