summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar namkazy2020-04-06 13:46:55 +0700
committerGravatar namkazy2020-04-06 13:46:55 +0700
commit2c98e14d13c7611f488c351c5b42b1c58d4b33ea (patch)
tree6d68629b66cb3ff19efe5e9269611fccf35fe51a
parentshader_decode: SULD.D avoid duplicate code block. (diff)
downloadyuzu-2c98e14d13c7611f488c351c5b42b1c58d4b33ea.tar.gz
yuzu-2c98e14d13c7611f488c351c5b42b1c58d4b33ea.tar.xz
yuzu-2c98e14d13c7611f488c351c5b42b1c58d4b33ea.zip
shader_decode: SULD.D using std::pair instead of out parameter
-rw-r--r--src/video_core/shader/decode/image.cpp30
-rw-r--r--src/video_core/shader/shader_ir.h4
2 files changed, 15 insertions, 19 deletions
diff --git a/src/video_core/shader/decode/image.cpp b/src/video_core/shader/decode/image.cpp
index 242cd6cc1..7ad908a0e 100644
--- a/src/video_core/shader/decode/image.cpp
+++ b/src/video_core/shader/decode/image.cpp
@@ -271,37 +271,36 @@ std::size_t GetImageTypeNumCoordinates(Tegra::Shader::ImageType image_type) {
271} 271}
272} // Anonymous namespace 272} // Anonymous namespace
273 273
274Node ShaderIR::GetComponentValue(ComponentType component_type, u32 component_size, 274std::pair<Node, bool> ShaderIR::GetComponentValue(ComponentType component_type, u32 component_size,
275 Node original_value, bool* is_signed) { 275 Node original_value) {
276 switch (component_type) { 276 switch (component_type) {
277 case ComponentType::SNORM: { 277 case ComponentType::SNORM: {
278 *is_signed = true;
279 // range [-1.0, 1.0] 278 // range [-1.0, 1.0]
280 auto cnv_value = Operation(OperationCode::FMul, original_value, 279 auto cnv_value = Operation(OperationCode::FMul, original_value,
281 Immediate(static_cast<float>(1 << component_size) / 2.f - 1.f)); 280 Immediate(static_cast<float>(1 << component_size) / 2.f - 1.f));
282 cnv_value = SignedOperation(OperationCode::ICastFloat, is_signed, std::move(cnv_value)); 281 cnv_value = Operation(OperationCode::ICastFloat, std::move(cnv_value));
283 return BitfieldExtract(std::move(cnv_value), 0, component_size); 282 return {BitfieldExtract(std::move(cnv_value), 0, component_size), true};
284 } 283 }
285 case ComponentType::SINT: 284 case ComponentType::SINT:
286 case ComponentType::UNORM: { 285 case ComponentType::UNORM: {
287 *is_signed = component_type == ComponentType::SINT; 286 bool is_signed = component_type == ComponentType::SINT;
288 // range [0.0, 1.0] 287 // range [0.0, 1.0]
289 auto cnv_value = Operation(OperationCode::FMul, original_value, 288 auto cnv_value = Operation(OperationCode::FMul, original_value,
290 Immediate(static_cast<float>(1 << component_size) - 1.f)); 289 Immediate(static_cast<float>(1 << component_size) - 1.f));
291 return SignedOperation(OperationCode::ICastFloat, is_signed, std::move(cnv_value)); 290 return {SignedOperation(OperationCode::ICastFloat, is_signed, std::move(cnv_value)),
291 is_signed};
292 } 292 }
293 case ComponentType::UINT: // range [0, (1 << component_size) - 1] 293 case ComponentType::UINT: // range [0, (1 << component_size) - 1]
294 *is_signed = false; 294 return {original_value, false};
295 return original_value;
296 case ComponentType::FLOAT: 295 case ComponentType::FLOAT:
297 if (component_size == 16) { 296 if (component_size == 16) {
298 return Operation(OperationCode::HCastFloat, original_value); 297 return {Operation(OperationCode::HCastFloat, original_value), true};
299 } else { 298 } else {
300 return original_value; 299 return {original_value, true};
301 } 300 }
302 default: 301 default:
303 UNIMPLEMENTED_MSG("Unimplement component type={}", component_type); 302 UNIMPLEMENTED_MSG("Unimplement component type={}", component_type);
304 return original_value; 303 return {original_value, true};
305 } 304 }
306} 305}
307 306
@@ -377,14 +376,11 @@ u32 ShaderIR::DecodeImage(NodeBlock& bb, u32 pc) {
377 } 376 }
378 const auto component_type = GetComponentType(descriptor, element); 377 const auto component_type = GetComponentType(descriptor, element);
379 const auto component_size = GetComponentSize(descriptor.format, element); 378 const auto component_size = GetComponentSize(descriptor.format, element);
380
381 bool is_signed = true;
382 MetaImage meta{image, {}, element}; 379 MetaImage meta{image, {}, element};
383 380
384 Node converted_value = GetComponentValue( 381 auto [converted_value, is_signed] = GetComponentValue(
385 component_type, component_size, 382 component_type, component_size,
386 Operation(OperationCode::ImageLoad, meta, GetCoordinates(type)), 383 Operation(OperationCode::ImageLoad, meta, GetCoordinates(type)));
387 &is_signed);
388 384
389 // shift element to correct position 385 // shift element to correct position
390 const auto shifted = shifted_counter; 386 const auto shifted = shifted_counter;
diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h
index 408cce71e..ca6c976c9 100644
--- a/src/video_core/shader/shader_ir.h
+++ b/src/video_core/shader/shader_ir.h
@@ -313,8 +313,8 @@ private:
313 Node GetSaturatedHalfFloat(Node value, bool saturate = true); 313 Node GetSaturatedHalfFloat(Node value, bool saturate = true);
314 314
315 /// Get image component value by type and size 315 /// Get image component value by type and size
316 Node GetComponentValue(Tegra::Texture::ComponentType component_type, u32 component_size, 316 std::pair<Node, bool> GetComponentValue(Tegra::Texture::ComponentType component_type,
317 const Node original_value, bool* is_signed); 317 u32 component_size, Node original_value);
318 318
319 /// Returns a predicate comparing two floats 319 /// Returns a predicate comparing two floats
320 Node GetPredicateComparisonFloat(Tegra::Shader::PredCondition condition, Node op_a, Node op_b); 320 Node GetPredicateComparisonFloat(Tegra::Shader::PredCondition condition, Node op_a, Node op_b);