summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl
diff options
context:
space:
mode:
authorGravatar ameerj2021-06-05 02:41:29 -0400
committerGravatar ameerj2021-07-22 21:51:37 -0400
commit421847cf1e33d5b95c9aa272bf3cf69afda3d964 (patch)
treea7fd72bf902697a9a32c18f023b0fb282a7029bf /src/shader_recompiler/backend/glsl
parentglsl: Fix image gather logic (diff)
downloadyuzu-421847cf1e33d5b95c9aa272bf3cf69afda3d964.tar.gz
yuzu-421847cf1e33d5b95c9aa272bf3cf69afda3d964.tar.xz
yuzu-421847cf1e33d5b95c9aa272bf3cf69afda3d964.zip
glsl: Implement image atomics and set layer
along with some more cleanup/oversight fixes
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.cpp11
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp12
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_image.cpp188
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp143
4 files changed, 202 insertions, 152 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index 76cf0bdf0..50a7a7447 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -197,7 +197,7 @@ void SetupOutPerVertex(EmitContext& ctx, std::string& header) {
197 if (ctx.info.stores_clip_distance) { 197 if (ctx.info.stores_clip_distance) {
198 header += "float gl_ClipDistance[];"; 198 header += "float gl_ClipDistance[];";
199 } 199 }
200 if (ctx.info.stores_viewport_index && ctx.profile.support_gl_vertex_viewport_layer && 200 if (ctx.info.stores_viewport_index && ctx.profile.support_viewport_index_layer_non_geometry &&
201 ctx.stage != Stage::Geometry) { 201 ctx.stage != Stage::Geometry) {
202 header += "int gl_ViewportIndex;"; 202 header += "int gl_ViewportIndex;";
203 } 203 }
@@ -314,7 +314,7 @@ void EmitContext::SetupExtensions(std::string&) {
314 header += "#extension GL_ARB_gpu_shader_int64 : enable\n"; 314 header += "#extension GL_ARB_gpu_shader_int64 : enable\n";
315 } 315 }
316 } 316 }
317 if (info.stores_viewport_index && profile.support_gl_vertex_viewport_layer && 317 if (info.stores_viewport_index && profile.support_viewport_index_layer_non_geometry &&
318 stage != Stage::Geometry) { 318 stage != Stage::Geometry) {
319 header += "#extension GL_ARB_shader_viewport_layer_array : enable\n"; 319 header += "#extension GL_ARB_shader_viewport_layer_array : enable\n";
320 } 320 }
@@ -497,12 +497,13 @@ std::string EmitContext::DefineGlobalMemoryFunctions() {
497void EmitContext::SetupImages(Bindings& bindings) { 497void EmitContext::SetupImages(Bindings& bindings) {
498 image_buffer_bindings.reserve(info.image_buffer_descriptors.size()); 498 image_buffer_bindings.reserve(info.image_buffer_descriptors.size());
499 for (const auto& desc : info.image_buffer_descriptors) { 499 for (const auto& desc : info.image_buffer_descriptors) {
500 image_buffer_bindings.push_back(bindings.image);
500 const auto indices{bindings.image + desc.count}; 501 const auto indices{bindings.image + desc.count};
502 const auto format{ImageFormatString(desc.format)};
501 for (u32 index = bindings.image; index < indices; ++index) { 503 for (u32 index = bindings.image; index < indices; ++index) {
502 header += fmt::format("layout(binding={}) uniform uimageBuffer img{};", bindings.image, 504 header += fmt::format("layout(binding={}{}) uniform uimageBuffer img{};",
503 index); 505 bindings.image, format, index);
504 } 506 }
505 image_buffer_bindings.push_back(bindings.image);
506 bindings.image += desc.count; 507 bindings.image += desc.count;
507 } 508 }
508 image_bindings.reserve(info.image_descriptors.size()); 509 image_bindings.reserve(info.image_descriptors.size());
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp
index 83ce6fcbb..4d35be152 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp
@@ -269,6 +269,15 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view val
269 const u32 element{static_cast<u32>(attr) % 4}; 269 const u32 element{static_cast<u32>(attr) % 4};
270 const char swizzle{"xyzw"[element]}; 270 const char swizzle{"xyzw"[element]};
271 switch (attr) { 271 switch (attr) {
272 case IR::Attribute::Layer:
273 if (ctx.stage != Stage::Geometry &&
274 !ctx.profile.support_viewport_index_layer_non_geometry) {
275 // LOG_WARNING(..., "Shader stores viewport layer but device does not support viewport
276 // layer extension");
277 break;
278 }
279 ctx.Add("gl_Layer=ftoi({});", value);
280 break;
272 case IR::Attribute::PointSize: 281 case IR::Attribute::PointSize:
273 ctx.Add("gl_PointSize={};", value); 282 ctx.Add("gl_PointSize={};", value);
274 break; 283 break;
@@ -279,7 +288,8 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view val
279 ctx.Add("gl_Position.{}={};", swizzle, value); 288 ctx.Add("gl_Position.{}={};", swizzle, value);
280 break; 289 break;
281 case IR::Attribute::ViewportIndex: 290 case IR::Attribute::ViewportIndex:
282 if (ctx.stage != Stage::Geometry && !ctx.profile.support_gl_vertex_viewport_layer) { 291 if (ctx.stage != Stage::Geometry &&
292 !ctx.profile.support_viewport_index_layer_non_geometry) {
283 // LOG_WARNING(..., "Shader stores viewport index but device does not support viewport 293 // LOG_WARNING(..., "Shader stores viewport index but device does not support viewport
284 // layer extension"); 294 // layer extension");
285 break; 295 break;
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
index f022c5f30..e3a69e3a5 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
@@ -45,7 +45,7 @@ std::string CastToIntVec(std::string_view value, const IR::TextureInstInfo& info
45 case TextureType::ColorArrayCube: 45 case TextureType::ColorArrayCube:
46 return fmt::format("ivec4({})", value); 46 return fmt::format("ivec4({})", value);
47 default: 47 default:
48 throw NotImplementedException("Offset type {}", info.type.Value()); 48 throw NotImplementedException("Integer cast for TextureType {}", info.type.Value());
49 } 49 }
50} 50}
51 51
@@ -64,7 +64,7 @@ std::string TexelFetchCastToInt(std::string_view value, const IR::TextureInstInf
64 case TextureType::ColorArrayCube: 64 case TextureType::ColorArrayCube:
65 return fmt::format("ivec4({})", value); 65 return fmt::format("ivec4({})", value);
66 default: 66 default:
67 throw NotImplementedException("Offset type {}", info.type.Value()); 67 throw NotImplementedException("TexelFetchCast type {}", info.type.Value());
68 } 68 }
69} 69}
70 70
@@ -98,7 +98,19 @@ std::string GetOffsetVec(EmitContext& ctx, const IR::Value& offset) {
98 break; 98 break;
99 } 99 }
100 } 100 }
101 return ctx.var_alloc.Consume(offset); 101 const auto offset_str{ctx.var_alloc.Consume(offset)};
102 switch (offset.Type()) {
103 case IR::Type::U32:
104 return fmt::format("int({})", offset_str);
105 case IR::Type::U32x2:
106 return fmt::format("ivec2({})", offset_str);
107 case IR::Type::U32x3:
108 return fmt::format("ivec3({})", offset_str);
109 case IR::Type::U32x4:
110 return fmt::format("ivec4({})", offset_str);
111 default:
112 throw NotImplementedException("Offset type {}", offset.Type());
113 }
102} 114}
103 115
104std::string PtpOffsets(const IR::Value& offset, const IR::Value& offset2) { 116std::string PtpOffsets(const IR::Value& offset, const IR::Value& offset2) {
@@ -528,6 +540,88 @@ void EmitImageWrite([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst
528 ctx.Add("imageStore({},{},{});", image, TexelFetchCastToInt(coords, info), color); 540 ctx.Add("imageStore({},{},{});", image, TexelFetchCastToInt(coords, info), color);
529} 541}
530 542
543void EmitImageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
544 std::string_view coords, std::string_view value) {
545 const auto info{inst.Flags<IR::TextureInstInfo>()};
546 const auto image{Image(ctx, info, index)};
547 ctx.AddU32("{}=imageAtomicAdd({},{},{});", inst, image, TexelFetchCastToInt(coords, info),
548 value);
549}
550
551void EmitImageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
552 std::string_view coords, std::string_view value) {
553 const auto info{inst.Flags<IR::TextureInstInfo>()};
554 const auto image{Image(ctx, info, index)};
555 ctx.AddU32("{}=imageAtomicMin({},{},int({}));", inst, image, TexelFetchCastToInt(coords, info),
556 value);
557}
558
559void EmitImageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
560 std::string_view coords, std::string_view value) {
561 const auto info{inst.Flags<IR::TextureInstInfo>()};
562 const auto image{Image(ctx, info, index)};
563 ctx.AddU32("{}=imageAtomicMin({},{},uint({}));", inst, image, TexelFetchCastToInt(coords, info),
564 value);
565}
566
567void EmitImageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
568 std::string_view coords, std::string_view value) {
569 const auto info{inst.Flags<IR::TextureInstInfo>()};
570 const auto image{Image(ctx, info, index)};
571 ctx.AddU32("{}=imageAtomicMax({},{},int({}));", inst, image, TexelFetchCastToInt(coords, info),
572 value);
573}
574
575void EmitImageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
576 std::string_view coords, std::string_view value) {
577 const auto info{inst.Flags<IR::TextureInstInfo>()};
578 const auto image{Image(ctx, info, index)};
579 ctx.AddU32("{}=imageAtomicMax({},{},uint({}));", inst, image, TexelFetchCastToInt(coords, info),
580 value);
581}
582
583void EmitImageAtomicInc32(EmitContext&, IR::Inst&, const IR::Value&, std::string_view,
584 std::string_view) {
585 NotImplemented();
586}
587
588void EmitImageAtomicDec32(EmitContext&, IR::Inst&, const IR::Value&, std::string_view,
589 std::string_view) {
590 NotImplemented();
591}
592
593void EmitImageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
594 std::string_view coords, std::string_view value) {
595 const auto info{inst.Flags<IR::TextureInstInfo>()};
596 const auto image{Image(ctx, info, index)};
597 ctx.AddU32("{}=imageAtomicAnd({},{},{});", inst, image, TexelFetchCastToInt(coords, info),
598 value);
599}
600
601void EmitImageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
602 std::string_view coords, std::string_view value) {
603 const auto info{inst.Flags<IR::TextureInstInfo>()};
604 const auto image{Image(ctx, info, index)};
605 ctx.AddU32("{}=imageAtomicOr({},{},{});", inst, image, TexelFetchCastToInt(coords, info),
606 value);
607}
608
609void EmitImageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
610 std::string_view coords, std::string_view value) {
611 const auto info{inst.Flags<IR::TextureInstInfo>()};
612 const auto image{Image(ctx, info, index)};
613 ctx.AddU32("{}=imageAtomicXor({},{},{});", inst, image, TexelFetchCastToInt(coords, info),
614 value);
615}
616
617void EmitImageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
618 std::string_view coords, std::string_view value) {
619 const auto info{inst.Flags<IR::TextureInstInfo>()};
620 const auto image{Image(ctx, info, index)};
621 ctx.AddU32("{}=imageAtomicExchange({},{},{});", inst, image, TexelFetchCastToInt(coords, info),
622 value);
623}
624
531void EmitBindlessImageSampleImplicitLod(EmitContext&) { 625void EmitBindlessImageSampleImplicitLod(EmitContext&) {
532 NotImplemented(); 626 NotImplemented();
533} 627}
@@ -624,4 +718,92 @@ void EmitBoundImageWrite(EmitContext&) {
624 NotImplemented(); 718 NotImplemented();
625} 719}
626 720
721void EmitBindlessImageAtomicIAdd32(EmitContext&) {
722 NotImplemented();
723}
724
725void EmitBindlessImageAtomicSMin32(EmitContext&) {
726 NotImplemented();
727}
728
729void EmitBindlessImageAtomicUMin32(EmitContext&) {
730 NotImplemented();
731}
732
733void EmitBindlessImageAtomicSMax32(EmitContext&) {
734 NotImplemented();
735}
736
737void EmitBindlessImageAtomicUMax32(EmitContext&) {
738 NotImplemented();
739}
740
741void EmitBindlessImageAtomicInc32(EmitContext&) {
742 NotImplemented();
743}
744
745void EmitBindlessImageAtomicDec32(EmitContext&) {
746 NotImplemented();
747}
748
749void EmitBindlessImageAtomicAnd32(EmitContext&) {
750 NotImplemented();
751}
752
753void EmitBindlessImageAtomicOr32(EmitContext&) {
754 NotImplemented();
755}
756
757void EmitBindlessImageAtomicXor32(EmitContext&) {
758 NotImplemented();
759}
760
761void EmitBindlessImageAtomicExchange32(EmitContext&) {
762 NotImplemented();
763}
764
765void EmitBoundImageAtomicIAdd32(EmitContext&) {
766 NotImplemented();
767}
768
769void EmitBoundImageAtomicSMin32(EmitContext&) {
770 NotImplemented();
771}
772
773void EmitBoundImageAtomicUMin32(EmitContext&) {
774 NotImplemented();
775}
776
777void EmitBoundImageAtomicSMax32(EmitContext&) {
778 NotImplemented();
779}
780
781void EmitBoundImageAtomicUMax32(EmitContext&) {
782 NotImplemented();
783}
784
785void EmitBoundImageAtomicInc32(EmitContext&) {
786 NotImplemented();
787}
788
789void EmitBoundImageAtomicDec32(EmitContext&) {
790 NotImplemented();
791}
792
793void EmitBoundImageAtomicAnd32(EmitContext&) {
794 NotImplemented();
795}
796
797void EmitBoundImageAtomicOr32(EmitContext&) {
798 NotImplemented();
799}
800
801void EmitBoundImageAtomicXor32(EmitContext&) {
802 NotImplemented();
803}
804
805void EmitBoundImageAtomicExchange32(EmitContext&) {
806 NotImplemented();
807}
808
627} // namespace Shader::Backend::GLSL 809} // namespace Shader::Backend::GLSL
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp
index c64d4325d..5ca73610b 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp
@@ -250,147 +250,4 @@ void EmitGetInBoundsFromOp(EmitContext& ctx) {
250 NotImplemented(); 250 NotImplemented();
251} 251}
252 252
253void EmitBindlessImageAtomicIAdd32(EmitContext&) {
254 NotImplemented();
255}
256
257void EmitBindlessImageAtomicSMin32(EmitContext&) {
258 NotImplemented();
259}
260
261void EmitBindlessImageAtomicUMin32(EmitContext&) {
262 NotImplemented();
263}
264
265void EmitBindlessImageAtomicSMax32(EmitContext&) {
266 NotImplemented();
267}
268
269void EmitBindlessImageAtomicUMax32(EmitContext&) {
270 NotImplemented();
271}
272
273void EmitBindlessImageAtomicInc32(EmitContext&) {
274 NotImplemented();
275}
276
277void EmitBindlessImageAtomicDec32(EmitContext&) {
278 NotImplemented();
279}
280
281void EmitBindlessImageAtomicAnd32(EmitContext&) {
282 NotImplemented();
283}
284
285void EmitBindlessImageAtomicOr32(EmitContext&) {
286 NotImplemented();
287}
288
289void EmitBindlessImageAtomicXor32(EmitContext&) {
290 NotImplemented();
291}
292
293void EmitBindlessImageAtomicExchange32(EmitContext&) {
294 NotImplemented();
295}
296
297void EmitBoundImageAtomicIAdd32(EmitContext&) {
298 NotImplemented();
299}
300
301void EmitBoundImageAtomicSMin32(EmitContext&) {
302 NotImplemented();
303}
304
305void EmitBoundImageAtomicUMin32(EmitContext&) {
306 NotImplemented();
307}
308
309void EmitBoundImageAtomicSMax32(EmitContext&) {
310 NotImplemented();
311}
312
313void EmitBoundImageAtomicUMax32(EmitContext&) {
314 NotImplemented();
315}
316
317void EmitBoundImageAtomicInc32(EmitContext&) {
318 NotImplemented();
319}
320
321void EmitBoundImageAtomicDec32(EmitContext&) {
322 NotImplemented();
323}
324
325void EmitBoundImageAtomicAnd32(EmitContext&) {
326 NotImplemented();
327}
328
329void EmitBoundImageAtomicOr32(EmitContext&) {
330 NotImplemented();
331}
332
333void EmitBoundImageAtomicXor32(EmitContext&) {
334 NotImplemented();
335}
336
337void EmitBoundImageAtomicExchange32(EmitContext&) {
338 NotImplemented();
339}
340
341void EmitImageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
342 std::string_view coords, std::string_view value) {
343 NotImplemented();
344}
345
346void EmitImageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
347 std::string_view coords, std::string_view value) {
348 NotImplemented();
349}
350
351void EmitImageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
352 std::string_view coords, std::string_view value) {
353 NotImplemented();
354}
355
356void EmitImageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
357 std::string_view coords, std::string_view value) {
358 NotImplemented();
359}
360
361void EmitImageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
362 std::string_view coords, std::string_view value) {
363 NotImplemented();
364}
365
366void EmitImageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
367 std::string_view coords, std::string_view value) {
368 NotImplemented();
369}
370
371void EmitImageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
372 std::string_view coords, std::string_view value) {
373 NotImplemented();
374}
375
376void EmitImageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
377 std::string_view coords, std::string_view value) {
378 NotImplemented();
379}
380
381void EmitImageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
382 std::string_view coords, std::string_view value) {
383 NotImplemented();
384}
385
386void EmitImageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
387 std::string_view coords, std::string_view value) {
388 NotImplemented();
389}
390
391void EmitImageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
392 std::string_view coords, std::string_view value) {
393 NotImplemented();
394}
395
396} // namespace Shader::Backend::GLSL 253} // namespace Shader::Backend::GLSL