diff options
| author | 2021-04-06 02:56:15 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:26 -0400 | |
| commit | 1f3eb601acdcdfa4c119cffbf36b5792147b893f (patch) | |
| tree | 1a8dcc5e4ce11e9090dd6d7a8b4e8aaa130ff67b /src/shader_recompiler/backend/spirv/emit_spirv_image.cpp | |
| parent | shader: Address feedback (diff) | |
| download | yuzu-1f3eb601acdcdfa4c119cffbf36b5792147b893f.tar.gz yuzu-1f3eb601acdcdfa4c119cffbf36b5792147b893f.tar.xz yuzu-1f3eb601acdcdfa4c119cffbf36b5792147b893f.zip | |
shader: Implement texture buffers
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_spirv_image.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_spirv_image.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp index fc40615af..525f67c6e 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp | |||
| @@ -128,12 +128,18 @@ Id Texture(EmitContext& ctx, const IR::Value& index) { | |||
| 128 | throw NotImplementedException("Indirect texture sample"); | 128 | throw NotImplementedException("Indirect texture sample"); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | Id TextureImage(EmitContext& ctx, const IR::Value& index) { | 131 | Id TextureImage(EmitContext& ctx, const IR::Value& index, IR::TextureInstInfo info) { |
| 132 | if (index.IsImmediate()) { | 132 | if (!index.IsImmediate()) { |
| 133 | throw NotImplementedException("Indirect texture sample"); | ||
| 134 | } | ||
| 135 | if (info.type == TextureType::Buffer) { | ||
| 136 | const Id sampler_id{ctx.texture_buffers.at(index.U32())}; | ||
| 137 | const Id id{ctx.OpLoad(ctx.sampled_texture_buffer_type, sampler_id)}; | ||
| 138 | return ctx.OpImage(ctx.image_buffer_type, id); | ||
| 139 | } else { | ||
| 133 | const TextureDefinition def{ctx.textures.at(index.U32())}; | 140 | const TextureDefinition def{ctx.textures.at(index.U32())}; |
| 134 | return ctx.OpImage(def.image_type, ctx.OpLoad(def.sampled_type, def.id)); | 141 | return ctx.OpImage(def.image_type, ctx.OpLoad(def.sampled_type, def.id)); |
| 135 | } | 142 | } |
| 136 | throw NotImplementedException("Indirect texture sample"); | ||
| 137 | } | 143 | } |
| 138 | 144 | ||
| 139 | Id Decorate(EmitContext& ctx, IR::Inst* inst, Id sample) { | 145 | Id Decorate(EmitContext& ctx, IR::Inst* inst, Id sample) { |
| @@ -297,17 +303,22 @@ Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, | |||
| 297 | ctx.F32[4], Texture(ctx, index), coords, dref, operands.Mask(), operands.Span()); | 303 | ctx.F32[4], Texture(ctx, index), coords, dref, operands.Mask(), operands.Span()); |
| 298 | } | 304 | } |
| 299 | 305 | ||
| 306 | #pragma optimize("", off) | ||
| 307 | |||
| 300 | Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset, | 308 | Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset, |
| 301 | Id lod, Id ms) { | 309 | Id lod, Id ms) { |
| 302 | const auto info{inst->Flags<IR::TextureInstInfo>()}; | 310 | const auto info{inst->Flags<IR::TextureInstInfo>()}; |
| 311 | if (info.type == TextureType::Buffer) { | ||
| 312 | lod = Id{}; | ||
| 313 | } | ||
| 303 | const ImageOperands operands(offset, lod, ms); | 314 | const ImageOperands operands(offset, lod, ms); |
| 304 | return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4], | 315 | return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4], |
| 305 | TextureImage(ctx, index), coords, operands.Mask(), operands.Span()); | 316 | TextureImage(ctx, index, info), coords, operands.Mask(), operands.Span()); |
| 306 | } | 317 | } |
| 307 | 318 | ||
| 308 | Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id lod) { | 319 | Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id lod) { |
| 309 | const auto info{inst->Flags<IR::TextureInstInfo>()}; | 320 | const auto info{inst->Flags<IR::TextureInstInfo>()}; |
| 310 | const Id image{TextureImage(ctx, index)}; | 321 | const Id image{TextureImage(ctx, index, info)}; |
| 311 | const Id zero{ctx.u32_zero_value}; | 322 | const Id zero{ctx.u32_zero_value}; |
| 312 | const auto mips{[&] { return ctx.OpImageQueryLevels(ctx.U32[1], image); }}; | 323 | const auto mips{[&] { return ctx.OpImageQueryLevels(ctx.U32[1], image); }}; |
| 313 | switch (info.type) { | 324 | switch (info.type) { |
| @@ -331,6 +342,9 @@ Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& i | |||
| 331 | case TextureType::ShadowArrayCube: | 342 | case TextureType::ShadowArrayCube: |
| 332 | return ctx.OpCompositeConstruct(ctx.U32[4], ctx.OpImageQuerySizeLod(ctx.U32[3], image, lod), | 343 | return ctx.OpCompositeConstruct(ctx.U32[4], ctx.OpImageQuerySizeLod(ctx.U32[3], image, lod), |
| 333 | mips()); | 344 | mips()); |
| 345 | case TextureType::Buffer: | ||
| 346 | return ctx.OpCompositeConstruct(ctx.U32[4], ctx.OpImageQuerySize(ctx.U32[1], image), zero, | ||
| 347 | zero, mips()); | ||
| 334 | } | 348 | } |
| 335 | throw LogicError("Unspecified image type {}", info.type.Value()); | 349 | throw LogicError("Unspecified image type {}", info.type.Value()); |
| 336 | } | 350 | } |