Explorar el Código

Fix buffer overrun and update bone transform code to us RPI function instead of WriteToBuffer util (#386)

Signed-off-by: Tommy Walton <[email protected]>
Tommy Walton hace 3 años
padre
commit
0c9cc3c045

+ 1 - 7
Gem/Code/Source/RHI/TrianglesConstantBufferExampleComponent.cpp

@@ -87,11 +87,8 @@ namespace AtomSampleViewer
             colorMultiplier.StoreToFloat4(&trianglesData[triangleIdx].m_colorMultiplier[0]);
         }
 
-        // Calculate the alignment
-        const uint32_t alignment = RHI::AlignUp(static_cast<uint32_t>(sizeof(InstanceInfo)), m_constantBufferAlighment);
-
         // All triangles data will be uploaded in one go to the constant buffer once per frame.
-        UploadDataToConstantBuffer(trianglesData, alignment, s_numberOfTrianglesTotal);
+        UploadDataToConstantBuffer(trianglesData, static_cast<uint32_t>(sizeof(InstanceInfo)), s_numberOfTrianglesTotal);
         
         BasicRHIComponent::OnFramePrepare(frameGraphBuilder);
     }
@@ -116,9 +113,6 @@ namespace AtomSampleViewer
 
         RHI::Ptr<RHI::Device> device = Utils::GetRHIDevice();
 
-        // Cache the alignment
-        m_constantBufferAlighment = device->GetLimits().m_minConstantBufferViewOffset;
-
         AZ::RHI::PipelineStateDescriptorForDraw pipelineStateDescriptor;
 
         // Creates Input Assembly buffer and Streams/Index Views

+ 0 - 3
Gem/Code/Source/RHI/TrianglesConstantBufferExampleComponent.h

@@ -103,9 +103,6 @@ namespace AtomSampleViewer
 
         AZ::RHI::Ptr<AZ::RHI::BufferView> m_constantBufferView;
 
-        // Cached Constant Buffer alignment queued from the device
-        uint32_t m_constantBufferAlighment = 0u;
-
         // --------------------------------------------------------
         // Pipeline state and SRG to be constructed from the shader
         // --------------------------------------------------------

+ 3 - 1
Gem/Code/Source/SkinnedMeshContainer.cpp

@@ -95,7 +95,9 @@ namespace AtomSampleViewer
 
                 if (m_skinnedMeshInstances[i].m_boneTransformBuffer)
                 {
-                    AZ::Render::WriteToBuffer(m_skinnedMeshInstances[i].m_boneTransformBuffer->GetRHIBuffer(), m_skinnedMeshes[i].m_proceduralSkinnedMesh.m_boneMatrices);
+                    m_skinnedMeshInstances[i].m_boneTransformBuffer->UpdateData(
+                        m_skinnedMeshes[i].m_proceduralSkinnedMesh.m_boneMatrices.data(),
+                        m_skinnedMeshes[i].m_proceduralSkinnedMesh.m_boneMatrices.size() * sizeof(AZ::Matrix3x4));
                 }
             }
         }