diff options
| author | 2019-09-05 23:26:05 -0300 | |
|---|---|---|
| committer | 2019-09-05 23:26:05 -0300 | |
| commit | 1f43e5296fcd2debaea672fd9740d2f07223406b (patch) | |
| tree | 382d7a0f82949a825755c38363c8aaf33bc47e98 /src/video_core/shader | |
| parent | texture_cache: Minor changes (diff) | |
| download | yuzu-1f43e5296fcd2debaea672fd9740d2f07223406b.tar.gz yuzu-1f43e5296fcd2debaea672fd9740d2f07223406b.tar.xz yuzu-1f43e5296fcd2debaea672fd9740d2f07223406b.zip | |
gl_shader_decompiler: Keep track of written images and mark them as modified
Diffstat (limited to 'src/video_core/shader')
| -rw-r--r-- | src/video_core/shader/decode/image.cpp | 40 | ||||
| -rw-r--r-- | src/video_core/shader/node.h | 48 | ||||
| -rw-r--r-- | src/video_core/shader/shader_ir.h | 8 |
3 files changed, 54 insertions, 42 deletions
diff --git a/src/video_core/shader/decode/image.cpp b/src/video_core/shader/decode/image.cpp index 77151a24b..008109a99 100644 --- a/src/video_core/shader/decode/image.cpp +++ b/src/video_core/shader/decode/image.cpp | |||
| @@ -61,56 +61,54 @@ u32 ShaderIR::DecodeImage(NodeBlock& bb, u32 pc) { | |||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | const auto type{instr.sust.image_type}; | 63 | const auto type{instr.sust.image_type}; |
| 64 | const auto& image{instr.sust.is_immediate ? GetImage(instr.image, type) | 64 | auto& image{instr.sust.is_immediate ? GetImage(instr.image, type) |
| 65 | : GetBindlessImage(instr.gpr39, type)}; | 65 | : GetBindlessImage(instr.gpr39, type)}; |
| 66 | image.MarkWrite(); | ||
| 67 | |||
| 66 | MetaImage meta{image, values}; | 68 | MetaImage meta{image, values}; |
| 67 | const Node store{Operation(OperationCode::ImageStore, meta, std::move(coords))}; | 69 | const Node store{Operation(OperationCode::ImageStore, meta, std::move(coords))}; |
| 68 | bb.push_back(store); | 70 | bb.push_back(store); |
| 69 | break; | 71 | break; |
| 70 | } | 72 | } |
| 71 | default: | 73 | default: |
| 72 | UNIMPLEMENTED_MSG("Unhandled conversion instruction: {}", opcode->get().GetName()); | 74 | UNIMPLEMENTED_MSG("Unhandled image instruction: {}", opcode->get().GetName()); |
| 73 | } | 75 | } |
| 74 | 76 | ||
| 75 | return pc; | 77 | return pc; |
| 76 | } | 78 | } |
| 77 | 79 | ||
| 78 | const Image& ShaderIR::GetImage(Tegra::Shader::Image image, Tegra::Shader::ImageType type) { | 80 | Image& ShaderIR::GetImage(Tegra::Shader::Image image, Tegra::Shader::ImageType type) { |
| 79 | const auto offset{static_cast<std::size_t>(image.index.Value())}; | 81 | const auto offset{static_cast<u64>(image.index.Value())}; |
| 80 | 82 | ||
| 81 | // If this image has already been used, return the existing mapping. | 83 | // If this image has already been used, return the existing mapping. |
| 82 | const auto itr{std::find_if(used_images.begin(), used_images.end(), | 84 | const auto it = used_images.find(offset); |
| 83 | [=](const Image& entry) { return entry.GetOffset() == offset; })}; | 85 | if (it != used_images.end()) { |
| 84 | if (itr != used_images.end()) { | 86 | ASSERT(it->second.GetType() == type); |
| 85 | ASSERT(itr->GetType() == type); | 87 | return it->second; |
| 86 | return *itr; | ||
| 87 | } | 88 | } |
| 88 | 89 | ||
| 89 | // Otherwise create a new mapping for this image. | 90 | // Otherwise create a new mapping for this image. |
| 90 | const std::size_t next_index{used_images.size()}; | 91 | const std::size_t next_index{used_images.size()}; |
| 91 | const Image entry{offset, next_index, type}; | 92 | return used_images.emplace(offset, Image{offset, next_index, type}).first->second; |
| 92 | return *used_images.emplace(entry).first; | ||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | const Image& ShaderIR::GetBindlessImage(Tegra::Shader::Register reg, | 95 | Image& ShaderIR::GetBindlessImage(Tegra::Shader::Register reg, Tegra::Shader::ImageType type) { |
| 96 | Tegra::Shader::ImageType type) { | ||
| 97 | const Node image_register{GetRegister(reg)}; | 96 | const Node image_register{GetRegister(reg)}; |
| 98 | const auto [base_image, cbuf_index, cbuf_offset]{ | 97 | const auto [base_image, cbuf_index, cbuf_offset]{ |
| 99 | TrackCbuf(image_register, global_code, static_cast<s64>(global_code.size()))}; | 98 | TrackCbuf(image_register, global_code, static_cast<s64>(global_code.size()))}; |
| 100 | const auto cbuf_key{(static_cast<u64>(cbuf_index) << 32) | static_cast<u64>(cbuf_offset)}; | 99 | const auto cbuf_key{(static_cast<u64>(cbuf_index) << 32) | static_cast<u64>(cbuf_offset)}; |
| 101 | 100 | ||
| 102 | // If this image has already been used, return the existing mapping. | 101 | // If this image has already been used, return the existing mapping. |
| 103 | const auto itr{std::find_if(used_images.begin(), used_images.end(), | 102 | const auto it = used_images.find(cbuf_key); |
| 104 | [=](const Image& entry) { return entry.GetOffset() == cbuf_key; })}; | 103 | if (it != used_images.end()) { |
| 105 | if (itr != used_images.end()) { | 104 | ASSERT(it->second.GetType() == type); |
| 106 | ASSERT(itr->GetType() == type); | 105 | return it->second; |
| 107 | return *itr; | ||
| 108 | } | 106 | } |
| 109 | 107 | ||
| 110 | // Otherwise create a new mapping for this image. | 108 | // Otherwise create a new mapping for this image. |
| 111 | const std::size_t next_index{used_images.size()}; | 109 | const std::size_t next_index{used_images.size()}; |
| 112 | const Image entry{cbuf_index, cbuf_offset, next_index, type}; | 110 | return used_images.emplace(cbuf_key, Image{cbuf_index, cbuf_offset, next_index, type}) |
| 113 | return *used_images.emplace(entry).first; | 111 | .first->second; |
| 114 | } | 112 | } |
| 115 | 113 | ||
| 116 | } // namespace VideoCommon::Shader | 114 | } // namespace VideoCommon::Shader |
diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h index 0397f4c6e..b29aedce8 100644 --- a/src/video_core/shader/node.h +++ b/src/video_core/shader/node.h | |||
| @@ -273,50 +273,64 @@ private: | |||
| 273 | bool is_bindless{}; ///< Whether this sampler belongs to a bindless texture or not. | 273 | bool is_bindless{}; ///< Whether this sampler belongs to a bindless texture or not. |
| 274 | }; | 274 | }; |
| 275 | 275 | ||
| 276 | class Image { | 276 | class Image final { |
| 277 | public: | 277 | public: |
| 278 | explicit Image(std::size_t offset, std::size_t index, Tegra::Shader::ImageType type) | 278 | constexpr explicit Image(u64 offset, std::size_t index, Tegra::Shader::ImageType type) |
| 279 | : offset{offset}, index{index}, type{type}, is_bindless{false} {} | 279 | : offset{offset}, index{index}, type{type}, is_bindless{false} {} |
| 280 | 280 | ||
| 281 | explicit Image(u32 cbuf_index, u32 cbuf_offset, std::size_t index, | 281 | constexpr explicit Image(u32 cbuf_index, u32 cbuf_offset, std::size_t index, |
| 282 | Tegra::Shader::ImageType type) | 282 | Tegra::Shader::ImageType type) |
| 283 | : offset{(static_cast<u64>(cbuf_index) << 32) | cbuf_offset}, index{index}, type{type}, | 283 | : offset{(static_cast<u64>(cbuf_index) << 32) | cbuf_offset}, index{index}, type{type}, |
| 284 | is_bindless{true} {} | 284 | is_bindless{true} {} |
| 285 | 285 | ||
| 286 | explicit Image(std::size_t offset, std::size_t index, Tegra::Shader::ImageType type, | 286 | constexpr explicit Image(std::size_t offset, std::size_t index, Tegra::Shader::ImageType type, |
| 287 | bool is_bindless) | 287 | bool is_bindless, bool is_written, bool is_read) |
| 288 | : offset{offset}, index{index}, type{type}, is_bindless{is_bindless} {} | 288 | : offset{offset}, index{index}, type{type}, is_bindless{is_bindless}, |
| 289 | is_written{is_written}, is_read{is_read} {} | ||
| 289 | 290 | ||
| 290 | std::size_t GetOffset() const { | 291 | void MarkRead() { |
| 292 | is_read = true; | ||
| 293 | } | ||
| 294 | |||
| 295 | void MarkWrite() { | ||
| 296 | is_written = true; | ||
| 297 | } | ||
| 298 | |||
| 299 | constexpr std::size_t GetOffset() const { | ||
| 291 | return offset; | 300 | return offset; |
| 292 | } | 301 | } |
| 293 | 302 | ||
| 294 | std::size_t GetIndex() const { | 303 | constexpr std::size_t GetIndex() const { |
| 295 | return index; | 304 | return index; |
| 296 | } | 305 | } |
| 297 | 306 | ||
| 298 | Tegra::Shader::ImageType GetType() const { | 307 | constexpr Tegra::Shader::ImageType GetType() const { |
| 299 | return type; | 308 | return type; |
| 300 | } | 309 | } |
| 301 | 310 | ||
| 302 | bool IsBindless() const { | 311 | constexpr bool IsBindless() const { |
| 303 | return is_bindless; | 312 | return is_bindless; |
| 304 | } | 313 | } |
| 305 | 314 | ||
| 306 | std::pair<u32, u32> GetBindlessCBuf() const { | 315 | constexpr bool IsRead() const { |
| 307 | return {static_cast<u32>(offset >> 32), static_cast<u32>(offset)}; | 316 | return is_read; |
| 317 | } | ||
| 318 | |||
| 319 | constexpr bool IsWritten() const { | ||
| 320 | return is_written; | ||
| 308 | } | 321 | } |
| 309 | 322 | ||
| 310 | bool operator<(const Image& rhs) const { | 323 | constexpr std::pair<u32, u32> GetBindlessCBuf() const { |
| 311 | return std::tie(offset, index, type, is_bindless) < | 324 | return {static_cast<u32>(offset >> 32), static_cast<u32>(offset)}; |
| 312 | std::tie(rhs.offset, rhs.index, rhs.type, rhs.is_bindless); | ||
| 313 | } | 325 | } |
| 314 | 326 | ||
| 315 | private: | 327 | private: |
| 316 | std::size_t offset{}; | 328 | u64 offset{}; |
| 317 | std::size_t index{}; | 329 | std::size_t index{}; |
| 318 | Tegra::Shader::ImageType type{}; | 330 | Tegra::Shader::ImageType type{}; |
| 319 | bool is_bindless{}; | 331 | bool is_bindless{}; |
| 332 | bool is_read{}; | ||
| 333 | bool is_written{}; | ||
| 320 | }; | 334 | }; |
| 321 | 335 | ||
| 322 | struct GlobalMemoryBase { | 336 | struct GlobalMemoryBase { |
diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index bcc9b79b6..0f891eace 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h | |||
| @@ -95,7 +95,7 @@ public: | |||
| 95 | return used_samplers; | 95 | return used_samplers; |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | const std::set<Image>& GetImages() const { | 98 | const std::map<u64, Image>& GetImages() const { |
| 99 | return used_images; | 99 | return used_images; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| @@ -272,10 +272,10 @@ private: | |||
| 272 | bool is_shadow); | 272 | bool is_shadow); |
| 273 | 273 | ||
| 274 | /// Accesses an image. | 274 | /// Accesses an image. |
| 275 | const Image& GetImage(Tegra::Shader::Image image, Tegra::Shader::ImageType type); | 275 | Image& GetImage(Tegra::Shader::Image image, Tegra::Shader::ImageType type); |
| 276 | 276 | ||
| 277 | /// Access a bindless image sampler. | 277 | /// Access a bindless image sampler. |
| 278 | const Image& GetBindlessImage(Tegra::Shader::Register reg, Tegra::Shader::ImageType type); | 278 | Image& GetBindlessImage(Tegra::Shader::Register reg, Tegra::Shader::ImageType type); |
| 279 | 279 | ||
| 280 | /// Extracts a sequence of bits from a node | 280 | /// Extracts a sequence of bits from a node |
| 281 | Node BitfieldExtract(Node value, u32 offset, u32 bits); | 281 | Node BitfieldExtract(Node value, u32 offset, u32 bits); |
| @@ -356,7 +356,7 @@ private: | |||
| 356 | std::set<Tegra::Shader::Attribute::Index> used_output_attributes; | 356 | std::set<Tegra::Shader::Attribute::Index> used_output_attributes; |
| 357 | std::map<u32, ConstBuffer> used_cbufs; | 357 | std::map<u32, ConstBuffer> used_cbufs; |
| 358 | std::set<Sampler> used_samplers; | 358 | std::set<Sampler> used_samplers; |
| 359 | std::set<Image> used_images; | 359 | std::map<u64, Image> used_images; |
| 360 | std::array<bool, Tegra::Engines::Maxwell3D::Regs::NumClipDistances> used_clip_distances{}; | 360 | std::array<bool, Tegra::Engines::Maxwell3D::Regs::NumClipDistances> used_clip_distances{}; |
| 361 | std::map<GlobalMemoryBase, GlobalMemoryUsage> used_global_memory; | 361 | std::map<GlobalMemoryBase, GlobalMemoryUsage> used_global_memory; |
| 362 | bool uses_layer{}; | 362 | bool uses_layer{}; |