Split engine to packages NazaraUtils and NZSL (#375)

* Move code to NazaraUtils and NZSL packages

* Reorder includes

* Tests: Remove glslang and spirv-tools deps

* Tests: Remove glslang init

* Remove NazaraUtils tests and fix Vector4Test

* Fix Linux compilation

* Update msys2-build.yml

* Fix assimp package

* Update xmake.lua

* Update xmake.lua

* Fix shader compilation on MinGW

* Final fixes

* The final fix 2: the fix strikes back!

* Disable cache on CI

* The return of the fix™️
This commit is contained in:
Jérôme Leclercq
2022-05-25 19:36:10 +02:00
committed by GitHub
parent 3f8f1c4653
commit 03e2801dbe
483 changed files with 1139 additions and 59112 deletions

View File

@@ -13,10 +13,10 @@
#include <Nazara/Audio/Formats/libflacLoader.hpp>
#include <Nazara/Audio/Formats/libvorbisLoader.hpp>
#include <Nazara/Audio/Formats/minimp3Loader.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <stdexcept>
#include <Nazara/Audio/Debug.hpp>

View File

@@ -8,7 +8,7 @@
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <algorithm>
#include <Nazara/Audio/Debug.hpp>

View File

@@ -8,12 +8,12 @@
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/SoundBuffer.hpp>
#include <Nazara/Audio/SoundStream.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/MemoryView.hpp>
#include <Nazara/Core/Stream.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <Nazara/Utils/Endianness.hpp>
#include <optional>
#define DR_WAV_IMPLEMENTATION

View File

@@ -8,12 +8,12 @@
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/SoundBuffer.hpp>
#include <Nazara/Audio/SoundStream.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/MemoryView.hpp>
#include <Nazara/Core/Stream.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <Nazara/Utils/Endianness.hpp>
#include <FLAC/stream_decoder.h>
#include <optional>
#include <set>

View File

@@ -8,12 +8,12 @@
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/SoundBuffer.hpp>
#include <Nazara/Audio/SoundStream.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/MemoryView.hpp>
#include <Nazara/Core/Stream.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <Nazara/Utils/Endianness.hpp>
#include <optional>
#include <set>

View File

@@ -8,11 +8,11 @@
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/SoundBuffer.hpp>
#include <Nazara/Audio/SoundStream.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/MemoryView.hpp>
#include <Nazara/Core/Stream.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <optional>
#define MINIMP3_IMPLEMENTATION

View File

@@ -9,7 +9,7 @@
#include <Nazara/Audio/AudioDevice.hpp>
#include <Nazara/Audio/AudioSource.hpp>
#include <Nazara/Audio/SoundStream.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <array>
#include <chrono>
#include <Nazara/Audio/Debug.hpp>

View File

@@ -4,11 +4,11 @@
#include <Nazara/Audio/OpenALLibrary.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <array>
#include <cstring>
#include <sstream>

View File

@@ -7,7 +7,7 @@
#include <Nazara/Audio/OpenALLibrary.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <Nazara/Audio/Debug.hpp>
namespace Nz

View File

@@ -1,34 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
namespace Detail
{
const UInt8 BitReverseTable256[256] =
{
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
};
}
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -8,5 +8,8 @@
#error This header should only be included after including X11/Xlib.h directly or indirectly in a .cpp
#endif
#undef Always
#undef Bool
#undef False
#undef None
#undef True

View File

@@ -3,9 +3,9 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <cstdlib>
#include <stdexcept>

View File

@@ -3,8 +3,8 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/FileLogger.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <array>
#include <ctime>
#include <filesystem>

View File

@@ -8,7 +8,7 @@
#include <Nazara/Core/GuillotineBinPack.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/StackVector.hpp>
#include <Nazara/Utils/StackVector.hpp>
#include <algorithm>
#include <limits>
#include <Nazara/Core/Debug.hpp>

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Hash/CRC32.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Utils/Endianness.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Hash/CRC64.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Utils/Endianness.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Hash/Fletcher16.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Utils/Endianness.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz

View File

@@ -27,7 +27,7 @@
*/
#include <Nazara/Core/Hash/MD5.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Utils/Endianness.hpp>
#include <cstring>
#include <Nazara/Core/Debug.hpp>

View File

@@ -38,7 +38,7 @@
*/
#include <Nazara/Core/Hash/SHA/Internal.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Utils/Endianness.hpp>
#include <cstring>
#include <Nazara/Core/Debug.hpp>

View File

@@ -43,6 +43,7 @@
#define NAZARA_CORE_HASH_SHA_INTERNAL_HPP
#include <Nazara/Prerequisites.hpp>
#include <cstddef>
/* Digest lengths for SHA-1/224/256/384/512 */
#define SHA1_DIGEST_LENGTH 20

View File

@@ -5,8 +5,8 @@
#include <Nazara/Core/ParameterList.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/MemoryHelper.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Utils/MemoryHelper.hpp>
#include <cstring>
#include <Nazara/Core/Debug.hpp>

View File

@@ -3,10 +3,10 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Win32/FileImpl.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Core/Win32/Time.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <memory>
#include <Nazara/Core/Debug.hpp>

View File

@@ -8,10 +8,10 @@
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
#include <Nazara/Graphics/UberShader.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Shader/FieldOffsets.hpp>
#include <Nazara/Shader/ShaderLangParser.hpp>
#include <Nazara/Utility/BufferMapper.hpp>
#include <Nazara/Utility/MaterialData.hpp>
#include <NZSL/FieldOffsets.hpp>
#include <NZSL/ShaderLangParser.hpp>
#include <cassert>
#include <Nazara/Graphics/Debug.hpp>
@@ -158,8 +158,8 @@ namespace Nz
ImageType::E2D
});
settings.sharedUniformBlocks.push_back(PredefinedInstanceData::GetUniformBlock(4, ShaderStageType::Vertex));
settings.sharedUniformBlocks.push_back(PredefinedViewerData::GetUniformBlock(5, ShaderStageType_All));
settings.sharedUniformBlocks.push_back(PredefinedInstanceData::GetUniformBlock(4, nzsl::ShaderStageType::Vertex));
settings.sharedUniformBlocks.push_back(PredefinedViewerData::GetUniformBlock(5, nzsl::ShaderStageType_All));
settings.predefinedBindings[UnderlyingCast(PredefinedShaderBinding::InstanceDataUbo)] = 4;
settings.predefinedBindings[UnderlyingCast(PredefinedShaderBinding::OverlayTexture)] = 3;
@@ -229,18 +229,18 @@ namespace Nz
std::vector<std::shared_ptr<UberShader>> BasicMaterial::BuildShaders()
{
auto shader = std::make_shared<UberShader>(ShaderStageType::Fragment | ShaderStageType::Vertex, "BasicMaterial");
auto shader = std::make_shared<UberShader>(nzsl::ShaderStageType::Fragment | nzsl::ShaderStageType::Vertex, "BasicMaterial");
return { std::move(shader) };
}
auto BasicMaterial::BuildUniformOffsets() -> std::pair<BasicUniformOffsets, FieldOffsets>
auto BasicMaterial::BuildUniformOffsets() -> std::pair<BasicUniformOffsets, nzsl::FieldOffsets>
{
FieldOffsets fieldOffsets(StructLayout::Std140);
nzsl::FieldOffsets fieldOffsets(nzsl::StructLayout::Std140);
BasicUniformOffsets uniformOffsets;
uniformOffsets.alphaThreshold = fieldOffsets.AddField(StructFieldType::Float1);
uniformOffsets.diffuseColor = fieldOffsets.AddField(StructFieldType::Float4);
uniformOffsets.alphaThreshold = fieldOffsets.AddField(nzsl::StructFieldType::Float1);
uniformOffsets.diffuseColor = fieldOffsets.AddField(nzsl::StructFieldType::Float4);
uniformOffsets.totalSize = fieldOffsets.GetAlignedSize();
return std::make_pair(std::move(uniformOffsets), std::move(fieldOffsets));

View File

@@ -3,15 +3,15 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/DepthMaterial.hpp>
#include <Nazara/Shader/FieldOffsets.hpp>
#include <Nazara/Shader/ShaderLangParser.hpp>
#include <NZSL/FieldOffsets.hpp>
#include <NZSL/ShaderLangParser.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
std::vector<std::shared_ptr<UberShader>> DepthMaterial::BuildShaders()
{
auto shader = std::make_shared<UberShader>(ShaderStageType::Fragment | ShaderStageType::Vertex, "DepthMaterial");
auto shader = std::make_shared<UberShader>(nzsl::ShaderStageType::Fragment | nzsl::ShaderStageType::Vertex, "DepthMaterial");
return { std::move(shader) };
}

View File

@@ -3,7 +3,6 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/ForwardFramePipeline.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/FrameGraph.hpp>
#include <Nazara/Graphics/Graphics.hpp>
@@ -21,6 +20,7 @@
#include <Nazara/Renderer/RenderFrame.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Renderer/UploadPool.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <array>
#include <Nazara/Graphics/Debug.hpp>

View File

@@ -7,8 +7,8 @@
#include <Nazara/Graphics/FrameGraph.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <stdexcept>
#include <unordered_set>
#include <Nazara/Graphics/Debug.hpp>

View File

@@ -6,9 +6,9 @@
#include <Nazara/Graphics/GuillotineTextureAtlas.hpp>
#include <Nazara/Graphics/MaterialPipeline.hpp>
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
#include <Nazara/Shader/Ast/AstSerializer.hpp>
#include <Nazara/Shader/Ast/Module.hpp>
#include <Nazara/Utility/Font.hpp>
#include <NZSL/Ast/AstSerializer.hpp>
#include <NZSL/Ast/Module.hpp>
#include <array>
#include <stdexcept>
#include <Nazara/Graphics/Debug.hpp>
@@ -145,7 +145,7 @@ namespace Nz
{
0, 0,
ShaderBindingType::Texture,
ShaderStageType::Fragment
nzsl::ShaderStageType::Fragment
}
});
@@ -153,12 +153,12 @@ namespace Nz
if (!m_blitPipelineLayout)
throw std::runtime_error("failed to instantiate fullscreen renderpipeline layout");
ShaderAst::ModulePtr blitShaderModule = m_shaderModuleResolver->Resolve("TextureBlit");
nzsl::Ast::ModulePtr blitShaderModule = m_shaderModuleResolver->Resolve("TextureBlit");
ShaderWriter::States states;
nzsl::ShaderWriter::States states;
states.shaderModuleResolver = m_shaderModuleResolver;
auto blitShader = m_renderDevice->InstantiateShaderModule(ShaderStageType::Fragment | ShaderStageType::Vertex, *blitShaderModule, states);
auto blitShader = m_renderDevice->InstantiateShaderModule(nzsl::ShaderStageType::Fragment | nzsl::ShaderStageType::Vertex, *blitShaderModule, states);
if (!blitShader)
throw std::runtime_error("failed to instantiate blit shader");
@@ -238,7 +238,7 @@ namespace Nz
void Graphics::RegisterShaderModules()
{
m_shaderModuleResolver = std::make_shared<FilesystemModuleResolver>();
m_shaderModuleResolver = std::make_shared<nzsl::FilesystemModuleResolver>();
RegisterEmbedShaderModule(r_basicMaterialShader);
RegisterEmbedShaderModule(r_depthMaterialShader);
RegisterEmbedShaderModule(r_phongMaterialShader);
@@ -261,7 +261,8 @@ namespace Nz
template<std::size_t N>
void Graphics::RegisterEmbedShaderModule(const UInt8(&content)[N])
{
m_shaderModuleResolver->RegisterModule(ShaderAst::UnserializeShader(content, N));
nzsl::Unserializer unserializer(content, N);
m_shaderModuleResolver->RegisterModule(nzsl::Ast::UnserializeShader(unserializer));
}
void Graphics::SelectDepthStencilFormats()

View File

@@ -140,7 +140,7 @@ namespace Nz
const auto& options = m_settings->GetOptions();
for (std::size_t optionIndex = 0; optionIndex < options.size(); ++optionIndex)
{
if (!std::holds_alternative<ShaderAst::NoValue>(m_optionValues[optionIndex]))
if (!std::holds_alternative<nzsl::Ast::NoValue>(m_optionValues[optionIndex]))
{
auto& optionValue = m_pipelineInfo.optionValues[m_pipelineInfo.optionCount];
optionValue.hash = options[optionIndex].hash;

View File

@@ -49,7 +49,7 @@ namespace Nz
renderPipelineInfo.pipelineLayout = m_pipelineInfo.settings->GetRenderPipelineLayout();
std::unordered_map<UInt32, ShaderAst::ConstantValue> optionValues;
std::unordered_map<UInt32, nzsl::Ast::ConstantValue> optionValues;
for (std::size_t i = 0; i < m_pipelineInfo.optionCount; ++i)
{
const auto& option = m_pipelineInfo.optionValues[i];

View File

@@ -7,10 +7,10 @@
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Shader/FieldOffsets.hpp>
#include <Nazara/Shader/ShaderLangParser.hpp>
#include <Nazara/Utility/BufferMapper.hpp>
#include <Nazara/Utility/MaterialData.hpp>
#include <NZSL/FieldOffsets.hpp>
#include <NZSL/ShaderLangParser.hpp>
#include <cassert>
#include <filesystem>
#include <Nazara/Graphics/Debug.hpp>
@@ -229,7 +229,7 @@ namespace Nz
options.defaultValues
});
settings.sharedUniformBlocks.push_back(PredefinedLightData::GetUniformBlock(6, ShaderStageType::Fragment));
settings.sharedUniformBlocks.push_back(PredefinedLightData::GetUniformBlock(6, nzsl::ShaderStageType::Fragment));
settings.predefinedBindings[UnderlyingCast(PredefinedShaderBinding::LightDataUbo)] = 6;
settings.shaders = options.shaders;
@@ -310,20 +310,20 @@ namespace Nz
std::vector<std::shared_ptr<UberShader>> PhongLightingMaterial::BuildShaders()
{
auto shader = std::make_shared<UberShader>(ShaderStageType::Fragment | ShaderStageType::Vertex, "PhongMaterial");
auto shader = std::make_shared<UberShader>(nzsl::ShaderStageType::Fragment | nzsl::ShaderStageType::Vertex, "PhongMaterial");
return { std::move(shader) };
}
auto PhongLightingMaterial::BuildUniformOffsets() -> std::pair<PhongUniformOffsets, FieldOffsets>
auto PhongLightingMaterial::BuildUniformOffsets() -> std::pair<PhongUniformOffsets, nzsl::FieldOffsets>
{
auto basicOffsets = BasicMaterial::BuildUniformOffsets();
FieldOffsets fieldOffsets = basicOffsets.second;
nzsl::FieldOffsets fieldOffsets = basicOffsets.second;
PhongUniformOffsets uniformOffsets;
uniformOffsets.ambientColor = fieldOffsets.AddField(StructFieldType::Float3);
uniformOffsets.specularColor = fieldOffsets.AddField(StructFieldType::Float3);
uniformOffsets.shininess = fieldOffsets.AddField(StructFieldType::Float1);
uniformOffsets.ambientColor = fieldOffsets.AddField(nzsl::StructFieldType::Float3);
uniformOffsets.specularColor = fieldOffsets.AddField(nzsl::StructFieldType::Float3);
uniformOffsets.shininess = fieldOffsets.AddField(nzsl::StructFieldType::Float1);
uniformOffsets.totalSize = fieldOffsets.GetAlignedSize();

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
#include <Nazara/Shader/FieldOffsets.hpp>
#include <NZSL/FieldOffsets.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
@@ -12,27 +12,27 @@ namespace Nz
{
PredefinedLightData lightData;
FieldOffsets lightStruct(StructLayout::Std140);
lightData.lightMemberOffsets.type = lightStruct.AddField(StructFieldType::Int1);
lightData.lightMemberOffsets.color = lightStruct.AddField(StructFieldType::Float4);
lightData.lightMemberOffsets.factor = lightStruct.AddField(StructFieldType::Float2);
lightData.lightMemberOffsets.parameter1 = lightStruct.AddField(StructFieldType::Float4);
lightData.lightMemberOffsets.parameter2 = lightStruct.AddField(StructFieldType::Float4);
lightData.lightMemberOffsets.parameter3 = lightStruct.AddField(StructFieldType::Float4);
lightData.lightMemberOffsets.shadowMappingFlag = lightStruct.AddField(StructFieldType::Bool1);
nzsl::FieldOffsets lightStruct(nzsl::StructLayout::Std140);
lightData.lightMemberOffsets.type = lightStruct.AddField(nzsl::StructFieldType::Int1);
lightData.lightMemberOffsets.color = lightStruct.AddField(nzsl::StructFieldType::Float4);
lightData.lightMemberOffsets.factor = lightStruct.AddField(nzsl::StructFieldType::Float2);
lightData.lightMemberOffsets.parameter1 = lightStruct.AddField(nzsl::StructFieldType::Float4);
lightData.lightMemberOffsets.parameter2 = lightStruct.AddField(nzsl::StructFieldType::Float4);
lightData.lightMemberOffsets.parameter3 = lightStruct.AddField(nzsl::StructFieldType::Float4);
lightData.lightMemberOffsets.shadowMappingFlag = lightStruct.AddField(nzsl::StructFieldType::Bool1);
lightData.lightSize = lightStruct.GetAlignedSize();
FieldOffsets lightDataStruct(StructLayout::Std140);
nzsl::FieldOffsets lightDataStruct(nzsl::StructLayout::Std140);
lightData.lightsOffset = lightDataStruct.AddStructArray(lightStruct, MaxLightCount);
lightData.lightCountOffset = lightDataStruct.AddField(StructFieldType::UInt1);
lightData.lightCountOffset = lightDataStruct.AddField(nzsl::StructFieldType::UInt1);
lightData.totalSize = lightDataStruct.GetAlignedSize();
return lightData;
}
MaterialSettings::SharedUniformBlock PredefinedLightData::GetUniformBlock(UInt32 bindingIndex, ShaderStageTypeFlags shaderStages)
MaterialSettings::SharedUniformBlock PredefinedLightData::GetUniformBlock(UInt32 bindingIndex, nzsl::ShaderStageTypeFlags shaderStages)
{
PredefinedLightData lightData = GetOffsets();
@@ -53,18 +53,18 @@ namespace Nz
PredefinedInstanceData PredefinedInstanceData::GetOffsets()
{
FieldOffsets viewerStruct(StructLayout::Std140);
nzsl::FieldOffsets viewerStruct(nzsl::StructLayout::Std140);
PredefinedInstanceData instanceData;
instanceData.worldMatrixOffset = viewerStruct.AddMatrix(StructFieldType::Float1, 4, 4, true);
instanceData.invWorldMatrixOffset = viewerStruct.AddMatrix(StructFieldType::Float1, 4, 4, true);
instanceData.worldMatrixOffset = viewerStruct.AddMatrix(nzsl::StructFieldType::Float1, 4, 4, true);
instanceData.invWorldMatrixOffset = viewerStruct.AddMatrix(nzsl::StructFieldType::Float1, 4, 4, true);
instanceData.totalSize = viewerStruct.GetAlignedSize();
return instanceData;
}
MaterialSettings::SharedUniformBlock PredefinedInstanceData::GetUniformBlock(UInt32 bindingIndex, ShaderStageTypeFlags shaderStages)
MaterialSettings::SharedUniformBlock PredefinedInstanceData::GetUniformBlock(UInt32 bindingIndex, nzsl::ShaderStageTypeFlags shaderStages)
{
PredefinedInstanceData instanceData = GetOffsets();
@@ -87,25 +87,25 @@ namespace Nz
PredefinedViewerData PredefinedViewerData::GetOffsets()
{
FieldOffsets viewerStruct(StructLayout::Std140);
nzsl::FieldOffsets viewerStruct(nzsl::StructLayout::Std140);
PredefinedViewerData viewerData;
viewerData.projMatrixOffset = viewerStruct.AddMatrix(StructFieldType::Float1, 4, 4, true);
viewerData.invProjMatrixOffset = viewerStruct.AddMatrix(StructFieldType::Float1, 4, 4, true);
viewerData.viewMatrixOffset = viewerStruct.AddMatrix(StructFieldType::Float1, 4, 4, true);
viewerData.invViewMatrixOffset = viewerStruct.AddMatrix(StructFieldType::Float1, 4, 4, true);
viewerData.viewProjMatrixOffset = viewerStruct.AddMatrix(StructFieldType::Float1, 4, 4, true);
viewerData.invViewProjMatrixOffset = viewerStruct.AddMatrix(StructFieldType::Float1, 4, 4, true);
viewerData.targetSizeOffset = viewerStruct.AddField(StructFieldType::Float2);
viewerData.invTargetSizeOffset = viewerStruct.AddField(StructFieldType::Float2);
viewerData.eyePositionOffset = viewerStruct.AddField(StructFieldType::Float3);
viewerData.projMatrixOffset = viewerStruct.AddMatrix(nzsl::StructFieldType::Float1, 4, 4, true);
viewerData.invProjMatrixOffset = viewerStruct.AddMatrix(nzsl::StructFieldType::Float1, 4, 4, true);
viewerData.viewMatrixOffset = viewerStruct.AddMatrix(nzsl::StructFieldType::Float1, 4, 4, true);
viewerData.invViewMatrixOffset = viewerStruct.AddMatrix(nzsl::StructFieldType::Float1, 4, 4, true);
viewerData.viewProjMatrixOffset = viewerStruct.AddMatrix(nzsl::StructFieldType::Float1, 4, 4, true);
viewerData.invViewProjMatrixOffset = viewerStruct.AddMatrix(nzsl::StructFieldType::Float1, 4, 4, true);
viewerData.targetSizeOffset = viewerStruct.AddField(nzsl::StructFieldType::Float2);
viewerData.invTargetSizeOffset = viewerStruct.AddField(nzsl::StructFieldType::Float2);
viewerData.eyePositionOffset = viewerStruct.AddField(nzsl::StructFieldType::Float3);
viewerData.totalSize = viewerStruct.GetAlignedSize();
return viewerData;
}
MaterialSettings::SharedUniformBlock PredefinedViewerData::GetUniformBlock(UInt32 bindingIndex, ShaderStageTypeFlags shaderStages)
MaterialSettings::SharedUniformBlock PredefinedViewerData::GetUniformBlock(UInt32 bindingIndex, nzsl::ShaderStageTypeFlags shaderStages)
{
PredefinedViewerData viewerData = GetOffsets();

View File

@@ -3,11 +3,11 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/RenderSpriteChain.hpp>
#include <Nazara/Graphics/WorldInstance.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz

View File

@@ -6,20 +6,20 @@
#include <Nazara/Core/Error.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Renderer/RenderDevice.hpp>
#include <Nazara/Shader/Ast/AstReflect.hpp>
#include <Nazara/Shader/Ast/SanitizeVisitor.hpp>
#include <NZSL/Ast/ReflectVisitor.hpp>
#include <NZSL/Ast/SanitizeVisitor.hpp>
#include <limits>
#include <stdexcept>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
UberShader::UberShader(ShaderStageTypeFlags shaderStages, std::string moduleName) :
UberShader::UberShader(nzsl::ShaderStageTypeFlags shaderStages, std::string moduleName) :
UberShader(shaderStages, *Graphics::Instance()->GetShaderModuleResolver(), std::move(moduleName))
{
}
UberShader::UberShader(ShaderStageTypeFlags shaderStages, ShaderModuleResolver& moduleResolver, std::string moduleName) :
UberShader::UberShader(nzsl::ShaderStageTypeFlags shaderStages, nzsl::ShaderModuleResolver& moduleResolver, std::string moduleName) :
m_shaderStages(shaderStages)
{
m_shaderModule = moduleResolver.Resolve(moduleName);
@@ -27,12 +27,12 @@ namespace Nz
m_shaderModule = Validate(*m_shaderModule, &m_optionIndexByName);
m_onShaderModuleUpdated.Connect(moduleResolver.OnModuleUpdated, [this, name = std::move(moduleName)](ShaderModuleResolver* resolver, const std::string& updatedModuleName)
m_onShaderModuleUpdated.Connect(moduleResolver.OnModuleUpdated, [this, name = std::move(moduleName)](nzsl::ShaderModuleResolver* resolver, const std::string& updatedModuleName)
{
if (updatedModuleName != name)
return;
ShaderAst::ModulePtr newShaderModule = resolver->Resolve(name);
nzsl::Ast::ModulePtr newShaderModule = resolver->Resolve(name);
if (!newShaderModule)
{
NazaraError("failed to retrieve updated shader module " + name);
@@ -56,7 +56,7 @@ namespace Nz
});
}
UberShader::UberShader(ShaderStageTypeFlags shaderStages, ShaderAst::ModulePtr shaderModule) :
UberShader::UberShader(nzsl::ShaderStageTypeFlags shaderStages, nzsl::Ast::ModulePtr shaderModule) :
m_shaderModule(std::move(shaderModule)),
m_shaderStages(shaderStages)
{
@@ -70,7 +70,7 @@ namespace Nz
auto it = m_combinations.find(config);
if (it == m_combinations.end())
{
ShaderWriter::States states;
nzsl::ShaderWriter::States states;
states.optionValues = config.optionValues;
states.shaderModuleResolver = Graphics::Instance()->GetShaderModuleResolver();
@@ -82,28 +82,28 @@ namespace Nz
return it->second;
}
ShaderAst::ModulePtr UberShader::Validate(const ShaderAst::Module& module, std::unordered_map<std::string, Option>* options)
nzsl::Ast::ModulePtr UberShader::Validate(const nzsl::Ast::Module& module, std::unordered_map<std::string, Option>* options)
{
NazaraAssert(m_shaderStages != 0, "there must be at least one shader stage");
assert(options);
// Try to partially sanitize shader
ShaderAst::SanitizeVisitor::Options sanitizeOptions;
nzsl::Ast::SanitizeVisitor::Options sanitizeOptions;
sanitizeOptions.allowPartialSanitization = true;
ShaderAst::ModulePtr sanitizedModule = ShaderAst::Sanitize(module, sanitizeOptions);
nzsl::Ast::ModulePtr sanitizedModule = nzsl::Ast::Sanitize(module, sanitizeOptions);
ShaderStageTypeFlags supportedStageType;
nzsl::ShaderStageTypeFlags supportedStageType;
ShaderAst::AstReflect::Callbacks callbacks;
callbacks.onEntryPointDeclaration = [&](ShaderStageType stageType, const std::string& /*name*/)
nzsl::Ast::ReflectVisitor::Callbacks callbacks;
callbacks.onEntryPointDeclaration = [&](nzsl::ShaderStageType stageType, const std::string& /*name*/)
{
supportedStageType |= stageType;
};
std::unordered_map<std::string, Option> optionByName;
callbacks.onOptionDeclaration = [&](const ShaderAst::DeclareOptionStatement& option)
callbacks.onOptionDeclaration = [&](const nzsl::Ast::DeclareOptionStatement& option)
{
//TODO: Check optionType
@@ -112,7 +112,7 @@ namespace Nz
};
};
ShaderAst::AstReflect reflect;
nzsl::Ast::ReflectVisitor reflect;
reflect.Reflect(*sanitizedModule->rootNode, callbacks);
if ((m_shaderStages & supportedStageType) != m_shaderStages)

View File

@@ -3,12 +3,12 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/ViewerInstance.hpp>
#include <Nazara/Core/StackVector.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Graphics/MaterialSettings.hpp>
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
#include <Nazara/Renderer/UploadPool.hpp>
#include <Nazara/Utils/StackVector.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz

View File

@@ -3,12 +3,12 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/WorldInstance.hpp>
#include <Nazara/Core/StackVector.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Graphics/MaterialSettings.hpp>
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
#include <Nazara/Renderer/UploadPool.hpp>
#include <Nazara/Utils/StackVector.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz

View File

@@ -13,10 +13,11 @@
*/
#include <Nazara/Network/ENetHost.hpp>
#include <Nazara/Core/OffsetOf.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include <Nazara/Network/Algorithm.hpp>
#include <Nazara/Network/ENetPeer.hpp>
#include <Nazara/Network/NetPacket.hpp>
#include <Nazara/Utils/OffsetOf.hpp>
#include <Nazara/Network/Debug.hpp>
namespace Nz

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Network/ENetPacket.hpp>
#include <Nazara/Core/MemoryPool.hpp>
#include <Nazara/Utils/MemoryPool.hpp>
#include <Nazara/Network/Debug.hpp>
namespace Nz

View File

@@ -3,12 +3,12 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Network/Network.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Network/Config.hpp>
#include <Nazara/Network/NetPacket.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Network/Win32/SocketImpl.hpp>

View File

@@ -4,10 +4,10 @@
#include <Nazara/Network/Posix/IpAddressImpl.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Network/Posix/SocketImpl.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <cstring>
#include <Nazara/Network/Debug.hpp>

View File

@@ -5,11 +5,11 @@
#include <Nazara/Network/Posix/SocketImpl.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Network/Algorithm.hpp>
#include <Nazara/Network/NetBuffer.hpp>
#include <Nazara/Network/Posix/IpAddressImpl.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <cstring>
#include <poll.h>
#include <unistd.h>

View File

@@ -5,8 +5,8 @@
// no header guards
#ifdef NAZARA_PLATFORM_WINDOWS
#include <winsock2.h>
#include <ws2tcpip.h>
#include <WS2tcpip.h>
#include <WinSock2.h>
#elif defined(NAZARA_PLATFORM_POSIX)
#include <sys/socket.h>
#endif

View File

@@ -3,10 +3,10 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Network/TcpClient.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Network/NetPacket.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <limits>
#if defined(NAZARA_PLATFORM_WINDOWS)

View File

@@ -4,10 +4,10 @@
#include <Nazara/Network/Win32/IpAddressImpl.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Network/Win32/SocketImpl.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <cstring>
#include <Nazara/Network/Debug.hpp>
@@ -24,7 +24,7 @@ namespace Nz
{
namespace Detail
{
#if NAZARA_CORE_WINDOWS_NT6
#if NAZARA_UTILS_WINDOWS_NT6
using addrinfoImpl = addrinfoW;
int GetAddressInfo(const std::string& hostname, const std::string& service, const addrinfoImpl* hints, addrinfoImpl** results)
@@ -119,7 +119,7 @@ namespace Nz
return IpAddress::Invalid;
}
#if NAZARA_CORE_WINDOWS_NT6
#if NAZARA_UTILS_WINDOWS_NT6
IpAddress IpAddressImpl::FromAddrinfo(const addrinfoW* info)
{
switch (info->ai_family)

View File

@@ -8,8 +8,8 @@
#define NAZARA_NETWORK_WIN32_IPADDRESSIMPL_HPP
#include <Nazara/Network/IpAddress.hpp>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <WS2tcpip.h>
#include <WinSock2.h>
#include <string>
namespace Nz
@@ -23,7 +23,7 @@ namespace Nz
~IpAddressImpl() = delete;
static IpAddress FromAddrinfo(const addrinfo* info);
#if NAZARA_CORE_WINDOWS_NT6
#if NAZARA_UTILS_WINDOWS_NT6
static IpAddress FromAddrinfo(const addrinfoW* info);
#endif
static IpAddress FromSockAddr(const sockaddr* address);

View File

@@ -6,9 +6,9 @@
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Network/Win32/IpAddressImpl.hpp>
#include <Nazara/Utils/StackArray.hpp>
// Some compilers (older versions of MinGW) lack Mstcpip.h which defines some structs/defines
#if defined(__has_include)
@@ -31,8 +31,6 @@ struct tcp_keepalive
#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4)
#endif
#include <WinSock2.h>
#include <Nazara/Network/Debug.hpp>
namespace Nz
@@ -824,7 +822,7 @@ namespace Nz
bool SocketImpl::SetIPv6Only(SocketHandle handle, bool ipv6Only, SocketError* error)
{
#if NAZARA_CORE_WINDOWS_NT6
#if NAZARA_UTILS_WINDOWS_NT6
NazaraAssert(handle != InvalidHandle, "Invalid handle");
DWORD option = ipv6Only;

View File

@@ -11,9 +11,9 @@
#include <Nazara/Network/IpAddress.hpp>
#include <Nazara/Network/NetBuffer.hpp>
#include <Nazara/Network/SocketHandle.hpp>
#include <winsock2.h>
#include <WinSock2.h>
#define NAZARA_NETWORK_POLL_SUPPORT NAZARA_CORE_WINDOWS_NT6
#define NAZARA_NETWORK_POLL_SUPPORT NAZARA_UTILS_WINDOWS_NT6
namespace Nz
{

View File

@@ -10,7 +10,7 @@
#include <Nazara/Network/IpAddress.hpp>
#include <Nazara/Network/SocketHandle.hpp>
#include <Nazara/Network/Win32/SocketImpl.hpp>
#include <winsock2.h>
#include <WinSock2.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/OpenGLBuffer.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <stdexcept>
#include <Nazara/OpenGLRenderer/Debug.hpp>

View File

@@ -3,14 +3,14 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Core/StackVector.hpp>
#include <Nazara/OpenGLRenderer/OpenGLCommandPool.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.hpp>
#include <Nazara/OpenGLRenderer/OpenGLVaoCache.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/VertexArray.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <Nazara/Utils/StackVector.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz

View File

@@ -3,7 +3,6 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPipeline.hpp>
@@ -11,6 +10,7 @@
#include <Nazara/OpenGLRenderer/OpenGLShaderBinding.hpp>
#include <Nazara/OpenGLRenderer/OpenGLTexture.hpp>
#include <Nazara/OpenGLRenderer/OpenGLUploadPool.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz

View File

@@ -3,9 +3,9 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/OpenGLCommandPool.hpp>
#include <Nazara/Core/MemoryHelper.hpp>
#include <Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.hpp>
#include <Nazara/Utils/MemoryHelper.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz

View File

@@ -144,12 +144,12 @@ namespace Nz
return std::make_shared<OpenGLRenderPipelineLayout>(std::move(pipelineLayoutInfo));
}
std::shared_ptr<ShaderModule> OpenGLDevice::InstantiateShaderModule(ShaderStageTypeFlags shaderStages, const ShaderAst::Module& shaderModule, const ShaderWriter::States& states)
std::shared_ptr<ShaderModule> OpenGLDevice::InstantiateShaderModule(nzsl::ShaderStageTypeFlags shaderStages, const nzsl::Ast::Module& shaderModule, const nzsl::ShaderWriter::States& states)
{
return std::make_shared<OpenGLShaderModule>(*this, shaderStages, shaderModule, states);
}
std::shared_ptr<ShaderModule> OpenGLDevice::InstantiateShaderModule(ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const void* source, std::size_t sourceSize, const ShaderWriter::States& states)
std::shared_ptr<ShaderModule> OpenGLDevice::InstantiateShaderModule(nzsl::ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const void* source, std::size_t sourceSize, const nzsl::ShaderWriter::States& states)
{
return std::make_shared<OpenGLShaderModule>(*this, shaderStages, lang, source, sourceSize, states);
}

View File

@@ -7,9 +7,9 @@
#include <Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.hpp>
#include <Nazara/OpenGLRenderer/OpenGLShaderModule.hpp>
#include <Nazara/OpenGLRenderer/Utils.hpp>
#include <Nazara/Shader/GlslWriter.hpp>
#include <Nazara/Shader/ShaderBuilder.hpp>
#include <Nazara/Shader/Ast/Module.hpp>
#include <NZSL/GlslWriter.hpp>
#include <NZSL/ShaderBuilder.hpp>
#include <NZSL/Ast/Module.hpp>
#include <cassert>
#include <stdexcept>
#include <Nazara/OpenGLRenderer/Debug.hpp>
@@ -33,7 +33,7 @@ namespace Nz
// Enable pipeline states before compiling and linking the program, for drivers which embed some pipeline states into the shader binary (to avoid recompilation later)
activeContext->UpdateStates(m_pipelineInfo, false);
ShaderStageTypeFlags stageFlags;
nzsl::ShaderStageTypeFlags stageFlags;
for (const auto& shaderModulePtr : m_pipelineInfo.shaderModules)
{
@@ -44,21 +44,21 @@ namespace Nz
// OpenGL ES programs must have both vertex and fragment shaders or a compute shader or a mesh and fragment shader.
if (device.GetReferenceContext().GetParams().type == GL::ContextType::OpenGL_ES)
{
auto GenerateIfMissing = [&](ShaderStageType stage)
auto GenerateIfMissing = [&](nzsl::ShaderStageType stage)
{
if (!stageFlags.Test(stage))
{
ShaderAst::Module dummyModule(100);
dummyModule.rootNode = ShaderBuilder::MultiStatement();
dummyModule.rootNode->statements.push_back(ShaderBuilder::DeclareFunction(stage, "main", {}, {}));
nzsl::Ast::Module dummyModule(100);
dummyModule.rootNode = nzsl::ShaderBuilder::MultiStatement();
dummyModule.rootNode->statements.push_back(nzsl::ShaderBuilder::DeclareFunction(stage, "main", {}, {}));
OpenGLShaderModule shaderModule(device, stage, dummyModule);
stageFlags |= shaderModule.Attach(m_program, pipelineLayout.GetBindingMapping());
}
};
GenerateIfMissing(ShaderStageType::Fragment);
GenerateIfMissing(ShaderStageType::Vertex);
GenerateIfMissing(nzsl::ShaderStageType::Fragment);
GenerateIfMissing(nzsl::ShaderStageType::Vertex);
}
m_program.Link();
@@ -67,7 +67,7 @@ namespace Nz
if (!m_program.GetLinkStatus(&errLog))
throw std::runtime_error("failed to link program: " + errLog);
m_flipYUniformLocation = m_program.GetUniformLocation(GlslWriter::GetFlipYUniformName());
m_flipYUniformLocation = m_program.GetUniformLocation(nzsl::GlslWriter::GetFlipYUniformName());
if (m_flipYUniformLocation != -1)
m_program.Uniform(m_flipYUniformLocation, 1.f);
}

View File

@@ -4,9 +4,9 @@
#include <Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/MemoryHelper.hpp>
#include <Nazara/Core/StackVector.hpp>
#include <Nazara/OpenGLRenderer/Utils.hpp>
#include <Nazara/Utils/MemoryHelper.hpp>
#include <Nazara/Utils/StackVector.hpp>
#include <cassert>
#include <stdexcept>
#include <Nazara/OpenGLRenderer/Debug.hpp>

View File

@@ -4,11 +4,11 @@
#include <Nazara/OpenGLRenderer/OpenGLShaderBinding.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/StackVector.hpp>
#include <Nazara/OpenGLRenderer/OpenGLBuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.hpp>
#include <Nazara/OpenGLRenderer/OpenGLTexture.hpp>
#include <Nazara/OpenGLRenderer/OpenGLTextureSampler.hpp>
#include <Nazara/Utils/StackVector.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz

View File

@@ -5,22 +5,22 @@
#include <Nazara/OpenGLRenderer/OpenGLShaderModule.hpp>
#include <Nazara/Core/MemoryView.hpp>
#include <Nazara/OpenGLRenderer/Utils.hpp>
#include <Nazara/Shader/ShaderLangLexer.hpp>
#include <Nazara/Shader/ShaderLangParser.hpp>
#include <Nazara/Shader/Ast/AstSerializer.hpp>
#include <NZSL/ShaderLangLexer.hpp>
#include <NZSL/ShaderLangParser.hpp>
#include <NZSL/Ast/AstSerializer.hpp>
#include <stdexcept>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz
{
OpenGLShaderModule::OpenGLShaderModule(OpenGLDevice& device, ShaderStageTypeFlags shaderStages, const ShaderAst::Module& shaderModule, const ShaderWriter::States& states) :
OpenGLShaderModule::OpenGLShaderModule(OpenGLDevice& device, nzsl::ShaderStageTypeFlags shaderStages, const nzsl::Ast::Module& shaderModule, const nzsl::ShaderWriter::States& states) :
m_device(device)
{
NazaraAssert(shaderStages != 0, "at least one shader stage must be specified");
Create(device, shaderStages, shaderModule, states);
}
OpenGLShaderModule::OpenGLShaderModule(OpenGLDevice& device, ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const void* source, std::size_t sourceSize, const ShaderWriter::States& states) :
OpenGLShaderModule::OpenGLShaderModule(OpenGLDevice& device, nzsl::ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const void* source, std::size_t sourceSize, const nzsl::ShaderWriter::States& states) :
m_device(device)
{
NazaraAssert(shaderStages != 0, "at least one shader stage must be specified");
@@ -29,9 +29,9 @@ namespace Nz
{
case ShaderLanguage::GLSL:
{
for (std::size_t i = 0; i < ShaderStageTypeCount; ++i)
for (std::size_t i = 0; i < nzsl::ShaderStageTypeCount; ++i)
{
ShaderStageType shaderStage = static_cast<ShaderStageType>(i);
nzsl::ShaderStageType shaderStage = static_cast<nzsl::ShaderStageType>(i);
if (shaderStages.Test(shaderStage))
{
NazaraAssert(shaderStages == shaderStage, "when supplying GLSL, only one shader stage type can be specified");
@@ -48,18 +48,19 @@ namespace Nz
case ShaderLanguage::NazaraBinary:
{
auto shader = ShaderAst::UnserializeShader(source, sourceSize);
nzsl::Unserializer unserializer(source, sourceSize);
auto shader = nzsl::Ast::UnserializeShader(unserializer);
Create(device, shaderStages, *shader, states);
break;
}
case ShaderLanguage::NazaraShader:
{
std::vector<Nz::ShaderLang::Token> tokens = Nz::ShaderLang::Tokenize(std::string_view(static_cast<const char*>(source), sourceSize));
std::vector<nzsl::Token> tokens = nzsl::Tokenize(std::string_view(static_cast<const char*>(source), sourceSize));
Nz::ShaderLang::Parser parser;
Nz::ShaderAst::ModulePtr shaderAst = parser.Parse(tokens);
Create(device, shaderStages, *shaderAst, states);
nzsl::Parser parser;
nzsl::Ast::ModulePtr module = parser.Parse(tokens);
Create(device, shaderStages, *module, states);
break;
}
@@ -82,12 +83,12 @@ namespace Nz
}
}
ShaderStageTypeFlags OpenGLShaderModule::Attach(GL::Program& program, const GlslWriter::BindingMapping& bindingMapping) const
nzsl::ShaderStageTypeFlags OpenGLShaderModule::Attach(GL::Program& program, const nzsl::GlslWriter::BindingMapping& bindingMapping) const
{
const auto& context = m_device.GetReferenceContext();
const auto& contextParams = context.GetParams();
GlslWriter::Environment env;
nzsl::GlslWriter::Environment env;
env.glES = (contextParams.type == GL::ContextType::OpenGL_ES);
env.glMajorVersion = contextParams.glMajorVersion;
env.glMinorVersion = contextParams.glMinorVersion;
@@ -98,10 +99,10 @@ namespace Nz
env.flipYPosition = true;
env.remapZPosition = true;
GlslWriter writer;
nzsl::GlslWriter writer;
writer.SetEnv(env);
ShaderStageTypeFlags stageFlags;
nzsl::ShaderStageTypeFlags stageFlags;
for (const auto& shaderEntry : m_shaders)
{
GL::Shader shader;
@@ -137,20 +138,20 @@ namespace Nz
return stageFlags;
}
void OpenGLShaderModule::Create(OpenGLDevice& /*device*/, ShaderStageTypeFlags shaderStages, const ShaderAst::Module& shaderModule, const ShaderWriter::States& states)
void OpenGLShaderModule::Create(OpenGLDevice& /*device*/, nzsl::ShaderStageTypeFlags shaderStages, const nzsl::Ast::Module& shaderModule, const nzsl::ShaderWriter::States& states)
{
m_states = states;
m_states.sanitized = true; //< Shader is always sanitized (because of keywords)
ShaderAst::SanitizeVisitor::Options options = GlslWriter::GetSanitizeOptions();
nzsl::Ast::SanitizeVisitor::Options options = nzsl::GlslWriter::GetSanitizeOptions();
options.optionValues = states.optionValues;
options.moduleResolver = states.shaderModuleResolver;
ShaderAst::ModulePtr sanitized = ShaderAst::Sanitize(shaderModule, options);
nzsl::Ast::ModulePtr sanitized = nzsl::Ast::Sanitize(shaderModule, options);
for (std::size_t i = 0; i < ShaderStageTypeCount; ++i)
for (std::size_t i = 0; i < nzsl::ShaderStageTypeCount; ++i)
{
ShaderStageType shaderStage = static_cast<ShaderStageType>(i);
nzsl::ShaderStageType shaderStage = static_cast<nzsl::ShaderStageType>(i);
if (shaderStages.Test(shaderStage))
{
auto& entry = m_shaders.emplace_back();

View File

@@ -3,8 +3,8 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/OpenGLTexture.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <stdexcept>
#include <Nazara/OpenGLRenderer/Debug.hpp>

View File

@@ -3,7 +3,6 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StringExt.hpp>
@@ -11,6 +10,7 @@
#include <Nazara/OpenGLRenderer/OpenGLTexture.hpp>
#include <Nazara/OpenGLRenderer/Utils.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Framebuffer.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <cstring>
#include <sstream>
#include <stdexcept>

View File

@@ -3,10 +3,10 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <array>
#include <cassert>
#include <Nazara/OpenGLRenderer/Debug.hpp>

View File

@@ -3,9 +3,9 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLContext.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLLoader.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <array>
#include <cassert>
#include <Nazara/OpenGLRenderer/Debug.hpp>

View File

@@ -3,11 +3,11 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics2D/Collider2D.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <Nazara/Physics2D/RigidBody2D.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <chipmunk/chipmunk.h>
#include <chipmunk/chipmunk_structs.h>
#include <array>

View File

@@ -3,8 +3,8 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Physics2D/Arbiter2D.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <chipmunk/chipmunk.h>
#include <Nazara/Physics2D/Debug.hpp>

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics3D/PhysWorld3D.hpp>
#include <Nazara/Core/StackVector.hpp>
#include <Nazara/Utils/StackVector.hpp>
#include <newton/Newton.h>
#include <cassert>
#include <Nazara/Physics3D/Debug.hpp>

View File

@@ -3,10 +3,10 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/Platform.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Window.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <Nazara/Platform/Debug.hpp>
namespace Nz

View File

@@ -8,10 +8,10 @@
#define NAZARA_PLATFORM_SDL2_CURSORIMPL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utils/MovablePtr.hpp>
#include <SDL_mouse.h>
namespace Nz

View File

@@ -8,8 +8,8 @@
#define NAZARA_PLATFORM_SDL2_ICONIMPL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utils/MovablePtr.hpp>
#include <SDL_surface.h>
namespace Nz

View File

@@ -3,11 +3,11 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/SDL2/InputImpl.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Platform/Window.hpp>
#include <Nazara/Platform/SDL2/SDLHelper.hpp>
#include <Nazara/Platform/SDL2/WindowImpl.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <SDL_clipboard.h>
#include <SDL_keyboard.h>
#include <SDL_keycode.h>

View File

@@ -3,11 +3,11 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/Window.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Icon.hpp>
#include <Nazara/Platform/SDL2/WindowImpl.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <Nazara/Platform/Debug.hpp>
namespace Nz

View File

@@ -11,7 +11,7 @@ namespace Nz
{
RenderDevice::~RenderDevice() = default;
std::shared_ptr<ShaderModule> RenderDevice::InstantiateShaderModule(ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const std::filesystem::path& sourcePath, const ShaderWriter::States& states)
std::shared_ptr<ShaderModule> RenderDevice::InstantiateShaderModule(nzsl::ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const std::filesystem::path& sourcePath, const nzsl::ShaderWriter::States& states)
{
File file(sourcePath);
if (!file.Open(OpenMode::ReadOnly | OpenMode::Text))

View File

@@ -3,7 +3,6 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StringExt.hpp>
@@ -12,6 +11,7 @@
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <filesystem>
#include <stdexcept>
#include <Nazara/Renderer/Debug.hpp>

View File

@@ -1,624 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstCloner.hpp>
#include <stdexcept>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
ExpressionPtr AstCloner::Clone(Expression& expr)
{
expr.Visit(*this);
assert(m_statementStack.empty() && m_expressionStack.size() == 1);
return PopExpression();
}
StatementPtr AstCloner::Clone(Statement& statement)
{
statement.Visit(*this);
assert(m_expressionStack.empty() && m_statementStack.size() == 1);
return PopStatement();
}
ExpressionPtr AstCloner::CloneExpression(Expression& expr)
{
expr.Visit(*this);
return PopExpression();
}
StatementPtr AstCloner::CloneStatement(Statement& statement)
{
statement.Visit(*this);
return PopStatement();
}
ExpressionValue<ExpressionType> AstCloner::CloneType(const ExpressionValue<ExpressionType>& exprType)
{
if (!exprType.HasValue())
return {};
if (exprType.IsExpression())
return CloneExpression(exprType.GetExpression());
else
{
assert(exprType.IsResultingValue());
return exprType.GetResultingValue();
}
}
StatementPtr AstCloner::Clone(BranchStatement& node)
{
auto clone = std::make_unique<BranchStatement>();
clone->condStatements.reserve(node.condStatements.size());
clone->isConst = node.isConst;
for (auto& cond : node.condStatements)
{
auto& condStatement = clone->condStatements.emplace_back();
condStatement.condition = CloneExpression(cond.condition);
condStatement.statement = CloneStatement(cond.statement);
}
clone->elseStatement = CloneStatement(node.elseStatement);
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(ConditionalStatement& node)
{
auto clone = std::make_unique<ConditionalStatement>();
clone->condition = CloneExpression(node.condition);
clone->statement = CloneStatement(node.statement);
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(DeclareAliasStatement& node)
{
auto clone = std::make_unique<DeclareAliasStatement>();
clone->aliasIndex = node.aliasIndex;
clone->name = node.name;
clone->expression = CloneExpression(node.expression);
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(DeclareConstStatement& node)
{
auto clone = std::make_unique<DeclareConstStatement>();
clone->constIndex = node.constIndex;
clone->name = node.name;
clone->type = Clone(node.type);
clone->expression = CloneExpression(node.expression);
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(DeclareExternalStatement& node)
{
auto clone = std::make_unique<DeclareExternalStatement>();
clone->bindingSet = Clone(node.bindingSet);
clone->externalVars.reserve(node.externalVars.size());
for (const auto& var : node.externalVars)
{
auto& cloneVar = clone->externalVars.emplace_back();
cloneVar.name = var.name;
cloneVar.varIndex = var.varIndex;
cloneVar.type = Clone(var.type);
cloneVar.bindingIndex = Clone(var.bindingIndex);
cloneVar.bindingSet = Clone(var.bindingSet);
cloneVar.sourceLocation = var.sourceLocation;
}
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(DeclareFunctionStatement& node)
{
auto clone = std::make_unique<DeclareFunctionStatement>();
clone->depthWrite = Clone(node.depthWrite);
clone->earlyFragmentTests = Clone(node.earlyFragmentTests);
clone->entryStage = Clone(node.entryStage);
clone->funcIndex = node.funcIndex;
clone->isExported = Clone(node.isExported);
clone->name = node.name;
clone->returnType = Clone(node.returnType);
clone->parameters.reserve(node.parameters.size());
for (auto& parameter : node.parameters)
{
auto& cloneParam = clone->parameters.emplace_back();
cloneParam.name = parameter.name;
cloneParam.type = Clone(parameter.type);
cloneParam.varIndex = parameter.varIndex;
cloneParam.sourceLocation = parameter.sourceLocation;
}
clone->statements.reserve(node.statements.size());
for (auto& statement : node.statements)
clone->statements.push_back(CloneStatement(statement));
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(DeclareOptionStatement& node)
{
auto clone = std::make_unique<DeclareOptionStatement>();
clone->defaultValue = CloneExpression(node.defaultValue);
clone->optIndex = node.optIndex;
clone->optName = node.optName;
clone->optType = Clone(node.optType);
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(DeclareStructStatement& node)
{
auto clone = std::make_unique<DeclareStructStatement>();
clone->isExported = Clone(node.isExported);
clone->structIndex = node.structIndex;
clone->description.layout = Clone(node.description.layout);
clone->description.name = node.description.name;
clone->description.members.reserve(node.description.members.size());
for (const auto& member : node.description.members)
{
auto& cloneMember = clone->description.members.emplace_back();
cloneMember.name = member.name;
cloneMember.type = Clone(member.type);
cloneMember.builtin = Clone(member.builtin);
cloneMember.cond = Clone(member.cond);
cloneMember.locationIndex = Clone(member.locationIndex);
cloneMember.sourceLocation = member.sourceLocation;
}
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(DeclareVariableStatement& node)
{
auto clone = std::make_unique<DeclareVariableStatement>();
clone->initialExpression = CloneExpression(node.initialExpression);
clone->varIndex = node.varIndex;
clone->varName = node.varName;
clone->varType = Clone(node.varType);
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(DiscardStatement& node)
{
auto clone = std::make_unique<DiscardStatement>();
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(ExpressionStatement& node)
{
auto clone = std::make_unique<ExpressionStatement>();
clone->expression = CloneExpression(node.expression);
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(ForStatement& node)
{
auto clone = std::make_unique<ForStatement>();
clone->fromExpr = CloneExpression(node.fromExpr);
clone->stepExpr = CloneExpression(node.stepExpr);
clone->toExpr = CloneExpression(node.toExpr);
clone->statement = CloneStatement(node.statement);
clone->unroll = Clone(node.unroll);
clone->varName = node.varName;
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(ForEachStatement& node)
{
auto clone = std::make_unique<ForEachStatement>();
clone->expression = CloneExpression(node.expression);
clone->statement = CloneStatement(node.statement);
clone->unroll = Clone(node.unroll);
clone->varName = node.varName;
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(ImportStatement& node)
{
auto clone = std::make_unique<ImportStatement>();
clone->moduleName = node.moduleName;
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(MultiStatement& node)
{
auto clone = std::make_unique<MultiStatement>();
clone->statements.reserve(node.statements.size());
for (auto& statement : node.statements)
clone->statements.push_back(CloneStatement(statement));
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(NoOpStatement& node)
{
auto clone = std::make_unique<NoOpStatement>();
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(ReturnStatement& node)
{
auto clone = std::make_unique<ReturnStatement>();
clone->returnExpr = CloneExpression(node.returnExpr);
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(ScopedStatement& node)
{
auto clone = std::make_unique<ScopedStatement>();
clone->statement = CloneStatement(node.statement);
clone->sourceLocation = node.sourceLocation;
return clone;
}
StatementPtr AstCloner::Clone(WhileStatement& node)
{
auto clone = std::make_unique<WhileStatement>();
clone->condition = CloneExpression(node.condition);
clone->body = CloneStatement(node.body);
clone->unroll = Clone(node.unroll);
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(AccessIdentifierExpression& node)
{
auto clone = std::make_unique<AccessIdentifierExpression>();
clone->identifiers = node.identifiers;
clone->expr = CloneExpression(node.expr);
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(AccessIndexExpression& node)
{
auto clone = std::make_unique<AccessIndexExpression>();
clone->expr = CloneExpression(node.expr);
clone->indices.reserve(node.indices.size());
for (auto& parameter : node.indices)
clone->indices.push_back(CloneExpression(parameter));
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(AliasValueExpression& node)
{
auto clone = std::make_unique<AliasValueExpression>();
clone->aliasId = node.aliasId;
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(AssignExpression& node)
{
auto clone = std::make_unique<AssignExpression>();
clone->op = node.op;
clone->left = CloneExpression(node.left);
clone->right = CloneExpression(node.right);
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(BinaryExpression& node)
{
auto clone = std::make_unique<BinaryExpression>();
clone->op = node.op;
clone->left = CloneExpression(node.left);
clone->right = CloneExpression(node.right);
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(CallFunctionExpression& node)
{
auto clone = std::make_unique<CallFunctionExpression>();
clone->targetFunction = CloneExpression(node.targetFunction);
clone->parameters.reserve(node.parameters.size());
for (auto& parameter : node.parameters)
clone->parameters.push_back(CloneExpression(parameter));
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(CallMethodExpression& node)
{
auto clone = std::make_unique<CallMethodExpression>();
clone->methodName = node.methodName;
clone->object = CloneExpression(node.object);
clone->parameters.reserve(node.parameters.size());
for (auto& parameter : node.parameters)
clone->parameters.push_back(CloneExpression(parameter));
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(CastExpression& node)
{
auto clone = std::make_unique<CastExpression>();
clone->targetType = Clone(node.targetType);
for (std::size_t expressionIndex = 0; expressionIndex < node.expressions.size(); ++expressionIndex)
{
auto& expr = node.expressions[expressionIndex];
if (!expr)
break;
clone->expressions[expressionIndex] = CloneExpression(expr);
}
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(ConditionalExpression& node)
{
auto clone = std::make_unique<ConditionalExpression>();
clone->condition = CloneExpression(node.condition);
clone->falsePath = CloneExpression(node.falsePath);
clone->truePath = CloneExpression(node.truePath);
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(ConstantExpression& node)
{
auto clone = std::make_unique<ConstantExpression>();
clone->constantId = node.constantId;
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(ConstantValueExpression& node)
{
auto clone = std::make_unique<ConstantValueExpression>();
clone->value = node.value;
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(FunctionExpression& node)
{
auto clone = std::make_unique<FunctionExpression>();
clone->funcId = node.funcId;
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(IdentifierExpression& node)
{
auto clone = std::make_unique<IdentifierExpression>();
clone->identifier = node.identifier;
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(IntrinsicExpression& node)
{
auto clone = std::make_unique<IntrinsicExpression>();
clone->intrinsic = node.intrinsic;
clone->parameters.reserve(node.parameters.size());
for (auto& parameter : node.parameters)
clone->parameters.push_back(CloneExpression(parameter));
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(IntrinsicFunctionExpression& node)
{
auto clone = std::make_unique<IntrinsicFunctionExpression>();
clone->intrinsicId = node.intrinsicId;
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(StructTypeExpression& node)
{
auto clone = std::make_unique<StructTypeExpression>();
clone->structTypeId = node.structTypeId;
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(SwizzleExpression& node)
{
auto clone = std::make_unique<SwizzleExpression>();
clone->componentCount = node.componentCount;
clone->components = node.components;
clone->expression = CloneExpression(node.expression);
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(TypeExpression& node)
{
auto clone = std::make_unique<TypeExpression>();
clone->typeId = node.typeId;
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(VariableValueExpression& node)
{
auto clone = std::make_unique<VariableValueExpression>();
clone->variableId = node.variableId;
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
ExpressionPtr AstCloner::Clone(UnaryExpression& node)
{
auto clone = std::make_unique<UnaryExpression>();
clone->expression = CloneExpression(node.expression);
clone->op = node.op;
clone->cachedExpressionType = node.cachedExpressionType;
clone->sourceLocation = node.sourceLocation;
return clone;
}
#define NAZARA_SHADERAST_EXPRESSION(NodeType) void AstCloner::Visit(NodeType& node) \
{ \
PushExpression(Clone(node)); \
}
#define NAZARA_SHADERAST_STATEMENT(NodeType) void AstCloner::Visit(NodeType& node) \
{ \
PushStatement(Clone(node)); \
}
#include <Nazara/Shader/Ast/AstNodeList.hpp>
void AstCloner::PushExpression(ExpressionPtr expression)
{
m_expressionStack.emplace_back(std::move(expression));
}
void AstCloner::PushStatement(StatementPtr statement)
{
m_statementStack.emplace_back(std::move(statement));
}
ExpressionPtr AstCloner::PopExpression()
{
assert(!m_expressionStack.empty());
ExpressionPtr expr = std::move(m_expressionStack.back());
m_expressionStack.pop_back();
return expr;
}
StatementPtr AstCloner::PopStatement()
{
assert(!m_statementStack.empty());
StatementPtr expr = std::move(m_statementStack.back());
m_statementStack.pop_back();
return expr;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,34 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstExportVisitor.hpp>
#include <stdexcept>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
void AstExportVisitor::Visit(Statement& statement, const Callbacks& callbacks)
{
m_callbacks = &callbacks;
statement.Visit(*this);
}
void AstExportVisitor::Visit(DeclareFunctionStatement& node)
{
if (!node.isExported.HasValue() || !node.isExported.GetResultingValue())
return;
if (m_callbacks->onExportedFunc)
m_callbacks->onExportedFunc(node);
}
void AstExportVisitor::Visit(DeclareStructStatement& node)
{
if (!node.isExported.HasValue() || !node.isExported.GetResultingValue())
return;
if (m_callbacks->onExportedStruct)
m_callbacks->onExportedStruct(node);
}
}

View File

@@ -1,11 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstExpressionVisitor.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
AstExpressionVisitor::~AstExpressionVisitor() = default;
}

View File

@@ -1,15 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstExpressionVisitorExcept.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
#define NAZARA_SHADERAST_EXPRESSION(Node) void AstExpressionVisitorExcept::Visit(ShaderAst::Node& /*node*/) \
{ \
throw std::runtime_error("unexpected " #Node " node"); \
}
#include <Nazara/Shader/Ast/AstNodeList.hpp>
}

View File

@@ -1,255 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstRecursiveVisitor.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
void AstRecursiveVisitor::Visit(AccessIdentifierExpression& node)
{
node.expr->Visit(*this);
}
void AstRecursiveVisitor::Visit(AccessIndexExpression& node)
{
node.expr->Visit(*this);
for (auto& index : node.indices)
index->Visit(*this);
}
void AstRecursiveVisitor::Visit(AliasValueExpression& /*node*/)
{
/* nothing to do */
}
void AstRecursiveVisitor::Visit(AssignExpression& node)
{
node.left->Visit(*this);
node.right->Visit(*this);
}
void AstRecursiveVisitor::Visit(BinaryExpression& node)
{
node.left->Visit(*this);
node.right->Visit(*this);
}
void AstRecursiveVisitor::Visit(CallFunctionExpression& node)
{
for (auto& param : node.parameters)
param->Visit(*this);
}
void AstRecursiveVisitor::Visit(CallMethodExpression& node)
{
node.object->Visit(*this);
for (auto& param : node.parameters)
param->Visit(*this);
}
void AstRecursiveVisitor::Visit(CastExpression& node)
{
for (auto& expr : node.expressions)
{
if (!expr)
break;
expr->Visit(*this);
}
}
void AstRecursiveVisitor::Visit(ConditionalExpression& node)
{
node.truePath->Visit(*this);
node.falsePath->Visit(*this);
}
void AstRecursiveVisitor::Visit(ConstantValueExpression& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(ConstantExpression& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(FunctionExpression& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(IdentifierExpression& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(IntrinsicExpression& node)
{
for (auto& param : node.parameters)
param->Visit(*this);
}
void AstRecursiveVisitor::Visit(IntrinsicFunctionExpression& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(StructTypeExpression& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(SwizzleExpression& node)
{
if (node.expression)
node.expression->Visit(*this);
}
void AstRecursiveVisitor::Visit(TypeExpression& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(VariableValueExpression& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(UnaryExpression& node)
{
if (node.expression)
node.expression->Visit(*this);
}
void AstRecursiveVisitor::Visit(BranchStatement& node)
{
for (auto& cond : node.condStatements)
{
cond.condition->Visit(*this);
cond.statement->Visit(*this);
}
if (node.elseStatement)
node.elseStatement->Visit(*this);
}
void AstRecursiveVisitor::Visit(ConditionalStatement& node)
{
node.statement->Visit(*this);
}
void AstRecursiveVisitor::Visit(DeclareAliasStatement& node)
{
if (node.expression)
node.expression->Visit(*this);
}
void AstRecursiveVisitor::Visit(DeclareConstStatement& node)
{
if (node.expression)
node.expression->Visit(*this);
}
void AstRecursiveVisitor::Visit(DeclareExternalStatement& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(DeclareFunctionStatement& node)
{
for (auto& statement : node.statements)
statement->Visit(*this);
}
void AstRecursiveVisitor::Visit(DeclareOptionStatement& node)
{
if (node.defaultValue)
node.defaultValue->Visit(*this);
}
void AstRecursiveVisitor::Visit(DeclareStructStatement& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(DeclareVariableStatement& node)
{
if (node.initialExpression)
node.initialExpression->Visit(*this);
}
void AstRecursiveVisitor::Visit(DiscardStatement& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(ExpressionStatement& node)
{
node.expression->Visit(*this);
}
void AstRecursiveVisitor::Visit(ForStatement& node)
{
if (node.fromExpr)
node.fromExpr->Visit(*this);
if (node.toExpr)
node.toExpr->Visit(*this);
if (node.stepExpr)
node.stepExpr->Visit(*this);
if (node.statement)
node.statement->Visit(*this);
}
void AstRecursiveVisitor::Visit(ForEachStatement& node)
{
if (node.expression)
node.expression->Visit(*this);
if (node.statement)
node.statement->Visit(*this);
}
void AstRecursiveVisitor::Visit(ImportStatement& /*node*/)
{
/* nothing to do */
}
void AstRecursiveVisitor::Visit(MultiStatement& node)
{
for (auto& statement : node.statements)
statement->Visit(*this);
}
void AstRecursiveVisitor::Visit(NoOpStatement& /*node*/)
{
/* Nothing to do */
}
void AstRecursiveVisitor::Visit(ReturnStatement& node)
{
if (node.returnExpr)
node.returnExpr->Visit(*this);
}
void AstRecursiveVisitor::Visit(ScopedStatement& node)
{
if (node.statement)
node.statement->Visit(*this);
}
void AstRecursiveVisitor::Visit(WhileStatement& node)
{
if (node.condition)
node.condition->Visit(*this);
if (node.body)
node.body->Visit(*this);
}
}

View File

@@ -1,142 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstReflect.hpp>
#include <stdexcept>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
void AstReflect::Reflect(Statement& statement, const Callbacks& callbacks)
{
m_callbacks = &callbacks;
statement.Visit(*this);
}
void AstReflect::Visit(DeclareAliasStatement& node)
{
assert(m_callbacks);
if (m_callbacks->onAliasDeclaration)
m_callbacks->onAliasDeclaration(node);
if (m_callbacks->onAliasIndex && node.aliasIndex)
m_callbacks->onAliasIndex(node.name, *node.aliasIndex, node.sourceLocation);
AstRecursiveVisitor::Visit(node);
}
void AstReflect::Visit(DeclareConstStatement& node)
{
assert(m_callbacks);
if (m_callbacks->onConstDeclaration)
m_callbacks->onConstDeclaration(node);
if (m_callbacks->onConstIndex && node.constIndex)
m_callbacks->onConstIndex(node.name, *node.constIndex, node.sourceLocation);
AstRecursiveVisitor::Visit(node);
}
void AstReflect::Visit(DeclareExternalStatement& node)
{
assert(m_callbacks);
if (m_callbacks->onExternalDeclaration)
m_callbacks->onExternalDeclaration(node);
if (m_callbacks->onVariableIndex)
{
for (const auto& extVar : node.externalVars)
{
if (extVar.varIndex)
m_callbacks->onVariableIndex(extVar.name, *extVar.varIndex, extVar.sourceLocation);
}
}
AstRecursiveVisitor::Visit(node);
}
void AstReflect::Visit(DeclareFunctionStatement& node)
{
assert(m_callbacks);
if (m_callbacks->onFunctionDeclaration)
m_callbacks->onFunctionDeclaration(node);
if (node.funcIndex && m_callbacks->onFunctionIndex)
m_callbacks->onFunctionIndex(node.name, *node.funcIndex, node.sourceLocation);
if (m_callbacks->onEntryPointDeclaration)
{
if (!node.entryStage.HasValue())
return;
m_callbacks->onEntryPointDeclaration(node.entryStage.GetResultingValue(), node.name);
}
if (m_callbacks->onVariableIndex)
{
for (const auto& parameter : node.parameters)
{
if (parameter.varIndex)
m_callbacks->onVariableIndex(parameter.name, *parameter.varIndex, parameter.sourceLocation);
}
}
AstRecursiveVisitor::Visit(node);
}
void AstReflect::Visit(DeclareOptionStatement& node)
{
assert(m_callbacks);
if (m_callbacks->onOptionDeclaration)
m_callbacks->onOptionDeclaration(node);
if (m_callbacks->onOptionIndex && node.optIndex)
m_callbacks->onOptionIndex(node.optName, *node.optIndex, node.sourceLocation);
AstRecursiveVisitor::Visit(node);
}
void AstReflect::Visit(DeclareStructStatement& node)
{
assert(m_callbacks);
if (m_callbacks->onStructDeclaration)
m_callbacks->onStructDeclaration(node);
if (m_callbacks->onStructIndex && node.structIndex)
m_callbacks->onStructIndex(node.description.name, *node.structIndex, node.sourceLocation);
AstRecursiveVisitor::Visit(node);
}
void AstReflect::Visit(DeclareVariableStatement& node)
{
assert(m_callbacks);
if (m_callbacks->onVariableDeclaration)
m_callbacks->onVariableDeclaration(node);
if (m_callbacks->onVariableIndex && node.varIndex)
m_callbacks->onVariableIndex(node.varName, *node.varIndex, node.sourceLocation);
AstRecursiveVisitor::Visit(node);
}
void AstReflect::Visit(ForStatement& node)
{
assert(m_callbacks);
if (m_callbacks->onVariableIndex && node.varIndex)
m_callbacks->onVariableIndex(node.varName, *node.varIndex, node.sourceLocation);
AstRecursiveVisitor::Visit(node);
}
void AstReflect::Visit(ForEachStatement& node)
{
assert(m_callbacks);
if (m_callbacks->onVariableIndex && node.varIndex)
m_callbacks->onVariableIndex(node.varName, *node.varIndex, node.sourceLocation);
AstRecursiveVisitor::Visit(node);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstStatementVisitor.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
AstStatementVisitor::~AstStatementVisitor() = default;
}

View File

@@ -1,15 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstStatementVisitorExcept.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
#define NAZARA_SHADERAST_STATEMENT(Node) void AstStatementVisitorExcept::Visit(ShaderAst::Node& /*node*/) \
{ \
throw std::runtime_error("unexpected " #Node " node"); \
}
#include <Nazara/Shader/Ast/AstNodeList.hpp>
}

View File

@@ -1,154 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstUtils.hpp>
#include <cassert>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
ExpressionCategory ShaderAstValueCategory::GetExpressionCategory(Expression& expression)
{
expression.Visit(*this);
return m_expressionCategory;
}
void ShaderAstValueCategory::Visit(AccessIdentifierExpression& node)
{
node.expr->Visit(*this);
}
void ShaderAstValueCategory::Visit(AccessIndexExpression& node)
{
node.expr->Visit(*this);
}
void ShaderAstValueCategory::Visit(AliasValueExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::LValue;
}
void ShaderAstValueCategory::Visit(AssignExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::RValue;
}
void ShaderAstValueCategory::Visit(BinaryExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::RValue;
}
void ShaderAstValueCategory::Visit(CallFunctionExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::RValue;
}
void ShaderAstValueCategory::Visit(CallMethodExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::RValue;
}
void ShaderAstValueCategory::Visit(CastExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::RValue;
}
void ShaderAstValueCategory::Visit(ConditionalExpression& node)
{
node.truePath->Visit(*this);
ExpressionCategory trueExprCategory = m_expressionCategory;
node.falsePath->Visit(*this);
ExpressionCategory falseExprCategory = m_expressionCategory;
if (trueExprCategory == ExpressionCategory::RValue || falseExprCategory == ExpressionCategory::RValue)
m_expressionCategory = ExpressionCategory::RValue;
else
m_expressionCategory = ExpressionCategory::LValue;
}
void ShaderAstValueCategory::Visit(ConstantValueExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::RValue;
}
void ShaderAstValueCategory::Visit(ConstantExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::LValue;
}
void ShaderAstValueCategory::Visit(FunctionExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::LValue;
}
void ShaderAstValueCategory::Visit(IdentifierExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::LValue;
}
void ShaderAstValueCategory::Visit(IntrinsicExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::RValue;
}
void ShaderAstValueCategory::Visit(IntrinsicFunctionExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::LValue;
}
void ShaderAstValueCategory::Visit(StructTypeExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::LValue;
}
void ShaderAstValueCategory::Visit(SwizzleExpression& node)
{
const ExpressionType* exprType = GetExpressionType(node);
assert(exprType);
if (IsPrimitiveType(*exprType) && node.componentCount > 1)
// Swizzling more than a component on a primitive produces a rvalue (a.xxxx cannot be assigned)
m_expressionCategory = ExpressionCategory::RValue;
else
{
bool isRVaLue = false;
std::array<bool, 4> used;
used.fill(false);
for (std::size_t i = 0; i < node.componentCount; ++i)
{
if (used[node.components[i]])
{
// Swizzling the same component multiple times produces a rvalue (a.xx cannot be assigned)
isRVaLue = true;
break;
}
used[node.components[i]] = true;
}
if (isRVaLue)
m_expressionCategory = ExpressionCategory::RValue;
else
node.expression->Visit(*this);
}
}
void ShaderAstValueCategory::Visit(TypeExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::LValue;
}
void ShaderAstValueCategory::Visit(VariableValueExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::LValue;
}
void ShaderAstValueCategory::Visit(UnaryExpression& /*node*/)
{
m_expressionCategory = ExpressionCategory::RValue;
}
}

View File

@@ -1,45 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/ConstantValue.hpp>
#include <Nazara/Shader/Ast/Nodes.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
ExpressionType GetConstantType(const ConstantValue& constant)
{
return std::visit([&](auto&& arg) -> ShaderAst::ExpressionType
{
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, NoValue>)
return NoType{};
else if constexpr (std::is_same_v<T, bool>)
return PrimitiveType::Boolean;
else if constexpr (std::is_same_v<T, float>)
return PrimitiveType::Float32;
else if constexpr (std::is_same_v<T, Int32>)
return PrimitiveType::Int32;
else if constexpr (std::is_same_v<T, UInt32>)
return PrimitiveType::UInt32;
else if constexpr (std::is_same_v<T, std::string>)
return PrimitiveType::String;
else if constexpr (std::is_same_v<T, Vector2f>)
return VectorType{ 2, PrimitiveType::Float32 };
else if constexpr (std::is_same_v<T, Vector3f>)
return VectorType{ 3, PrimitiveType::Float32 };
else if constexpr (std::is_same_v<T, Vector4f>)
return VectorType{ 4, PrimitiveType::Float32 };
else if constexpr (std::is_same_v<T, Vector2i32>)
return VectorType{ 2, PrimitiveType::Int32 };
else if constexpr (std::is_same_v<T, Vector3i32>)
return VectorType{ 3, PrimitiveType::Int32 };
else if constexpr (std::is_same_v<T, Vector4i32>)
return VectorType{ 4, PrimitiveType::Int32 };
else
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
}, constant);
}
}

View File

@@ -1,212 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/DependencyCheckerVisitor.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
void DependencyCheckerVisitor::Register(Statement& statement, const Config& config)
{
m_config = config;
statement.Visit(*this);
}
auto DependencyCheckerVisitor::GetContextUsageSet() -> UsageSet&
{
if (m_currentAliasDeclIndex)
return Retrieve(m_aliasUsages, *m_currentAliasDeclIndex);
else if (m_currentVariableDeclIndex)
return Retrieve(m_variableUsages, *m_currentVariableDeclIndex);
else
{
assert(m_currentFunctionIndex);
return Retrieve(m_functionUsages, *m_currentFunctionIndex);
}
}
void DependencyCheckerVisitor::RegisterType(UsageSet& usageSet, const ExpressionType& exprType)
{
std::visit([&](auto&& arg)
{
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, AliasType>)
usageSet.usedAliases.UnboundedSet(arg.aliasIndex);
else if constexpr (std::is_same_v<T, StructType>)
usageSet.usedStructs.UnboundedSet(arg.structIndex);
else if constexpr (std::is_same_v<T, UniformType>)
usageSet.usedStructs.UnboundedSet(arg.containedType.structIndex);
}, exprType);
}
void DependencyCheckerVisitor::Resolve(const UsageSet& usageSet, bool allowUnknownId)
{
m_resolvedUsage.usedAliases |= usageSet.usedAliases;
m_resolvedUsage.usedFunctions |= usageSet.usedFunctions;
m_resolvedUsage.usedStructs |= usageSet.usedStructs;
m_resolvedUsage.usedVariables |= usageSet.usedVariables;
for (std::size_t aliasIndex = usageSet.usedAliases.FindFirst(); aliasIndex != usageSet.usedAliases.npos; aliasIndex = usageSet.usedAliases.FindNext(aliasIndex))
{
auto it = m_aliasUsages.find(aliasIndex);
if (it != m_aliasUsages.end())
Resolve(it->second, allowUnknownId);
else if (!allowUnknownId)
throw std::runtime_error("unknown alias #" + std::to_string(aliasIndex));
}
for (std::size_t funcIndex = usageSet.usedFunctions.FindFirst(); funcIndex != usageSet.usedFunctions.npos; funcIndex = usageSet.usedFunctions.FindNext(funcIndex))
{
auto it = m_functionUsages.find(funcIndex);
if (it != m_functionUsages.end())
Resolve(it->second, allowUnknownId);
else if (!allowUnknownId)
throw std::runtime_error("unknown func #" + std::to_string(funcIndex));
}
for (std::size_t structIndex = usageSet.usedStructs.FindFirst(); structIndex != usageSet.usedStructs.npos; structIndex = usageSet.usedStructs.FindNext(structIndex))
{
auto it = m_structUsages.find(structIndex);
if (it != m_structUsages.end())
Resolve(it->second, allowUnknownId);
else if (!allowUnknownId)
throw std::runtime_error("unknown struct #" + std::to_string(structIndex));
}
for (std::size_t varIndex = usageSet.usedVariables.FindFirst(); varIndex != usageSet.usedVariables.npos; varIndex = usageSet.usedVariables.FindNext(varIndex))
{
auto it = m_variableUsages.find(varIndex);
if (it != m_variableUsages.end())
Resolve(it->second, allowUnknownId);
else if (!allowUnknownId)
throw std::runtime_error("unknown var #" + std::to_string(varIndex));
}
}
void DependencyCheckerVisitor::Visit(DeclareAliasStatement& node)
{
assert(node.aliasIndex);
assert(m_aliasUsages.find(*node.aliasIndex) == m_aliasUsages.end());
m_aliasUsages.emplace(*node.aliasIndex, UsageSet{});
assert(node.aliasIndex);
m_currentAliasDeclIndex = *node.aliasIndex;
AstRecursiveVisitor::Visit(node);
m_currentAliasDeclIndex = {};
}
void DependencyCheckerVisitor::Visit(DeclareExternalStatement& node)
{
for (const auto& externalVar : node.externalVars)
{
assert(externalVar.varIndex);
std::size_t varIndex = *externalVar.varIndex;
assert(m_variableUsages.find(varIndex) == m_variableUsages.end());
UsageSet& usageSet = m_variableUsages[varIndex];
const auto& exprType = externalVar.type.GetResultingValue();
RegisterType(usageSet, exprType);
++varIndex;
}
AstRecursiveVisitor::Visit(node);
}
void DependencyCheckerVisitor::Visit(DeclareFunctionStatement& node)
{
assert(node.funcIndex);
assert(m_functionUsages.find(*node.funcIndex) == m_functionUsages.end());
UsageSet& usageSet = m_functionUsages[*node.funcIndex];
// Register struct used in parameters or return type
if (!node.parameters.empty())
{
for (auto& parameter : node.parameters)
{
assert(parameter.varIndex);
// Since parameters must always be defined, their type isn't a dependency of parameter variables
assert(m_variableUsages.find(*parameter.varIndex) == m_variableUsages.end());
m_variableUsages.emplace(*parameter.varIndex, UsageSet{});
const auto& exprType = parameter.type.GetResultingValue();
RegisterType(usageSet, exprType);
}
}
if (node.returnType.HasValue())
{
const auto& returnExprType = node.returnType.GetResultingValue();
RegisterType(usageSet, returnExprType);
}
if (node.entryStage.HasValue())
{
ShaderStageType shaderStage = node.entryStage.GetResultingValue();
if (m_config.usedShaderStages & shaderStage)
m_globalUsage.usedFunctions.UnboundedSet(*node.funcIndex);
}
m_currentFunctionIndex = node.funcIndex;
AstRecursiveVisitor::Visit(node);
m_currentFunctionIndex = {};
}
void DependencyCheckerVisitor::Visit(DeclareStructStatement& node)
{
assert(node.structIndex);
assert(m_structUsages.find(*node.structIndex) == m_structUsages.end());
UsageSet& usageSet = m_structUsages[*node.structIndex];
for (const auto& structMember : node.description.members)
{
const auto& memberExprType = structMember.type.GetResultingValue();
RegisterType(usageSet, memberExprType);
}
AstRecursiveVisitor::Visit(node);
}
void DependencyCheckerVisitor::Visit(DeclareVariableStatement& node)
{
assert(node.varIndex);
assert(m_variableUsages.find(*node.varIndex) == m_variableUsages.end());
UsageSet& usageSet = m_variableUsages[*node.varIndex];
const auto& varType = node.varType.GetResultingValue();
RegisterType(usageSet, varType);
m_currentVariableDeclIndex = node.varIndex;
AstRecursiveVisitor::Visit(node);
m_currentVariableDeclIndex = {};
}
void DependencyCheckerVisitor::Visit(AliasValueExpression& node)
{
UsageSet& usageSet = GetContextUsageSet();
usageSet.usedAliases.UnboundedSet(node.aliasId);
}
void DependencyCheckerVisitor::Visit(FunctionExpression& node)
{
UsageSet& usageSet = GetContextUsageSet();
usageSet.usedFunctions.UnboundedSet(node.funcId);
}
void DependencyCheckerVisitor::Visit(StructTypeExpression& node)
{
UsageSet& usageSet = GetContextUsageSet();
usageSet.usedStructs.UnboundedSet(node.structTypeId);
}
void DependencyCheckerVisitor::Visit(VariableValueExpression& node)
{
UsageSet& usageSet = GetContextUsageSet();
usageSet.usedVariables.UnboundedSet(node.variableId);
}
}

View File

@@ -1,134 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/EliminateUnusedPassVisitor.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Shader/ShaderBuilder.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
struct EliminateUnusedPassVisitor::Context
{
const DependencyCheckerVisitor::UsageSet& usageSet;
};
ModulePtr EliminateUnusedPassVisitor::Process(const Module& shaderModule, const DependencyCheckerVisitor::UsageSet& usageSet)
{
auto rootNode = StaticUniquePointerCast<MultiStatement>(Process(*shaderModule.rootNode, usageSet));
return std::make_shared<Module>(shaderModule.metadata, std::move(rootNode), shaderModule.importedModules);
}
StatementPtr EliminateUnusedPassVisitor::Process(Statement& statement, const DependencyCheckerVisitor::UsageSet& usageSet)
{
Context context{
usageSet
};
m_context = &context;
CallOnExit onExit([this]()
{
m_context = nullptr;
});
return Clone(statement);
}
StatementPtr EliminateUnusedPassVisitor::Clone(DeclareAliasStatement& node)
{
assert(node.aliasIndex);
if (!IsAliasUsed(*node.aliasIndex))
return ShaderBuilder::NoOp();
return AstCloner::Clone(node);
}
StatementPtr EliminateUnusedPassVisitor::Clone(DeclareExternalStatement& node)
{
bool isUsed = false;
for (const auto& externalVar : node.externalVars)
{
assert(externalVar.varIndex);
std::size_t varIndex = *externalVar.varIndex;
if (IsVariableUsed(varIndex))
{
isUsed = true;
break;
}
}
if (!isUsed)
return ShaderBuilder::NoOp();
auto clonedNode = AstCloner::Clone(node);
auto& externalStatement = static_cast<DeclareExternalStatement&>(*clonedNode);
for (auto it = externalStatement.externalVars.begin(); it != externalStatement.externalVars.end(); )
{
const auto& externalVar = *it;
assert(externalVar.varIndex);
std::size_t varIndex = *externalVar.varIndex;
if (!IsVariableUsed(varIndex))
it = externalStatement.externalVars.erase(it);
else
++it;
}
return clonedNode;
}
StatementPtr EliminateUnusedPassVisitor::Clone(DeclareFunctionStatement& node)
{
assert(node.funcIndex);
if (!IsFunctionUsed(*node.funcIndex))
return ShaderBuilder::NoOp();
return AstCloner::Clone(node);
}
StatementPtr EliminateUnusedPassVisitor::Clone(DeclareStructStatement& node)
{
assert(node.structIndex);
if (!IsStructUsed(*node.structIndex))
return ShaderBuilder::NoOp();
return AstCloner::Clone(node);
}
StatementPtr EliminateUnusedPassVisitor::Clone(DeclareVariableStatement& node)
{
assert(node.varIndex);
if (!IsVariableUsed(*node.varIndex))
return ShaderBuilder::NoOp();
return AstCloner::Clone(node);
}
bool EliminateUnusedPassVisitor::IsAliasUsed(std::size_t aliasIndex) const
{
assert(m_context);
return m_context->usageSet.usedAliases.UnboundedTest(aliasIndex);
}
bool EliminateUnusedPassVisitor::IsFunctionUsed(std::size_t funcIndex) const
{
assert(m_context);
return m_context->usageSet.usedFunctions.UnboundedTest(funcIndex);
}
bool EliminateUnusedPassVisitor::IsStructUsed(std::size_t structIndex) const
{
assert(m_context);
return m_context->usageSet.usedStructs.UnboundedTest(structIndex);
}
bool EliminateUnusedPassVisitor::IsVariableUsed(std::size_t varIndex) const
{
assert(m_context);
return m_context->usageSet.usedVariables.UnboundedTest(varIndex);
}
}

View File

@@ -1,244 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/ExpressionType.hpp>
#include <Nazara/Shader/Ast/AstCloner.hpp>
#include <Nazara/Shader/Ast/AstCompare.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
AliasType::AliasType(const AliasType& alias) :
aliasIndex(alias.aliasIndex)
{
assert(alias.targetType);
targetType = std::make_unique<ContainedType>(*alias.targetType);
}
AliasType& AliasType::operator=(const AliasType& alias)
{
aliasIndex = alias.aliasIndex;
assert(alias.targetType);
targetType = std::make_unique<ContainedType>(*alias.targetType);
return *this;
}
bool AliasType::operator==(const AliasType& rhs) const
{
assert(targetType);
assert(rhs.targetType);
if (aliasIndex != rhs.aliasIndex)
return false;
if (targetType->type != rhs.targetType->type)
return false;
return true;
}
ArrayType::ArrayType(const ArrayType& array) :
length(array.length)
{
assert(array.containedType);
containedType = std::make_unique<ContainedType>(*array.containedType);
}
ArrayType& ArrayType::operator=(const ArrayType& array)
{
assert(array.containedType);
containedType = std::make_unique<ContainedType>(*array.containedType);
length = array.length;
return *this;
}
bool ArrayType::operator==(const ArrayType& rhs) const
{
assert(containedType);
assert(rhs.containedType);
if (length != rhs.length)
return false;
if (containedType->type != rhs.containedType->type)
return false;
return true;
}
MethodType::MethodType(const MethodType& methodType) :
methodIndex(methodType.methodIndex)
{
assert(methodType.objectType);
objectType = std::make_unique<ContainedType>(*methodType.objectType);
}
MethodType& MethodType::operator=(const MethodType& methodType)
{
assert(methodType.objectType);
methodIndex = methodType.methodIndex;
objectType = std::make_unique<ContainedType>(*methodType.objectType);
return *this;
}
bool MethodType::operator==(const MethodType& rhs) const
{
assert(objectType);
assert(rhs.objectType);
return objectType->type == rhs.objectType->type && methodIndex == rhs.methodIndex;
}
std::string ToString(const AliasType& type, const Stringifier& stringifier)
{
std::string str = "alias ";
if (stringifier.aliasStringifier)
str += stringifier.aliasStringifier(type.aliasIndex);
else
{
str += "#";
str += std::to_string(type.aliasIndex);
}
str += " -> ";
str += ToString(type.targetType->type);
return str;
}
std::string ToString(const ArrayType& type, const Stringifier& stringifier)
{
std::string str = "array[";
str += ToString(type.containedType->type, stringifier);
str += ", ";
str += std::to_string(type.length);
str += "]";
return str;
}
std::string ToString(const ExpressionType& type, const Stringifier& stringifier)
{
return std::visit([&](auto&& arg)
{
return ToString(arg, stringifier);
}, type);
}
std::string ToString(const FunctionType& /*type*/, const Stringifier& /*stringifier*/)
{
return "<function type>";
}
std::string ToString(const IntrinsicFunctionType& /*type*/, const Stringifier& /*stringifier*/)
{
return "<intrinsic function type>";
}
std::string ToString(const MatrixType& type, const Stringifier& /*stringifier*/)
{
std::string str = "mat";
if (type.columnCount == type.rowCount)
str += std::to_string(type.columnCount);
else
{
str += std::to_string(type.columnCount);
str += "x";
str += std::to_string(type.rowCount);
}
str += "[";
str += ToString(type.type);
str += "]";
return str;
}
std::string ToString(const MethodType& type, const Stringifier& /*stringifier*/)
{
return "<method of object " + ToString(type.objectType->type) + " type>";
}
std::string ToString(NoType /*type*/, const Stringifier& /*stringifier*/)
{
return "()";
}
std::string ToString(PrimitiveType type, const Stringifier& /*stringifier*/)
{
switch (type)
{
case ShaderAst::PrimitiveType::Boolean: return "bool";
case ShaderAst::PrimitiveType::Float32: return "f32";
case ShaderAst::PrimitiveType::Int32: return "i32";
case ShaderAst::PrimitiveType::UInt32: return "u32";
case ShaderAst::PrimitiveType::String: return "string";
}
return "<unhandled primitive type>";
}
std::string ToString(const SamplerType& type, const Stringifier& /*stringifier*/)
{
std::string str = "sampler";
switch (type.dim)
{
case ImageType::E1D: str += "1D"; break;
case ImageType::E1D_Array: str += "1DArray"; break;
case ImageType::E2D: str += "2D"; break;
case ImageType::E2D_Array: str += "2DArray"; break;
case ImageType::E3D: str += "3D"; break;
case ImageType::Cubemap: str += "Cube"; break;
}
str += "[";
str += ToString(type.sampledType);
str += "]";
return str;
}
std::string ToString(const StructType& type, const Stringifier& stringifier)
{
if (stringifier.structStringifier)
return "struct " + stringifier.structStringifier(type.structIndex);
else
return "struct #" + std::to_string(type.structIndex);
}
std::string ToString(const Type& type, const Stringifier& stringifier)
{
if (stringifier.typeStringifier)
return "type " + stringifier.typeStringifier(type.typeIndex);
else
return "type #" + std::to_string(type.typeIndex);
}
std::string ToString(const UniformType& type, const Stringifier& stringifier)
{
std::string str = "uniform[";
str += ToString(type.containedType, stringifier);
str += "]";
return str;
}
std::string ToString(const VectorType& type, const Stringifier& /*stringifier*/)
{
std::string str = "vec";
str += std::to_string(type.componentCount);
str += "[";
str += ToString(type.type);
str += "]";
return str;
}
}

View File

@@ -1,290 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/IndexRemapperVisitor.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <unordered_map>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
namespace
{
template<typename T, typename U> void UniqueInsert(std::unordered_map<T, U>& map, T key, U value)
{
assert(map.find(key) == map.end());
map.emplace(std::move(key), std::move(value));
}
}
struct IndexRemapperVisitor::Context
{
const IndexRemapperVisitor::Options* options;
std::unordered_map<std::size_t, std::size_t> newAliasIndices;
std::unordered_map<std::size_t, std::size_t> newConstIndices;
std::unordered_map<std::size_t, std::size_t> newFuncIndices;
std::unordered_map<std::size_t, std::size_t> newStructIndices;
std::unordered_map<std::size_t, std::size_t> newVarIndices;
};
StatementPtr IndexRemapperVisitor::Clone(Statement& statement, const Options& options)
{
assert(options.aliasIndexGenerator);
assert(options.constIndexGenerator);
assert(options.funcIndexGenerator);
assert(options.structIndexGenerator);
//assert(options.typeIndexGenerator);
assert(options.varIndexGenerator);
Context context;
context.options = &options;
m_context = &context;
return AstCloner::Clone(statement);
}
StatementPtr IndexRemapperVisitor::Clone(DeclareAliasStatement& node)
{
DeclareAliasStatementPtr clone = StaticUniquePointerCast<DeclareAliasStatement>(AstCloner::Clone(node));
if (clone->aliasIndex)
{
std::size_t newAliasIndex = m_context->options->aliasIndexGenerator(*clone->aliasIndex);
UniqueInsert(m_context->newAliasIndices, *clone->aliasIndex, newAliasIndex);
clone->aliasIndex = newAliasIndex;
}
else if (m_context->options->forceIndexGeneration)
clone->aliasIndex = m_context->options->aliasIndexGenerator(std::numeric_limits<std::size_t>::max());
return clone;
}
StatementPtr IndexRemapperVisitor::Clone(DeclareConstStatement& node)
{
DeclareConstStatementPtr clone = StaticUniquePointerCast<DeclareConstStatement>(AstCloner::Clone(node));
if (clone->constIndex)
{
std::size_t newConstIndex = m_context->options->constIndexGenerator(*clone->constIndex);
UniqueInsert(m_context->newConstIndices, *clone->constIndex, newConstIndex);
clone->constIndex = newConstIndex;
}
else if (m_context->options->forceIndexGeneration)
clone->constIndex = m_context->options->constIndexGenerator(std::numeric_limits<std::size_t>::max());
return clone;
}
StatementPtr IndexRemapperVisitor::Clone(DeclareExternalStatement& node)
{
DeclareExternalStatementPtr clone = StaticUniquePointerCast<DeclareExternalStatement>(AstCloner::Clone(node));
for (auto& extVar : clone->externalVars)
{
if (extVar.varIndex)
{
std::size_t newVarIndex = m_context->options->varIndexGenerator(*extVar.varIndex);
UniqueInsert(m_context->newVarIndices, *extVar.varIndex, newVarIndex);
extVar.varIndex = newVarIndex;
}
else if (m_context->options->forceIndexGeneration)
extVar.varIndex = m_context->options->varIndexGenerator(std::numeric_limits<std::size_t>::max());
}
return clone;
}
StatementPtr IndexRemapperVisitor::Clone(DeclareFunctionStatement& node)
{
DeclareFunctionStatementPtr clone = StaticUniquePointerCast<DeclareFunctionStatement>(AstCloner::Clone(node));
if (clone->funcIndex)
{
std::size_t newFuncIndex = m_context->options->funcIndexGenerator(*clone->funcIndex);
UniqueInsert(m_context->newFuncIndices, *clone->funcIndex, newFuncIndex);
clone->funcIndex = newFuncIndex;
}
else if (m_context->options->forceIndexGeneration)
clone->funcIndex = m_context->options->funcIndexGenerator(std::numeric_limits<std::size_t>::max());
if (!clone->parameters.empty())
{
for (auto& parameter : clone->parameters)
{
if (parameter.varIndex)
parameter.varIndex = Retrieve(m_context->newVarIndices, *parameter.varIndex);
else if (m_context->options->forceIndexGeneration)
parameter.varIndex = m_context->options->varIndexGenerator(std::numeric_limits<std::size_t>::max());
HandleType(parameter.type);
}
}
if (node.returnType.HasValue())
HandleType(node.returnType);
return clone;
}
StatementPtr IndexRemapperVisitor::Clone(DeclareStructStatement& node)
{
DeclareStructStatementPtr clone = StaticUniquePointerCast<DeclareStructStatement>(AstCloner::Clone(node));
if (clone->structIndex)
{
std::size_t newStructIndex = m_context->options->structIndexGenerator(*clone->structIndex);
UniqueInsert(m_context->newStructIndices, *clone->structIndex, newStructIndex);
clone->structIndex = newStructIndex;
}
else if (m_context->options->forceIndexGeneration)
clone->structIndex = m_context->options->structIndexGenerator(std::numeric_limits<std::size_t>::max());
for (auto& structMember : clone->description.members)
HandleType(structMember.type);
return clone;
}
StatementPtr IndexRemapperVisitor::Clone(DeclareVariableStatement& node)
{
DeclareVariableStatementPtr clone = StaticUniquePointerCast<DeclareVariableStatement>(AstCloner::Clone(node));
if (clone->varIndex)
{
std::size_t newVarIndex = m_context->options->varIndexGenerator(*clone->varIndex);
UniqueInsert(m_context->newConstIndices, *clone->varIndex, newVarIndex);
clone->varIndex = newVarIndex;
}
else if (m_context->options->forceIndexGeneration)
clone->varIndex = m_context->options->varIndexGenerator(std::numeric_limits<std::size_t>::max());
HandleType(node.varType);
return clone;
}
ExpressionPtr IndexRemapperVisitor::Clone(AliasValueExpression& node)
{
AliasValueExpressionPtr clone = StaticUniquePointerCast<AliasValueExpression>(AstCloner::Clone(node));
if (clone->aliasId)
clone->aliasId = Retrieve(m_context->newAliasIndices, clone->aliasId);
else if (m_context->options->forceIndexGeneration)
clone->aliasId = m_context->options->aliasIndexGenerator(std::numeric_limits<std::size_t>::max());
return clone;
}
ExpressionPtr IndexRemapperVisitor::Clone(ConstantExpression& node)
{
ConstantExpressionPtr clone = StaticUniquePointerCast<ConstantExpression>(AstCloner::Clone(node));
if (clone->constantId)
clone->constantId = Retrieve(m_context->newConstIndices, clone->constantId);
else if (m_context->options->forceIndexGeneration)
clone->constantId = m_context->options->constIndexGenerator(std::numeric_limits<std::size_t>::max());
return clone;
}
ExpressionPtr IndexRemapperVisitor::Clone(FunctionExpression& node)
{
FunctionExpressionPtr clone = StaticUniquePointerCast<FunctionExpression>(AstCloner::Clone(node));
if (clone->funcId)
clone->funcId = Retrieve(m_context->newFuncIndices, clone->funcId);
else if (m_context->options->forceIndexGeneration)
clone->funcId = m_context->options->funcIndexGenerator(std::numeric_limits<std::size_t>::max());
return clone;
}
ExpressionPtr IndexRemapperVisitor::Clone(StructTypeExpression& node)
{
StructTypeExpressionPtr clone = StaticUniquePointerCast<StructTypeExpression>(AstCloner::Clone(node));
if (clone->structTypeId)
clone->structTypeId = Retrieve(m_context->newStructIndices, clone->structTypeId);
else if (m_context->options->forceIndexGeneration)
clone->structTypeId = m_context->options->structIndexGenerator(std::numeric_limits<std::size_t>::max());
return clone;
}
ExpressionPtr IndexRemapperVisitor::Clone(VariableValueExpression& node)
{
VariableValueExpressionPtr clone = StaticUniquePointerCast<VariableValueExpression>(AstCloner::Clone(node));
if (clone->variableId)
clone->variableId = Retrieve(m_context->newVarIndices, clone->variableId);
else if (m_context->options->forceIndexGeneration)
clone->variableId = m_context->options->varIndexGenerator(std::numeric_limits<std::size_t>::max());
return clone;
}
void IndexRemapperVisitor::HandleType(ExpressionValue<ExpressionType>& exprType)
{
if (!exprType.IsResultingValue())
return;
const auto& resultingType = exprType.GetResultingValue();
exprType = RemapType(resultingType);
}
ExpressionType IndexRemapperVisitor::RemapType(const ExpressionType& exprType)
{
if (IsAliasType(exprType))
{
const AliasType& aliasType = std::get<AliasType>(exprType);
AliasType remappedAliasType;
remappedAliasType.aliasIndex = Retrieve(m_context->newAliasIndices, aliasType.aliasIndex);
remappedAliasType.targetType = std::make_unique<ContainedType>();
remappedAliasType.targetType->type = RemapType(aliasType.targetType->type);
return remappedAliasType;
}
else if (IsArrayType(exprType))
{
const ArrayType& arrayType = std::get<ArrayType>(exprType);
ArrayType remappedArrayType;
remappedArrayType.containedType = std::make_unique<ContainedType>();
remappedArrayType.containedType->type = RemapType(arrayType.containedType->type);
remappedArrayType.length = arrayType.length;
return remappedArrayType;
}
else if (IsFunctionType(exprType))
{
std::size_t newFuncIndex = Retrieve(m_context->newFuncIndices, std::get<FunctionType>(exprType).funcIndex);
return FunctionType{ newFuncIndex };
}
else if (IsMethodType(exprType))
{
const MethodType& methodType = std::get<MethodType>(exprType);
MethodType remappedMethodType;
remappedMethodType.methodIndex = methodType.methodIndex;
remappedMethodType.objectType = std::make_unique<ContainedType>();
remappedMethodType.objectType->type = RemapType(methodType.objectType->type);
return remappedMethodType;
}
else if (IsStructType(exprType))
{
std::size_t newStructIndex = Retrieve(m_context->newStructIndices, std::get<StructType>(exprType).structIndex);
return StructType{ newStructIndex };
}
else if (IsUniformType(exprType))
{
UniformType uniformType;
uniformType.containedType.structIndex = Retrieve(m_context->newStructIndices, std::get<UniformType>(exprType).containedType.structIndex);
return uniformType;
}
else
return exprType;
}
}

View File

@@ -1,32 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/Nodes.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Shader/Ast/AstExpressionVisitor.hpp>
#include <Nazara/Shader/Ast/AstStatementVisitor.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
Node::~Node() = default;
#define NAZARA_SHADERAST_NODE(Node) NodeType Node::GetType() const \
{ \
return NodeType:: Node; \
}
#include <Nazara/Shader/Ast/AstNodeList.hpp>
#define NAZARA_SHADERAST_EXPRESSION(Node) void Node::Visit(AstExpressionVisitor& visitor) \
{\
visitor.Visit(*this); \
}
#define NAZARA_SHADERAST_STATEMENT(Node) void Node::Visit(AstStatementVisitor& visitor) \
{\
visitor.Visit(*this); \
}
#include <Nazara/Shader/Ast/AstNodeList.hpp>
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,31 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Config.hpp>
#if NAZARA_SHADER_MANAGE_MEMORY
#include <Nazara/Core/MemoryManager.hpp>
#include <new> // Nécessaire ?
void* operator new(std::size_t size)
{
return Nz::MemoryManager::Allocate(size, false);
}
void* operator new[](std::size_t size)
{
return Nz::MemoryManager::Allocate(size, true);
}
void operator delete(void* pointer) noexcept
{
Nz::MemoryManager::Free(pointer, false);
}
void operator delete[](void* pointer) noexcept
{
Nz::MemoryManager::Free(pointer, true);
}
#endif // NAZARA_SHADER_MANAGE_MEMORY

View File

@@ -1,101 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/FieldOffsets.hpp>
#include <algorithm>
#include <cassert>
#include <Nazara/Shader/Debug.hpp>
namespace Nz
{
std::size_t FieldOffsets::AddField(StructFieldType type)
{
std::size_t fieldAlignement = GetAlignement(m_layout, type);
m_largestFieldAlignment = std::max(m_largestFieldAlignment, fieldAlignement);
std::size_t offset = Align(m_size, Align(fieldAlignement, m_offsetRounding));
m_size = offset + GetSize(type);
m_offsetRounding = 1;
return offset;
}
std::size_t FieldOffsets::AddFieldArray(StructFieldType type, std::size_t arraySize)
{
std::size_t fieldAlignement = GetAlignement(m_layout, type);
if (m_layout == StructLayout::Std140)
fieldAlignement = Align(fieldAlignement, GetAlignement(StructLayout::Std140, StructFieldType::Float4));
m_largestFieldAlignment = std::max(fieldAlignement, m_largestFieldAlignment);
std::size_t offset = Align(m_size, Align(fieldAlignement, m_offsetRounding));
m_size = offset + GetSize(type) * arraySize;
m_offsetRounding = 1;
return offset;
}
std::size_t FieldOffsets::AddMatrix(StructFieldType cellType, unsigned int columns, unsigned int rows, bool columnMajor)
{
assert(GetCount(cellType) == 1);
assert(columns >= 2 && columns <= 4);
assert(rows >= 2 && rows <= 4);
if (columnMajor)
return AddFieldArray(static_cast<StructFieldType>(UnderlyingCast(cellType) + rows - 1), columns);
else
return AddFieldArray(static_cast<StructFieldType>(UnderlyingCast(cellType) + columns - 1), rows);
}
std::size_t FieldOffsets::AddMatrixArray(StructFieldType cellType, unsigned int columns, unsigned int rows, bool columnMajor, std::size_t arraySize)
{
assert(GetCount(cellType) == 1);
assert(columns >= 2 && columns <= 4);
assert(rows >= 2 && rows <= 4);
if (columnMajor)
return AddFieldArray(static_cast<StructFieldType>(UnderlyingCast(cellType) + rows - 1), columns * arraySize);
else
return AddFieldArray(static_cast<StructFieldType>(UnderlyingCast(cellType) + columns - 1), rows * arraySize);
}
std::size_t FieldOffsets::AddStruct(const FieldOffsets& fieldStruct)
{
std::size_t fieldAlignement = fieldStruct.GetLargestFieldAlignement();
if (m_layout == StructLayout::Std140)
fieldAlignement = Align(fieldAlignement, GetAlignement(StructLayout::Std140, StructFieldType::Float4));
m_largestFieldAlignment = std::max(m_largestFieldAlignment, fieldAlignement);
std::size_t offset = Align(m_size, Align(fieldAlignement, m_offsetRounding));
m_size = offset + fieldStruct.GetSize();
m_offsetRounding = std::max<std::size_t>(Align(fieldStruct.GetSize(), fieldAlignement) - fieldStruct.GetSize(), 1);
return offset;
}
std::size_t FieldOffsets::AddStructArray(const FieldOffsets& fieldStruct, std::size_t arraySize)
{
assert(arraySize > 0);
std::size_t fieldAlignement = fieldStruct.GetLargestFieldAlignement();
if (m_layout == StructLayout::Std140)
fieldAlignement = Align(fieldAlignement, GetAlignement(StructLayout::Std140, StructFieldType::Float4));
m_largestFieldAlignment = std::max(m_largestFieldAlignment, fieldAlignement);
std::size_t offset = Align(m_size, Align(fieldAlignement, m_offsetRounding));
m_size = offset
+ fieldStruct.GetSize() * arraySize
+ (Align(fieldStruct.GetSize(), fieldAlignement) - fieldStruct.GetSize()) * (arraySize - 1);
m_offsetRounding = fieldAlignement;
return offset;
}
}

View File

@@ -1,208 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/FilesystemModuleResolver.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Shader/ShaderLangParser.hpp>
#include <Nazara/Shader/Ast/AstSerializer.hpp>
#include <efsw/efsw.h>
#include <cassert>
#include <Nazara/Shader/Debug.hpp>
namespace Nz
{
FilesystemModuleResolver::FilesystemModuleResolver()
{
m_fileWatcher = efsw_create(0);
efsw_watch(m_fileWatcher);
}
FilesystemModuleResolver::~FilesystemModuleResolver()
{
if (m_fileWatcher)
efsw_release(m_fileWatcher);
}
void FilesystemModuleResolver::RegisterModule(const std::filesystem::path& realPath)
{
ShaderAst::ModulePtr module;
try
{
std::string ext = realPath.extension().generic_u8string();
if (ext == CompiledModuleExtension)
{
Nz::File file(realPath);
if (!file.Open(Nz::OpenMode::ReadOnly | Nz::OpenMode::Text))
throw std::runtime_error("failed to open " + realPath.generic_u8string());
std::size_t length = static_cast<std::size_t>(file.GetSize());
std::vector<Nz::UInt8> content(length);
if (length > 0 && file.Read(&content[0], length) != length)
throw std::runtime_error("failed to read " + realPath.generic_u8string());
module = ShaderAst::UnserializeShader(content.data(), content.size());
}
else if (ext == ModuleExtension)
module = ShaderLang::ParseFromFile(realPath);
else
throw std::runtime_error("unknown extension " + ext);
}
catch (const std::exception& e)
{
NazaraError("failed to register module from file " + realPath.generic_u8string() + ": " + e.what());
return;
}
if (!module)
return;
std::string moduleName = module->metadata->moduleName;
RegisterModule(std::move(module));
std::filesystem::path canonicalPath = std::filesystem::canonical(realPath);
m_moduleByFilepath.emplace(canonicalPath.generic_u8string(), std::move(moduleName));
}
void FilesystemModuleResolver::RegisterModule(std::string_view moduleSource)
{
ShaderAst::ModulePtr module = ShaderLang::Parse(moduleSource);
if (!module)
return;
return RegisterModule(std::move(module));
}
void FilesystemModuleResolver::RegisterModule(ShaderAst::ModulePtr module)
{
assert(module);
std::string moduleName = module->metadata->moduleName;
if (moduleName.empty())
throw std::runtime_error("cannot register anonymous module");
auto it = m_modules.find(moduleName);
if (it != m_modules.end())
{
it->second = std::move(module);
OnModuleUpdated(this, moduleName);
}
else
m_modules.emplace(std::move(moduleName), std::move(module));
}
void FilesystemModuleResolver::RegisterModuleDirectory(const std::filesystem::path& realPath, bool watchDirectory)
{
if (!std::filesystem::is_directory(realPath))
return;
auto FileSystemCallback = [](efsw_watcher /*watcher*/, efsw_watchid /*watchid*/, const char* dir, const char* filename, efsw_action action, const char* oldFileName, void* param)
{
FilesystemModuleResolver* resolver = static_cast<FilesystemModuleResolver*>(param);
switch (action)
{
case EFSW_ADD:
resolver->OnFileAdded(dir, filename);
break;
case EFSW_DELETE:
resolver->OnFileRemoved(dir, filename);
break;
case EFSW_MODIFIED:
resolver->OnFileUpdated(dir, filename);
break;
case EFSW_MOVED:
resolver->OnFileMoved(dir, filename, (oldFileName) ? oldFileName : std::string_view());
break;
}
};
if (watchDirectory)
efsw_addwatch(m_fileWatcher, realPath.generic_u8string().c_str(), FileSystemCallback, 1, this);
for (const auto& entry : std::filesystem::recursive_directory_iterator(realPath))
{
if (entry.is_regular_file() && CheckExtension(entry.path().generic_u8string()))
{
try
{
RegisterModule(entry.path());
}
catch (const std::exception& e)
{
NazaraWarning("failed to register module " + entry.path().generic_u8string() + ": " + e.what());
}
}
}
}
ShaderAst::ModulePtr FilesystemModuleResolver::Resolve(const std::string& moduleName)
{
auto it = m_modules.find(moduleName);
if (it == m_modules.end())
return {};
return it->second;
}
void FilesystemModuleResolver::OnFileAdded(std::string_view directory, std::string_view filename)
{
if (!CheckExtension(filename))
return;
RegisterModule(std::filesystem::path(directory) / filename);
}
void FilesystemModuleResolver::OnFileRemoved(std::string_view directory, std::string_view filename)
{
if (!CheckExtension(filename))
return;
std::filesystem::path canonicalPath = std::filesystem::canonical(std::filesystem::path(directory) / filename);
auto it = m_moduleByFilepath.find(canonicalPath.generic_u8string());
if (it != m_moduleByFilepath.end())
{
m_modules.erase(it->second);
m_moduleByFilepath.erase(it);
}
}
void FilesystemModuleResolver::OnFileMoved(std::string_view directory, std::string_view filename, std::string_view oldFilename)
{
if (oldFilename.empty() || !CheckExtension(oldFilename))
return;
std::filesystem::path canonicalPath = std::filesystem::canonical(std::filesystem::path(directory) / oldFilename);
auto it = m_moduleByFilepath.find(canonicalPath.generic_u8string());
if (it != m_moduleByFilepath.end())
{
std::filesystem::path newCanonicalPath = std::filesystem::canonical(std::filesystem::path(directory) / filename);
std::string moduleName = std::move(it->second);
m_moduleByFilepath.erase(it);
m_moduleByFilepath.emplace(newCanonicalPath.generic_u8string(), std::move(moduleName));
}
}
void FilesystemModuleResolver::OnFileUpdated(std::string_view directory, std::string_view filename)
{
if (!CheckExtension(filename))
return;
RegisterModule(std::filesystem::path(directory) / filename);
}
bool FilesystemModuleResolver::CheckExtension(std::string_view filename)
{
return EndsWith(filename, ModuleExtension, Nz::CaseIndependent{}) || EndsWith(filename, CompiledModuleExtension, Nz::CaseIndependent{});
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Shader.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz
{
Shader::Shader(Config /*config*/) :
ModuleBase("Shader", this)
{
}
Shader* Shader::s_instance = nullptr;
}

View File

@@ -1,167 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/ShaderLangErrors.hpp>
#include <fmt/format.h>
#include <string>
#include <utility>
#include <Nazara/Shader/Debug.hpp>
// https://fmt.dev/latest/api.html#udt
template <>
struct fmt::formatter<Nz::ShaderAst::AttributeType> : formatter<string_view>
{
template <typename FormatContext>
auto format(const Nz::ShaderAst::AttributeType& p, FormatContext& ctx) -> decltype(ctx.out())
{
// TODO: Add ToString
std::string_view name = "<unhandled attribute type>";
switch (p)
{
case Nz::ShaderAst::AttributeType::Binding: name = "binding"; break;
case Nz::ShaderAst::AttributeType::Builtin: name = "builtin"; break;
case Nz::ShaderAst::AttributeType::Cond: name = "cond"; break;
case Nz::ShaderAst::AttributeType::DepthWrite: name = "depth_write"; break;
case Nz::ShaderAst::AttributeType::EarlyFragmentTests: name = "early_fragment_tests"; break;
case Nz::ShaderAst::AttributeType::Entry: name = "entry"; break;
case Nz::ShaderAst::AttributeType::Export: name = "export"; break;
case Nz::ShaderAst::AttributeType::Layout: name = "layout"; break;
case Nz::ShaderAst::AttributeType::Location: name = "location"; break;
case Nz::ShaderAst::AttributeType::LangVersion: name = "nzsl_version"; break;
case Nz::ShaderAst::AttributeType::Set: name = "set"; break;
case Nz::ShaderAst::AttributeType::Unroll: name = "unroll"; break;
case Nz::ShaderAst::AttributeType::Uuid: name = "uuid"; break;
}
return formatter<string_view>::format(name, ctx);
}
};
template <>
struct fmt::formatter<Nz::ShaderLang::ErrorCategory> : formatter<string_view>
{
template <typename FormatContext>
auto format(const Nz::ShaderLang::ErrorCategory& p, FormatContext& ctx) -> decltype(ctx.out())
{
return formatter<string_view>::format(ToString(p), ctx);
}
};
template <>
struct fmt::formatter<Nz::ShaderLang::ErrorType> : formatter<string_view>
{
template <typename FormatContext>
auto format(const Nz::ShaderLang::ErrorType& p, FormatContext& ctx) -> decltype(ctx.out())
{
return formatter<string_view>::format(ToString(p), ctx);
}
};
template <>
struct fmt::formatter<Nz::ShaderStageType> : formatter<string_view>
{
template <typename FormatContext>
auto format(const Nz::ShaderStageType& p, FormatContext& ctx) -> decltype(ctx.out())
{
// TODO: Add ToString
std::string_view name = "<unhandled shader stage>";
switch (p)
{
case Nz::ShaderStageType::Fragment: name = "fragment"; break;
case Nz::ShaderStageType::Vertex: name = "vertex"; break;
}
return formatter<string_view>::format(name, ctx);
}
};
template <>
struct fmt::formatter<Nz::ShaderLang::TokenType> : formatter<string_view>
{
template <typename FormatContext>
auto format(const Nz::ShaderLang::TokenType& p, FormatContext& ctx) -> decltype(ctx.out())
{
return formatter<string_view>::format(ToString(p), ctx);
}
};
namespace Nz::ShaderLang
{
std::string_view ToString(ErrorCategory errorCategory)
{
switch (errorCategory)
{
case ErrorCategory::Ast: return "Ast";
case ErrorCategory::Compilation: return "Compilation";
case ErrorCategory::Lexing: return "Lexing";
case ErrorCategory::Parsing: return "Parsing";
}
return "<unhandled error category>";
}
std::string_view ToString(ErrorType errorType)
{
switch (errorType)
{
#define NAZARA_SHADERLANG_ERROR(ErrorPrefix, ErrorName, ...) case ErrorType:: ErrorPrefix ## ErrorName: return #ErrorPrefix #ErrorName;
#include <Nazara/Shader/ShaderLangErrorList.hpp>
}
return "<unhandled error type>";
}
const std::string& Error::GetErrorMessage() const
{
if (m_errorMessage.empty())
m_errorMessage = BuildErrorMessage();
return m_errorMessage;
}
const std::string& Error::GetFullErrorMessage() const
{
if (m_fullErrorMessage.empty())
{
if (m_sourceLocation.IsValid())
{
std::string_view sourceFile;
if (m_sourceLocation.file)
sourceFile = *m_sourceLocation.file;
if (m_sourceLocation.startLine != m_sourceLocation.endLine)
m_fullErrorMessage = fmt::format("{}({} -> {},{} -> {}): {} error: {}", sourceFile, m_sourceLocation.startLine, m_sourceLocation.endLine, m_sourceLocation.startColumn, m_sourceLocation.endColumn, m_errorType, GetErrorMessage());
else if (m_sourceLocation.startColumn != m_sourceLocation.endColumn)
m_fullErrorMessage = fmt::format("{}({},{} -> {}): {} error: {}", sourceFile, m_sourceLocation.startLine, m_sourceLocation.startColumn, m_sourceLocation.endColumn, m_errorType, GetErrorMessage());
else
m_fullErrorMessage = fmt::format("{}({}, {}): {} error: {}", sourceFile, m_sourceLocation.startLine, m_sourceLocation.startColumn, m_errorType, GetErrorMessage());
}
else
m_fullErrorMessage = fmt::format("?: {} error: {}", m_errorType, GetErrorMessage());
}
return m_fullErrorMessage;
}
const char* Error::what() const noexcept
{
return GetFullErrorMessage().c_str();
}
#define NAZARA_SHADERLANG_NEWERRORTYPE(Prefix, ErrorType, ErrorName, ErrorString, ...) \
std::string Prefix ## ErrorName ## Error::BuildErrorMessage() const \
{ \
return std::apply([&](const auto... args) { return fmt::format(ErrorString, args...); }, m_parameters); \
}
#define NAZARA_SHADERLANG_AST_ERROR(ErrorName, ErrorString, ...) NAZARA_SHADERLANG_NEWERRORTYPE(Ast, A, ErrorName, ErrorString, __VA_ARGS__)
#define NAZARA_SHADERLANG_LEXER_ERROR(ErrorName, ErrorString, ...) NAZARA_SHADERLANG_NEWERRORTYPE(Lexer, L, ErrorName, ErrorString, __VA_ARGS__)
#define NAZARA_SHADERLANG_PARSER_ERROR(ErrorName, ErrorString, ...) NAZARA_SHADERLANG_NEWERRORTYPE(Parser, P, ErrorName, ErrorString, __VA_ARGS__)
#define NAZARA_SHADERLANG_COMPILER_ERROR(ErrorName, ErrorString, ...) NAZARA_SHADERLANG_NEWERRORTYPE(Compiler, C, ErrorName, ErrorString, __VA_ARGS__)
#include <Nazara/Shader/ShaderLangErrorList.hpp>
#undef NAZARA_SHADERLANG_NEWERRORTYPE
}

View File

@@ -1,562 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/ShaderLangLexer.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Shader/ShaderLangErrors.hpp>
#include <frozen/string.h>
#include <frozen/unordered_map.h>
#include <cctype>
#include <charconv>
#include <locale>
#include <optional>
#include <sstream>
#include <stdexcept>
#include <unordered_map>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderLang
{
namespace
{
class ForceCLocale
{
public:
ForceCLocale()
{
m_previousLocale = std::locale::global(std::locale::classic());
}
~ForceCLocale()
{
std::locale::global(m_previousLocale);
}
private:
std::locale m_previousLocale;
};
constexpr auto s_reservedKeywords = frozen::make_unordered_map<frozen::string, TokenType>({
{ "alias", TokenType::Alias },
{ "const", TokenType::Const },
{ "const_select", TokenType::ConstSelect },
{ "discard", TokenType::Discard },
{ "else", TokenType::Else },
{ "external", TokenType::External },
{ "false", TokenType::BoolFalse },
{ "fn", TokenType::FunctionDeclaration },
{ "for", TokenType::For },
{ "if", TokenType::If },
{ "import", TokenType::Import },
{ "in", TokenType::In },
{ "let", TokenType::Let },
{ "module", TokenType::Module },
{ "option", TokenType::Option },
{ "return", TokenType::Return },
{ "struct", TokenType::Struct },
{ "true", TokenType::BoolTrue },
{ "while", TokenType::While }
});
}
std::vector<Token> Tokenize(const std::string_view& str, const std::string& filePath)
{
// Can't use std::from_chars for double, thanks to libc++ and libstdc++ developers for being lazy, so we have to force C locale
ForceCLocale forceCLocale;
std::size_t currentPos = 0;
auto Peek = [&](std::size_t advance = 1) -> char
{
if (currentPos + advance < str.size() && str[currentPos + advance] != '\0')
return str[currentPos + advance];
else
return '\0';
};
auto IsAlphaNum = [&](const char c)
{
return std::isalnum(c) || c == '_';
};
UInt32 currentLine = 1;
std::size_t lineStartPos = 0;
std::vector<Token> tokens;
auto HandleNewLine = [&]
{
currentLine++;
lineStartPos = currentPos + 1;
};
std::shared_ptr<const std::string> currentFile;
if (!filePath.empty())
currentFile = std::make_shared<std::string>(filePath);
for (;;)
{
char c = Peek(0);
Token token;
token.location.startColumn = SafeCast<UInt32>(currentPos - lineStartPos) + 1;
token.location.startLine = currentLine;
token.location.file = currentFile;
if (c == '\0')
{
token.type = TokenType::EndOfStream;
tokens.push_back(std::move(token));
break;
}
std::optional<TokenType> tokenType;
switch (c)
{
case ' ':
case '\t':
case '\r':
break; //< Ignore blank spaces
case '\n':
HandleNewLine();
break;
case '-':
{
char next = Peek();
if (next == '>')
{
currentPos++;
tokenType = TokenType::Arrow;
break;
}
else if (next == '=')
{
currentPos++;
tokenType = TokenType::MinusAssign;
}
else
tokenType = TokenType::Minus;
break;
}
case '/':
{
char next = Peek();
if (next == '/')
{
// Line comment
do
{
currentPos++;
next = Peek();
}
while (next != -1 && next != '\n');
}
else if (next == '*')
{
// Block comment
do
{
currentPos++;
next = Peek();
if (next == '*')
{
currentPos++;
if (Peek() == '/')
{
currentPos++;
break;
}
}
else if (next == '\n')
HandleNewLine();
}
while (next != -1);
}
else if (next == '=')
{
currentPos++;
tokenType = TokenType::DivideAssign;
}
else
tokenType = TokenType::Divide;
break;
}
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
bool floatingPoint = false;
std::size_t start = currentPos;
char next = Peek();
if (next == 'x' || next == 'X')
currentPos++;
for (;;)
{
next = Peek();
if (!isdigit(next))
{
if (next != '.')
break;
if (floatingPoint)
break;
floatingPoint = true;
}
currentPos++;
}
token.location.endColumn = SafeCast<UInt32>(currentPos - lineStartPos) + 1;
token.location.endLine = currentLine;
if (floatingPoint)
{
tokenType = TokenType::FloatingPointValue;
std::string valueStr(str.substr(start, currentPos - start + 1));
const char* ptr = valueStr.c_str();
char* end;
double value = std::strtod(ptr, &end);
if (end != &ptr[valueStr.size()])
throw LexerBadNumberError{ token.location };
token.data = value;
}
else
{
tokenType = TokenType::IntegerValue;
// avoid std::string_view operator[] assertions (if &str[currentPos + 1] is out of the string)
const char* first = &str[start];
const char* last = first + (currentPos - start + 1);
long long value;
std::from_chars_result r = std::from_chars(first, last, value);
if (r.ptr == last && r.ec == std::errc{})
token.data = value;
else if (r.ec == std::errc::result_out_of_range)
throw LexerNumberOutOfRangeError{ token.location };
else
throw LexerBadNumberError{ token.location };
}
break;
}
case '=':
{
char next = Peek();
if (next == '=')
{
currentPos++;
tokenType = TokenType::Equal;
}
else
tokenType = TokenType::Assign;
break;
}
case '|':
{
char next = Peek();
if (next == '|')
{
currentPos++;
next = Peek();
if (next == '=')
{
currentPos++;
tokenType = TokenType::LogicalOrAssign;
}
else
tokenType = TokenType::LogicalOr;
}
else
throw LexerUnrecognizedTokenError{ token.location }; //< TODO: Add BOR (a | b)
break;
}
case '&':
{
char next = Peek();
if (next == '&')
{
currentPos++;
next = Peek();
if (next == '=')
{
currentPos++;
tokenType = TokenType::LogicalAndAssign;
}
else
tokenType = TokenType::LogicalAnd;
}
else
throw LexerUnrecognizedTokenError{ token.location }; //< TODO: Add BAND (a & b)
break;
}
case '<':
{
char next = Peek();
if (next == '=')
{
currentPos++;
tokenType = TokenType::LessThanEqual;
}
else
tokenType = TokenType::LessThan;
break;
}
case '>':
{
char next = Peek();
if (next == '=')
{
currentPos++;
tokenType = TokenType::GreaterThanEqual;
}
else
tokenType = TokenType::GreaterThan;
break;
}
case '!':
{
char next = Peek();
if (next == '=')
{
currentPos++;
tokenType = TokenType::NotEqual;
}
else
tokenType = TokenType::Not;
break;
}
case '+':
{
char next = Peek();
if (next == '=')
{
currentPos++;
tokenType = TokenType::PlusAssign;
}
else
tokenType = TokenType::Plus;
break;
}
case '*':
{
char next = Peek();
if (next == '=')
{
currentPos++;
tokenType = TokenType::MultiplyAssign;
}
else
tokenType = TokenType::Multiply;
break;
}
case ':': tokenType = TokenType::Colon; break;
case ';': tokenType = TokenType::Semicolon; break;
case '.': tokenType = TokenType::Dot; break;
case ',': tokenType = TokenType::Comma; break;
case '{': tokenType = TokenType::OpenCurlyBracket; break;
case '}': tokenType = TokenType::ClosingCurlyBracket; break;
case '(': tokenType = TokenType::OpenParenthesis; break;
case ')': tokenType = TokenType::ClosingParenthesis; break;
case '[': tokenType = TokenType::OpenSquareBracket; break;
case ']': tokenType = TokenType::ClosingSquareBracket; break;
case '"':
{
// string litteral
currentPos++;
std::string litteral;
char current;
while ((current = Peek(0)) != '"')
{
char character;
switch (current)
{
case '\0':
case '\n':
case '\r':
token.location.endColumn = SafeCast<UInt32>(currentPos - lineStartPos) + 1;
token.location.endLine = currentLine;
throw LexerUnfinishedStringError{ token.location };
case '\\':
{
currentPos++;
char next = Peek(0);
switch (next)
{
case 'n': character = '\n'; break;
case 'r': character = '\r'; break;
case 't': character = '\t'; break;
case '"': character = '"'; break;
case '\\': character = '\\'; break;
default:
token.location.endColumn = SafeCast<UInt32>(currentPos - lineStartPos) + 1;
token.location.endLine = currentLine;
throw LexerUnrecognizedCharError{ token.location };
}
break;
}
default:
character = current;
break;
}
litteral.push_back(character);
currentPos++;
}
tokenType = TokenType::StringValue;
token.data = std::move(litteral);
break;
}
default:
{
if (IsAlphaNum(c))
{
std::size_t start = currentPos;
while (IsAlphaNum(Peek()))
currentPos++;
std::string_view identifier = str.substr(start, currentPos - start + 1);
if (auto it = s_reservedKeywords.find(identifier); it == s_reservedKeywords.end())
{
tokenType = TokenType::Identifier;
token.data = std::string(identifier);
}
else
tokenType = it->second;
break;
}
else
{
token.location.endColumn = SafeCast<UInt32>(currentPos - lineStartPos) + 1;
token.location.endLine = currentLine;
throw LexerUnrecognizedTokenError{ token.location };
}
}
}
if (tokenType)
{
token.location.endColumn = SafeCast<UInt32>(currentPos - lineStartPos) + 1;
token.location.endLine = currentLine;
token.type = *tokenType;
tokens.push_back(std::move(token));
}
currentPos++;
}
return tokens;
}
const char* ToString(TokenType tokenType)
{
switch (tokenType)
{
#define NAZARA_SHADERLANG_TOKEN(X) case TokenType:: X: return #X;
#include <Nazara/Shader/ShaderLangTokenList.hpp>
}
return "<Error>";
}
std::string ToString(const std::vector<Token>& tokens, bool pretty)
{
if (tokens.empty())
return {};
unsigned int lastLineNumber = tokens.front().location.startLine;
std::stringstream ss;
bool empty = true;
for (const Token& token : tokens)
{
if (token.location.startLine != lastLineNumber && pretty)
{
lastLineNumber = token.location.startLine;
if (!empty)
ss << '\n';
}
else if (!empty)
ss << ' ';
ss << ToString(token.type);
switch (token.type)
{
case TokenType::FloatingPointValue:
ss << "(" << std::get<double>(token.data) << ")";
break;
case TokenType::Identifier:
ss << "(" << std::get<std::string>(token.data) << ")";
break;
case TokenType::IntegerValue:
ss << "(" << std::get<long long>(token.data) << ")";
break;
case TokenType::StringValue:
ss << "(\"" << std::get<std::string>(token.data) << "\")";
break;
default:
break;
}
empty = false;
}
return std::move(ss).str();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/ShaderModuleResolver.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz
{
ShaderModuleResolver::~ShaderModuleResolver() = default;
}

View File

@@ -1,12 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/ShaderWriter.hpp>
#include <Nazara/Shader/Ast/Nodes.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz
{
ShaderWriter::~ShaderWriter() = default;
}

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More