Skip to content

Commit

Permalink
UnityPlugin: Release 2.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
PopcornFX Bot committed Dec 12, 2024
1 parent c804353 commit d76a318
Show file tree
Hide file tree
Showing 186 changed files with 116,339 additions and 209,872 deletions.
1 change: 1 addition & 0 deletions Native/ImplemGraphicsAPI/RenderAPI_DX11Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void *CDX11Data::BeginModifyNativeBuffer(SBufferHandles &bufferHandle, bool isId
GET_IMMEDIATE_CONTEXT(device, immediateCtx, return null);
D3D11_BUFFER_DESC deviceLocalDesc = {};
deviceLocalBuff->GetDesc(&deviceLocalDesc);
PK_ASSERT(deviceLocalDesc.ByteWidth == fullSize);
if ((deviceLocalDesc.CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) != 0)
{
immediateCtx->Map(deviceLocalBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
Expand Down
22 changes: 16 additions & 6 deletions Native/ImplemGraphicsAPI/RenderAPI_Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ SFlagsToUseSemantic flagsToUseSemantic[__Semantic_Count] =
{ 0U, ShaderVariationFlags::Has_Color }, // Semantic_Color0
{ 0U, ShaderVariationFlags::Has_CorrectDeformation }, // Semantic_UvFactors
{ 0U, ShaderVariationFlags::Has_CorrectDeformation }, // Semantic_UvScaleAndOffset
{ ShaderVariationFlags::Has_CorrectDeformation, ShaderVariationFlags::Has_DiffuseMap | ShaderVariationFlags::Has_DistortionMap }, // Semantic_Uv0
{ ShaderVariationFlags::Has_CorrectDeformation, ShaderVariationFlags::Has_DiffuseMap | ShaderVariationFlags::Has_DistortionMap | ShaderVariationFlags::Has_Emissive }, // Semantic_Uv0
{ 0U, ShaderVariationFlags::Has_AnimBlend }, // Semantic_Uv1
{ 0U, ShaderVariationFlags::Has_AnimBlend | ShaderVariationFlags::Has_TransformUVs }, // Semantic_AtlasId
{ 0U, ShaderVariationFlags::Has_AlphaRemap }, // Semantic_AlphaCursor
{ 0U, ShaderVariationFlags::Has_Emissive }, // Semantic_EmissiveColor
{ 0U, ShaderVariationFlags::Has_Emissive }, // Semantic_EmissiveColor3
{ 0U, ShaderVariationFlags::Has_Emissive }, // Semantic_EmissiveColor4
{ 0U, ShaderVariationFlags::Has_TransformUVs }, // Semantic_TransformUvsRotate
{ 0U, ShaderVariationFlags::Has_TransformUVs }, // Semantic_TransformUvsScaleAndOffset
{ ShaderVariationFlags::Has_TransformUVs, ShaderVariationFlags::Has_AlphaMasks }, // Semantic_AlphaMasksCursors
Expand All @@ -158,7 +159,8 @@ u32 semanticSize[__Semantic_Count] =
2 * sizeof(float), // Semantic_Uv1
1 * sizeof(float), // Semantic_AtlasId
1 * sizeof(float), // Semantic_AlphaCursor
4 * sizeof(float), // Semantic_EmissiveColor
3 * sizeof(float), // Semantic_EmissiveColor3
4 * sizeof(float), // Semantic_EmissiveColor4
1 * sizeof(float), // Semantic_TransformUvsRotate
4 * sizeof(float), // Semantic_TransformUvsScaleAndOffset
2 * sizeof(float), // Semantic_AlphaMasksCursors
Expand Down Expand Up @@ -235,7 +237,7 @@ IRenderAPIData *IRenderAPIData::GetRenderAPISpecificData(UnityGfxRenderer device

//----------------------------------------------------------------------------

u32 FillOffsetTableAndGetVertexBufferStride(u32 offsetTable[__Semantic_Count], u32 shaderVariationFlags)
u32 FillOffsetTableAndGetVertexBufferStride(u32 offsetTable[__Semantic_Count], u32 shaderVariationFlags, bool isEmissive3 /*= false*/)
{
u32 vertexOffset = 0;

Expand Down Expand Up @@ -309,8 +311,16 @@ u32 FillOffsetTableAndGetVertexBufferStride(u32 offsetTable[__Semantic_Count], u
}
if ((shaderVariationFlags & ShaderVariationFlags::Has_Emissive) != 0)
{
offsetTable[Semantic_EmissiveColor] = vertexOffset;
vertexOffset += semanticSize[Semantic_EmissiveColor];
if (isEmissive3)
{
offsetTable[Semantic_EmissiveColor3] = vertexOffset;
vertexOffset += semanticSize[Semantic_EmissiveColor3] + sizeof(float);
}
else
{
offsetTable[Semantic_EmissiveColor4] = vertexOffset;
vertexOffset += semanticSize[Semantic_EmissiveColor4];
}
}
if ((shaderVariationFlags & ShaderVariationFlags::Has_TransformUVs) != 0)
{
Expand Down
22 changes: 19 additions & 3 deletions Native/ImplemGraphicsAPI/RenderAPI_Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ enum EVertexSemantic
Semantic_AtlasId,

Semantic_AlphaCursor,
Semantic_EmissiveColor,
Semantic_EmissiveColor3,
Semantic_EmissiveColor4,

Semantic_TransformUVsRotate,
Semantic_TransformUVsScaleAndOffset,
Expand All @@ -104,7 +105,7 @@ enum EVertexSemantic
__Semantic_Count
};

u32 FillOffsetTableAndGetVertexBufferStride(u32 offsetTable[__Semantic_Count], u32 shaderVariationFlags);
u32 FillOffsetTableAndGetVertexBufferStride(u32 offsetTable[__Semantic_Count], u32 shaderVariationFlags, bool isEmissive3 = false);
u32 GetGeomBillboardVertexBufferStride(EBillboardMode bbMode, u32 shaderVariationFlags);

#define SIMDFY 0
Expand Down Expand Up @@ -173,7 +174,7 @@ PK_INLINE void FillColors(void * const stream, volatile void * const dstPtr, con

PK_INLINE void FillEmissiveColors(void *const stream, volatile void *const dstPtr, const u32(&offsetTable)[__Semantic_Count])
{
volatile void *dst = Mem::AdvanceRawPointer(dstPtr, offsetTable[Semantic_EmissiveColor]);
volatile void *dst = Mem::AdvanceRawPointer(dstPtr, offsetTable[Semantic_EmissiveColor4]);
#if (SIMDFY != 0)
const SIMD::Float4 norm_s = SIMD::Float4::LoadAligned16(stream);

Expand All @@ -183,6 +184,21 @@ PK_INLINE void FillEmissiveColors(void *const stream, volatile void *const dstPt
#endif
}

//-------------------------------------------------------------------------------------

PK_INLINE void FillEmissiveColors3(void *const stream, volatile void *const dstPtr, const u32(&offsetTable)[__Semantic_Count])
{
volatile void *dst = Mem::AdvanceRawPointer(dstPtr, offsetTable[Semantic_EmissiveColor3]);
#if (SIMDFY != 0)
const SIMD::Float4 norm_s = SIMD::Float4::LoadAligned16(stream);

norm_s.StoreFloat3(dst);
#else
*(CFloat3 *)dst = *(const CFloat3 *)stream;
#endif
}


//-------------------------------------------------------------------------------------

PK_INLINE void FillUVFactors(void * const stream, volatile void * const dstPtr, const u32(&offsetTable)[__Semantic_Count])
Expand Down
17 changes: 15 additions & 2 deletions Native/PKUnity_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ void CPKFXScene::Reset()
void CPKFXScene::HardReset()
{
_ResetParticleMediumCollections();
m_RenderDataFactory.EmptyAllBatches();
m_RenderDataFactory.Reset();
}

Expand Down Expand Up @@ -718,6 +719,8 @@ bool CPKFXScene::GameThread_WaitForUpdateEnd()
// Can get called before update startup (med col creation)
if (m_WaitForUpdateOnRenderThread && m_ParticleMediumCollection != null)
m_ParticleMediumCollection->UpdateFence();
else if (m_GameThreadMediumCollection != null)
m_GameThreadMediumCollection->UpdateFence();
return true;
}

Expand Down Expand Up @@ -1169,6 +1172,18 @@ void CPKFXScene::BroadcastEvent( Threads::SThreadContext *threadCtx,

bool CPKFXScene::_ResetParticleMediumCollections()
{
m_IsMediumCollectionInitialized = false;
if (m_GameThreadMediumCollection && m_GameThreadFrameCollector)
{
// Release the collected frame prior to deleting the medium collection
m_GameThreadFrameCollector->ReleaseRenderedFrame();
m_GameThreadFrameCollector->UpdateThread_UninstallFromMediumCollection(m_GameThreadMediumCollection);
}
if (m_ParticleMediumCollection && m_ParticleFrameCollector)
{
m_ParticleFrameCollector->ReleaseRenderedFrame();
m_ParticleFrameCollector->UpdateThread_UninstallFromMediumCollection(m_ParticleMediumCollection);
}
PK_SAFE_DELETE(m_ParticleMediumCollection);
PK_SAFE_DELETE(m_GameThreadMediumCollection);

Expand Down Expand Up @@ -1237,7 +1252,6 @@ bool CPKFXScene::_ResetParticleMediumCollections()
// Instal the game thread frame collector:
m_GameThreadFrameCollector->UpdateThread_InstallToMediumCollection(m_ParticleMediumCollection);
}

if (m_MediumCollectionSettings.m_Initialized)
{
// Enable/Disable bounds
Expand All @@ -1263,7 +1277,6 @@ bool CPKFXScene::_ResetParticleMediumCollections()
}

m_IsMediumCollectionInitialized = true;

return true;
}

Expand Down
64 changes: 52 additions & 12 deletions Native/RenderingIntegration/UnityBillboardingBatchPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ bool CUnityBillboardingBatchPolicy::AllocBuffers(SUnityRenderContext &ctx, const
if (PK_VERIFY(bbRequest != null))
m_AtlasList = bbRequest->m_Atlas;
}
for (u32 i = 0; i < allocBuffers.m_ToGenerate.m_AdditionalGeneratedInputs.Count(); ++i)
{
const SRendererFeatureFieldDefinition &addInput = allocBuffers.m_ToGenerate.m_AdditionalGeneratedInputs[i];
if (addInput.m_Name == BasicRendererProperties::SID_Emissive_EmissiveColor() && (addInput.m_Type == BaseType_Float4 || addInput.m_Type == BaseType_Float3))
{
if (addInput.m_Type == BaseType_Float3)
m_IsEmissive3 = true;
}
}
}
}
}
Expand Down Expand Up @@ -1136,6 +1145,8 @@ void CUnityBillboardingBatchPolicy::_UpdateThread_ResizeUnityMeshInstanceCount(c
}
else if (addInput.m_Name == BasicRendererProperties::SID_Emissive_EmissiveColor() && (addInput.m_Type == BaseType_Float4 || addInput.m_Type == BaseType_Float3))
{
if (addInput.m_Type == BaseType_Float3)
m_IsEmissive3 = true;
perMeshDataSize += sizeof(CFloat4);
hasEmissiveColor = true;
}
Expand Down Expand Up @@ -1218,7 +1229,6 @@ void CUnityBillboardingBatchPolicy::_UpdateThread_ResizeUnityMeshInstanceCount(c
perMeshDataSize += sizeof(float);
m_HasDissolve = true;
}

}

m_UseSkeletalAnimData = (skeletalAnimMask & 0x3) == 0x3;
Expand Down Expand Up @@ -1437,8 +1447,10 @@ bool CUnityBillboardingBatchPolicy::_RenderThread_AllocBillboardingBuffers(const
m_ParticleBuffers.m_Colors.ResizeIFN(m_VertexCount);
if (_FindAdditionalInput(BasicRendererProperties::SID_Atlas_TextureID(), BaseType_Float, genInputs))
m_ParticleBuffers.m_AtlasId.ResizeIFN(m_VertexCount);
if (_FindAdditionalInput(BasicRendererProperties::SID_Emissive_EmissiveColor(), BaseType_Float4, genInputs) || _FindAdditionalInput(BasicRendererProperties::SID_Emissive_EmissiveColor(), BaseType_Float3, genInputs))
m_ParticleBuffers.m_EmissiveColors.ResizeIFN(m_VertexCount);
if (_FindAdditionalInput(BasicRendererProperties::SID_Emissive_EmissiveColor(), BaseType_Float4, genInputs))
m_ParticleBuffers.m_EmissiveColors4.ResizeIFN(m_VertexCount);
if (_FindAdditionalInput(BasicRendererProperties::SID_Emissive_EmissiveColor(), BaseType_Float3, genInputs))
m_ParticleBuffers.m_EmissiveColors3.ResizeIFN(m_VertexCount);
if (_FindAdditionalInput(BasicRendererProperties::SID_AlphaRemap_Cursor(), BaseType_Float, genInputs))
m_ParticleBuffers.m_AlphaCursor.ResizeIFN(m_VertexCount);

Expand Down Expand Up @@ -1561,16 +1573,24 @@ bool CUnityBillboardingBatchPolicy::_RenderThread_SetupBuffersBillboards(const S
field.m_Storage.m_RawDataPtr = (u8 *)m_ParticleBuffers.m_AtlasId.m_Ptr;
field.m_Storage.m_Stride = sizeof(float);
}
else if (addInput.m_Name == BasicRendererProperties::SID_Emissive_EmissiveColor() && (addInput.m_Type == BaseType_Float3 || addInput.m_Type == BaseType_Float4))
else if (addInput.m_Name == BasicRendererProperties::SID_Emissive_EmissiveColor())
{
if (!PK_VERIFY(m_ParticleBuffers.m_AdditionalFieldsBuffers.PushBack().Valid()))
return false;
Drawers::SCopyFieldDesc &field = m_ParticleBuffers.m_AdditionalFieldsBuffers.Last();
field.m_AdditionalInputIndex = i;

field.m_Storage.m_Count = m_VertexCount;
field.m_Storage.m_RawDataPtr = (u8 *)m_ParticleBuffers.m_EmissiveColors.m_Ptr;
field.m_Storage.m_Stride = sizeof(CFloat4);
if (addInput.m_Type == BaseType_Float3)
{
field.m_Storage.m_RawDataPtr = (u8 *)m_ParticleBuffers.m_EmissiveColors3.m_Ptr;
field.m_Storage.m_Stride = sizeof(CFloat3);
}
else if (addInput.m_Type == BaseType_Float4)
{
field.m_Storage.m_RawDataPtr = (u8 *)m_ParticleBuffers.m_EmissiveColors4.m_Ptr;
field.m_Storage.m_Stride = sizeof(CFloat4);
}
}
else if (addInput.m_Name == BasicRendererProperties::SID_AlphaRemap_Cursor() && addInput.m_Type == BaseType_Float)
{
Expand Down Expand Up @@ -1912,8 +1932,16 @@ bool CUnityBillboardingBatchPolicy::_RenderThread_SetupBuffersRibbons(const SGen
Drawers::SCopyFieldDesc& field = m_ParticleBuffers.m_AdditionalFieldsBuffers.Last();
field.m_AdditionalInputIndex = i;
field.m_Storage.m_Count = m_VertexCount;
field.m_Storage.m_RawDataPtr = (u8*)m_ParticleBuffers.m_EmissiveColors.m_Ptr;
field.m_Storage.m_Stride = sizeof(CFloat4);
if (addInput.m_Type == BaseType_Float3)
{
field.m_Storage.m_RawDataPtr = (u8 *)m_ParticleBuffers.m_EmissiveColors3.m_Ptr;
field.m_Storage.m_Stride = sizeof(CFloat3);
}
else if (addInput.m_Type == BaseType_Float4)
{
field.m_Storage.m_RawDataPtr = (u8 *)m_ParticleBuffers.m_EmissiveColors4.m_Ptr;
field.m_Storage.m_Stride = sizeof(CFloat4);
}
}
else if (addInput.m_Name == BasicRendererProperties::SID_AlphaRemap_Cursor() && addInput.m_Type == BaseType_Float)
{
Expand Down Expand Up @@ -2287,8 +2315,16 @@ bool CUnityBillboardingBatchPolicy::_RenderThread_SetupBuffersTriangles(const SG
Drawers::SCopyFieldDesc &field = m_ParticleBuffers.m_AdditionalFieldsBuffers.Last();
field.m_AdditionalInputIndex = i;
field.m_Storage.m_Count = m_VertexCount;
field.m_Storage.m_RawDataPtr = (u8 *)m_ParticleBuffers.m_EmissiveColors.m_Ptr;
field.m_Storage.m_Stride = sizeof(CFloat4);
if (addInput.m_Type == BaseType_Float3)
{
field.m_Storage.m_RawDataPtr = (u8 *)m_ParticleBuffers.m_EmissiveColors3.m_Ptr;
field.m_Storage.m_Stride = sizeof(CFloat3);
}
else if (addInput.m_Type == BaseType_Float4)
{
field.m_Storage.m_RawDataPtr = (u8 *)m_ParticleBuffers.m_EmissiveColors4.m_Ptr;
field.m_Storage.m_Stride = sizeof(CFloat4);
}
}
else if (addInput.m_Name == BasicRendererProperties::SID_AlphaRemap_Cursor() && addInput.m_Type == BaseType_Float)
{
Expand Down Expand Up @@ -2410,6 +2446,7 @@ bool CUnityBillboardingBatchPolicy::_PrepareCopySOA2AOS(const SUnityRenderContex
{
m_Exec_SAO2AOS[idx].m_IdxView = idx;
m_Exec_SAO2AOS[idx].m_ShaderVariationFlags = m_MaterialDescBillboard.m_Flags.m_ShaderVariationFlags;
m_Exec_SAO2AOS[idx].m_IsEmissive3 = m_IsEmissive3;
m_Exec_SAO2AOS[idx].m_ParticleBuffers.Clear();
m_Exec_SAO2AOS[idx].m_ParticleBuffers.FromParticleBuffers(m_ParticleBuffers, idx);
m_Exec_SAO2AOS[idx].m_SemanticOffsets = &m_UnityMeshInfo.m_SemanticOffsets;
Expand Down Expand Up @@ -2488,13 +2525,16 @@ void CUnityBillboardingBatchPolicy::CBillboard_Exec_SOA_OAS::_CopyData(u32 verte
{
FillUV0(&(m_ParticleBuffers.m_TexCoords0[vertexID]), bfPtr, *m_SemanticOffsets);
if ((m_ShaderVariationFlags & ShaderVariationFlags::Has_AlphaRemap) != 0)
FillAlphaCursor(&(m_ParticleBuffers.m_AlphaCursor[vertexID]), bfPtr, *m_SemanticOffsets); // Packed with UV0
FillAlphaCursor(&(m_ParticleBuffers.m_AlphaCursor[vertexID]), bfPtr, *m_SemanticOffsets); // Packed with UV0
}
}

if ((m_ShaderVariationFlags & ShaderVariationFlags::Has_Emissive) != 0)
{
FillEmissiveColors(&(m_ParticleBuffers.m_EmissiveColors[vertexID]), bfPtr, *m_SemanticOffsets);
if (m_IsEmissive3)
FillEmissiveColors3(&(m_ParticleBuffers.m_EmissiveColors3[vertexID]), bfPtr, *m_SemanticOffsets);
else
FillEmissiveColors(&(m_ParticleBuffers.m_EmissiveColors4[vertexID]), bfPtr, *m_SemanticOffsets);
}
if ((m_ShaderVariationFlags & ShaderVariationFlags::Has_TransformUVs) != 0)
{
Expand Down
14 changes: 10 additions & 4 deletions Native/RenderingIntegration/UnityBillboardingBatchPolicy.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class CUnityBillboardingBatchPolicy
bool m_HasAlphaMasks;
bool m_HasUVDistortions;
bool m_HasDissolve;
bool m_IsEmissive3 = false;

// ----------------------------------------------------------------------------
// FILLED ON RENDER THREAD - ALLOC BILLBOARDING BUFFERS:
Expand Down Expand Up @@ -251,7 +252,8 @@ class CUnityBillboardingBatchPolicy
// Additional fields that we handle:
SSizedBuffer<float> m_AtlasId;
SSizedBuffer<CFloat4> m_Colors;
SSizedBuffer<CFloat4> m_EmissiveColors;
SSizedBuffer<CFloat3> m_EmissiveColors3;
SSizedBuffer<CFloat4> m_EmissiveColors4;
SSizedBuffer<float> m_AlphaCursor;
SSizedBuffer<float> m_TransformUVsRotate;
SSizedBuffer<CFloat2> m_TransformUVsScale;
Expand Down Expand Up @@ -281,7 +283,8 @@ class CUnityBillboardingBatchPolicy
m_AtlasId.FreeIFN();
m_UVRemap.FreeIFN();
m_Colors.FreeIFN();
m_EmissiveColors.FreeIFN();
m_EmissiveColors3.FreeIFN();
m_EmissiveColors4.FreeIFN();
m_AlphaCursor.FreeIFN();

m_TransformUVsRotate.FreeIFN();
Expand Down Expand Up @@ -358,7 +361,8 @@ class CUnityBillboardingBatchPolicy
float *m_AtlasId;
CFloat4 *m_UVRemap;
CFloat4 *m_Colors;
CFloat4 *m_EmissiveColors;
CFloat3 *m_EmissiveColors3;
CFloat4 *m_EmissiveColors4;
float *m_AlphaCursor;

float *m_TransformUVsRotate;
Expand Down Expand Up @@ -405,7 +409,8 @@ class CUnityBillboardingBatchPolicy
m_AtlasId = buffers.m_AtlasId.m_Ptr;
m_UVRemap = buffers.m_UVRemap.m_Ptr;
m_Colors = buffers.m_Colors.m_Ptr;
m_EmissiveColors = buffers.m_EmissiveColors.m_Ptr;
m_EmissiveColors3 = buffers.m_EmissiveColors3.m_Ptr;
m_EmissiveColors4 = buffers.m_EmissiveColors4.m_Ptr;
m_AlphaCursor = buffers.m_AlphaCursor.m_Ptr;
m_TransformUVsRotate = buffers.m_TransformUVsRotate.m_Ptr;
m_TransformUVsOffset = buffers.m_TransformUVsOffset.m_Ptr;
Expand Down Expand Up @@ -461,6 +466,7 @@ class CUnityBillboardingBatchPolicy
public:
u32 m_IdxView = 0;
u32 m_ShaderVariationFlags;
bool m_IsEmissive3 = false;

SParticleSourceBuffers m_ParticleBuffers; // Src
TArray<void*> m_MappedVertexBuffer; // Dst vtx
Expand Down
6 changes: 5 additions & 1 deletion Native/RenderingIntegration/UnityRenderDataFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "UnityRendererCache.h"
#include "UnityBillboardingBatchPolicy.h"

#include <pk_render_helpers/include/render_features/rh_features_basic.h>

#include <pk_render_helpers/include/batches/rh_ribbon_batch.h>
#include <pk_render_helpers/include/batches/rh_billboard_batch.h>
#include <pk_render_helpers/include/batches/rh_mesh_batch.h>
Expand Down Expand Up @@ -153,7 +155,9 @@ PRendererCacheBase CUnityRenderDataFactory::UpdateThread_CreateRendererCache(con
}
}
}
rendererCache->CreateUnityMesh(rendererCount, m_UseGPUBillboarding);
const SRendererDeclaration::SAdditionalFieldDefinition *emissive = renderer->m_Declaration.FindAdditionalFieldDefinition(BasicRendererProperties::SID_Emissive_EmissiveColor());
bool isEmissive3 = (emissive != null && emissive->m_Type == BaseType_Float3) ? true : false;
rendererCache->CreateUnityMesh(rendererCount, m_UseGPUBillboarding, isEmissive3);
{
PK_SCOPEDLOCK_WRITE(m_CacheLock);
m_RendererCaches.PushBack(rendererCache);
Expand Down
Loading

0 comments on commit d76a318

Please sign in to comment.