Skip to content

Commit

Permalink
Clustered decals progress
Browse files Browse the repository at this point in the history
* Updated GLSLang
  • Loading branch information
Benjamin Glatzel committed Jun 8, 2017
1 parent fba3b95 commit 9a18f10
Show file tree
Hide file tree
Showing 330 changed files with 7,600 additions and 1,817 deletions.
53 changes: 52 additions & 1 deletion IntrinsicCore/src/IntrinsicCoreComponentsDecal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ struct DecalData : Dod::Components::ComponentDataBase
DecalData()
: Dod::Components::ComponentDataBase(_INTR_MAX_DECAL_COMPONENT_COUNT)
{
descAlbedoTextureName.resize(_INTR_MAX_DECAL_COMPONENT_COUNT);
descNormalTextureName.resize(_INTR_MAX_DECAL_COMPONENT_COUNT);
descPBRTextureName.resize(_INTR_MAX_DECAL_COMPONENT_COUNT);

descHalfExtent.resize(_INTR_MAX_DECAL_COMPONENT_COUNT);
}

_INTR_ARRAY(Name) descAlbedoTextureName;
_INTR_ARRAY(Name) descNormalTextureName;
_INTR_ARRAY(Name) descPBRTextureName;

_INTR_ARRAY(glm::vec3) descHalfExtent;
};

Expand All @@ -52,8 +60,12 @@ struct DecalManager

// <-

_INTR_INLINE static void resetToDefault(MeshRef p_Ref)
_INTR_INLINE static void resetToDefault(DecalRef p_Ref)
{
_descAlbedoTextureName(p_Ref) = _N(checkerboard);
_descNormalTextureName(p_Ref) = _N(default_NRM);
_descPBRTextureName(p_Ref) = _N(checkerboard_PBR);

_descHalfExtent(p_Ref) = glm::vec3(2.0f, 2.0f, 2.0f);
}

Expand All @@ -72,6 +84,22 @@ struct DecalManager
rapidjson::Value& p_Properties,
rapidjson::Document& p_Document)
{
p_Properties.AddMember(
"albedoTextureName",
_INTR_CREATE_PROP(p_Document, p_GenerateDesc, _N(Decal), _N(string),
_descAlbedoTextureName(p_Ref), false, false),
p_Document.GetAllocator());
p_Properties.AddMember(
"normalTextureName",
_INTR_CREATE_PROP(p_Document, p_GenerateDesc, _N(Decal), _N(string),
_descNormalTextureName(p_Ref), false, false),
p_Document.GetAllocator());
p_Properties.AddMember(
"pbrTextureName",
_INTR_CREATE_PROP(p_Document, p_GenerateDesc, _N(Decal), _N(string),
_descPBRTextureName(p_Ref), false, false),
p_Document.GetAllocator());

p_Properties.AddMember(
"halfExtent",
_INTR_CREATE_PROP(p_Document, p_GenerateDesc, _N(Decal), _N(vec3),
Expand All @@ -84,6 +112,16 @@ struct DecalManager
_INTR_INLINE static void initFromDescriptor(DecalRef p_Ref,
rapidjson::Value& p_Properties)
{
if (p_Properties.HasMember("albedoTextureName"))
_descAlbedoTextureName(p_Ref) =
JsonHelper::readPropertyName(p_Properties["albedoTextureName"]);
if (p_Properties.HasMember("normalTextureName"))
_descNormalTextureName(p_Ref) =
JsonHelper::readPropertyName(p_Properties["normalTextureName"]);
if (p_Properties.HasMember("pbrTextureName"))
_descPBRTextureName(p_Ref) =
JsonHelper::readPropertyName(p_Properties["pbrTextureName"]);

if (p_Properties.HasMember("halfExtent"))
_descHalfExtent(p_Ref) =
JsonHelper::readPropertyVec3(p_Properties["halfExtent"]);
Expand All @@ -95,6 +133,19 @@ struct DecalManager
// ->

// Description
_INTR_INLINE static Name& _descAlbedoTextureName(DecalRef p_Ref)
{
return _data.descAlbedoTextureName[p_Ref._id];
}
_INTR_INLINE static Name& _descNormalTextureName(DecalRef p_Ref)
{
return _data.descNormalTextureName[p_Ref._id];
}
_INTR_INLINE static Name& _descPBRTextureName(DecalRef p_Ref)
{
return _data.descPBRTextureName[p_Ref._id];
}

_INTR_INLINE static glm::vec3& _descHalfExtent(DecalRef p_Ref)
{
return _data.descHalfExtent[p_Ref._id];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ struct DrawCallParallelTaskSet : enki::ITaskSet
currentPipeline = newPipeline;
}

VkDescriptorSet descSets[2] = {
Resources::DrawCallManager::_vkDescriptorSet(drawCallRef),
Resources::ImageManager::getGlobalDescriptorSet()};

_INTR_ASSERT(Resources::DrawCallManager::_vkDescriptorSet(drawCallRef));
vkCmdBindDescriptorSets(
secondCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
Resources::PipelineLayoutManager::_vkPipelineLayout(
pipelineLayoutRef),
0u, 1u, &Resources::DrawCallManager::_vkDescriptorSet(drawCallRef),
0u, 2u, descSets,
(uint32_t)Resources::DrawCallManager::_dynamicOffsets(drawCallRef)
.size(),
Resources::DrawCallManager::_dynamicOffsets(drawCallRef).data());
Expand Down
18 changes: 18 additions & 0 deletions IntrinsicRendererVulkan/src/IntrinsicRendererVulkanEnumsStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ enum Enum
};
}

namespace ImageTextureType
{
enum Enum
{
kUnknown,

k1D,
k1DArray,
k2D,
k2DArray,
k3D,
k3DArray,

kCube,
kCubeArray
};
}

namespace ImageFlags
{
enum Flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ _INTR_INLINE void initResource(TBuiltInResource& p_Resource)
p_Resource.maxVertexUniformComponents = 4096;
p_Resource.maxVaryingFloats = 64;
p_Resource.maxVertexTextureImageUnits = 32;
p_Resource.maxCombinedTextureImageUnits = 80;
p_Resource.maxCombinedTextureImageUnits = 4096;
p_Resource.maxTextureImageUnits = 32;
p_Resource.maxFragmentUniformComponents = 4096;
p_Resource.maxDrawBuffers = 32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct Decal
{
glm::mat4 viewProjMatrix;
glm::vec4 posAndRadiusVS;
glm::uvec4 textureIds;
};

_INTR_ARRAY(TestLight) _testLights;
Expand Down Expand Up @@ -384,6 +385,19 @@ _INTR_INLINE void cullAndWriteBuffers(Components::CameraRef p_CameraRef)
decal.viewProjMatrix =
(decalProjectionMatrix * decalViewMatrix) *
Components::CameraManager::_inverseViewMatrix(p_CameraRef);
decal.textureIds = glm::uvec4(
Resources::ImageManager::getTextureId(
Resources::ImageManager::getResourceByName(
Components::DecalManager::_descAlbedoTextureName(
decalRef))),
Resources::ImageManager::getTextureId(
Resources::ImageManager::getResourceByName(
Components::DecalManager::_descNormalTextureName(
decalRef))),
Resources::ImageManager::getTextureId(
Resources::ImageManager::getResourceByName(
Components::DecalManager::_descPBRTextureName(decalRef))),
0u);
}
_decalBufferMemory[_currentDecalCount] = decal;

Expand Down Expand Up @@ -638,10 +652,20 @@ _INTR_INLINE void renderDecals(Components::CameraRef p_CameraRef)

const ImageRef gbufferAlbedoRef =
ImageManager::getResourceByName(_N(GBufferAlbedo));
const ImageRef gbufferNormalRef =
ImageManager::getResourceByName(_N(GBufferNormal));
const ImageRef gbufferParameter0 =
ImageManager::getResourceByName(_N(GBufferParameter0));

ImageManager::insertImageMemoryBarrier(
gbufferAlbedoRef, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
ImageManager::insertImageMemoryBarrier(
gbufferNormalRef, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
ImageManager::insertImageMemoryBarrier(
gbufferParameter0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);

RenderSystem::beginRenderPass(_renderPassDecalsRef, _framebufferDecalsRef,
VK_SUBPASS_CONTENTS_INLINE);
Expand All @@ -653,6 +677,12 @@ _INTR_INLINE void renderDecals(Components::CameraRef p_CameraRef)
ImageManager::insertImageMemoryBarrier(
gbufferAlbedoRef, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
ImageManager::insertImageMemoryBarrier(
gbufferNormalRef, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
ImageManager::insertImageMemoryBarrier(
gbufferParameter0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}
}

Expand Down Expand Up @@ -713,6 +743,10 @@ void Clustering::init()

RenderPassManager::_descAttachments(_renderPassDecalsRef)
.push_back(colorAttachment);
RenderPassManager::_descAttachments(_renderPassDecalsRef)
.push_back(colorAttachment);
RenderPassManager::_descAttachments(_renderPassDecalsRef)
.push_back(colorAttachment);
}
renderpassesToCreate.push_back(_renderPassDecalsRef);

Expand Down Expand Up @@ -746,10 +780,10 @@ void Clustering::init()
PipelineManager::_descVertexLayout(_pipelineDecalsRef) = Dod::Ref();
PipelineManager::_descDepthStencilState(_pipelineDecalsRef) =
DepthStencilStates::kDefaultNoDepthTestAndWrite;

PipelineManager::_descBlendStates(_pipelineDecalsRef).clear();
PipelineManager::_descBlendStates(_pipelineDecalsRef)
.push_back(BlendStates::kAlphaBlend);
.push_back(BlendStates::kDefault);
PipelineManager::_descBlendStates(_pipelineDecalsRef)
.push_back(BlendStates::kDefault);
}
pipelinesToCreate.push_back(_pipelineLightingRef);

Expand Down Expand Up @@ -979,10 +1013,6 @@ _INTR_INLINE void setupDecalsDrawCall(Resources::DrawCallRef p_DrawCallRef)
GpuProgramType::kFragment,
ImageManager::getResourceByName(_N(GBufferDepth)),
Samplers::kNearestClamp);
DrawCallManager::bindImage(
p_DrawCallRef, _N(testTex), GpuProgramType::kFragment,
ImageManager::getResourceByName(_N(foam)), Samplers::kLinearClamp);

DrawCallManager::bindBuffer(
p_DrawCallRef, _N(DecalBuffer), GpuProgramType::kFragment, _decalBuffer,
UboType::kInvalidUbo, BufferManager::_descSizeInBytes(_decalBuffer));
Expand Down Expand Up @@ -1117,6 +1147,10 @@ void Clustering::onReinitRendering()

FramebufferManager::_descAttachedImages(_framebufferDecalsRef)
.push_back(ImageManager::getResourceByName(_N(GBufferAlbedo)));
FramebufferManager::_descAttachedImages(_framebufferDecalsRef)
.push_back(ImageManager::getResourceByName(_N(GBufferNormal)));
FramebufferManager::_descAttachedImages(_framebufferDecalsRef)
.push_back(ImageManager::getResourceByName(_N(GBufferParameter0)));

FramebufferManager::_descDimensions(_framebufferDecalsRef) =
glm::uvec2(RenderSystem::_backbufferDimensions.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,23 @@ void RenderSystem::init(void* p_PlatformHandle, void* p_PlatformWindow)

{
_INTR_PROFILE_AUTO("Compile Shaders");

GpuProgramManager::compileAllShaders();
}

{
_INTR_PROFILE_AUTO("Create GPU Program Resources");

GpuProgramManager::createAllResources();
}

RenderPassManager::createAllResources();

{
_INTR_PROFILE_AUTO("Create Image Resources");

ImageManager::createAllResources();
ImageManager::updateGlobalDescriptorSet();
}

VertexLayoutManager::createAllResources();
Expand Down Expand Up @@ -303,13 +307,16 @@ void RenderSystem::dispatchDrawCall(Dod::Ref p_DrawCall,
vkCmdBindPipeline(p_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
newPipeline);

VkDescriptorSet descSets[2] = {
Resources::DrawCallManager::_vkDescriptorSet(p_DrawCall),
Resources::ImageManager::getGlobalDescriptorSet()};

if (DrawCallManager::_vkDescriptorSet(p_DrawCall))
{
vkCmdBindDescriptorSets(
p_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
PipelineLayoutManager::_vkPipelineLayout(pipelineLayoutRef), 0u, 1u,
&DrawCallManager::_vkDescriptorSet(p_DrawCall),
(uint32_t)DrawCallManager::_dynamicOffsets(p_DrawCall).size(),
PipelineLayoutManager::_vkPipelineLayout(pipelineLayoutRef), 0u, 2u,
descSets, (uint32_t)DrawCallManager::_dynamicOffsets(p_DrawCall).size(),
DrawCallManager::_dynamicOffsets(p_DrawCall).data());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ void GpuProgramManager::reflectPipelineLayout(
{
spirv_cross::Resource& res = resources.uniform_buffers[i];

if (glsl.get_decoration(res.id, spv::DecorationDescriptorSet) != 0u)
continue;

const bool isDynamic = res.name == "PerInstance" ||
res.name == "PerMaterial" ||
res.name == "PerFrame";
Expand All @@ -253,6 +256,9 @@ void GpuProgramManager::reflectPipelineLayout(
{
spirv_cross::Resource& res = resources.sampled_images[i];

if (glsl.get_decoration(res.id, spv::DecorationDescriptorSet) != 0u)
continue;

BindingDescription bd;
{
bd.name = res.name.c_str();
Expand All @@ -270,6 +276,9 @@ void GpuProgramManager::reflectPipelineLayout(
{
spirv_cross::Resource& res = resources.storage_images[i];

if (glsl.get_decoration(res.id, spv::DecorationDescriptorSet) != 0u)
continue;

BindingDescription bd;
{
bd.name = res.name.c_str();
Expand All @@ -287,6 +296,9 @@ void GpuProgramManager::reflectPipelineLayout(
{
spirv_cross::Resource& res = resources.storage_buffers[i];

if (glsl.get_decoration(res.id, spv::DecorationDescriptorSet) != 0u)
continue;

BindingDescription bd;
{
bd.name = res.name.c_str();
Expand Down
Loading

0 comments on commit 9a18f10

Please sign in to comment.