Refactor: Compositor: Use int32_t as result type
This patches uses an explicit int32_t fixed width integer instead of int for result types. For consistency with other node systems.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
@@ -141,7 +142,7 @@ class Result {
|
||||
* which will be identical to that stored in the data_ member. The active variant member depends
|
||||
* on the type of the result. This member is uninitialized and should not be used if the result
|
||||
* is not a single value. */
|
||||
std::variant<float, float2, float3, float4, int, int2> single_value_ = 0.0f;
|
||||
std::variant<float, float2, float3, float4, int32_t, int2> single_value_ = 0.0f;
|
||||
/* The domain of the result. This only matters if the result was not a single value. See the
|
||||
* discussion in COM_domain.hh for more information. */
|
||||
Domain domain_ = Domain::identity();
|
||||
@@ -537,7 +538,7 @@ template<typename T> BLI_INLINE_METHOD void Result::set_single_value(const T &va
|
||||
|
||||
switch (storage_type_) {
|
||||
case ResultStorageType::GPU:
|
||||
if constexpr (is_same_any_v<T, int, int2>) {
|
||||
if constexpr (is_same_any_v<T, int32_t, int2>) {
|
||||
if constexpr (std::is_scalar_v<T>) {
|
||||
GPU_texture_update(this->gpu_texture(), GPU_DATA_INT, &value);
|
||||
}
|
||||
|
||||
@@ -1675,7 +1675,7 @@ static void compute_single_value(Result &input, Result &output)
|
||||
output.set_single_value(input.get_single_value<float>());
|
||||
break;
|
||||
case ResultType::Int:
|
||||
output.set_single_value(input.get_single_value<int>());
|
||||
output.set_single_value(input.get_single_value<int32_t>());
|
||||
break;
|
||||
case ResultType::Int2:
|
||||
output.set_single_value(input.get_single_value<int2>());
|
||||
|
||||
@@ -216,16 +216,16 @@ void ConversionOperation::execute_single(const Result &input, Result &output)
|
||||
case ResultType::Int:
|
||||
switch (this->get_result().type()) {
|
||||
case ResultType::Float:
|
||||
output.set_single_value(int_to_float(input.get_single_value<int>()));
|
||||
output.set_single_value(int_to_float(input.get_single_value<int32_t>()));
|
||||
return;
|
||||
case ResultType::Float3:
|
||||
output.set_single_value(int_to_float3(input.get_single_value<int>()));
|
||||
output.set_single_value(int_to_float3(input.get_single_value<int32_t>()));
|
||||
return;
|
||||
case ResultType::Color:
|
||||
output.set_single_value(int_to_color(input.get_single_value<int>()));
|
||||
output.set_single_value(int_to_color(input.get_single_value<int32_t>()));
|
||||
return;
|
||||
case ResultType::Float4:
|
||||
output.set_single_value(int_to_float4(input.get_single_value<int>()));
|
||||
output.set_single_value(int_to_float4(input.get_single_value<int32_t>()));
|
||||
return;
|
||||
case ResultType::Int:
|
||||
/* Same type, no conversion needed. */
|
||||
@@ -352,22 +352,22 @@ void ConversionOperation::execute_cpu(const Result &input, Result &output)
|
||||
switch (this->get_result().type()) {
|
||||
case ResultType::Float:
|
||||
parallel_for(input.domain().size, [&](const int2 texel) {
|
||||
output.store_pixel(texel, int_to_float(input.load_pixel<int>(texel)));
|
||||
output.store_pixel(texel, int_to_float(input.load_pixel<int32_t>(texel)));
|
||||
});
|
||||
return;
|
||||
case ResultType::Float3:
|
||||
parallel_for(input.domain().size, [&](const int2 texel) {
|
||||
output.store_pixel(texel, int_to_float3(input.load_pixel<int>(texel)));
|
||||
output.store_pixel(texel, int_to_float3(input.load_pixel<int32_t>(texel)));
|
||||
});
|
||||
return;
|
||||
case ResultType::Color:
|
||||
parallel_for(input.domain().size, [&](const int2 texel) {
|
||||
output.store_pixel(texel, int_to_color(input.load_pixel<int>(texel)));
|
||||
output.store_pixel(texel, int_to_color(input.load_pixel<int32_t>(texel)));
|
||||
});
|
||||
return;
|
||||
case ResultType::Float4:
|
||||
parallel_for(input.domain().size, [&](const int2 texel) {
|
||||
output.store_pixel(texel, int_to_float4(input.load_pixel<int>(texel)));
|
||||
output.store_pixel(texel, int_to_float4(input.load_pixel<int32_t>(texel)));
|
||||
});
|
||||
return;
|
||||
case ResultType::Int:
|
||||
|
||||
@@ -64,7 +64,7 @@ static void add_single_value_input_parameter(mf::ParamsBuilder ¶meter_builde
|
||||
parameter_builder.add_readonly_single_input_value(input.get_single_value<float>());
|
||||
return;
|
||||
case ResultType::Int:
|
||||
parameter_builder.add_readonly_single_input_value(input.get_single_value<int>());
|
||||
parameter_builder.add_readonly_single_input_value(input.get_single_value<int32_t>());
|
||||
return;
|
||||
case ResultType::Color:
|
||||
parameter_builder.add_readonly_single_input_value(input.get_single_value<float4>());
|
||||
@@ -92,7 +92,7 @@ static void add_single_value_output_parameter(mf::ParamsBuilder ¶meter_build
|
||||
parameter_builder.add_uninitialized_single_output(&output.get_single_value<float>());
|
||||
return;
|
||||
case ResultType::Int:
|
||||
parameter_builder.add_uninitialized_single_output(&output.get_single_value<int>());
|
||||
parameter_builder.add_uninitialized_single_output(&output.get_single_value<int32_t>());
|
||||
return;
|
||||
case ResultType::Color:
|
||||
parameter_builder.add_uninitialized_single_output(&output.get_single_value<float4>());
|
||||
@@ -120,7 +120,7 @@ static void upload_single_value_output_to_gpu(Result &output)
|
||||
output.set_single_value(output.get_single_value<float>());
|
||||
return;
|
||||
case ResultType::Int:
|
||||
output.set_single_value(output.get_single_value<int>());
|
||||
output.set_single_value(output.get_single_value<int32_t>());
|
||||
return;
|
||||
case ResultType::Color:
|
||||
output.set_single_value(output.get_single_value<float4>());
|
||||
@@ -299,7 +299,7 @@ mf::Variable *MultiFunctionProcedureOperation::get_constant_input_variable(DInpu
|
||||
}
|
||||
case SOCK_INT: {
|
||||
const int value = input->default_value_typed<bNodeSocketValueInt>()->value;
|
||||
constant_function = &procedure_.construct_function<mf::CustomMF_Constant<int>>(value);
|
||||
constant_function = &procedure_.construct_function<mf::CustomMF_Constant<int32_t>>(value);
|
||||
break;
|
||||
}
|
||||
case SOCK_VECTOR: {
|
||||
|
||||
@@ -57,7 +57,7 @@ void ReduceToSingleValueOperation::execute()
|
||||
result.set_single_value(*static_cast<float *>(pixel));
|
||||
break;
|
||||
case ResultType::Int:
|
||||
result.set_single_value(*static_cast<int *>(pixel));
|
||||
result.set_single_value(*static_cast<int32_t *>(pixel));
|
||||
break;
|
||||
case ResultType::Float2:
|
||||
case ResultType::Int2:
|
||||
|
||||
@@ -227,7 +227,7 @@ const CPPType &Result::cpp_type(const ResultType type)
|
||||
case ResultType::Float:
|
||||
return CPPType::get<float>();
|
||||
case ResultType::Int:
|
||||
return CPPType::get<int>();
|
||||
return CPPType::get<int32_t>();
|
||||
case ResultType::Color:
|
||||
return CPPType::get<float4>();
|
||||
case ResultType::Float4:
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "BLI_math_vector.hh"
|
||||
#include "BLI_math_vector_types.hh"
|
||||
|
||||
@@ -15,9 +17,9 @@ namespace blender::compositor {
|
||||
* Float to other.
|
||||
*/
|
||||
|
||||
inline int float_to_int(const float &value)
|
||||
inline int32_t float_to_int(const float &value)
|
||||
{
|
||||
return int(value);
|
||||
return int32_t(value);
|
||||
}
|
||||
|
||||
inline float3 float_to_float3(const float &value)
|
||||
@@ -39,22 +41,22 @@ inline float4 float_to_float4(const float &value)
|
||||
* Int to other.
|
||||
*/
|
||||
|
||||
inline float int_to_float(const int &value)
|
||||
inline float int_to_float(const int32_t &value)
|
||||
{
|
||||
return float(value);
|
||||
}
|
||||
|
||||
inline float3 int_to_float3(const int &value)
|
||||
inline float3 int_to_float3(const int32_t &value)
|
||||
{
|
||||
return float_to_float3(int_to_float(value));
|
||||
}
|
||||
|
||||
inline float4 int_to_color(const int &value)
|
||||
inline float4 int_to_color(const int32_t &value)
|
||||
{
|
||||
return float_to_color(int_to_float(value));
|
||||
}
|
||||
|
||||
inline float4 int_to_float4(const int &value)
|
||||
inline float4 int_to_float4(const int32_t &value)
|
||||
{
|
||||
return float_to_float4(int_to_float(value));
|
||||
}
|
||||
@@ -68,7 +70,7 @@ inline float float3_to_float(const float3 &value)
|
||||
return math::reduce_add(value) / 3.0f;
|
||||
}
|
||||
|
||||
inline int float3_to_int(const float3 &value)
|
||||
inline int32_t float3_to_int(const float3 &value)
|
||||
{
|
||||
return float_to_int(float3_to_float(value));
|
||||
}
|
||||
@@ -92,7 +94,7 @@ inline float color_to_float(const float4 &value)
|
||||
return IMB_colormanagement_get_luminance(value);
|
||||
}
|
||||
|
||||
inline int color_to_int(const float4 &value)
|
||||
inline int32_t color_to_int(const float4 &value)
|
||||
{
|
||||
return float_to_int(color_to_float(value));
|
||||
}
|
||||
@@ -116,7 +118,7 @@ inline float float4_to_float(const float4 &value)
|
||||
return math::reduce_add(value) / 4.0f;
|
||||
}
|
||||
|
||||
inline int float4_to_int(const float4 &value)
|
||||
inline int32_t float4_to_int(const float4 &value)
|
||||
{
|
||||
return float_to_int(float4_to_float(value));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user