summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2021-11-16 18:52:11 -0800
committerGravatar GitHub2021-11-16 18:52:11 -0800
commit71313509f75aeafe425e531824d1faa9e7c0a40b (patch)
treecb1df371d288677fcede6a3409eb079e0d278163 /src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
parentMerge pull request #7347 from lioncash/catch (diff)
parentTextureCache: Fix Automatic Anisotropic. (diff)
downloadyuzu-71313509f75aeafe425e531824d1faa9e7c0a40b.tar.gz
yuzu-71313509f75aeafe425e531824d1faa9e7c0a40b.tar.xz
yuzu-71313509f75aeafe425e531824d1faa9e7c0a40b.zip
Merge pull request #7219 from FernandoS27/aristotles-right-testicle
Project A.R.T. Advanced Rendering Techniques
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_spirv_image.cpp')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_image.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
index 1d5364309..4d168a96d 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
@@ -224,6 +224,36 @@ Id Emit(MethodPtrType sparse_ptr, MethodPtrType non_sparse_ptr, EmitContext& ctx
224 Decorate(ctx, inst, sample); 224 Decorate(ctx, inst, sample);
225 return ctx.OpCompositeExtract(result_type, sample, 1U); 225 return ctx.OpCompositeExtract(result_type, sample, 1U);
226} 226}
227
228Id IsScaled(EmitContext& ctx, const IR::Value& index, Id member_index, u32 base_index) {
229 const Id push_constant_u32{ctx.TypePointer(spv::StorageClass::PushConstant, ctx.U32[1])};
230 Id bit{};
231 if (index.IsImmediate()) {
232 // Use BitwiseAnd instead of BitfieldExtract for better codegen on Nvidia OpenGL.
233 // LOP32I.NZ is used to set the predicate rather than BFE+ISETP.
234 const u32 index_value{index.U32() + base_index};
235 const Id word_index{ctx.Const(index_value / 32)};
236 const Id bit_index_mask{ctx.Const(1u << (index_value % 32))};
237 const Id pointer{ctx.OpAccessChain(push_constant_u32, ctx.rescaling_push_constants,
238 member_index, word_index)};
239 const Id word{ctx.OpLoad(ctx.U32[1], pointer)};
240 bit = ctx.OpBitwiseAnd(ctx.U32[1], word, bit_index_mask);
241 } else {
242 Id index_value{ctx.Def(index)};
243 if (base_index != 0) {
244 index_value = ctx.OpIAdd(ctx.U32[1], index_value, ctx.Const(base_index));
245 }
246 const Id bit_index{ctx.OpBitwiseAnd(ctx.U32[1], index_value, ctx.Const(31u))};
247 bit = ctx.OpBitFieldUExtract(ctx.U32[1], index_value, bit_index, ctx.Const(1u));
248 }
249 return ctx.OpINotEqual(ctx.U1, bit, ctx.u32_zero_value);
250}
251
252Id BitTest(EmitContext& ctx, Id mask, Id bit) {
253 const Id shifted{ctx.OpShiftRightLogical(ctx.U32[1], mask, bit)};
254 const Id bit_value{ctx.OpBitwiseAnd(ctx.U32[1], shifted, ctx.Const(1u))};
255 return ctx.OpINotEqual(ctx.U1, bit_value, ctx.u32_zero_value);
256}
227} // Anonymous namespace 257} // Anonymous namespace
228 258
229Id EmitBindlessImageSampleImplicitLod(EmitContext&) { 259Id EmitBindlessImageSampleImplicitLod(EmitContext&) {
@@ -470,4 +500,28 @@ void EmitImageWrite(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id
470 ctx.OpImageWrite(Image(ctx, index, info), coords, color); 500 ctx.OpImageWrite(Image(ctx, index, info), coords, color);
471} 501}
472 502
503Id EmitIsTextureScaled(EmitContext& ctx, const IR::Value& index) {
504 if (ctx.profile.unified_descriptor_binding) {
505 const Id member_index{ctx.Const(ctx.rescaling_textures_member_index)};
506 return IsScaled(ctx, index, member_index, ctx.texture_rescaling_index);
507 } else {
508 const Id composite{ctx.OpLoad(ctx.F32[4], ctx.rescaling_uniform_constant)};
509 const Id mask_f32{ctx.OpCompositeExtract(ctx.F32[1], composite, 0u)};
510 const Id mask{ctx.OpBitcast(ctx.U32[1], mask_f32)};
511 return BitTest(ctx, mask, ctx.Def(index));
512 }
513}
514
515Id EmitIsImageScaled(EmitContext& ctx, const IR::Value& index) {
516 if (ctx.profile.unified_descriptor_binding) {
517 const Id member_index{ctx.Const(ctx.rescaling_images_member_index)};
518 return IsScaled(ctx, index, member_index, ctx.image_rescaling_index);
519 } else {
520 const Id composite{ctx.OpLoad(ctx.F32[4], ctx.rescaling_uniform_constant)};
521 const Id mask_f32{ctx.OpCompositeExtract(ctx.F32[1], composite, 1u)};
522 const Id mask{ctx.OpBitcast(ctx.U32[1], mask_f32)};
523 return BitTest(ctx, mask, ctx.Def(index));
524 }
525}
526
473} // namespace Shader::Backend::SPIRV 527} // namespace Shader::Backend::SPIRV