summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp93
1 files changed, 15 insertions, 78 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index b48d30466..6485d75a8 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -191,48 +191,21 @@ public:
191 UnsignedInteger, 191 UnsignedInteger,
192 }; 192 };
193 193
194 GLSLRegister(size_t index, ShaderWriter& shader, const std::string& suffix) 194 GLSLRegister(size_t index, const std::string& suffix) : index{index}, suffix{suffix} {}
195 : index{index}, shader{shader}, suffix{suffix} {}
196 195
197 /// Gets the GLSL type string for a register 196 /// Gets the GLSL type string for a register
198 static std::string GetTypeString(Type type) { 197 static std::string GetTypeString() {
199 switch (type) { 198 return "float";
200 case Type::Float:
201 return "float";
202 case Type::Integer:
203 return "int";
204 case Type::UnsignedInteger:
205 return "uint";
206 }
207
208 UNREACHABLE();
209 return {};
210 } 199 }
211 200
212 /// Gets the GLSL register prefix string, used for declarations and referencing 201 /// Gets the GLSL register prefix string, used for declarations and referencing
213 static std::string GetPrefixString(Type type) { 202 static std::string GetPrefixString() {
214 return "reg_" + GetTypeString(type) + '_'; 203 return "reg_";
215 } 204 }
216 205
217 /// Returns a GLSL string representing the current state of the register 206 /// Returns a GLSL string representing the current state of the register
218 std::string GetActiveString() { 207 std::string GetString() const {
219 declr_type.insert(active_type); 208 return GetPrefixString() + std::to_string(index) + '_' + suffix;
220 return GetPrefixString(active_type) + std::to_string(index) + '_' + suffix;
221 }
222
223 /// Returns true if the active type is a float
224 bool IsFloat() const {
225 return active_type == Type::Float;
226 }
227
228 /// Returns true if the active type is an integer
229 bool IsInteger() const {
230 return active_type == Type::Integer;
231 }
232
233 /// Returns the current active type of the register
234 Type GetActiveType() const {
235 return active_type;
236 } 209 }
237 210
238 /// Returns the index of the register 211 /// Returns the index of the register
@@ -240,18 +213,8 @@ public:
240 return index; 213 return index;
241 } 214 }
242 215
243 /// Returns a set of the declared types of the register
244 const std::set<Type>& DeclaredTypes() const {
245 return declr_type;
246 }
247
248private: 216private:
249 const size_t index; 217 const size_t index;
250 const std::string float_str;
251 const std::string integer_str;
252 ShaderWriter& shader;
253 Type active_type{Type::Float};
254 std::set<Type> declr_type;
255 const std::string& suffix; 218 const std::string& suffix;
256}; 219};
257 220
@@ -297,7 +260,6 @@ public:
297 * @returns GLSL string corresponding to the register as a float. 260 * @returns GLSL string corresponding to the register as a float.
298 */ 261 */
299 std::string GetRegisterAsFloat(const Register& reg, unsigned elem = 0) { 262 std::string GetRegisterAsFloat(const Register& reg, unsigned elem = 0) {
300 ASSERT(regs[reg].IsFloat());
301 return GetRegister(reg, elem); 263 return GetRegister(reg, elem);
302 } 264 }
303 265
@@ -311,12 +273,8 @@ public:
311 */ 273 */
312 std::string GetRegisterAsInteger(const Register& reg, unsigned elem = 0, bool is_signed = true, 274 std::string GetRegisterAsInteger(const Register& reg, unsigned elem = 0, bool is_signed = true,
313 Register::Size size = Register::Size::Word) { 275 Register::Size size = Register::Size::Word) {
314 const std::string func = GetGLSLConversionFunc( 276 const std::string func{is_signed ? "floatBitsToInt" : "floatBitsToUint"};
315 GLSLRegister::Type::Float, 277 const std::string value{func + '(' + GetRegister(reg, elem) + ')'};
316 is_signed ? GLSLRegister::Type::Integer : GLSLRegister::Type::UnsignedInteger);
317
318 std::string value = func + '(' + GetRegister(reg, elem) + ')';
319
320 return ConvertIntegerSize(value, size); 278 return ConvertIntegerSize(value, size);
321 } 279 }
322 280
@@ -355,9 +313,7 @@ public:
355 u64 dest_elem = 0, Register::Size size = Register::Size::Word) { 313 u64 dest_elem = 0, Register::Size size = Register::Size::Word) {
356 ASSERT_MSG(!is_saturated, "Unimplemented"); 314 ASSERT_MSG(!is_saturated, "Unimplemented");
357 315
358 const std::string func = GetGLSLConversionFunc( 316 const std::string func{is_signed ? "intBitsToFloat" : "uintBitsToFloat"};
359 is_signed ? GLSLRegister::Type::Integer : GLSLRegister::Type::UnsignedInteger,
360 GLSLRegister::Type::Float);
361 317
362 SetRegister(reg, elem, func + '(' + ConvertIntegerSize(value, size) + ')', 318 SetRegister(reg, elem, func + '(' + ConvertIntegerSize(value, size) + ')',
363 dest_num_components, value_num_components, dest_elem); 319 dest_num_components, value_num_components, dest_elem);
@@ -373,14 +329,7 @@ public:
373 void SetRegisterToInputAttibute(const Register& reg, u64 elem, Attribute::Index attribute) { 329 void SetRegisterToInputAttibute(const Register& reg, u64 elem, Attribute::Index attribute) {
374 std::string dest = GetRegisterAsFloat(reg); 330 std::string dest = GetRegisterAsFloat(reg);
375 std::string src = GetInputAttribute(attribute) + GetSwizzle(elem); 331 std::string src = GetInputAttribute(attribute) + GetSwizzle(elem);
376 332 shader.AddLine(dest + " = " + src + ';');
377 if (regs[reg].IsFloat()) {
378 shader.AddLine(dest + " = " + src + ';');
379 } else if (regs[reg].IsInteger()) {
380 shader.AddLine(dest + " = floatBitsToInt(" + src + ");");
381 } else {
382 UNREACHABLE();
383 }
384 } 333 }
385 334
386 /** 335 /**
@@ -393,7 +342,6 @@ public:
393 void SetOutputAttributeToRegister(Attribute::Index attribute, u64 elem, const Register& reg) { 342 void SetOutputAttributeToRegister(Attribute::Index attribute, u64 elem, const Register& reg) {
394 std::string dest = GetOutputAttribute(attribute) + GetSwizzle(elem); 343 std::string dest = GetOutputAttribute(attribute) + GetSwizzle(elem);
395 std::string src = GetRegisterAsFloat(reg); 344 std::string src = GetRegisterAsFloat(reg);
396 ASSERT_MSG(regs[reg].IsFloat(), "Output attributes must be set to a float");
397 shader.AddLine(dest + " = " + src + ';'); 345 shader.AddLine(dest + " = " + src + ';');
398 } 346 }
399 347
@@ -434,11 +382,8 @@ public:
434 /// Add declarations for registers 382 /// Add declarations for registers
435 void GenerateDeclarations(const std::string& suffix) { 383 void GenerateDeclarations(const std::string& suffix) {
436 for (const auto& reg : regs) { 384 for (const auto& reg : regs) {
437 for (const auto& type : reg.DeclaredTypes()) { 385 declarations.AddLine(GLSLRegister::GetTypeString() + ' ' + reg.GetPrefixString() +
438 declarations.AddLine(GLSLRegister::GetTypeString(type) + ' ' + 386 std::to_string(reg.GetIndex()) + '_' + suffix + " = 0;");
439 reg.GetPrefixString(type) + std::to_string(reg.GetIndex()) +
440 '_' + suffix + " = 0;");
441 }
442 } 387 }
443 declarations.AddNewLine(); 388 declarations.AddNewLine();
444 389
@@ -516,21 +461,13 @@ public:
516 } 461 }
517 462
518private: 463private:
519 /// Build GLSL conversion function, e.g. floatBitsToInt, intBitsToFloat, etc.
520 std::string GetGLSLConversionFunc(GLSLRegister::Type src, GLSLRegister::Type dest) const {
521 const std::string src_type = GLSLRegister::GetTypeString(src);
522 std::string dest_type = GLSLRegister::GetTypeString(dest);
523 dest_type[0] = toupper(dest_type[0]);
524 return src_type + "BitsTo" + dest_type;
525 }
526
527 /// Generates code representing a temporary (GPR) register. 464 /// Generates code representing a temporary (GPR) register.
528 std::string GetRegister(const Register& reg, unsigned elem) { 465 std::string GetRegister(const Register& reg, unsigned elem) {
529 if (reg == Register::ZeroIndex) { 466 if (reg == Register::ZeroIndex) {
530 return "0"; 467 return "0";
531 } 468 }
532 469
533 return regs[reg.GetSwizzledIndex(elem)].GetActiveString(); 470 return regs[reg.GetSwizzledIndex(elem)].GetString();
534 } 471 }
535 472
536 /** 473 /**
@@ -560,7 +497,7 @@ private:
560 /// Build the GLSL register list. 497 /// Build the GLSL register list.
561 void BuildRegisterList() { 498 void BuildRegisterList() {
562 for (size_t index = 0; index < Register::NumRegisters; ++index) { 499 for (size_t index = 0; index < Register::NumRegisters; ++index) {
563 regs.emplace_back(index, shader, suffix); 500 regs.emplace_back(index, suffix);
564 } 501 }
565 } 502 }
566 503