From 70f733ffb8437b51cfce6ad386a46d5bddfb6e7f Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Thu, 2 May 2024 00:22:13 +0300 Subject: [PATCH 1/2] GPU: Handle invalid floating point uniform writes --- include/PICA/shader.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/PICA/shader.hpp b/include/PICA/shader.hpp index 5b05e0b7..a9216b17 100644 --- a/include/PICA/shader.hpp +++ b/include/PICA/shader.hpp @@ -256,8 +256,10 @@ class PICAShader { void uploadFloatUniform(u32 word) { floatUniformBuffer[floatUniformWordCount++] = word; - if (floatUniformIndex >= 96) { - Helpers::panic("[PICA] Tried to write float uniform %d", floatUniformIndex); + // Check if the program tries to upload to a non-existent uniform, and empty the queue without writing in that case + if (floatUniformIndex >= 96) [[unlikely]] { + floatUniformWordCount = 0; + return; } if ((f32UniformTransfer && floatUniformWordCount >= 4) || (!f32UniformTransfer && floatUniformWordCount >= 3)) { From 81932421cfe08cf0994bfa3a5dccb909e562a4cd Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Thu, 2 May 2024 00:28:13 +0300 Subject: [PATCH 2/2] Optimize float uniform setting --- include/PICA/shader.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/PICA/shader.hpp b/include/PICA/shader.hpp index a9216b17..10f6ec88 100644 --- a/include/PICA/shader.hpp +++ b/include/PICA/shader.hpp @@ -256,16 +256,16 @@ class PICAShader { void uploadFloatUniform(u32 word) { floatUniformBuffer[floatUniformWordCount++] = word; - // Check if the program tries to upload to a non-existent uniform, and empty the queue without writing in that case - if (floatUniformIndex >= 96) [[unlikely]] { - floatUniformWordCount = 0; - return; - } if ((f32UniformTransfer && floatUniformWordCount >= 4) || (!f32UniformTransfer && floatUniformWordCount >= 3)) { - vec4f& uniform = floatUniforms[floatUniformIndex++]; floatUniformWordCount = 0; + // Check if the program tries to upload to a non-existent uniform, and empty the queue without writing in that case + if (floatUniformIndex >= 96) [[unlikely]] { + return; + } + vec4f& uniform = floatUniforms[floatUniformIndex++]; + if (f32UniformTransfer) { uniform[0] = f24::fromFloat32(*(float*)&floatUniformBuffer[3]); uniform[1] = f24::fromFloat32(*(float*)&floatUniformBuffer[2]);