Commit current work
Reworked conditions, added uber-shaders, comparison nodes, fixed Discard
This commit is contained in:
@@ -88,7 +88,7 @@ namespace Nz
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
wchar_t* buffer = nullptr;
|
||||
|
||||
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
DWORD length = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr,
|
||||
code,
|
||||
0,
|
||||
@@ -96,6 +96,9 @@ namespace Nz
|
||||
0,
|
||||
nullptr);
|
||||
|
||||
if (length == 0)
|
||||
return "<internal error: FormatMessageW failed with " + std::to_string(::GetLastError()) + ">";
|
||||
|
||||
CallOnExit freeOnExit([buffer] { LocalFree(buffer); });
|
||||
return FromWideString(buffer);
|
||||
#elif defined(NAZARA_PLATFORM_POSIX)
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Graphics/PredefinedShaderStructs.hpp>
|
||||
#include <Nazara/Graphics/UberShader.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Shader/ShaderAstSerializer.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/FieldOffsets.hpp>
|
||||
#include <Nazara/Utility/MaterialData.hpp>
|
||||
@@ -33,12 +35,17 @@ namespace Nz
|
||||
const std::shared_ptr<const MaterialSettings>& materialSettings = material.GetSettings();
|
||||
if (materialSettings == s_materialSettings)
|
||||
{
|
||||
m_conditionIndexes = s_conditionIndexes;
|
||||
m_textureIndexes = s_textureIndexes;
|
||||
m_uniformBlockIndex = s_uniformBlockIndex;
|
||||
m_uniformOffsets = s_uniformOffsets;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_conditionIndexes.alphaTest = materialSettings->GetConditionIndex("AlphaTest");
|
||||
m_conditionIndexes.hasAlphaMap = materialSettings->GetConditionIndex("HasAlphaMap");
|
||||
m_conditionIndexes.hasDiffuseMap = materialSettings->GetConditionIndex("HasDiffuseMap");
|
||||
|
||||
m_textureIndexes.alpha = materialSettings->GetTextureIndex("Alpha");
|
||||
m_textureIndexes.diffuse = materialSettings->GetTextureIndex("Diffuse");
|
||||
|
||||
@@ -49,9 +56,9 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
float BasicMaterial::GetAlphaThreshold() const
|
||||
float BasicMaterial::GetAlphaTestThreshold() const
|
||||
{
|
||||
NazaraAssert(HasAlphaThreshold(), "Material has no alpha threshold uniform");
|
||||
NazaraAssert(HasAlphaTestThreshold(), "Material has no alpha threshold uniform");
|
||||
|
||||
BufferMapper<UniformBuffer> mapper(m_material.GetUniformBuffer(m_uniformBlockIndex), BufferAccess_ReadOnly);
|
||||
return AccessByOffset<const float&>(mapper.GetPointer(), m_uniformOffsets.alphaThreshold);
|
||||
@@ -67,9 +74,9 @@ namespace Nz
|
||||
return Color(colorPtr[0] * 255, colorPtr[1] * 255, colorPtr[2] * 255, colorPtr[3] * 255); //< TODO: Make color able to use float
|
||||
}
|
||||
|
||||
void BasicMaterial::SetAlphaThreshold(float alphaThreshold)
|
||||
void BasicMaterial::SetAlphaTestThreshold(float alphaThreshold)
|
||||
{
|
||||
NazaraAssert(HasAlphaThreshold(), "Material has no alpha threshold uniform");
|
||||
NazaraAssert(HasAlphaTestThreshold(), "Material has no alpha threshold uniform");
|
||||
|
||||
BufferMapper<UniformBuffer> mapper(m_material.GetUniformBuffer(m_uniformBlockIndex), BufferAccess_WriteOnly);
|
||||
AccessByOffset<float&>(mapper.GetPointer(), m_uniformOffsets.alphaThreshold) = alphaThreshold;
|
||||
@@ -87,20 +94,16 @@ namespace Nz
|
||||
colorPtr[3] = diffuse.a / 255.f;
|
||||
}
|
||||
|
||||
const std::shared_ptr<MaterialSettings>& BasicMaterial::GetSettings()
|
||||
{
|
||||
return s_materialSettings;
|
||||
}
|
||||
|
||||
bool BasicMaterial::Initialize()
|
||||
{
|
||||
FieldOffsets fieldOffsets(StructLayout_Std140);
|
||||
|
||||
s_uniformOffsets.diffuseColor = fieldOffsets.AddField(StructFieldType_Float4);
|
||||
s_uniformOffsets.alphaThreshold = fieldOffsets.AddField(StructFieldType_Float1);
|
||||
s_uniformOffsets.diffuseColor = fieldOffsets.AddField(StructFieldType_Float4);
|
||||
s_uniformOffsets.totalSize = fieldOffsets.GetSize();
|
||||
|
||||
MaterialSettings::PredefinedBinding predefinedBinding;
|
||||
predefinedBinding.fill(MaterialSettings::InvalidIndex);
|
||||
MaterialSettings::Builder settings;
|
||||
settings.predefinedBinding.fill(MaterialSettings::InvalidIndex);
|
||||
|
||||
std::vector<MaterialSettings::UniformVariable> variables;
|
||||
variables.assign({
|
||||
@@ -120,31 +123,29 @@ namespace Nz
|
||||
AccessByOffset<Vector4f&>(defaultValues.data(), s_uniformOffsets.diffuseColor) = Vector4f(1.f, 1.f, 1.f, 1.f);
|
||||
AccessByOffset<float&>(defaultValues.data(), s_uniformOffsets.alphaThreshold) = 0.2f;
|
||||
|
||||
std::vector<MaterialSettings::Texture> textures;
|
||||
s_textureIndexes.alpha = textures.size();
|
||||
textures.push_back({
|
||||
s_textureIndexes.alpha = settings.textures.size();
|
||||
settings.textures.push_back({
|
||||
"MaterialAlphaMap",
|
||||
"Alpha",
|
||||
ImageType_2D
|
||||
});
|
||||
|
||||
s_textureIndexes.diffuse = textures.size();
|
||||
textures.push_back({
|
||||
|
||||
s_textureIndexes.diffuse = settings.textures.size();
|
||||
settings.textures.push_back({
|
||||
"MaterialDiffuseMap",
|
||||
"Diffuse",
|
||||
ImageType_2D
|
||||
});
|
||||
|
||||
predefinedBinding[UnderlyingCast(PredefinedShaderBinding::TexOverlay)] = textures.size();
|
||||
textures.push_back({
|
||||
settings.predefinedBinding[UnderlyingCast(PredefinedShaderBinding::TexOverlay)] = settings.textures.size();
|
||||
settings.textures.push_back({
|
||||
"TextureOverlay",
|
||||
"Overlay",
|
||||
ImageType_2D
|
||||
});
|
||||
|
||||
std::vector<MaterialSettings::UniformBlock> uniformBlocks;
|
||||
s_uniformBlockIndex = uniformBlocks.size();
|
||||
uniformBlocks.assign({
|
||||
s_uniformBlockIndex = settings.uniformBlocks.size();
|
||||
settings.uniformBlocks.assign({
|
||||
{
|
||||
fieldOffsets.GetSize(),
|
||||
"BasicSettings",
|
||||
@@ -154,19 +155,61 @@ namespace Nz
|
||||
}
|
||||
});
|
||||
|
||||
std::vector<MaterialSettings::SharedUniformBlock> sharedUniformBlock;
|
||||
settings.predefinedBinding[UnderlyingCast(PredefinedShaderBinding::UboInstanceData)] = settings.textures.size() + settings.uniformBlocks.size() + settings.sharedUniformBlocks.size();
|
||||
settings.sharedUniformBlocks.push_back(PredefinedInstanceData::GetUniformBlock());
|
||||
|
||||
predefinedBinding[UnderlyingCast(PredefinedShaderBinding::UboInstanceData)] = textures.size() + uniformBlocks.size() + sharedUniformBlock.size();
|
||||
sharedUniformBlock.push_back(PredefinedInstanceData::GetUniformBlock());
|
||||
predefinedBinding[UnderlyingCast(PredefinedShaderBinding::UboViewerData)] = textures.size() + uniformBlocks.size() + sharedUniformBlock.size();
|
||||
sharedUniformBlock.push_back(PredefinedViewerData::GetUniformBlock());
|
||||
settings.predefinedBinding[UnderlyingCast(PredefinedShaderBinding::UboViewerData)] = settings.textures.size() + settings.uniformBlocks.size() + settings.sharedUniformBlocks.size();
|
||||
settings.sharedUniformBlocks.push_back(PredefinedViewerData::GetUniformBlock());
|
||||
|
||||
// Shaders
|
||||
MaterialSettings::DefaultShaders defaultShaders;
|
||||
defaultShaders[UnderlyingCast(ShaderStageType::Fragment)] = Graphics::Instance()->GetRenderDevice().InstantiateShaderStage(Nz::ShaderStageType::Fragment, Nz::ShaderLanguage::NazaraBinary, r_fragmentShader, sizeof(r_fragmentShader));
|
||||
defaultShaders[UnderlyingCast(ShaderStageType::Vertex)] = Graphics::Instance()->GetRenderDevice().InstantiateShaderStage(Nz::ShaderStageType::Vertex, Nz::ShaderLanguage::NazaraBinary, r_vertexShader, sizeof(r_vertexShader));
|
||||
auto& fragmentShader = settings.shaders[UnderlyingCast(ShaderStageType::Fragment)];
|
||||
auto& vertexShader = settings.shaders[UnderlyingCast(ShaderStageType::Vertex)];
|
||||
|
||||
s_materialSettings = std::make_shared<MaterialSettings>(std::move(textures), std::move(uniformBlocks), std::move(sharedUniformBlock), predefinedBinding, std::move(defaultShaders));
|
||||
fragmentShader = std::make_shared<UberShader>(UnserializeShader(r_fragmentShader, sizeof(r_fragmentShader)));
|
||||
vertexShader = std::make_shared<UberShader>(UnserializeShader(r_vertexShader, sizeof(r_vertexShader)));
|
||||
|
||||
// Conditions
|
||||
|
||||
// HasDiffuseMap
|
||||
{
|
||||
std::array<UInt64, ShaderStageTypeCount> shaderConditions;
|
||||
shaderConditions.fill(0);
|
||||
shaderConditions[UnderlyingCast(ShaderStageType::Fragment)] = fragmentShader->GetConditionFlagByName("HAS_DIFFUSE_TEXTURE");
|
||||
|
||||
s_conditionIndexes.hasDiffuseMap = settings.conditions.size();
|
||||
settings.conditions.push_back({
|
||||
"HasDiffuseMap",
|
||||
shaderConditions
|
||||
});
|
||||
}
|
||||
|
||||
// HasAlphaMap
|
||||
{
|
||||
std::array<UInt64, ShaderStageTypeCount> shaderConditions;
|
||||
shaderConditions.fill(0);
|
||||
shaderConditions[UnderlyingCast(ShaderStageType::Fragment)] = fragmentShader->GetConditionFlagByName("HAS_ALPHA_TEXTURE");
|
||||
|
||||
s_conditionIndexes.hasAlphaMap = settings.conditions.size();
|
||||
settings.conditions.push_back({
|
||||
"HasAlphaMap",
|
||||
shaderConditions
|
||||
});
|
||||
}
|
||||
|
||||
// AlphaTest
|
||||
{
|
||||
std::array<UInt64, ShaderStageTypeCount> shaderConditions;
|
||||
shaderConditions.fill(0);
|
||||
shaderConditions[UnderlyingCast(ShaderStageType::Fragment)] = fragmentShader->GetConditionFlagByName("ALPHA_TEST");
|
||||
|
||||
s_conditionIndexes.alphaTest = settings.conditions.size();
|
||||
settings.conditions.push_back({
|
||||
"AlphaTest",
|
||||
shaderConditions
|
||||
});
|
||||
}
|
||||
|
||||
s_materialSettings = std::make_shared<MaterialSettings>(std::move(settings));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -178,6 +221,7 @@ namespace Nz
|
||||
|
||||
std::shared_ptr<MaterialSettings> BasicMaterial::s_materialSettings;
|
||||
std::size_t BasicMaterial::s_uniformBlockIndex;
|
||||
BasicMaterial::ConditionIndexes BasicMaterial::s_conditionIndexes;
|
||||
BasicMaterial::TextureIndexes BasicMaterial::s_textureIndexes;
|
||||
BasicMaterial::UniformOffsets BasicMaterial::s_uniformOffsets;
|
||||
}
|
||||
|
||||
@@ -24,11 +24,15 @@ namespace Nz
|
||||
*/
|
||||
Material::Material(std::shared_ptr<const MaterialSettings> settings) :
|
||||
m_settings(std::move(settings)),
|
||||
m_enabledConditions(0),
|
||||
m_pipelineUpdated(false),
|
||||
m_shadowCastingEnabled(true)
|
||||
{
|
||||
m_pipelineInfo.settings = m_settings;
|
||||
m_pipelineInfo.shaders = m_settings->GetDefaultShaders();
|
||||
|
||||
const auto& shaders = m_settings->GetShaders();
|
||||
for (std::size_t i = 0; i < ShaderStageTypeCount; ++i)
|
||||
m_pipelineInfo.shaders[i].uberShader = shaders[i];
|
||||
|
||||
m_textures.resize(m_settings->GetTextures().size());
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/MaterialSettings.hpp>
|
||||
#include <Nazara/Graphics/PhongLightingMaterial.hpp>
|
||||
#include <Nazara/Graphics/UberShader.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
@@ -47,10 +48,10 @@ namespace Nz
|
||||
|
||||
renderPipelineInfo.pipelineLayout = m_pipelineInfo.settings->GetRenderPipelineLayout();
|
||||
|
||||
for (const auto& shaderStage : m_pipelineInfo.shaders)
|
||||
for (const auto& shaderEntry : m_pipelineInfo.shaders)
|
||||
{
|
||||
if (shaderStage)
|
||||
renderPipelineInfo.shaderStages.push_back(shaderStage);
|
||||
if (shaderEntry.uberShader)
|
||||
renderPipelineInfo.shaderStages.push_back(shaderEntry.uberShader->Get(shaderEntry.enabledConditions));
|
||||
}
|
||||
|
||||
renderPipelineInfo.vertexBuffers = vertexBuffers;
|
||||
|
||||
@@ -151,8 +151,8 @@ namespace Nz
|
||||
s_phongUniformOffsets.diffuseColor = phongUniformStruct.AddField(StructFieldType_Float4);
|
||||
s_phongUniformOffsets.specularColor = phongUniformStruct.AddField(StructFieldType_Float4);
|
||||
|
||||
MaterialSettings::PredefinedBinding predefinedBinding;
|
||||
predefinedBinding.fill(MaterialSettings::InvalidIndex);
|
||||
MaterialSettings::Builder settings;
|
||||
settings.predefinedBinding.fill(MaterialSettings::InvalidIndex);
|
||||
|
||||
std::vector<MaterialSettings::UniformVariable> phongVariables;
|
||||
phongVariables.assign({
|
||||
@@ -187,10 +187,8 @@ namespace Nz
|
||||
AccessByOffset<float&>(defaultValues.data(), s_phongUniformOffsets.alphaThreshold) = 0.2f;
|
||||
AccessByOffset<float&>(defaultValues.data(), s_phongUniformOffsets.shininess) = 50.f;
|
||||
|
||||
std::vector<MaterialSettings::UniformBlock> uniformBlocks;
|
||||
|
||||
s_phongUniformBlockIndex = uniformBlocks.size();
|
||||
uniformBlocks.push_back({
|
||||
s_phongUniformBlockIndex = settings.uniformBlocks.size();
|
||||
settings.uniformBlocks.push_back({
|
||||
phongUniformStruct.GetSize(),
|
||||
"PhongSettings",
|
||||
"MaterialPhongSettings",
|
||||
@@ -198,65 +196,63 @@ namespace Nz
|
||||
std::move(defaultValues)
|
||||
});
|
||||
|
||||
std::vector<MaterialSettings::SharedUniformBlock> sharedUniformBlock;
|
||||
predefinedBinding[UnderlyingCast(PredefinedShaderBinding::UboInstanceData)] = sharedUniformBlock.size();
|
||||
sharedUniformBlock.push_back(PredefinedInstanceData::GetUniformBlock());
|
||||
predefinedBinding[UnderlyingCast(PredefinedShaderBinding::UboLighData)] = sharedUniformBlock.size();
|
||||
sharedUniformBlock.push_back(PredefinedLightData::GetUniformBlock());
|
||||
predefinedBinding[UnderlyingCast(PredefinedShaderBinding::UboViewerData)] = sharedUniformBlock.size();
|
||||
sharedUniformBlock.push_back(PredefinedViewerData::GetUniformBlock());
|
||||
settings.predefinedBinding[UnderlyingCast(PredefinedShaderBinding::UboInstanceData)] = settings.sharedUniformBlocks.size();
|
||||
settings.sharedUniformBlocks.push_back(PredefinedInstanceData::GetUniformBlock());
|
||||
settings.predefinedBinding[UnderlyingCast(PredefinedShaderBinding::UboLighData)] = settings.sharedUniformBlocks.size();
|
||||
settings.sharedUniformBlocks.push_back(PredefinedLightData::GetUniformBlock());
|
||||
settings.predefinedBinding[UnderlyingCast(PredefinedShaderBinding::UboViewerData)] = settings.sharedUniformBlocks.size();
|
||||
settings.sharedUniformBlocks.push_back(PredefinedViewerData::GetUniformBlock());
|
||||
|
||||
std::vector<MaterialSettings::Texture> textures;
|
||||
s_textureIndexes.alpha = textures.size();
|
||||
textures.push_back({
|
||||
s_textureIndexes.alpha = settings.textures.size();
|
||||
settings.textures.push_back({
|
||||
"MaterialAlphaMap",
|
||||
"Alpha",
|
||||
ImageType_2D
|
||||
});
|
||||
|
||||
s_textureIndexes.diffuse = textures.size();
|
||||
textures.push_back({
|
||||
s_textureIndexes.diffuse = settings.textures.size();
|
||||
settings.textures.push_back({
|
||||
"MaterialDiffuseMap",
|
||||
"Diffuse",
|
||||
ImageType_2D
|
||||
});
|
||||
|
||||
s_textureIndexes.emissive = textures.size();
|
||||
textures.push_back({
|
||||
s_textureIndexes.emissive = settings.textures.size();
|
||||
settings.textures.push_back({
|
||||
"MaterialEmissiveMap",
|
||||
"Emissive",
|
||||
ImageType_2D
|
||||
});
|
||||
|
||||
s_textureIndexes.height = textures.size();
|
||||
textures.push_back({
|
||||
s_textureIndexes.height = settings.textures.size();
|
||||
settings.textures.push_back({
|
||||
"MaterialHeightMap",
|
||||
"Height",
|
||||
ImageType_2D
|
||||
});
|
||||
|
||||
s_textureIndexes.normal = textures.size();
|
||||
textures.push_back({
|
||||
s_textureIndexes.normal = settings.textures.size();
|
||||
settings.textures.push_back({
|
||||
"MaterialNormalMap",
|
||||
"Normal",
|
||||
ImageType_2D
|
||||
});
|
||||
|
||||
s_textureIndexes.specular = textures.size();
|
||||
textures.push_back({
|
||||
s_textureIndexes.specular = settings.textures.size();
|
||||
settings.textures.push_back({
|
||||
"MaterialSpecularMap",
|
||||
"Specular",
|
||||
ImageType_2D
|
||||
});
|
||||
|
||||
predefinedBinding[UnderlyingCast(PredefinedShaderBinding::TexOverlay)] = textures.size();
|
||||
textures.push_back({
|
||||
settings.predefinedBinding[UnderlyingCast(PredefinedShaderBinding::TexOverlay)] = settings.textures.size();
|
||||
settings.textures.push_back({
|
||||
"TextureOverlay",
|
||||
"Overlay",
|
||||
ImageType_2D,
|
||||
});
|
||||
|
||||
s_materialSettings = std::make_shared<MaterialSettings>(std::move(textures), std::move(uniformBlocks), std::move(sharedUniformBlock), predefinedBinding, MaterialSettings::DefaultShaders{});
|
||||
s_materialSettings = std::make_shared<MaterialSettings>(std::move(settings));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
78,83,72,82,0,0,0,1,0,0,0,0,0,0,0,3,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,0,0,0,2,0,0,0,14,65,108,112,104,97,84,104,114,101,115,104,111,108,100,0,0,0,0,1,0,0,0,12,68,105,102,102,117,115,101,67,111,108,111,114,0,0,0,0,3,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,0,0,0,2,0,0,0,11,119,111,114,108,100,77,97,116,114,105,120,0,0,0,0,9,0,0,0,14,105,110,118,87,111,114,108,100,77,97,116,114,105,120,0,0,0,0,9,0,0,0,10,86,105,101,119,101,114,68,97,116,97,0,0,0,9,0,0,0,16,112,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,0,0,0,0,9,0,0,0,19,105,110,118,80,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,0,0,0,0,9,0,0,0,10,118,105,101,119,77,97,116,114,105,120,0,0,0,0,9,0,0,0,13,105,110,118,86,105,101,119,77,97,116,114,105,120,0,0,0,0,9,0,0,0,14,118,105,101,119,80,114,111,106,77,97,116,114,105,120,0,0,0,0,9,0,0,0,17,105,110,118,86,105,101,119,80,114,111,106,77,97,116,114,105,120,0,0,0,0,9,0,0,0,16,114,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,0,0,0,0,2,0,0,0,19,105,110,118,82,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,0,0,0,0,2,0,0,0,11,101,121,101,80,111,115,105,116,105,111,110,0,0,0,0,3,0,0,0,2,0,0,0,10,118,101,114,116,78,111,114,109,97,108,0,0,0,0,3,1,0,0,0,0,0,0,0,6,118,101,114,116,85,86,0,0,0,0,2,1,0,0,0,1,0,0,0,1,0,0,0,13,82,101,110,100,101,114,84,97,114,103,101,116,48,0,0,0,0,4,1,0,0,0,0,0,0,0,6,0,0,0,10,118,105,101,119,101,114,68,97,116,97,1,0,0,0,10,86,105,101,119,101,114,68,97,116,97,1,0,0,0,5,1,0,0,0,0,0,0,0,12,105,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,4,1,0,0,0,0,0,0,0,8,115,101,116,116,105,110,103,115,1,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,1,0,0,0,3,1,0,0,0,0,0,0,0,16,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,0,0,0,0,10,1,0,0,0,0,0,0,0,0,18,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,0,0,0,0,10,1,0,0,0,1,0,0,0,0,14,84,101,120,116,117,114,101,79,118,101,114,108,97,121,0,0,0,0,10,1,0,0,0,2,0,0,0,0,1,0,0,0,4,109,97,105,110,0,0,0,11,0,0,0,0,0,0,0,13,0,0,0,3,0,0,0,7,0,0,0,2,0,0,0,8,108,105,103,104,116,68,105,114,0,0,0,0,3,0,0,0,5,0,0,0,5,0,0,0,0,191,52,253,244,63,52,253,244,0,0,0,7,0,0,0,2,0,0,0,11,108,105,103,104,116,70,97,99,116,111,114,0,0,0,0,1,0,0,0,10,0,0,0,1,0,0,0,2,0,0,0,9,0,0,0,1,0,0,0,10,118,101,114,116,78,111,114,109,97,108,0,0,0,0,3,0,0,0,9,0,0,0,2,0,0,0,8,108,105,103,104,116,68,105,114,0,0,0,0,3,0,0,0,8,0,0,0,1,0,0,0,0,0,0,0,9,0,0,0,3,0,0,0,13,82,101,110,100,101,114,84,97,114,103,101,116,48,0,0,0,0,4,0,0,0,2,0,0,0,2,0,0,0,9,0,0,0,2,0,0,0,11,108,105,103,104,116,70,97,99,116,111,114,0,0,0,0,1,0,0,0,11,0,0,0,9,0,0,0,5,0,0,0,18,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,0,0,0,0,10,0,0,0,9,0,0,0,1,0,0,0,6,118,101,114,116,85,86,0,0,0,0,2,84,97,114,103,101,116,48,0,0,0,0,4,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,9,0,0,0,2,0,0,0,11,108,105,103,104,116,70,97,99,116,111,114,0,0,0,0,1,0,0,0,11,0,0,0,9,0,0,0,5,0,0,0,18,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,0,0,0,0,10,0,0,0,9,0,0,0,1,0,0,0,6,118,101,114,116,85,86,0,0,0,0,2,0,0,0,9,0,0,0,2,0,0,0,10,109,97,116,68,105,102,102,117,115,101,0,0,0,0,4,
|
||||
78,83,72,82,0,0,0,1,0,0,0,0,0,0,0,3,0,0,0,19,72,65,83,95,68,73,70,70,85,83,69,95,84,69,88,84,85,82,69,0,0,0,17,72,65,83,95,65,76,80,72,65,95,84,69,88,84,85,82,69,0,0,0,10,65,76,80,72,65,95,84,69,83,84,0,0,0,3,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,0,0,0,2,0,0,0,14,65,108,112,104,97,84,104,114,101,115,104,111,108,100,0,0,0,0,1,0,0,0,12,68,105,102,102,117,115,101,67,111,108,111,114,0,0,0,0,4,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,0,0,0,2,0,0,0,11,119,111,114,108,100,77,97,116,114,105,120,0,0,0,0,9,0,0,0,14,105,110,118,87,111,114,108,100,77,97,116,114,105,120,0,0,0,0,9,0,0,0,10,86,105,101,119,101,114,68,97,116,97,0,0,0,9,0,0,0,16,112,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,0,0,0,0,9,0,0,0,19,105,110,118,80,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,0,0,0,0,9,0,0,0,10,118,105,101,119,77,97,116,114,105,120,0,0,0,0,9,0,0,0,13,105,110,118,86,105,101,119,77,97,116,114,105,120,0,0,0,0,9,0,0,0,14,118,105,101,119,80,114,111,106,77,97,116,114,105,120,0,0,0,0,9,0,0,0,17,105,110,118,86,105,101,119,80,114,111,106,77,97,116,114,105,120,0,0,0,0,9,0,0,0,16,114,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,0,0,0,0,2,0,0,0,19,105,110,118,82,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,0,0,0,0,2,0,0,0,11,101,121,101,80,111,115,105,116,105,111,110,0,0,0,0,3,0,0,0,2,0,0,0,10,118,101,114,116,78,111,114,109,97,108,0,0,0,0,3,1,0,0,0,0,0,0,0,6,118,101,114,116,85,86,0,0,0,0,2,1,0,0,0,1,0,0,0,1,0,0,0,13,82,101,110,100,101,114,84,97,114,103,101,116,48,0,0,0,0,4,1,0,0,0,0,0,0,0,6,0,0,0,10,118,105,101,119,101,114,68,97,116,97,1,0,0,0,10,86,105,101,119,101,114,68,97,116,97,1,0,0,0,5,1,0,0,0,0,0,0,0,12,105,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,4,1,0,0,0,0,0,0,0,8,115,101,116,116,105,110,103,115,1,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,1,0,0,0,3,1,0,0,0,0,0,0,0,16,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,0,0,0,0,10,1,0,0,0,0,0,0,0,0,18,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,0,0,0,0,10,1,0,0,0,1,0,0,0,0,14,84,101,120,116,117,114,101,79,118,101,114,108,97,121,0,0,0,0,10,1,0,0,0,2,0,0,0,0,1,0,0,0,4,109,97,105,110,0,0,0,11,0,0,0,0,0,0,0,15,0,0,0,6,0,0,0,8,0,0,0,2,0,0,0,8,108,105,103,104,116,68,105,114,0,0,0,0,3,0,0,0,5,0,0,0,5,0,0,0,0,191,52,253,244,63,52,253,244,0,0,0,8,0,0,0,2,0,0,0,11,108,105,103,104,116,70,97,99,116,111,114,0,0,0,0,1,0,0,0,12,0,0,0,1,0,0,0,2,0,0,0,11,0,0,0,1,0,0,0,10,118,101,114,116,78,111,114,109,97,108,0,0,0,0,3,0,0,0,11,0,0,0,2,0,0,0,8,108,105,103,104,116,68,105,114,0,0,0,0,3,0,0,0,8,0,0,0,2,0,0,0,12,116,101,120,116,117,114,101,67,111,108,111,114,0,0,0,0,4,0,0,0,2,0,0,0,2,0,0,0,11,0,0,0,2,0,0,0,11,108,105,103,104,116,70,97,99,116,111,114,0,0,0,0,1,0,0,0,6,0,0,0,19,72,65,83,95,68,73,70,70,85,83,69,95,84,69,88,84,85,82,69,0,0,0,2,0,0,0,2,0,0,0,13,0,0,0,11,0,0,0,5,0,0,0,18,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,0,0,0,0,10,0,0,0,11,0,0,0,1,0,0,0,6,118,101,114,116,85,86,0,0,0,0,2,0,0,0,0,0,0,0,11,0,0,0,5,0,0,0,8,115,101,116,116,105,110,103,115,1,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,0,0,0,0,4,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,11,0,0,0,5,0,0,0,8,115,101,116,116,105,110,103,115,1,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,0,0,0,0,4,0,0,0,1,0,0,0,1,0,0,0,8,0,0,0,2,0,0,0,4,118,97,114,48,0,0,0,0,4,0,0,0,6,0,0,0,17,72,65,83,95,65,76,80,72,65,95,84,69,88,84,85,82,69,0,0,0,4,0,0,0,4,0,0,0,14,0,0,0,0,0,0,0,1,0,0,0,11,0,0,0,2,0,0,0,12,116,101,120,116,117,114,101,67,111,108,111,114,0,0,0,0,4,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,1,0,0,0,11,0,0,0,2,0,0,0,12,116,101,120,116,117,114,101,67,111,108,111,114,0,0,0,0,4,0,0,0,1,0,0,0,14,0,0,0,0,0,0,0,1,0,0,0,11,0,0,0,2,0,0,0,12,116,101,120,116,117,114,101,67,111,108,111,114,0,0,0,0,4,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,14,0,0,0,0,0,0,0,1,0,0,0,13,0,0,0,11,0,0,0,5,0,0,0,16,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,0,0,0,0,10,0,0,0,11,0,0,0,1,0,0,0,6,118,101,114,116,85,86,0,0,0,0,2,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,1,0,0,0,11,0,0,0,2,0,0,0,12,116,101,120,116,117,114,101,67,111,108,111,114,0,0,0,0,4,0,0,0,3,0,0,0,11,0,0,0,2,0,0,0,12,116,101,120,116,117,114,101,67,111,108,111,114,0,0,0,0,4,0,0,0,3,0,0,0,1,0,0,0,2,0,0,0,4,0,0,0,6,0,0,0,10,65,76,80,72,65,95,84,69,83,84,0,0,0,2,0,0,0,8,0,0,0,14,0,0,0,0,0,0,0,1,0,0,0,11,0,0,0,2,0,0,0,4,118,97,114,48,0,0,0,0,4,0,0,0,3,0,0,0,0,0,0,0,11,0,0,0,5,0,0,0,8,115,101,116,116,105,110,103,115,1,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,5,0,0,0,0,1,0,0,0,9,255,255,255,255,0,0,0,10,0,0,0,1,0,0,0,0,0,0,0,11,0,0,0,3,0,0,0,13,82,101,110,100,101,114,84,97,114,103,101,116,48,0,0,0,0,4,0,0,0,11,0,0,0,2,0,0,0,4,118,97,114,48,0,0,0,0,4,
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
78,83,72,82,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,0,0,0,2,0,0,0,14,65,108,112,104,97,84,104,114,101,115,104,111,108,100,0,0,0,0,1,0,0,0,12,68,105,102,102,117,115,101,67,111,108,111,114,0,0,0,0,3,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,0,0,0,2,0,0,0,11,119,111,114,108,100,77,97,116,114,105,120,0,0,0,0,9,0,0,0,14,105,110,118,87,111,114,108,100,77,97,116,114,105,120,0,0,0,0,9,0,0,0,10,86,105,101,119,101,114,68,97,116,97,0,0,0,9,0,0,0,16,112,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,0,0,0,0,9,0,0,0,19,105,110,118,80,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,0,0,0,0,9,0,0,0,10,118,105,101,119,77,97,116,114,105,120,0,0,0,0,9,0,0,0,13,105,110,118,86,105,101,119,77,97,116,114,105,120,0,0,0,0,9,0,0,0,14,118,105,101,119,80,114,111,106,77,97,116,114,105,120,0,0,0,0,9,0,0,0,17,105,110,118,86,105,101,119,80,114,111,106,77,97,116,114,105,120,0,0,0,0,9,0,0,0,16,114,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,0,0,0,0,2,0,0,0,19,105,110,118,82,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,0,0,0,0,2,0,0,0,11,101,121,101,80,111,115,105,116,105,111,110,0,0,0,0,3,0,0,0,3,0,0,0,5,105,110,80,111,115,0,0,0,0,3,1,0,0,0,0,0,0,0,9,105,110,78,111,114,109,97,108,115,0,0,0,0,3,1,0,0,0,1,0,0,0,10,105,110,84,101,120,67,111,111,114,100,0,0,0,0,2,1,0,0,0,2,0,0,0,2,0,0,0,10,118,101,114,116,78,111,114,109,97,108,0,0,0,0,3,1,0,0,0,0,0,0,0,6,118,101,114,116,85,86,0,0,0,0,2,1,0,0,0,1,0,0,0,3,0,0,0,10,118,105,101,119,101,114,68,97,116,97,1,0,0,0,10,86,105,101,119,101,114,68,97,116,97,1,0,0,0,5,1,0,0,0,0,0,0,0,12,105,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,4,1,0,0,0,0,0,0,0,8,115,101,116,116,105,110,103,115,1,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,1,0,0,0,3,1,0,0,0,0,0,0,0,1,0,0,0,4,109,97,105,110,0,0,0,11,0,0,0,0,0,0,0,13,0,0,0,3,0,0,0,8,0,0,0,1,0,0,0,0,0,0,0,9,0,0,0,3,0,0,0,6,118,101,114,116,85,86,0,0,0,0,2,0,0,0,9,0,0,0,1,0,0,0,10,105,110,84,101,120,67,111,111,114,100,0,0,0,0,2,0,0,0,8,0,0,0,1,0,0,0,0,0,0,0,9,0,0,0,3,0,0,0,10,118,101,114,116,78,111,114,109,97,108,0,0,0,0,3,0,0,0,9,0,0,0,1,0,0,0,9,105,110,78,111,114,109,97,108,115,0,0,0,0,3,0,0,0,8,0,0,0,1,0,0,0,0,0,0,0,9,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,9,0,0,0,5,0,0,0,10,118,105,101,119,101,114,68,97,116,97,1,0,0,0,10,86,105,101,119,101,114,68,97,116,97,0,0,0,0,9,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0,5,0,0,0,10,118,105,101,119,101,114,68,97,116,97,1,0,0,0,10,86,105,101,119,101,114,68,97,116,97,0,0,0,0,9,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0,9,0,0,0,5,0,0,0,12,105,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,0,0,0,0,9,0,0,0,1,0,0,0,0,0,0,0,4,0,0,0,4,0,0,0,9,0,0,0,1,0,0,0,5,105,110,80,111,115,0,0,0,0,3,0,0,0,5,0,0,0,1,63,128,0,0,255,255,255,255,255,255,255,255,
|
||||
78,83,72,82,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,3,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,0,0,0,2,0,0,0,14,65,108,112,104,97,84,104,114,101,115,104,111,108,100,0,0,0,0,1,0,0,0,12,68,105,102,102,117,115,101,67,111,108,111,114,0,0,0,0,4,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,0,0,0,2,0,0,0,11,119,111,114,108,100,77,97,116,114,105,120,0,0,0,0,9,0,0,0,14,105,110,118,87,111,114,108,100,77,97,116,114,105,120,0,0,0,0,9,0,0,0,10,86,105,101,119,101,114,68,97,116,97,0,0,0,9,0,0,0,16,112,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,0,0,0,0,9,0,0,0,19,105,110,118,80,114,111,106,101,99,116,105,111,110,77,97,116,114,105,120,0,0,0,0,9,0,0,0,10,118,105,101,119,77,97,116,114,105,120,0,0,0,0,9,0,0,0,13,105,110,118,86,105,101,119,77,97,116,114,105,120,0,0,0,0,9,0,0,0,14,118,105,101,119,80,114,111,106,77,97,116,114,105,120,0,0,0,0,9,0,0,0,17,105,110,118,86,105,101,119,80,114,111,106,77,97,116,114,105,120,0,0,0,0,9,0,0,0,16,114,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,0,0,0,0,2,0,0,0,19,105,110,118,82,101,110,100,101,114,84,97,114,103,101,116,83,105,122,101,0,0,0,0,2,0,0,0,11,101,121,101,80,111,115,105,116,105,111,110,0,0,0,0,3,0,0,0,3,0,0,0,5,105,110,80,111,115,0,0,0,0,3,1,0,0,0,0,0,0,0,9,105,110,78,111,114,109,97,108,115,0,0,0,0,3,1,0,0,0,1,0,0,0,10,105,110,84,101,120,67,111,111,114,100,0,0,0,0,2,1,0,0,0,2,0,0,0,2,0,0,0,10,118,101,114,116,78,111,114,109,97,108,0,0,0,0,3,1,0,0,0,0,0,0,0,6,118,101,114,116,85,86,0,0,0,0,2,1,0,0,0,1,0,0,0,3,0,0,0,10,118,105,101,119,101,114,68,97,116,97,1,0,0,0,10,86,105,101,119,101,114,68,97,116,97,1,0,0,0,5,1,0,0,0,0,0,0,0,12,105,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,4,1,0,0,0,0,0,0,0,8,115,101,116,116,105,110,103,115,1,0,0,0,13,66,97,115,105,99,83,101,116,116,105,110,103,115,1,0,0,0,3,1,0,0,0,0,0,0,0,1,0,0,0,4,109,97,105,110,0,0,0,11,0,0,0,0,0,0,0,15,0,0,0,3,0,0,0,10,0,0,0,1,0,0,0,0,0,0,0,11,0,0,0,3,0,0,0,6,118,101,114,116,85,86,0,0,0,0,2,0,0,0,11,0,0,0,1,0,0,0,10,105,110,84,101,120,67,111,111,114,100,0,0,0,0,2,0,0,0,10,0,0,0,1,0,0,0,0,0,0,0,11,0,0,0,3,0,0,0,10,118,101,114,116,78,111,114,109,97,108,0,0,0,0,3,0,0,0,11,0,0,0,1,0,0,0,9,105,110,78,111,114,109,97,108,115,0,0,0,0,3,0,0,0,10,0,0,0,1,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,11,0,0,0,5,0,0,0,10,118,105,101,119,101,114,68,97,116,97,1,0,0,0,10,86,105,101,119,101,114,68,97,116,97,0,0,0,0,9,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,5,0,0,0,10,118,105,101,119,101,114,68,97,116,97,1,0,0,0,10,86,105,101,119,101,114,68,97,116,97,0,0,0,0,9,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0,11,0,0,0,5,0,0,0,12,105,110,115,116,97,110,99,101,68,97,116,97,1,0,0,0,12,73,110,115,116,97,110,99,101,68,97,116,97,0,0,0,0,9,0,0,0,1,0,0,0,0,0,0,0,4,0,0,0,4,0,0,0,11,0,0,0,1,0,0,0,5,105,110,80,111,115,0,0,0,0,3,0,0,0,5,0,0,0,1,63,128,0,0,255,255,255,255,255,255,255,255,
|
||||
54
src/Nazara/Graphics/UberShader.cpp
Normal file
54
src/Nazara/Graphics/UberShader.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/UberShader.hpp>
|
||||
#include <Nazara/Graphics/Graphics.hpp>
|
||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||
#include <Nazara/Shader/ShaderAst.hpp>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
UberShader::UberShader(ShaderAst shaderAst) :
|
||||
m_shaderAst(std::move(shaderAst))
|
||||
{
|
||||
std::size_t conditionCount = m_shaderAst.GetConditionCount();
|
||||
|
||||
if (conditionCount >= 64)
|
||||
throw std::runtime_error("Too many conditions");
|
||||
|
||||
m_combinationMask = std::numeric_limits<UInt64>::max();
|
||||
m_combinationMask <<= conditionCount;
|
||||
m_combinationMask = ~m_combinationMask;
|
||||
}
|
||||
|
||||
UInt64 UberShader::GetConditionFlagByName(const std::string_view& condition) const
|
||||
{
|
||||
std::size_t conditionIndex = m_shaderAst.FindConditionByName(condition);
|
||||
if (conditionIndex != ShaderAst::InvalidCondition)
|
||||
return SetBit<UInt64>(0, conditionIndex);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
const std::shared_ptr<ShaderStage>& UberShader::Get(UInt64 combination)
|
||||
{
|
||||
combination &= m_combinationMask;
|
||||
|
||||
auto it = m_combinations.find(combination);
|
||||
if (it == m_combinations.end())
|
||||
{
|
||||
ShaderWriter::States states;
|
||||
states.enabledConditions = combination;
|
||||
|
||||
std::shared_ptr<ShaderStage> stage = Graphics::Instance()->GetRenderDevice().InstantiateShaderStage(m_shaderAst, std::move(states));
|
||||
|
||||
it = m_combinations.emplace(combination, std::move(stage)).first;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,7 @@ namespace Nz
|
||||
command.framebuffer->Activate();
|
||||
|
||||
context = GL::Context::GetCurrentContext();
|
||||
context->glClearColor(0.5, 0.5, 0.5, 1.0);
|
||||
context->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -68,6 +68,11 @@ namespace Nz
|
||||
return std::make_shared<OpenGLRenderPipelineLayout>(std::move(pipelineLayoutInfo));
|
||||
}
|
||||
|
||||
std::shared_ptr<ShaderStage> OpenGLDevice::InstantiateShaderStage(const ShaderAst& shaderAst, const ShaderWriter::States& states)
|
||||
{
|
||||
return std::make_shared<OpenGLShaderStage>(*this, shaderAst, states);
|
||||
}
|
||||
|
||||
std::shared_ptr<ShaderStage> OpenGLDevice::InstantiateShaderStage(ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
return std::make_shared<OpenGLShaderStage>(*this, type, lang, source, sourceSize);
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace Nz
|
||||
const auto& textureDescriptor = m_owner.GetTextureDescriptor(m_poolIndex, m_bindingIndex, i);
|
||||
|
||||
UInt32 textureIndex = textureDescriptor.bindingIndex;
|
||||
if (textureIndex == OpenGLRenderPipelineLayout::InvalidIndex)
|
||||
continue;
|
||||
|
||||
context.BindSampler(textureIndex, textureDescriptor.sampler);
|
||||
context.BindTexture(textureIndex, textureDescriptor.textureTarget, textureDescriptor.texture);
|
||||
@@ -29,6 +31,10 @@ namespace Nz
|
||||
{
|
||||
const auto& uboDescriptor = m_owner.GetUniformBufferDescriptor(m_poolIndex, m_bindingIndex, i);
|
||||
|
||||
UInt32 uboIndex = uboDescriptor.bindingIndex;
|
||||
if (uboIndex == OpenGLRenderPipelineLayout::InvalidIndex)
|
||||
continue;
|
||||
|
||||
context.BindUniformBuffer(uboDescriptor.bindingIndex, uboDescriptor.buffer, uboDescriptor.offset, uboDescriptor.size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,15 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
OpenGLShaderStage::OpenGLShaderStage(OpenGLDevice& device, const ShaderAst& shaderAst, const ShaderWriter::States& states)
|
||||
{
|
||||
if (!m_shader.Create(device, ToOpenGL(shaderAst.GetStage())))
|
||||
throw std::runtime_error("failed to create shader"); //< TODO: Handle error message
|
||||
|
||||
Create(device, shaderAst, states);
|
||||
CheckCompilationStatus();
|
||||
}
|
||||
|
||||
OpenGLShaderStage::OpenGLShaderStage(OpenGLDevice& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
if (!m_shader.Create(device, ToOpenGL(type)))
|
||||
@@ -28,32 +37,11 @@ namespace Nz
|
||||
|
||||
case ShaderLanguage::NazaraBinary:
|
||||
{
|
||||
ByteStream byteStream(source, sourceSize);
|
||||
auto shader = Nz::UnserializeShader(byteStream);
|
||||
|
||||
auto shader = UnserializeShader(source, sourceSize);
|
||||
if (shader.GetStage() != type)
|
||||
throw std::runtime_error("incompatible shader stage");
|
||||
|
||||
const auto& context = device.GetReferenceContext();
|
||||
const auto& contextParams = context.GetParams();
|
||||
|
||||
GlslWriter::Environment env;
|
||||
env.glES = (contextParams.type == GL::ContextType::OpenGL_ES);
|
||||
env.glMajorVersion = contextParams.glMajorVersion;
|
||||
env.glMinorVersion = contextParams.glMinorVersion;
|
||||
env.extCallback = [&](const std::string_view& ext)
|
||||
{
|
||||
return context.IsExtensionSupported(std::string(ext));
|
||||
};
|
||||
env.flipYPosition = true;
|
||||
|
||||
GlslWriter writer;
|
||||
writer.SetEnv(env);
|
||||
|
||||
std::string code = writer.Generate(shader);
|
||||
|
||||
m_shader.SetSource(code.data(), code.size());
|
||||
m_shader.Compile();
|
||||
Create(device, shader, {});
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -71,8 +59,39 @@ namespace Nz
|
||||
throw std::runtime_error("Unsupported shader language");
|
||||
}
|
||||
|
||||
CheckCompilationStatus();
|
||||
}
|
||||
|
||||
void OpenGLShaderStage::CheckCompilationStatus()
|
||||
{
|
||||
std::string errorLog;
|
||||
if (!m_shader.GetCompilationStatus(&errorLog))
|
||||
throw std::runtime_error("Failed to compile shader: " + errorLog);
|
||||
}
|
||||
|
||||
void OpenGLShaderStage::Create(OpenGLDevice& device, const ShaderAst& shaderAst, const ShaderWriter::States& states)
|
||||
{
|
||||
const auto& context = device.GetReferenceContext();
|
||||
const auto& contextParams = context.GetParams();
|
||||
|
||||
GlslWriter::Environment env;
|
||||
env.glES = (contextParams.type == GL::ContextType::OpenGL_ES);
|
||||
env.glMajorVersion = contextParams.glMajorVersion;
|
||||
env.glMinorVersion = contextParams.glMinorVersion;
|
||||
env.extCallback = [&](const std::string_view& ext)
|
||||
{
|
||||
return context.IsExtensionSupported(std::string(ext));
|
||||
};
|
||||
env.flipYPosition = true;
|
||||
|
||||
GlslWriter writer;
|
||||
writer.SetEnv(env);
|
||||
|
||||
std::string code = writer.Generate(shaderAst, states);
|
||||
|
||||
NazaraError(code);
|
||||
|
||||
m_shader.SetSource(code.data(), code.size());
|
||||
m_shader.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace Nz::GL
|
||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB
|
||||
};
|
||||
|
||||
m_handle = baseContext->wglCreateContextAttribsARB(m_deviceContext, nullptr, attributes.data());
|
||||
m_handle = baseContext->wglCreateContextAttribsARB(m_deviceContext, (shareContext) ? shareContext->m_handle : nullptr, attributes.data());
|
||||
if (m_handle)
|
||||
{
|
||||
m_params.type = ContextType::OpenGL;
|
||||
@@ -198,16 +198,16 @@ namespace Nz::GL
|
||||
return false;
|
||||
}
|
||||
|
||||
m_params.type = ContextType::OpenGL;
|
||||
}
|
||||
|
||||
if (shareContext)
|
||||
{
|
||||
if (!m_loader.wglShareLists(shareContext->m_handle, m_handle))
|
||||
if (shareContext)
|
||||
{
|
||||
NazaraError("failed to share context objects: " + Error::GetLastSystemError());
|
||||
return false;
|
||||
if (!m_loader.wglShareLists(shareContext->m_handle, m_handle))
|
||||
{
|
||||
NazaraError("failed to share context objects: " + Error::GetLastSystemError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_params.type = ContextType::OpenGL;
|
||||
}
|
||||
|
||||
LoadWGLExt();
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Nz
|
||||
|
||||
float Arbiter2D::GetContactDepth(std::size_t i) const
|
||||
{
|
||||
return cpArbiterGetDepth(m_arbiter, int(i));
|
||||
return float(cpArbiterGetDepth(m_arbiter, int(i)));
|
||||
}
|
||||
|
||||
Nz::Vector2f Arbiter2D::GetContactPointA(std::size_t i) const
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <Nazara/Shader/GlslWriter.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Shader/ShaderBuilder.hpp>
|
||||
#include <Nazara/Shader/ShaderAstCloner.hpp>
|
||||
#include <Nazara/Shader/ShaderAstValidator.hpp>
|
||||
@@ -418,21 +419,17 @@ namespace Nz
|
||||
|
||||
switch (node.op)
|
||||
{
|
||||
case ShaderNodes::BinaryType::Add:
|
||||
Append(" + ");
|
||||
break;
|
||||
case ShaderNodes::BinaryType::Substract:
|
||||
Append(" - ");
|
||||
break;
|
||||
case ShaderNodes::BinaryType::Multiply:
|
||||
Append(" * ");
|
||||
break;
|
||||
case ShaderNodes::BinaryType::Divide:
|
||||
Append(" / ");
|
||||
break;
|
||||
case ShaderNodes::BinaryType::Equality:
|
||||
Append(" == ");
|
||||
break;
|
||||
case ShaderNodes::BinaryType::Add: Append(" + "); break;
|
||||
case ShaderNodes::BinaryType::Substract: Append(" - "); break;
|
||||
case ShaderNodes::BinaryType::Multiply: Append(" * "); break;
|
||||
case ShaderNodes::BinaryType::Divide: Append(" / "); break;
|
||||
|
||||
case ShaderNodes::BinaryType::CompEq: Append(" == "); break;
|
||||
case ShaderNodes::BinaryType::CompGe: Append(" >= "); break;
|
||||
case ShaderNodes::BinaryType::CompGt: Append(" > "); break;
|
||||
case ShaderNodes::BinaryType::CompLe: Append(" <= "); break;
|
||||
case ShaderNodes::BinaryType::CompLt: Append(" < "); break;
|
||||
case ShaderNodes::BinaryType::CompNe: Append(" != "); break;
|
||||
}
|
||||
|
||||
Visit(node.right, true);
|
||||
@@ -448,15 +445,17 @@ namespace Nz
|
||||
Append(node.exprType);
|
||||
Append("(");
|
||||
|
||||
for (std::size_t i = 0; node.expressions[i]; ++i)
|
||||
bool first = true;
|
||||
for (const auto& exprPtr : node.expressions)
|
||||
{
|
||||
if (i != 0)
|
||||
if (!exprPtr)
|
||||
break;
|
||||
|
||||
if (!first)
|
||||
m_currentState->stream << ", ";
|
||||
|
||||
const auto& exprPtr = node.expressions[i];
|
||||
NazaraAssert(exprPtr, "Invalid expression");
|
||||
|
||||
Visit(exprPtr);
|
||||
first = false;
|
||||
}
|
||||
|
||||
Append(")");
|
||||
@@ -465,7 +464,10 @@ namespace Nz
|
||||
|
||||
void GlslWriter::Visit(ShaderNodes::ConditionalExpression& node)
|
||||
{
|
||||
if (m_context.states->enabledConditions.count(node.conditionName) != 0)
|
||||
std::size_t conditionIndex = m_context.shader->FindConditionByName(node.conditionName);
|
||||
assert(conditionIndex != ShaderAst::InvalidCondition);
|
||||
|
||||
if (TestBit<Nz::UInt64>(m_context.states->enabledConditions, conditionIndex))
|
||||
Visit(node.truePath);
|
||||
else
|
||||
Visit(node.falsePath);
|
||||
@@ -473,7 +475,10 @@ namespace Nz
|
||||
|
||||
void GlslWriter::Visit(ShaderNodes::ConditionalStatement& node)
|
||||
{
|
||||
if (m_context.states->enabledConditions.count(node.conditionName) != 0)
|
||||
std::size_t conditionIndex = m_context.shader->FindConditionByName(node.conditionName);
|
||||
assert(conditionIndex != ShaderAst::InvalidCondition);
|
||||
|
||||
if (TestBit<Nz::UInt64>(m_context.states->enabledConditions, conditionIndex))
|
||||
Visit(node.statement);
|
||||
}
|
||||
|
||||
@@ -604,7 +609,7 @@ namespace Nz
|
||||
|
||||
void GlslWriter::Visit(ShaderNodes::SwizzleOp& node)
|
||||
{
|
||||
Visit(node.expression);
|
||||
Visit(node.expression, true);
|
||||
Append(".");
|
||||
|
||||
for (std::size_t i = 0; i < node.componentCount; ++i)
|
||||
|
||||
@@ -659,6 +659,9 @@ namespace Nz
|
||||
Int32 nodeTypeInt;
|
||||
m_stream >> nodeTypeInt;
|
||||
|
||||
if (nodeTypeInt < static_cast<Int32>(ShaderNodes::NodeType::None) || nodeTypeInt > static_cast<Int32>(ShaderNodes::NodeType::Max))
|
||||
throw std::runtime_error("invalid node type");
|
||||
|
||||
ShaderNodes::NodeType nodeType = static_cast<ShaderNodes::NodeType>(nodeTypeInt);
|
||||
|
||||
#define HandleType(Type) case ShaderNodes::NodeType:: Type : node = std::make_shared<ShaderNodes:: Type>(); break
|
||||
|
||||
@@ -150,8 +150,17 @@ namespace Nz
|
||||
|
||||
switch (node.op)
|
||||
{
|
||||
case ShaderNodes::BinaryType::CompGe:
|
||||
case ShaderNodes::BinaryType::CompGt:
|
||||
case ShaderNodes::BinaryType::CompLe:
|
||||
case ShaderNodes::BinaryType::CompLt:
|
||||
if (leftType == ShaderNodes::BasicType::Boolean)
|
||||
throw AstError{ "this operation is not supported for booleans" };
|
||||
|
||||
[[fallthrough]];
|
||||
case ShaderNodes::BinaryType::Add:
|
||||
case ShaderNodes::BinaryType::Equality:
|
||||
case ShaderNodes::BinaryType::CompEq:
|
||||
case ShaderNodes::BinaryType::CompNe:
|
||||
case ShaderNodes::BinaryType::Substract:
|
||||
TypeMustMatch(node.left, node.right);
|
||||
break;
|
||||
@@ -236,7 +245,7 @@ namespace Nz
|
||||
}
|
||||
|
||||
if (componentCount != requiredComponents)
|
||||
throw AstError{ "Component count doesn't match required component count" };
|
||||
throw AstError{ "component count doesn't match required component count" };
|
||||
|
||||
ShaderAstRecursiveVisitor::Visit(node);
|
||||
}
|
||||
@@ -246,28 +255,16 @@ namespace Nz
|
||||
MandatoryNode(node.truePath);
|
||||
MandatoryNode(node.falsePath);
|
||||
|
||||
for (std::size_t i = 0; i < m_shader.GetConditionCount(); ++i)
|
||||
{
|
||||
const auto& condition = m_shader.GetCondition(i);
|
||||
if (condition.name == node.conditionName)
|
||||
return;
|
||||
}
|
||||
|
||||
throw AstError{ "Condition not found" };
|
||||
if (m_shader.FindConditionByName(node.conditionName) == ShaderAst::InvalidCondition)
|
||||
throw AstError{ "condition not found" };
|
||||
}
|
||||
|
||||
void ShaderAstValidator::Visit(ShaderNodes::ConditionalStatement& node)
|
||||
{
|
||||
MandatoryNode(node.statement);
|
||||
|
||||
for (std::size_t i = 0; i < m_shader.GetConditionCount(); ++i)
|
||||
{
|
||||
const auto& condition = m_shader.GetCondition(i);
|
||||
if (condition.name == node.conditionName)
|
||||
return;
|
||||
}
|
||||
|
||||
throw AstError{ "Condition not found" };
|
||||
if (m_shader.FindConditionByName(node.conditionName) == ShaderAst::InvalidCondition)
|
||||
throw AstError{ "condition not found" };
|
||||
}
|
||||
|
||||
void ShaderAstValidator::Visit(ShaderNodes::Constant& /*node*/)
|
||||
|
||||
@@ -140,7 +140,12 @@ namespace Nz::ShaderNodes
|
||||
break;
|
||||
}
|
||||
|
||||
case BinaryType::Equality:
|
||||
case BinaryType::CompEq:
|
||||
case BinaryType::CompGe:
|
||||
case BinaryType::CompGt:
|
||||
case BinaryType::CompLe:
|
||||
case BinaryType::CompLt:
|
||||
case BinaryType::CompNe:
|
||||
exprType = BasicType::Boolean;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace Nz
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderNodes::BinaryType::Equality:
|
||||
case ShaderNodes::BinaryType::CompEq:
|
||||
{
|
||||
switch (leftType)
|
||||
{
|
||||
@@ -185,6 +185,166 @@ namespace Nz
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderNodes::BinaryType::CompGe:
|
||||
{
|
||||
switch (leftType)
|
||||
{
|
||||
case ShaderNodes::BasicType::Float1:
|
||||
case ShaderNodes::BasicType::Float2:
|
||||
case ShaderNodes::BasicType::Float3:
|
||||
case ShaderNodes::BasicType::Float4:
|
||||
case ShaderNodes::BasicType::Mat4x4:
|
||||
return SpirvOp::OpFOrdGreaterThan;
|
||||
|
||||
case ShaderNodes::BasicType::Int1:
|
||||
case ShaderNodes::BasicType::Int2:
|
||||
case ShaderNodes::BasicType::Int3:
|
||||
case ShaderNodes::BasicType::Int4:
|
||||
return SpirvOp::OpSGreaterThan;
|
||||
|
||||
case ShaderNodes::BasicType::UInt1:
|
||||
case ShaderNodes::BasicType::UInt2:
|
||||
case ShaderNodes::BasicType::UInt3:
|
||||
case ShaderNodes::BasicType::UInt4:
|
||||
return SpirvOp::OpUGreaterThan;
|
||||
|
||||
case ShaderNodes::BasicType::Boolean:
|
||||
case ShaderNodes::BasicType::Sampler2D:
|
||||
case ShaderNodes::BasicType::Void:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderNodes::BinaryType::CompGt:
|
||||
{
|
||||
switch (leftType)
|
||||
{
|
||||
case ShaderNodes::BasicType::Float1:
|
||||
case ShaderNodes::BasicType::Float2:
|
||||
case ShaderNodes::BasicType::Float3:
|
||||
case ShaderNodes::BasicType::Float4:
|
||||
case ShaderNodes::BasicType::Mat4x4:
|
||||
return SpirvOp::OpFOrdGreaterThanEqual;
|
||||
|
||||
case ShaderNodes::BasicType::Int1:
|
||||
case ShaderNodes::BasicType::Int2:
|
||||
case ShaderNodes::BasicType::Int3:
|
||||
case ShaderNodes::BasicType::Int4:
|
||||
return SpirvOp::OpSGreaterThanEqual;
|
||||
|
||||
case ShaderNodes::BasicType::UInt1:
|
||||
case ShaderNodes::BasicType::UInt2:
|
||||
case ShaderNodes::BasicType::UInt3:
|
||||
case ShaderNodes::BasicType::UInt4:
|
||||
return SpirvOp::OpUGreaterThanEqual;
|
||||
|
||||
case ShaderNodes::BasicType::Boolean:
|
||||
case ShaderNodes::BasicType::Sampler2D:
|
||||
case ShaderNodes::BasicType::Void:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderNodes::BinaryType::CompLe:
|
||||
{
|
||||
switch (leftType)
|
||||
{
|
||||
case ShaderNodes::BasicType::Float1:
|
||||
case ShaderNodes::BasicType::Float2:
|
||||
case ShaderNodes::BasicType::Float3:
|
||||
case ShaderNodes::BasicType::Float4:
|
||||
case ShaderNodes::BasicType::Mat4x4:
|
||||
return SpirvOp::OpFOrdLessThanEqual;
|
||||
|
||||
case ShaderNodes::BasicType::Int1:
|
||||
case ShaderNodes::BasicType::Int2:
|
||||
case ShaderNodes::BasicType::Int3:
|
||||
case ShaderNodes::BasicType::Int4:
|
||||
return SpirvOp::OpSLessThanEqual;
|
||||
|
||||
case ShaderNodes::BasicType::UInt1:
|
||||
case ShaderNodes::BasicType::UInt2:
|
||||
case ShaderNodes::BasicType::UInt3:
|
||||
case ShaderNodes::BasicType::UInt4:
|
||||
return SpirvOp::OpULessThanEqual;
|
||||
|
||||
case ShaderNodes::BasicType::Boolean:
|
||||
case ShaderNodes::BasicType::Sampler2D:
|
||||
case ShaderNodes::BasicType::Void:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderNodes::BinaryType::CompLt:
|
||||
{
|
||||
switch (leftType)
|
||||
{
|
||||
case ShaderNodes::BasicType::Float1:
|
||||
case ShaderNodes::BasicType::Float2:
|
||||
case ShaderNodes::BasicType::Float3:
|
||||
case ShaderNodes::BasicType::Float4:
|
||||
case ShaderNodes::BasicType::Mat4x4:
|
||||
return SpirvOp::OpFOrdLessThan;
|
||||
|
||||
case ShaderNodes::BasicType::Int1:
|
||||
case ShaderNodes::BasicType::Int2:
|
||||
case ShaderNodes::BasicType::Int3:
|
||||
case ShaderNodes::BasicType::Int4:
|
||||
return SpirvOp::OpSLessThan;
|
||||
|
||||
case ShaderNodes::BasicType::UInt1:
|
||||
case ShaderNodes::BasicType::UInt2:
|
||||
case ShaderNodes::BasicType::UInt3:
|
||||
case ShaderNodes::BasicType::UInt4:
|
||||
return SpirvOp::OpULessThan;
|
||||
|
||||
case ShaderNodes::BasicType::Boolean:
|
||||
case ShaderNodes::BasicType::Sampler2D:
|
||||
case ShaderNodes::BasicType::Void:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderNodes::BinaryType::CompNe:
|
||||
{
|
||||
switch (leftType)
|
||||
{
|
||||
case ShaderNodes::BasicType::Boolean:
|
||||
return SpirvOp::OpLogicalNotEqual;
|
||||
|
||||
case ShaderNodes::BasicType::Float1:
|
||||
case ShaderNodes::BasicType::Float2:
|
||||
case ShaderNodes::BasicType::Float3:
|
||||
case ShaderNodes::BasicType::Float4:
|
||||
case ShaderNodes::BasicType::Mat4x4:
|
||||
return SpirvOp::OpFOrdNotEqual;
|
||||
|
||||
case ShaderNodes::BasicType::Int1:
|
||||
case ShaderNodes::BasicType::Int2:
|
||||
case ShaderNodes::BasicType::Int3:
|
||||
case ShaderNodes::BasicType::Int4:
|
||||
case ShaderNodes::BasicType::UInt1:
|
||||
case ShaderNodes::BasicType::UInt2:
|
||||
case ShaderNodes::BasicType::UInt3:
|
||||
case ShaderNodes::BasicType::UInt4:
|
||||
return SpirvOp::OpINotEqual;
|
||||
|
||||
case ShaderNodes::BasicType::Sampler2D:
|
||||
case ShaderNodes::BasicType::Void:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderNodes::BinaryType::Multiply:
|
||||
{
|
||||
|
||||
@@ -33,7 +33,8 @@ namespace Nz
|
||||
using LocalContainer = std::unordered_set<std::shared_ptr<const ShaderNodes::LocalVariable>>;
|
||||
using ParameterContainer = std::unordered_set< std::shared_ptr<const ShaderNodes::ParameterVariable>>;
|
||||
|
||||
PreVisitor(const SpirvWriter::States& conditions, SpirvConstantCache& constantCache) :
|
||||
PreVisitor(const ShaderAst& shader, const SpirvWriter::States& conditions, SpirvConstantCache& constantCache) :
|
||||
m_shader(shader),
|
||||
m_conditions(conditions),
|
||||
m_constantCache(constantCache)
|
||||
{
|
||||
@@ -52,7 +53,10 @@ namespace Nz
|
||||
|
||||
void Visit(ShaderNodes::ConditionalExpression& node) override
|
||||
{
|
||||
if (m_conditions.enabledConditions.count(node.conditionName) != 0)
|
||||
std::size_t conditionIndex = m_shader.FindConditionByName(node.conditionName);
|
||||
assert(conditionIndex != ShaderAst::InvalidCondition);
|
||||
|
||||
if (TestBit<Nz::UInt64>(m_conditions.enabledConditions, conditionIndex))
|
||||
Visit(node.truePath);
|
||||
else
|
||||
Visit(node.falsePath);
|
||||
@@ -60,7 +64,10 @@ namespace Nz
|
||||
|
||||
void Visit(ShaderNodes::ConditionalStatement& node) override
|
||||
{
|
||||
if (m_conditions.enabledConditions.count(node.conditionName) != 0)
|
||||
std::size_t conditionIndex = m_shader.FindConditionByName(node.conditionName);
|
||||
assert(conditionIndex != ShaderAst::InvalidCondition);
|
||||
|
||||
if (TestBit<Nz::UInt64>(m_conditions.enabledConditions, conditionIndex))
|
||||
Visit(node.statement);
|
||||
}
|
||||
|
||||
@@ -141,6 +148,7 @@ namespace Nz
|
||||
ParameterContainer paramVars;
|
||||
|
||||
private:
|
||||
const ShaderAst& m_shader;
|
||||
const SpirvWriter::States& m_conditions;
|
||||
SpirvConstantCache& m_constantCache;
|
||||
};
|
||||
@@ -229,7 +237,7 @@ namespace Nz
|
||||
|
||||
ShaderAstCloner cloner;
|
||||
|
||||
PreVisitor preVisitor(conditions, state.constantTypeCache);
|
||||
PreVisitor preVisitor(shader, conditions, state.constantTypeCache);
|
||||
for (const auto& func : shader.GetFunctions())
|
||||
{
|
||||
functionStatements.emplace_back(cloner.Clone(func.statement));
|
||||
|
||||
@@ -39,6 +39,15 @@ namespace Nz
|
||||
return pipelineLayout;
|
||||
}
|
||||
|
||||
std::shared_ptr<ShaderStage> VulkanDevice::InstantiateShaderStage(const ShaderAst& shaderAst, const ShaderWriter::States& states)
|
||||
{
|
||||
auto stage = std::make_shared<VulkanShaderStage>();
|
||||
if (!stage->Create(*this, shaderAst, states))
|
||||
return {};
|
||||
|
||||
return stage;
|
||||
}
|
||||
|
||||
std::shared_ptr<ShaderStage> VulkanDevice::InstantiateShaderStage(ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
auto stage = std::make_shared<VulkanShaderStage>();
|
||||
|
||||
@@ -10,6 +10,26 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
bool VulkanShaderStage::Create(Vk::Device& device, const ShaderAst& shader, const ShaderWriter::States& states)
|
||||
{
|
||||
m_stage = shader.GetStage();
|
||||
|
||||
SpirvWriter::Environment env;
|
||||
|
||||
SpirvWriter writer;
|
||||
writer.SetEnv(env);
|
||||
|
||||
std::vector<UInt32> code = writer.Generate(shader, states);
|
||||
|
||||
if (!m_shaderModule.Create(device, code.data(), code.size() * sizeof(UInt32)))
|
||||
{
|
||||
NazaraError("Failed to create shader module");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VulkanShaderStage::Create(Vk::Device& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
m_stage = type;
|
||||
@@ -18,24 +38,12 @@ namespace Nz
|
||||
{
|
||||
case ShaderLanguage::NazaraBinary:
|
||||
{
|
||||
ByteStream byteStream(source, sourceSize);
|
||||
auto shader = Nz::UnserializeShader(byteStream);
|
||||
|
||||
auto shader = UnserializeShader(source, sourceSize);
|
||||
if (shader.GetStage() != type)
|
||||
throw std::runtime_error("incompatible shader stage");
|
||||
|
||||
SpirvWriter::Environment env;
|
||||
|
||||
SpirvWriter writer;
|
||||
writer.SetEnv(env);
|
||||
|
||||
std::vector<UInt32> code = writer.Generate(shader);
|
||||
|
||||
if (!m_shaderModule.Create(device, code.data(), code.size() * sizeof(UInt32)))
|
||||
{
|
||||
NazaraError("Failed to create shader module");
|
||||
if (!Create(device, shader, {}))
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,11 @@ namespace Nz
|
||||
ss << "[Validation]";
|
||||
|
||||
|
||||
ss << "[" << pCallbackData->messageIdNumber << ":" << pCallbackData->pMessageIdName << "]: " << pCallbackData->pMessage;
|
||||
ss << "[" << pCallbackData->messageIdNumber;
|
||||
if (pCallbackData->pMessageIdName)
|
||||
ss << ":" << pCallbackData->pMessageIdName;
|
||||
|
||||
ss << "]: " << pCallbackData->pMessage;
|
||||
|
||||
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
|
||||
NazaraError(ss.str());
|
||||
|
||||
Reference in New Issue
Block a user