diff --git a/Apps/Playground/Scripts/config.json b/Apps/Playground/Scripts/config.json index 59dcb2e5f..40ce6fbad 100644 --- a/Apps/Playground/Scripts/config.json +++ b/Apps/Playground/Scripts/config.json @@ -692,9 +692,7 @@ { "title": "Attractors", "playgroundId": "#DEZ79M#57", - "referenceImage": "attractors.png", - "excludeFromAutomaticTesting": true, - "reason": "Test crashes on Linux (ASSERT bx::isAligned _stride 16 in bgfx)" + "referenceImage": "attractors.png" }, { "title": "PBR in mirror", @@ -904,7 +902,7 @@ "title": "GPUPicker", "playgroundId": "#1RWFMT#8", "excludeFromAutomaticTesting": true, - "reason": "Pixel comparison fails (more than 20% pixels differ)", + "reason": "Pixel diff after #1691 instance-data stride fix; not stride-related, needs follow-up.", "referenceImage": "gpuPicker.png" }, { @@ -1210,7 +1208,7 @@ "playgroundId": "#1VGT5D#2", "renderCount": 50, "excludeFromAutomaticTesting": true, - "reason": "Pixel comparison fails (more than 20% pixels differ)", + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up.", "referenceImage": "particle-helper.png" }, { @@ -1662,7 +1660,7 @@ "renderCount": 100, "referenceImage": "particles.png", "excludeFromAutomaticTesting": true, - "reason": "Test crashes on Linux Clang/GCC (ASSERT, exit 133)" + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "PBRMetallicRoughnessMaterial", @@ -2443,7 +2441,7 @@ "playgroundId": "#544N0Q#67", "renderCount": 120, "excludeFromAutomaticTesting": true, - "reason": "Pixel comparison fails (more than 20% pixels differ)", + "reason": "After #1569 stride fix, hits bgfx 'Invalid texture attachment' frame buffer validation (exit 1); needs separate investigation.", "referenceImage": "fluidParticleSystem.png" }, { @@ -2865,7 +2863,7 @@ "playgroundId": "#2441BU#1", "renderCount": 20, "excludeFromAutomaticTesting": true, - "reason": "Pixel comparison fails (more than 20% pixels differ)", + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up.", "referenceImage": "halo-particle-system.png" }, { @@ -2881,7 +2879,7 @@ "playgroundId": "#DMLLV2", "renderCount": 5, "excludeFromAutomaticTesting": true, - "reason": "Test crashes or hangs on Babylon Native", + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up.", "referenceImage": "particle-system-with-custom-nme-shader.png" }, { @@ -4294,23 +4292,19 @@ "renderCount": 120, "referenceImage": "NME-Particles-with-PositionW.png", "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Basic Properties - Size", "playgroundId": "#0K3AQ2#3780", "renderCount": 120, - "referenceImage": "particles-basic-size.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-size.png" }, { "title": "Particles - Basic Properties - Scale", "playgroundId": "#0K3AQ2#3782", "renderCount": 120, - "referenceImage": "particles-basic-scale.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-scale.png" }, { "title": "Particles - Basic Properties - Color", @@ -4318,39 +4312,31 @@ "renderCount": 120, "referenceImage": "particles-basic-color.png", "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Basic Properties - Speed", "playgroundId": "#0K3AQ2#3791", "renderCount": 120, - "referenceImage": "particles-basic-speed.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-speed.png" }, { "title": "Particles - Basic Properties - Angular Speed", "playgroundId": "#0K3AQ2#3796", "renderCount": 120, - "referenceImage": "particles-basic-angular-speed.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-angular-speed.png" }, { "title": "Particles - Basic Properties - Angular Speed - Rotation", "playgroundId": "#0K3AQ2#3806", "renderCount": 120, - "referenceImage": "particles-basic-angular-speed-rotation.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-angular-speed-rotation.png" }, { "title": "Particles - Basic Properties - Translation Pivot", "playgroundId": "#0K3AQ2#3808", "renderCount": 120, - "referenceImage": "particles-basic-translation-pivot.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-translation-pivot.png" }, { "title": "Particles - Basic Properties - Direction", @@ -4358,23 +4344,19 @@ "renderCount": 120, "referenceImage": "particles-basic-direction.png", "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Basic Properties - Direction - Gravity", "playgroundId": "#0K3AQ2#3816", "renderCount": 120, - "referenceImage": "particles-basic-direction-gravity.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-direction-gravity.png" }, { "title": "Particles - Basic Properties - Emit Rate - Slow", "playgroundId": "#0K3AQ2#3821", "renderCount": 120, - "referenceImage": "particles-basic-emit-rate-slow.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-emit-rate-slow.png" }, { "title": "Particles - Basic Properties - Emit Rate - Fast", @@ -4382,31 +4364,25 @@ "renderCount": 120, "referenceImage": "particles-basic-emit-rate-fast.png", "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Basic Properties - Emission Limits", "playgroundId": "#0K3AQ2#3825", "renderCount": 120, - "referenceImage": "particles-basic-emission-limits.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-emission-limits.png" }, { "title": "Particles - Basic Properties - Lifetime - Short", "playgroundId": "#0K3AQ2#3829", "renderCount": 120, - "referenceImage": "particles-basic-lifetime-short.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-lifetime-short.png" }, { "title": "Particles - Basic Properties - Lifetime - Long", "playgroundId": "#0K3AQ2#3834", "renderCount": 120, - "referenceImage": "particles-basic-lifetime-long.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-lifetime-long.png" }, { "title": "Particles - Change - Size", @@ -4414,15 +4390,13 @@ "renderCount": 120, "referenceImage": "particles-basic-change-size.png", "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Change - Size 2", "playgroundId": "#0K3AQ2#3844", "renderCount": 120, - "referenceImage": "particles-basic-change-size-2.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-size-2.png" }, { "title": "Particles - Change - Color", @@ -4430,7 +4404,7 @@ "renderCount": 120, "referenceImage": "particles-basic-change-color.png", "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Change - Color 2", @@ -4438,79 +4412,61 @@ "renderCount": 120, "referenceImage": "particles-basic-change-color-2.png", "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Change - Speed", "playgroundId": "#0K3AQ2#3853", "renderCount": 120, - "referenceImage": "particles-basic-change-speed.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-speed.png" }, { "title": "Particles - Change - Speed 2", "playgroundId": "#0K3AQ2#3855", "renderCount": 120, - "referenceImage": "particles-basic-change-speed-2.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-speed-2.png" }, { "title": "Particles - Change - Speed Limit", "playgroundId": "#0K3AQ2#3859", "renderCount": 120, - "referenceImage": "particles-basic-change-speed-limit.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-speed-limit.png" }, { "title": "Particles - Change - Angular Speed", "playgroundId": "#0K3AQ2#3862", "renderCount": 120, - "referenceImage": "particles-basic-change-angular-speed.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-angular-speed.png" }, { "title": "Particles - Change - Angular Speed 2", "playgroundId": "#0K3AQ2#3865", "renderCount": 120, - "referenceImage": "particles-basic-change-angular-speed-2.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-angular-speed-2.png" }, { "title": "Particles - Change - Drag", "playgroundId": "#0K3AQ2#3868", "renderCount": 120, - "referenceImage": "particles-basic-change-drag.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-drag.png" }, { "title": "Particles - Change - Drag 2", "playgroundId": "#0K3AQ2#3872", "renderCount": 120, - "referenceImage": "particles-basic-change-drag-2.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-drag-2.png" }, { "title": "Particles - Change - Emit Rate", "playgroundId": "#0K3AQ2#3875", "renderCount": 120, - "referenceImage": "particles-basic-change-emit-rate.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-emit-rate.png" }, { "title": "Particles - Change - Emit Rate 2", "playgroundId": "#0K3AQ2#3879", "renderCount": 120, - "referenceImage": "particles-basic-change-emit-rate-2.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-emit-rate-2.png" }, { "title": "Particles - Change - Lifetime", @@ -4518,23 +4474,19 @@ "renderCount": 120, "referenceImage": "particles-basic-change-lifetime.png", "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Change - Lifetime 2", "playgroundId": "#0K3AQ2#3890", "renderCount": 120, - "referenceImage": "particles-basic-change-lifetime-2.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-lifetime-2.png" }, { "title": "Particles - Change - Start Size", "playgroundId": "#0K3AQ2#3897", "renderCount": 120, - "referenceImage": "particles-basic-change-start-size.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-basic-change-start-size.png" }, { "title": "Particles - Emitters - Point", @@ -4542,7 +4494,7 @@ "renderCount": 120, "referenceImage": "particles-emitters-point.png", "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Emitters - Box", @@ -4550,7 +4502,7 @@ "renderCount": 120, "referenceImage": "particles-emitters-box.png", "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Emitters - Sphere", @@ -4558,23 +4510,19 @@ "renderCount": 120, "referenceImage": "particles-emitters-sphere.png", "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Emitters - Directed Sphere", "playgroundId": "#WLX2I2#10", "renderCount": 120, - "referenceImage": "particles-emitters-directed-sphere.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-emitters-directed-sphere.png" }, { "title": "Particles - Emitters - Hemisphere", "playgroundId": "#WLX2I2#11", "renderCount": 120, - "referenceImage": "particles-emitters-hemisphere.png", - "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "referenceImage": "particles-emitters-hemisphere.png" }, { "title": "Particles - Emitters - Cylinder", @@ -4582,7 +4530,7 @@ "renderCount": 120, "referenceImage": "particles-emitters-cylinder.png", "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Emitters - Directed Cylinder", @@ -4596,9 +4544,7 @@ "title": "Particles - Emitters - Cone", "playgroundId": "#WLX2I2#16", "renderCount": 120, - "referenceImage": "particles-emitters-cone.png", - "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "referenceImage": "particles-emitters-cone.png" }, { "title": "Particles - Emitters - Directed Cone", @@ -4606,63 +4552,49 @@ "renderCount": 120, "referenceImage": "particles-emitters-directed-cone.png", "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Emitters - Mesh", "playgroundId": "#WLX2I2#20", "renderCount": 120, - "referenceImage": "particles-emitters-mesh.png", - "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "referenceImage": "particles-emitters-mesh.png" }, { "title": "Particles - Emitters - Custom", "playgroundId": "#WLX2I2#22", "renderCount": 120, - "referenceImage": "particles-emitters-custom.png", - "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "referenceImage": "particles-emitters-custom.png" }, { "title": "Particles - Animations", "playgroundId": "#2MI0A1#7", "renderCount": 120, - "referenceImage": "particles-animations.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-animations.png" }, { "title": "Particles - Animations 2", "playgroundId": "#2MI0A1#8", "renderCount": 120, - "referenceImage": "particles-animations-2.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-animations-2.png" }, { "title": "Particles - Ramp Gradient", "playgroundId": "#I2D9MM#15", "renderCount": 120, - "referenceImage": "particles-ramp-gradient.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-ramp-gradient.png" }, { "title": "Particles - Ramp Gradient Remap", "playgroundId": "#E3VU3R", "renderCount": 120, - "excludeFromAutomaticTesting": true, - "reason": "Test crashes or hangs on Babylon Native", "referenceImage": "particles-ramp-gradient-remap.png" }, { "title": "Particles - Ramp Gradient Remap Alpha", "playgroundId": "#I2D9MM#16", "renderCount": 120, - "referenceImage": "particles-ramp-gradient-remap-alpha.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "particles-ramp-gradient-remap-alpha.png" }, { "title": "Particles - Billboard Y", @@ -4678,7 +4610,7 @@ "renderCount": 120, "referenceImage": "particles-billboard-false.png", "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Multiply Blend", @@ -4700,9 +4632,7 @@ "title": "Particles - Effects", "playgroundId": "#1ASENS#424", "renderCount": 120, - "referenceImage": "particles-effects.png", - "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "referenceImage": "particles-effects.png" }, { "title": "Particles - Helper - Sun", @@ -4710,7 +4640,7 @@ "renderCount": 120, "referenceImage": "particles-helper-sun.png", "excludeFromAutomaticTesting": true, - "reason": "Newly added test triggers bgfx ASSERT 'Stride must be multiple of 16' on Linux Clang/GCC JSC OpenGL builds (exit code 133)." + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up." }, { "title": "Particles - Helper - Smoke", @@ -4733,7 +4663,7 @@ "playgroundId": "#DEZ79M#73", "renderCount": 240, "excludeFromAutomaticTesting": true, - "reason": "Pixel comparison fails (more than 20% pixels differ)", + "reason": "Pixel diff after #1569 instance-data stride fix; not stride-related, needs follow-up.", "referenceImage": "particles-attractors.png" }, { @@ -4762,9 +4692,7 @@ { "title": "Selection outline layer with instances and LOD", "playgroundId": "#8I487I#0", - "referenceImage": "Selection-outline-layer-with-instances-and-LOD.png", - "excludeFromAutomaticTesting": true, - "reason": "Test fails locally on Win32 D3D11 sweep; disabled until BabylonNative fixes are made." + "referenceImage": "Selection-outline-layer-with-instances-and-LOD.png" }, { "title": "Vertex Pulling - Normals UVs Colors Tangents", diff --git a/Plugins/NativeEngine/Source/VertexBuffer.cpp b/Plugins/NativeEngine/Source/VertexBuffer.cpp index f4666a841..388151ae2 100644 --- a/Plugins/NativeEngine/Source/VertexBuffer.cpp +++ b/Plugins/NativeEngine/Source/VertexBuffer.cpp @@ -126,37 +126,50 @@ namespace Babylon void VertexBuffer::BuildInstanceDataBuffer(bgfx::InstanceDataBuffer& instanceDataBuffer, const std::map& instances, uint32_t instanceCount) { - uint16_t instanceStride{}; - for (auto& pair : instances) + // bgfx expects that each instance attribute occupies exactly one 16-byte slot. + static constexpr uint16_t kSlotSize = 16; + + if (instances.empty()) { - if (instanceCount == 0) - { - const auto* vertexBuffer{pair.second.Buffer}; - instanceCount = static_cast(vertexBuffer->m_bytes.size()) / pair.second.Stride; - } + return; + } + + if (instanceCount == 0) + { + const auto& first{instances.begin()->second}; + instanceCount = static_cast(first.Buffer->m_bytes.size()) / first.Stride; + } - instanceStride += static_cast(pair.second.ElementSize); + if (instanceCount == 0) + { + return; } + const uint16_t instanceStride = static_cast(instances.size() * kSlotSize); + // Create instance datas. Instance Data Buffer is transient. bgfx::allocInstanceDataBuffer(&instanceDataBuffer, instanceCount, instanceStride); - // Copy instance data. uint8_t* data{instanceDataBuffer.data}; - uint32_t offset{}; + + // Zero the buffer so any unused bytes within a 16-byte slot (when ElementSize < 16) read as + // zero in the shader instead of leaking transient ring-buffer garbage. + std::memset(data, 0, static_cast(instanceStride) * instanceCount); // Reverse because bgfx maps instance data in reverse attrib order: // D3D11: TEXCOORD7 = i_data0, TEXCOORD6 = i_data1, etc. // OpenGL also expects this layout since bgfx abstracts the mapping. + uint32_t slotOffset{}; for (auto iter = instances.rbegin(); iter != instances.rend(); ++iter) { const auto& element{iter->second}; + assert(element.ElementSize <= kSlotSize); const auto* source{element.Buffer->m_bytes.data()}; for (uint32_t instance = 0; instance < instanceCount; instance++) { - std::memcpy(data + instance * instanceStride + offset, source + instance * element.Stride + element.Offset, element.ElementSize); + std::memcpy(data + instance * instanceStride + slotOffset, source + instance * element.Stride + element.Offset, element.ElementSize); } - offset += iter->second.ElementSize; + slotOffset += kSlotSize; } } }