Added tests for material binding and fixed some crashes

This commit is contained in:
Kah Wei 2022-09-27 21:06:14 +08:00
parent 055a0a1711
commit 61219f5136
11 changed files with 35 additions and 18 deletions

View File

@ -9,6 +9,7 @@
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
#include "Scripting/SHScriptEngine.h"
#include "Math/Transform/SHTransformComponent.h"
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
#include "Assets/SHAssetManager.h"
@ -66,6 +67,8 @@ namespace Sandbox
// Create Materials
auto matInst = graphicsSystem->AddOrGetBaseMaterialInstance();
auto customMat = graphicsSystem->AddMaterialInstanceCopy(matInst);
customMat->SetProperty("data.color", SHVec4(0.0f, 1.0f, 1.0f, 1.0f));
// Create Stress Test Objects
static const SHVec3 TEST_OBJ_SCALE = { 0.2f, 0.2f, 0.2f };
@ -95,7 +98,7 @@ namespace Sandbox
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
renderable.Mesh = handles.front();
renderable.SetMaterial(matInst);
renderable.SetMaterial(customMat);
////transform.SetLocalScale(TEST_OBJ_SCALE);

View File

@ -206,7 +206,7 @@ namespace SHADE
transformDataBuffer[frameIndex]->WriteToMemory(transformData.data(), static_cast<uint32_t>(transformData.size() * sizeof(SHMatrix)), 0, 0);
}
void SHBatch::Build(Handle<SHVkLogicalDevice> device, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex)
void SHBatch::Build(Handle<SHVkLogicalDevice> _device, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex)
{
if (frameIndex >= SHGraphicsConstants::NUM_FRAME_BUFFERS)
{
@ -214,6 +214,9 @@ namespace SHADE
return;
}
// Save logical device
device = _device;
// No need to build as there are no changes
if (!isDirty[frameIndex])
return;
@ -247,7 +250,7 @@ namespace SHADE
{
singleMatPropSize = SHADER_INFO->GetBytesRequired();
singleMatPropAlignedSize = device->PadSSBOSize(singleMatPropSize);
matPropTotalBytes = drawData.size() * singleMatPropAlignedSize;
matPropTotalBytes = numTotalElements * singleMatPropAlignedSize;
if (matPropsDataSize < matPropTotalBytes)
{
matPropsData.reset(new char[matPropTotalBytes]);
@ -319,9 +322,6 @@ namespace SHADE
// Mark this frame as no longer dirty
isDirty[frameIndex] = false;
// Save logical device
this->device = device;
}
/*---------------------------------------------------------------------------------*/
@ -377,7 +377,7 @@ namespace SHADE
matPropsDescSet[frameIndex] = descPool->Allocate
(
{ SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE] },
{ static_cast<uint32_t>(drawData.size()) }
{ 0 }
);
}
std::array<Handle<SHVkBuffer>, 1> bufferList = { matPropsBuffer[frameIndex] };
@ -386,7 +386,7 @@ namespace SHADE
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
bufferList,
0, 1
0, matPropsDataSize
);
matPropsDescSet[frameIndex]->UpdateDescriptorSetBuffer
(

View File

@ -187,8 +187,8 @@ namespace SHADE
shaderModuleLibrary.ImportFromSourceLibrary(device, shaderSourceLibrary);
auto cubeVS = shaderModuleLibrary.GetShaderModule("TestCubeVs.glsl");
auto cubeFS = shaderModuleLibrary.GetShaderModule("TestCubeFs.glsl");
//triVS->Reflect();
//triFS->Reflect();
cubeVS->Reflect();
cubeFS->Reflect();
defaultMaterial = AddMaterial(cubeVS, cubeFS, gBufferWriteSubpass);
}

View File

@ -40,8 +40,6 @@ namespace SHADE
void SHMaterialInstance::ExportProperties(void* dest)
{
assert(dataStore != nullptr);
if (!baseMaterial)
throw std::runtime_error("[SHMaterialInstance] Attempted to set export a Material Instance with no base Material!");

View File

@ -15,6 +15,7 @@ of DigiPen Institute of Technology is prohibited.
// Project Includes
#include "Resource/Handle.h"
#include "Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h"
#include "SH_API.h"
namespace SHADE
{
@ -34,7 +35,7 @@ namespace SHADE
a SHRenderable.
*/
/***********************************************************************************/
class SHMaterialInstance
class SH_API SHMaterialInstance
{
public:
/*-----------------------------------------------------------------------------*/

View File

@ -48,7 +48,7 @@ namespace SHADE
}
// Get offset and modify the memory directly
T* dataPtr = dataStore.get() + od.StoredDataOffset;
T* dataPtr = reinterpret_cast<T*>(dataStore.get() + od.StoredDataOffset);
*dataPtr = value;
// Save the override data information

View File

@ -27,7 +27,7 @@ namespace SHADE
SHADE::SHShaderBlockInterface::Variable const* const SHShaderBlockInterface::GetVariable(uint32_t index) const noexcept
{
if (variableIndexing.size() < index)
if (index < variableIndexing.size())
return &variables.at(index);
return nullptr;

View File

@ -2,10 +2,12 @@
#include <unordered_map>
#include "SH_API.h"
namespace SHADE
{
class SHShaderBlockInterface
class SH_API SHShaderBlockInterface
{
public:
struct Variable

View File

@ -111,6 +111,7 @@ namespace SHADE
biggestAlignment = std::max(biggestAlignment, 4u);
break;
case SpvOp::SpvOpTypeStruct:
case SpvOp::SpvOpTypeRuntimeArray:
recurseForInfo(&member, interfaceHdl, member.offset, biggestAlignment, parentVarName + std::string(member.name) + ".");
break;
}

View File

@ -31,6 +31,18 @@ layout(location = 0) out vec4 outColor;
//layout(binding = 3) uniform sampler2D glossinessMap;
//layout(binding = 4) uniform sampler2D samplerRoughnessMap;
struct MatPropData
{
vec4 color;
float alpha;
vec3 beta;
};
layout(set = 3, binding = 0) buffer MaterialProperties
{
MatPropData data[];
} MatProp;
void main()
{
//vec3 normal;
@ -67,6 +79,6 @@ void main()
//outColor.rgb = pow(outColor.rgb, vec3(1.0f / gamma));
//outColor.a = diffuseColor.a;
outColor = vec4 (1.0f);
outColor = MatProp.data[0].color;
//outColor = vec4 (1.0f);
}

Binary file not shown.