From 7b065d778186b582db57cc1dee44b579f8cb5578 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Thu, 1 Nov 2018 13:28:15 +0300 Subject: [PATCH] rsx: Fixup; input attributes blob decoding - Use an unstructured blob and index into the vec4 structures to extract the real data --- rpcs3/Emu/RSX/Common/GLSLCommon.h | 66 +++++++++++++++++----------- rpcs3/Emu/RSX/GL/GLVertexProgram.cpp | 4 +- rpcs3/Emu/RSX/RSXThread.cpp | 4 +- rpcs3/Emu/RSX/VK/VKVertexProgram.cpp | 4 +- 4 files changed, 47 insertions(+), 31 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/GLSLCommon.h b/rpcs3/Emu/RSX/Common/GLSLCommon.h index c334fc3fb..003602fce 100644 --- a/rpcs3/Emu/RSX/Common/GLSLCommon.h +++ b/rpcs3/Emu/RSX/Common/GLSLCommon.h @@ -161,25 +161,25 @@ namespace glsl OS << "struct attribute_desc\n" "{\n" - " int type;\n" - " int attribute_size;\n" - " int starting_offset;\n" - " int stride;\n" - " int swap_bytes;\n" - " int is_volatile;\n" - " int frequency;\n" - " int modulo;\n" + " uint type;\n" + " uint attribute_size;\n" + " uint starting_offset;\n" + " uint stride;\n" + " uint frequency;\n" + " bool swap_bytes;\n" + " bool is_volatile;\n" + " bool modulo;\n" "};\n\n" - "uint get_bits(uvec4 v, int swap)\n" + "uint get_bits(uvec4 v, bool swap)\n" "{\n" - " if (swap != 0) return (v.w | v.z << 8 | v.y << 16 | v.x << 24);\n" + " if (swap) return (v.w | v.z << 8 | v.y << 16 | v.x << 24);\n" " return (v.x | v.y << 8 | v.z << 16 | v.w << 24);\n" "}\n\n" - "uint get_bits(uvec2 v, int swap)\n" + "uint get_bits(uvec2 v, bool swap)\n" "{\n" - " if (swap != 0) return (v.y | v.x << 8);\n" + " if (swap) return (v.y | v.x << 8);\n" " return (v.x | v.y << 8);\n" "}\n\n" @@ -207,11 +207,24 @@ namespace glsl " case 3: vector.w = scalar; return;\n" " }\n" "}\n"; + + OS << + "uint ref(in uvec4 vector, in int index)\n" + "{\n" + " switch(index)\n" + " {\n" + " case 0: return vector.x;\n" + " case 1: return vector.y;\n" + " case 2: return vector.z;\n" + " case 3: return vector.w;\n" + " }\n" + "}\n"; } else { OS << - "#define mov(v, i, s) v[i] = s\n"; + "#define mov(v, i, s) v[i] = s\n" + "#define ref(v, i) v[i]\n"; } OS << @@ -223,7 +236,7 @@ namespace glsl " uint bits;\n" " bool reverse_order = false;\n" "\n" - " int first_byte = (vertex_id * desc.stride) + desc.starting_offset;\n" + " int first_byte = int((vertex_id * desc.stride) + desc.starting_offset);\n" " for (int n = 0; n < 4; n++)\n" " {\n" " if (n == desc.attribute_size) break;\n" @@ -255,7 +268,7 @@ namespace glsl " //unsigned byte\n" " mov(result, n, texelFetch(input_stream, first_byte++).x);\n" " mov(scale, n, 255.);\n" - " reverse_order = (desc.swap_bytes != 0);\n" + " reverse_order = desc.swap_bytes;\n" " break;\n" " case 4:\n" " //signed word\n" @@ -279,7 +292,7 @@ namespace glsl " case 6:\n" " //ub256\n" " mov(result, n, float(texelFetch(input_stream, first_byte++).x));\n" - " reverse_order = (desc.swap_bytes != 0);\n" + " reverse_order = desc.swap_bytes;\n" " break;\n" " }\n" " }\n\n" @@ -294,21 +307,24 @@ namespace glsl " // [8-24] attribute divisor\n" " // [24-27] attribute type\n" " // [27-30] attribute size\n" + " // [30-31] reserved\n" " // [32-60] starting offset\n" " // [60-61] swap bytes flag\n" " // [61-62] volatile flag\n" " // [62-63] modulo enable flag\n" + " int block = (location >> 1);\n" + " int sub_block = (location & 1) << 1;\n" + " uint attrib0 = ref(input_attributes_blob[block], sub_block + 0);\n" + " uint attrib1 = ref(input_attributes_blob[block], sub_block + 1);\n" " attribute_desc result;\n" - " int attrib0 = input_attributes[location].x;\n" - " int attrib1 = input_attributes[location].y;\n" " result.stride = attrib0 & 0xFF;\n" " result.frequency = (attrib0 >> 8) & 0xFFFF;\n" " result.type = (attrib0 >> 24) & 0x7;\n" " result.attribute_size = (attrib0 >> 27) & 0x7;\n" " result.starting_offset = (attrib1 & 0x1FFFFFFF);\n" - " result.swap_bytes = (attrib1 >> 29) & 0x1;\n" - " result.is_volatile = (attrib1 >> 30) & 0x1;\n" - " result.modulo = (attrib1 >> 31) & 0x3;\n" + " result.swap_bytes = ((attrib1 >> 29) & 0x1) != 0;\n" + " result.is_volatile = ((attrib1 >> 30) & 0x1) != 0;\n" + " result.modulo = ((attrib1 >> 31) & 0x1) != 0;\n" " return result;\n" "}\n\n" @@ -339,17 +355,17 @@ namespace glsl " else if (desc.frequency > 1)\n" " {\n" " //if a vertex modifier is active; vertex_base must be 0 and is ignored\n" - " if (desc.modulo != 0)\n" + " if (desc.modulo)\n" " {\n" - " vertex_id = " << vertex_id_name << " % desc.frequency;\n" + " vertex_id = " << vertex_id_name << " % int(desc.frequency);\n" " }\n" " else\n" " {\n" - " vertex_id = " << vertex_id_name << " / desc.frequency; \n" + " vertex_id = " << vertex_id_name << " / int(desc.frequency); \n" " }\n" " }\n" "\n" - " if (desc.is_volatile != 0)\n" + " if (desc.is_volatile)\n" " return fetch_attribute(desc, vertex_id, volatile_input_stream);\n" " else\n" " return fetch_attribute(desc, vertex_id, persistent_input_stream);\n" diff --git a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp index 793d80518..59acd1d21 100644 --- a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp @@ -44,8 +44,8 @@ void GLVertexDecompilerThread::insertHeader(std::stringstream &OS) OS << "layout(std140, binding = 1) uniform VertexLayoutBuffer\n"; OS << "{\n"; - OS << " uint vertex_base_index;\n"; - OS << " ivec2 input_attributes[16];\n"; + OS << " uint vertex_base_index;\n"; + OS << " uvec4 input_attributes_blob[16 / 2];\n"; OS << "};\n\n"; } diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index a09d8a395..b2970ee56 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -2155,8 +2155,8 @@ namespace rsx attrib0 |= (size << 27); attrib1 |= offset_in_block[index]; - buffer[index * 4 + 0] = attrib0; - buffer[index * 4 + 1] = attrib1; + buffer[index * 2 + 0] = attrib0; + buffer[index * 2 + 1] = attrib1; } } diff --git a/rpcs3/Emu/RSX/VK/VKVertexProgram.cpp b/rpcs3/Emu/RSX/VK/VKVertexProgram.cpp index 718116282..327975dab 100644 --- a/rpcs3/Emu/RSX/VK/VKVertexProgram.cpp +++ b/rpcs3/Emu/RSX/VK/VKVertexProgram.cpp @@ -43,8 +43,8 @@ void VKVertexDecompilerThread::insertHeader(std::stringstream &OS) OS << "layout(std140, set = 0, binding = 1) uniform VertexLayoutBuffer\n"; OS << "{\n"; - OS << " uint vertex_base_index;\n"; - OS << " ivec2 input_attributes[16];\n"; + OS << " uint vertex_base_index;\n"; + OS << " uvec4 input_attributes_blob[16 / 2];\n"; OS << "};\n\n"; vk::glsl::program_input in;