diff options
Diffstat (limited to '3rdparty/bgfx/src/shader.cpp')
-rw-r--r-- | 3rdparty/bgfx/src/shader.cpp | 149 |
1 files changed, 136 insertions, 13 deletions
diff --git a/3rdparty/bgfx/src/shader.cpp b/3rdparty/bgfx/src/shader.cpp index f6dfb3e350d..2629569e3e5 100644 --- a/3rdparty/bgfx/src/shader.cpp +++ b/3rdparty/bgfx/src/shader.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -10,14 +10,121 @@ namespace bgfx { + struct DescriptorTypeToId + { + DescriptorType::Enum type; + uint16_t id; + }; + + static DescriptorTypeToId s_descriptorTypeToId[] = + { + // NOTICE: + // DescriptorType must be in order how it appears in DescriptorType::Enum! id is + // unique and should not be changed if new DescriptorTypes are added. + { DescriptorType::StorageBuffer, 0x0007 }, + { DescriptorType::StorageImage, 0x0003 }, + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_descriptorTypeToId) == DescriptorType::Count); + + DescriptorType::Enum idToDescriptorType(uint16_t _id) + { + for (uint32_t ii = 0; ii < BX_COUNTOF(s_descriptorTypeToId); ++ii) + { + if (s_descriptorTypeToId[ii].id == _id) + { + return s_descriptorTypeToId[ii].type; + } + } + + return DescriptorType::Count; + } + + uint16_t descriptorTypeToId(DescriptorType::Enum _type) + { + return s_descriptorTypeToId[_type].id; + } + + struct TextureComponentTypeToId + { + TextureComponentType::Enum type; + uint8_t id; + }; + + static TextureComponentTypeToId s_textureComponentTypeToId[] = + { + // see comment in s_descriptorTypeToId + { TextureComponentType::Float, 0x00 }, + { TextureComponentType::Int, 0x01 }, + { TextureComponentType::Uint, 0x02 }, + { TextureComponentType::Depth, 0x03 }, + { TextureComponentType::UnfilterableFloat, 0x04 }, + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_textureComponentTypeToId) == TextureComponentType::Count); + + TextureComponentType::Enum idToTextureComponentType(uint8_t _id) + { + for (uint32_t ii = 0; ii < BX_COUNTOF(s_textureComponentTypeToId); ++ii) + { + if (s_textureComponentTypeToId[ii].id == _id) + { + return s_textureComponentTypeToId[ii].type; + } + } + + return TextureComponentType::Count; + } + + uint8_t textureComponentTypeToId(TextureComponentType::Enum _type) + { + return s_textureComponentTypeToId[_type].id; + } + + struct TextureDimensionToId + { + TextureDimension::Enum dimension; + uint8_t id; + }; + + static TextureDimensionToId s_textureDimensionToId[] = + { + // see comment in s_descriptorTypeToId + { TextureDimension::Dimension1D, 0x01 }, + { TextureDimension::Dimension2D, 0x02 }, + { TextureDimension::Dimension2DArray, 0x03 }, + { TextureDimension::DimensionCube, 0x04 }, + { TextureDimension::DimensionCubeArray, 0x05 }, + { TextureDimension::Dimension3D, 0x06 }, + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_textureDimensionToId) == TextureDimension::Count); + + TextureDimension::Enum idToTextureDimension(uint8_t _id) + { + for (uint32_t ii = 0; ii < BX_COUNTOF(s_textureDimensionToId); ++ii) + { + if (s_textureDimensionToId[ii].id == _id) + { + return s_textureDimensionToId[ii].dimension; + } + } + + return TextureDimension::Count; + } + + uint8_t textureDimensionToId(TextureDimension::Enum _dim) + { + return s_textureDimensionToId[_dim].id; + } + static bool printAsm(uint32_t _offset, const DxbcInstruction& _instruction, void* _userData) { BX_UNUSED(_offset); bx::WriterI* writer = reinterpret_cast<bx::WriterI*>(_userData); char temp[512]; toString(temp, sizeof(temp), _instruction); - bx::write(writer, temp, (int32_t)bx::strLen(temp) ); - bx::write(writer, '\n'); + + bx::Error err; + bx::write(writer, temp, (int32_t)bx::strLen(temp), &err); + bx::write(writer, '\n', &err); return true; } @@ -27,8 +134,10 @@ namespace bgfx bx::WriterI* writer = reinterpret_cast<bx::WriterI*>(_userData); char temp[512]; toString(temp, sizeof(temp), _instruction); - bx::write(writer, temp, (int32_t)bx::strLen(temp) ); - bx::write(writer, '\n'); + + bx::Error err; + bx::write(writer, temp, (int32_t)bx::strLen(temp), &err); + bx::write(writer, '\n', &err); return true; } @@ -38,15 +147,17 @@ namespace bgfx bx::WriterI* writer = reinterpret_cast<bx::WriterI*>(_userData); char temp[512]; toString(temp, sizeof(temp), _instruction); - bx::write(writer, temp, (int32_t)bx::strLen(temp) ); - bx::write(writer, '\n'); + + bx::Error err; + bx::write(writer, temp, (int32_t)bx::strLen(temp), &err); + bx::write(writer, '\n', &err); return true; } void disassembleByteCode(bx::WriterI* _writer, bx::ReaderSeekerI* _reader, bx::Error* _err) { uint32_t magic; - bx::peek(_reader, magic); + bx::peek(_reader, magic, _err); if (magic == SPV_CHUNK_HEADER) { @@ -73,14 +184,14 @@ namespace bgfx BX_ERROR_SCOPE(_err); uint32_t magic; - bx::peek(_reader, magic); + bx::peek(_reader, magic, _err); if (isShaderBin(magic) ) { - bx::read(_reader, magic); + bx::read(_reader, magic, _err); uint32_t hashIn; - bx::read(_reader, hashIn); + bx::read(_reader, hashIn, _err); uint32_t hashOut; @@ -90,7 +201,7 @@ namespace bgfx } else { - bx::read(_reader, hashOut); + bx::read(_reader, hashOut, _err); } uint16_t count; @@ -120,6 +231,18 @@ namespace bgfx uint16_t regCount; bx::read(_reader, regCount, _err); + + if (!isShaderVerLess(magic, 8) ) + { + uint16_t texInfo; + bx::read(_reader, texInfo, _err); + } + + if (!isShaderVerLess(magic, 10) ) + { + uint16_t texFormat = 0; + bx::read(_reader, texFormat, _err); + } } uint32_t shaderSize; |