From 4667ed8e22cff003cebfdd469b65b13b035cfe55 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Thu, 14 Mar 2019 02:45:51 -0300 Subject: vk_shader_decompiler: Implement texture decompilation helper functions --- .../renderer_vulkan/vk_shader_decompiler.cpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/video_core/renderer_vulkan') diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp index 9f717b836..3f23ba749 100644 --- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp @@ -804,6 +804,38 @@ private: return {}; } + Id GetTextureSampler(Operation operation) { + const auto meta = std::get_if(&operation.GetMeta()); + const auto entry = sampler_images.at(static_cast(meta->sampler.GetIndex())); + return Emit(OpLoad(entry.sampled_image_type, entry.sampler)); + } + + Id GetTextureImage(Operation operation) { + const auto meta = std::get_if(&operation.GetMeta()); + const auto entry = sampler_images.at(static_cast(meta->sampler.GetIndex())); + return Emit(OpImage(entry.image_type, GetTextureSampler(operation))); + } + + Id GetTextureCoordinates(Operation operation) { + const auto meta = std::get_if(&operation.GetMeta()); + std::vector coords; + for (std::size_t i = 0; i < operation.GetOperandsCount(); ++i) { + coords.push_back(Visit(operation[i])); + } + if (meta->sampler.IsArray()) { + const Id array_integer = BitcastTo(Visit(meta->array)); + coords.push_back(Emit(OpConvertSToF(t_float, array_integer))); + } + if (meta->sampler.IsShadow()) { + coords.push_back(Visit(meta->depth_compare)); + } + + const std::array t_float_lut = {nullptr, t_float2, t_float3, t_float4}; + return coords.size() == 1 + ? coords[0] + : Emit(OpCompositeConstruct(t_float_lut.at(coords.size() - 1), coords)); + } + Id Texture(Operation operation) { UNIMPLEMENTED(); return {}; -- cgit v1.2.3