diff options
| author | 2021-04-05 04:03:12 +0200 | |
|---|---|---|
| committer | 2021-07-22 21:51:26 -0400 | |
| commit | dcaf0e91508562a70a49db7011ad09f13f811d71 (patch) | |
| tree | 9d3f48adc0a94c6a8b411a8e98c0e7a2d06b1d81 /src/shader_recompiler/backend/spirv/emit_context.cpp | |
| parent | shader: Implement indexed Position and ClipDistances (diff) | |
| download | yuzu-dcaf0e91508562a70a49db7011ad09f13f811d71.tar.gz yuzu-dcaf0e91508562a70a49db7011ad09f13f811d71.tar.xz yuzu-dcaf0e91508562a70a49db7011ad09f13f811d71.zip | |
shader: Address feedback
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_context.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index e22bb5371..2d39ea373 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -314,7 +314,7 @@ void EmitContext::DefineSharedMemory(const IR::Program& program) { | |||
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | void EmitContext::DefineAttributeMemAccess(const Info& info) { | 316 | void EmitContext::DefineAttributeMemAccess(const Info& info) { |
| 317 | const auto make_load{[&]() { | 317 | const auto make_load{[&] { |
| 318 | const Id end_block{OpLabel()}; | 318 | const Id end_block{OpLabel()}; |
| 319 | const Id default_label{OpLabel()}; | 319 | const Id default_label{OpLabel()}; |
| 320 | 320 | ||
| @@ -322,9 +322,9 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 322 | const Id func{OpFunction(F32[1], spv::FunctionControlMask::MaskNone, func_type_load)}; | 322 | const Id func{OpFunction(F32[1], spv::FunctionControlMask::MaskNone, func_type_load)}; |
| 323 | const Id offset{OpFunctionParameter(U32[1])}; | 323 | const Id offset{OpFunctionParameter(U32[1])}; |
| 324 | AddLabel(); | 324 | AddLabel(); |
| 325 | const Id base_index{OpShiftRightLogical(U32[1], offset, Constant(U32[1], 2U))}; | 325 | const Id base_index{OpShiftRightArithmetic(U32[1], offset, Constant(U32[1], 2U))}; |
| 326 | const Id masked_index{OpBitwiseAnd(U32[1], base_index, Constant(U32[1], 3U))}; | 326 | const Id masked_index{OpBitwiseAnd(U32[1], base_index, Constant(U32[1], 3U))}; |
| 327 | const Id compare_index{OpShiftRightLogical(U32[1], base_index, Constant(U32[1], 2U))}; | 327 | const Id compare_index{OpShiftRightArithmetic(U32[1], base_index, Constant(U32[1], 2U))}; |
| 328 | std::vector<Sirit::Literal> literals; | 328 | std::vector<Sirit::Literal> literals; |
| 329 | std::vector<Id> labels; | 329 | std::vector<Id> labels; |
| 330 | if (info.loads_position) { | 330 | if (info.loads_position) { |
| @@ -343,22 +343,22 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 343 | OpSwitch(compare_index, default_label, literals, labels); | 343 | OpSwitch(compare_index, default_label, literals, labels); |
| 344 | AddLabel(default_label); | 344 | AddLabel(default_label); |
| 345 | OpReturnValue(Constant(F32[1], 0.0f)); | 345 | OpReturnValue(Constant(F32[1], 0.0f)); |
| 346 | size_t label_index = 0; | 346 | size_t label_index{0}; |
| 347 | if (info.loads_position) { | 347 | if (info.loads_position) { |
| 348 | AddLabel(labels[label_index]); | 348 | AddLabel(labels[label_index]); |
| 349 | const Id result{OpLoad(F32[1], OpAccessChain(input_f32, input_position, masked_index))}; | 349 | const Id result{OpLoad(F32[1], OpAccessChain(input_f32, input_position, masked_index))}; |
| 350 | OpReturnValue(result); | 350 | OpReturnValue(result); |
| 351 | label_index++; | 351 | ++label_index; |
| 352 | } | 352 | } |
| 353 | for (u32 i = 0; i < info.input_generics.size(); i++) { | 353 | for (size_t i = 0; i < info.input_generics.size(); i++) { |
| 354 | if (!info.input_generics[i].used) { | 354 | if (!info.input_generics[i].used) { |
| 355 | continue; | 355 | continue; |
| 356 | } | 356 | } |
| 357 | AddLabel(labels[label_index]); | 357 | AddLabel(labels[label_index]); |
| 358 | const auto type{AttrTypes(*this, i)}; | 358 | const auto type{AttrTypes(*this, static_cast<u32>(i))}; |
| 359 | if (!type) { | 359 | if (!type) { |
| 360 | OpReturnValue(Constant(F32[1], 0.0f)); | 360 | OpReturnValue(Constant(F32[1], 0.0f)); |
| 361 | label_index++; | 361 | ++label_index; |
| 362 | continue; | 362 | continue; |
| 363 | } | 363 | } |
| 364 | const Id generic_id{input_generics.at(i)}; | 364 | const Id generic_id{input_generics.at(i)}; |
| @@ -366,14 +366,14 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 366 | const Id value{OpLoad(type->id, pointer)}; | 366 | const Id value{OpLoad(type->id, pointer)}; |
| 367 | const Id result{type->needs_cast ? OpBitcast(F32[1], value) : value}; | 367 | const Id result{type->needs_cast ? OpBitcast(F32[1], value) : value}; |
| 368 | OpReturnValue(result); | 368 | OpReturnValue(result); |
| 369 | label_index++; | 369 | ++label_index; |
| 370 | } | 370 | } |
| 371 | AddLabel(end_block); | 371 | AddLabel(end_block); |
| 372 | OpUnreachable(); | 372 | OpUnreachable(); |
| 373 | OpFunctionEnd(); | 373 | OpFunctionEnd(); |
| 374 | return func; | 374 | return func; |
| 375 | }}; | 375 | }}; |
| 376 | const auto make_store{[&]() { | 376 | const auto make_store{[&] { |
| 377 | const Id end_block{OpLabel()}; | 377 | const Id end_block{OpLabel()}; |
| 378 | const Id default_label{OpLabel()}; | 378 | const Id default_label{OpLabel()}; |
| 379 | 379 | ||
| @@ -382,9 +382,9 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 382 | const Id offset{OpFunctionParameter(U32[1])}; | 382 | const Id offset{OpFunctionParameter(U32[1])}; |
| 383 | const Id store_value{OpFunctionParameter(F32[1])}; | 383 | const Id store_value{OpFunctionParameter(F32[1])}; |
| 384 | AddLabel(); | 384 | AddLabel(); |
| 385 | const Id base_index{OpShiftRightLogical(U32[1], offset, Constant(U32[1], 2U))}; | 385 | const Id base_index{OpShiftRightArithmetic(U32[1], offset, Constant(U32[1], 2U))}; |
| 386 | const Id masked_index{OpBitwiseAnd(U32[1], base_index, Constant(U32[1], 3U))}; | 386 | const Id masked_index{OpBitwiseAnd(U32[1], base_index, Constant(U32[1], 3U))}; |
| 387 | const Id compare_index{OpShiftRightLogical(U32[1], base_index, Constant(U32[1], 2U))}; | 387 | const Id compare_index{OpShiftRightArithmetic(U32[1], base_index, Constant(U32[1], 2U))}; |
| 388 | std::vector<Sirit::Literal> literals; | 388 | std::vector<Sirit::Literal> literals; |
| 389 | std::vector<Id> labels; | 389 | std::vector<Id> labels; |
| 390 | if (info.stores_position) { | 390 | if (info.stores_position) { |
| @@ -392,11 +392,11 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 392 | labels.push_back(OpLabel()); | 392 | labels.push_back(OpLabel()); |
| 393 | } | 393 | } |
| 394 | const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2; | 394 | const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2; |
| 395 | for (u32 i = 0; i < info.stores_generics.size(); i++) { | 395 | for (size_t i = 0; i < info.stores_generics.size(); i++) { |
| 396 | if (!info.stores_generics[i]) { | 396 | if (!info.stores_generics[i]) { |
| 397 | continue; | 397 | continue; |
| 398 | } | 398 | } |
| 399 | literals.push_back(base_attribute_value + i); | 399 | literals.push_back(base_attribute_value + static_cast<u32>(i)); |
| 400 | labels.push_back(OpLabel()); | 400 | labels.push_back(OpLabel()); |
| 401 | } | 401 | } |
| 402 | if (info.stores_clip_distance) { | 402 | if (info.stores_clip_distance) { |
| @@ -409,15 +409,15 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 409 | OpSwitch(compare_index, default_label, literals, labels); | 409 | OpSwitch(compare_index, default_label, literals, labels); |
| 410 | AddLabel(default_label); | 410 | AddLabel(default_label); |
| 411 | OpReturn(); | 411 | OpReturn(); |
| 412 | size_t label_index = 0; | 412 | size_t label_index{0}; |
| 413 | if (info.stores_position) { | 413 | if (info.stores_position) { |
| 414 | AddLabel(labels[label_index]); | 414 | AddLabel(labels[label_index]); |
| 415 | const Id pointer{OpAccessChain(output_f32, output_position, masked_index)}; | 415 | const Id pointer{OpAccessChain(output_f32, output_position, masked_index)}; |
| 416 | OpStore(pointer, store_value); | 416 | OpStore(pointer, store_value); |
| 417 | OpReturn(); | 417 | OpReturn(); |
| 418 | label_index++; | 418 | ++label_index; |
| 419 | } | 419 | } |
| 420 | for (u32 i = 0; i < info.stores_generics.size(); i++) { | 420 | for (size_t i = 0; i < info.stores_generics.size(); i++) { |
| 421 | if (!info.stores_generics[i]) { | 421 | if (!info.stores_generics[i]) { |
| 422 | continue; | 422 | continue; |
| 423 | } | 423 | } |
| @@ -426,20 +426,20 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 426 | const Id pointer{OpAccessChain(output_f32, generic_id, masked_index)}; | 426 | const Id pointer{OpAccessChain(output_f32, generic_id, masked_index)}; |
| 427 | OpStore(pointer, store_value); | 427 | OpStore(pointer, store_value); |
| 428 | OpReturn(); | 428 | OpReturn(); |
| 429 | label_index++; | 429 | ++label_index; |
| 430 | } | 430 | } |
| 431 | if (info.stores_clip_distance) { | 431 | if (info.stores_clip_distance) { |
| 432 | AddLabel(labels[label_index]); | 432 | AddLabel(labels[label_index]); |
| 433 | const Id pointer{OpAccessChain(output_f32, clip_distances, masked_index)}; | 433 | const Id pointer{OpAccessChain(output_f32, clip_distances, masked_index)}; |
| 434 | OpStore(pointer, store_value); | 434 | OpStore(pointer, store_value); |
| 435 | OpReturn(); | 435 | OpReturn(); |
| 436 | label_index++; | 436 | ++label_index; |
| 437 | AddLabel(labels[label_index]); | 437 | AddLabel(labels[label_index]); |
| 438 | const Id fixed_index{OpIAdd(U32[1], masked_index, Constant(U32[1], 4))}; | 438 | const Id fixed_index{OpIAdd(U32[1], masked_index, Constant(U32[1], 4))}; |
| 439 | const Id pointer2{OpAccessChain(output_f32, clip_distances, fixed_index)}; | 439 | const Id pointer2{OpAccessChain(output_f32, clip_distances, fixed_index)}; |
| 440 | OpStore(pointer2, store_value); | 440 | OpStore(pointer2, store_value); |
| 441 | OpReturn(); | 441 | OpReturn(); |
| 442 | label_index++; | 442 | ++label_index; |
| 443 | } | 443 | } |
| 444 | AddLabel(end_block); | 444 | AddLabel(end_block); |
| 445 | OpUnreachable(); | 445 | OpUnreachable(); |