Cleanup: use const arguments

This commit is contained in:
Campbell Barton
2024-07-30 12:23:09 +10:00
parent 4dfd8e33e0
commit d8c2301ee8
6 changed files with 65 additions and 57 deletions

View File

@@ -31,7 +31,7 @@ template<typename keyT, template<typename> typename hashT> class AllocStringStor
* *
* \return `true` if the \a key is found in storage, false otherwise. * \return `true` if the \a key is found in storage, false otherwise.
*/ */
bool contains(keyT &key) bool contains(const keyT &key)
{ {
return storage_.count(key) != 0; return storage_.count(key) != 0;
} }
@@ -41,7 +41,7 @@ template<typename keyT, template<typename> typename hashT> class AllocStringStor
* *
* \return A pointer to the stored string if \a key is found, `nullptr` otherwise. * \return A pointer to the stored string if \a key is found, `nullptr` otherwise.
*/ */
const char *find(keyT &key) const char *find(const keyT &key)
{ {
if (storage_.count(key) != 0) { if (storage_.count(key) != 0) {
return storage_[key].c_str(); return storage_[key].c_str();
@@ -56,7 +56,7 @@ template<typename keyT, template<typename> typename hashT> class AllocStringStor
* \param alloc_string: The alloc string to store at \a key. * \param alloc_string: The alloc string to store at \a key.
* \return A pointer to the inserted stored string. * \return A pointer to the inserted stored string.
*/ */
const char *insert(keyT &key, std::string alloc_string) const char *insert(const keyT &key, std::string alloc_string)
{ {
#ifndef NDEBUG #ifndef NDEBUG
assert(storage_.count(key) == 0); assert(storage_.count(key) == 0);

View File

@@ -210,7 +210,7 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
/* Upload each tile one by one. */ /* Upload each tile one by one. */
LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
ImageTile_Runtime *tile_runtime = &tile->runtime; const ImageTile_Runtime *tile_runtime = &tile->runtime;
const int tilelayer = tile_runtime->tilearray_layer; const int tilelayer = tile_runtime->tilearray_layer;
const int *tileoffset = tile_runtime->tilearray_offset; const int *tileoffset = tile_runtime->tilearray_offset;
const int *tilesize = tile_runtime->tilearray_size; const int *tilesize = tile_runtime->tilearray_size;

View File

@@ -295,10 +295,10 @@ void VolumeProbeModule::set_view(View & /*view*/)
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ; eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ;
int3 grid_size = int3(cache->size); int3 grid_size = int3(cache->size);
if (cache->baking.L0) { if (cache->baking.L0) {
irradiance_a_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (float *)cache->baking.L0); irradiance_a_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (const float *)cache->baking.L0);
irradiance_b_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (float *)cache->baking.L1_a); irradiance_b_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (const float *)cache->baking.L1_a);
irradiance_c_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (float *)cache->baking.L1_b); irradiance_c_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (const float *)cache->baking.L1_b);
irradiance_d_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (float *)cache->baking.L1_c); irradiance_d_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (const float *)cache->baking.L1_c);
validity_tx.ensure_3d(GPU_R16F, grid_size, usage, cache->baking.validity); validity_tx.ensure_3d(GPU_R16F, grid_size, usage, cache->baking.validity);
if (cache->baking.validity == nullptr) { if (cache->baking.validity == nullptr) {
/* Avoid displaying garbage data. */ /* Avoid displaying garbage data. */
@@ -306,10 +306,13 @@ void VolumeProbeModule::set_view(View & /*view*/)
} }
} }
else if (cache->irradiance.L0) { else if (cache->irradiance.L0) {
irradiance_a_tx.ensure_3d(GPU_RGB16F, grid_size, usage, (float *)cache->irradiance.L0); irradiance_a_tx.ensure_3d(GPU_RGB16F, grid_size, usage, (const float *)cache->irradiance.L0);
irradiance_b_tx.ensure_3d(GPU_RGB16F, grid_size, usage, (float *)cache->irradiance.L1_a); irradiance_b_tx.ensure_3d(
irradiance_c_tx.ensure_3d(GPU_RGB16F, grid_size, usage, (float *)cache->irradiance.L1_b); GPU_RGB16F, grid_size, usage, (const float *)cache->irradiance.L1_a);
irradiance_d_tx.ensure_3d(GPU_RGB16F, grid_size, usage, (float *)cache->irradiance.L1_c); irradiance_c_tx.ensure_3d(
GPU_RGB16F, grid_size, usage, (const float *)cache->irradiance.L1_b);
irradiance_d_tx.ensure_3d(
GPU_RGB16F, grid_size, usage, (const float *)cache->irradiance.L1_c);
validity_tx.ensure_3d(GPU_R8, grid_size, usage); validity_tx.ensure_3d(GPU_R8, grid_size, usage);
if (cache->connectivity.validity) { if (cache->connectivity.validity) {
/* TODO(fclem): Make texture creation API work with different data types. */ /* TODO(fclem): Make texture creation API work with different data types. */
@@ -333,7 +336,7 @@ void VolumeProbeModule::set_view(View & /*view*/)
if (irradiance_a_tx.is_valid() == false) { if (irradiance_a_tx.is_valid() == false) {
inst_.info += "Error: Could not allocate irradiance staging texture\n"; inst_.info += "Error: Could not allocate irradiance staging texture\n";
/* Avoid undefined behavior with uninitialized values. Still load a clear texture. */ /* Avoid undefined behavior with uninitialized values. Still load a clear texture. */
float4 zero(0.0f); const float4 zero(0.0f);
irradiance_a_tx.ensure_3d(GPU_RGB16F, int3(1), usage, zero); irradiance_a_tx.ensure_3d(GPU_RGB16F, int3(1), usage, zero);
irradiance_b_tx.ensure_3d(GPU_RGB16F, int3(1), usage, zero); irradiance_b_tx.ensure_3d(GPU_RGB16F, int3(1), usage, zero);
irradiance_c_tx.ensure_3d(GPU_RGB16F, int3(1), usage, zero); irradiance_c_tx.ensure_3d(GPU_RGB16F, int3(1), usage, zero);
@@ -349,10 +352,10 @@ void VolumeProbeModule::set_view(View & /*view*/)
draw::Texture visibility_c_tx = {"visibility_c_tx"}; draw::Texture visibility_c_tx = {"visibility_c_tx"};
draw::Texture visibility_d_tx = {"visibility_d_tx"}; draw::Texture visibility_d_tx = {"visibility_d_tx"};
if (visibility_available) { if (visibility_available) {
visibility_a_tx.ensure_3d(GPU_R16F, grid_size, usage, (float *)cache->visibility.L0); visibility_a_tx.ensure_3d(GPU_R16F, grid_size, usage, (const float *)cache->visibility.L0);
visibility_b_tx.ensure_3d(GPU_R16F, grid_size, usage, (float *)cache->visibility.L1_a); visibility_b_tx.ensure_3d(GPU_R16F, grid_size, usage, (const float *)cache->visibility.L1_a);
visibility_c_tx.ensure_3d(GPU_R16F, grid_size, usage, (float *)cache->visibility.L1_b); visibility_c_tx.ensure_3d(GPU_R16F, grid_size, usage, (const float *)cache->visibility.L1_b);
visibility_d_tx.ensure_3d(GPU_R16F, grid_size, usage, (float *)cache->visibility.L1_c); visibility_d_tx.ensure_3d(GPU_R16F, grid_size, usage, (const float *)cache->visibility.L1_c);
GPU_texture_swizzle_set(visibility_a_tx, "111r"); GPU_texture_swizzle_set(visibility_a_tx, "111r");
GPU_texture_swizzle_set(visibility_b_tx, "111r"); GPU_texture_swizzle_set(visibility_b_tx, "111r");
@@ -506,10 +509,10 @@ void VolumeProbeModule::debug_pass_draw(View &view, GPUFrameBuffer *view_fb)
Texture debug_data_tx = {"debug_data_tx"}; Texture debug_data_tx = {"debug_data_tx"};
if (inst_.debug_mode == eDebugMode::DEBUG_IRRADIANCE_CACHE_VALIDITY) { if (inst_.debug_mode == eDebugMode::DEBUG_IRRADIANCE_CACHE_VALIDITY) {
float *data; const float *data;
if (cache->baking.validity) { if (cache->baking.validity) {
data = (float *)cache->baking.validity; data = cache->baking.validity;
debug_data_tx.ensure_3d(GPU_R16F, grid_size, usage, (float *)data); debug_data_tx.ensure_3d(GPU_R16F, grid_size, usage, data);
} }
else if (cache->connectivity.validity) { else if (cache->connectivity.validity) {
debug_data_tx.ensure_3d(GPU_R8, grid_size, usage); debug_data_tx.ensure_3d(GPU_R8, grid_size, usage);
@@ -531,7 +534,7 @@ void VolumeProbeModule::debug_pass_draw(View &view, GPUFrameBuffer *view_fb)
} }
else { else {
if (cache->baking.virtual_offset) { if (cache->baking.virtual_offset) {
float *data = (float *)cache->baking.virtual_offset; const float *data = (const float *)cache->baking.virtual_offset;
debug_data_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, data); debug_data_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, data);
} }
else { else {
@@ -577,21 +580,24 @@ void VolumeProbeModule::display_pass_draw(View &view, GPUFrameBuffer *view_fb)
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ; eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ;
int3 grid_size = int3(cache->size); int3 grid_size = int3(cache->size);
if (cache->baking.L0) { if (cache->baking.L0) {
irradiance_a_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (float *)cache->baking.L0); irradiance_a_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (const float *)cache->baking.L0);
irradiance_b_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (float *)cache->baking.L1_a); irradiance_b_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (const float *)cache->baking.L1_a);
irradiance_c_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (float *)cache->baking.L1_b); irradiance_c_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (const float *)cache->baking.L1_b);
irradiance_d_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (float *)cache->baking.L1_c); irradiance_d_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (const float *)cache->baking.L1_c);
validity_tx.ensure_3d(GPU_R16F, grid_size, usage, (float *)cache->baking.validity); validity_tx.ensure_3d(GPU_R16F, grid_size, usage, (const float *)cache->baking.validity);
if (cache->baking.validity == nullptr) { if (cache->baking.validity == nullptr) {
/* Avoid displaying garbage data. */ /* Avoid displaying garbage data. */
validity_tx.clear(float4(0.0)); validity_tx.clear(float4(0.0));
} }
} }
else if (cache->irradiance.L0) { else if (cache->irradiance.L0) {
irradiance_a_tx.ensure_3d(GPU_RGB16F, grid_size, usage, (float *)cache->irradiance.L0); irradiance_a_tx.ensure_3d(GPU_RGB16F, grid_size, usage, (const float *)cache->irradiance.L0);
irradiance_b_tx.ensure_3d(GPU_RGB16F, grid_size, usage, (float *)cache->irradiance.L1_a); irradiance_b_tx.ensure_3d(
irradiance_c_tx.ensure_3d(GPU_RGB16F, grid_size, usage, (float *)cache->irradiance.L1_b); GPU_RGB16F, grid_size, usage, (const float *)cache->irradiance.L1_a);
irradiance_d_tx.ensure_3d(GPU_RGB16F, grid_size, usage, (float *)cache->irradiance.L1_c); irradiance_c_tx.ensure_3d(
GPU_RGB16F, grid_size, usage, (const float *)cache->irradiance.L1_b);
irradiance_d_tx.ensure_3d(
GPU_RGB16F, grid_size, usage, (const float *)cache->irradiance.L1_c);
validity_tx.ensure_3d(GPU_R8, grid_size, usage); validity_tx.ensure_3d(GPU_R8, grid_size, usage);
if (cache->connectivity.validity) { if (cache->connectivity.validity) {
/* TODO(fclem): Make texture creation API work with different data types. */ /* TODO(fclem): Make texture creation API work with different data types. */

View File

@@ -539,7 +539,7 @@ class Texture : NonCopyable {
eGPUTextureFormat format, eGPUTextureFormat format,
eGPUTextureUsage usage, eGPUTextureUsage usage,
int extent, int extent,
float *data = nullptr, const float *data = nullptr,
bool cubemap = false, bool cubemap = false,
int mip_len = 1) int mip_len = 1)
: name_(name) : name_(name)
@@ -552,7 +552,7 @@ class Texture : NonCopyable {
eGPUTextureUsage usage, eGPUTextureUsage usage,
int extent, int extent,
int layers, int layers,
float *data = nullptr, const float *data = nullptr,
bool cubemap = false, bool cubemap = false,
int mip_len = 1) int mip_len = 1)
: name_(name) : name_(name)
@@ -564,7 +564,7 @@ class Texture : NonCopyable {
eGPUTextureFormat format, eGPUTextureFormat format,
eGPUTextureUsage usage, eGPUTextureUsage usage,
int2 extent, int2 extent,
float *data = nullptr, const float *data = nullptr,
int mip_len = 1) int mip_len = 1)
: name_(name) : name_(name)
{ {
@@ -576,7 +576,7 @@ class Texture : NonCopyable {
eGPUTextureUsage usage, eGPUTextureUsage usage,
int2 extent, int2 extent,
int layers, int layers,
float *data = nullptr, const float *data = nullptr,
int mip_len = 1) int mip_len = 1)
: name_(name) : name_(name)
{ {
@@ -587,7 +587,7 @@ class Texture : NonCopyable {
eGPUTextureFormat format, eGPUTextureFormat format,
eGPUTextureUsage usage, eGPUTextureUsage usage,
int3 extent, int3 extent,
float *data = nullptr, const float *data = nullptr,
int mip_len = 1) int mip_len = 1)
: name_(name) : name_(name)
{ {
@@ -653,7 +653,7 @@ class Texture : NonCopyable {
bool ensure_1d(eGPUTextureFormat format, bool ensure_1d(eGPUTextureFormat format,
int extent, int extent,
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL, eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL,
float *data = nullptr, const float *data = nullptr,
int mip_len = 1) int mip_len = 1)
{ {
return ensure_impl(extent, 0, 0, mip_len, format, usage, data, false, false); return ensure_impl(extent, 0, 0, mip_len, format, usage, data, false, false);
@@ -667,7 +667,7 @@ class Texture : NonCopyable {
int extent, int extent,
int layers, int layers,
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL, eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL,
float *data = nullptr, const float *data = nullptr,
int mip_len = 1) int mip_len = 1)
{ {
BLI_assert(layers > 0); BLI_assert(layers > 0);
@@ -681,7 +681,7 @@ class Texture : NonCopyable {
bool ensure_2d(eGPUTextureFormat format, bool ensure_2d(eGPUTextureFormat format,
int2 extent, int2 extent,
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL, eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL,
float *data = nullptr, const float *data = nullptr,
int mip_len = 1) int mip_len = 1)
{ {
return ensure_impl(UNPACK2(extent), 0, mip_len, format, usage, data, false, false); return ensure_impl(UNPACK2(extent), 0, mip_len, format, usage, data, false, false);
@@ -695,7 +695,7 @@ class Texture : NonCopyable {
int2 extent, int2 extent,
int layers, int layers,
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL, eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL,
float *data = nullptr, const float *data = nullptr,
int mip_len = 1) int mip_len = 1)
{ {
BLI_assert(layers > 0); BLI_assert(layers > 0);
@@ -709,7 +709,7 @@ class Texture : NonCopyable {
bool ensure_3d(eGPUTextureFormat format, bool ensure_3d(eGPUTextureFormat format,
int3 extent, int3 extent,
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL, eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL,
float *data = nullptr, const float *data = nullptr,
int mip_len = 1) int mip_len = 1)
{ {
return ensure_impl(UNPACK3(extent), mip_len, format, usage, data, false, false); return ensure_impl(UNPACK3(extent), mip_len, format, usage, data, false, false);
@@ -736,7 +736,7 @@ class Texture : NonCopyable {
int extent, int extent,
int layers, int layers,
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL, eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL,
float *data = nullptr, const float *data = nullptr,
int mip_len = 1) int mip_len = 1)
{ {
return ensure_impl(extent, extent, layers, mip_len, format, usage, data, true, true); return ensure_impl(extent, extent, layers, mip_len, format, usage, data, true, true);
@@ -995,7 +995,7 @@ class Texture : NonCopyable {
int mip_len = 1, int mip_len = 1,
eGPUTextureFormat format = GPU_RGBA8, eGPUTextureFormat format = GPU_RGBA8,
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL, eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL,
float *data = nullptr, const float *data = nullptr,
bool layered = false, bool layered = false,
bool cubemap = false) bool cubemap = false)
@@ -1116,13 +1116,15 @@ class TextureFromPool : public Texture, NonMovable {
} }
/** Remove methods that are forbidden with this type of textures. */ /** Remove methods that are forbidden with this type of textures. */
bool ensure_1d(int, int, eGPUTextureFormat, eGPUTextureUsage, float *) = delete; bool ensure_1d(int, int, eGPUTextureFormat, eGPUTextureUsage, const float *) = delete;
bool ensure_1d_array(int, int, int, eGPUTextureFormat, eGPUTextureUsage, float *) = delete; bool ensure_1d_array(int, int, int, eGPUTextureFormat, eGPUTextureUsage, const float *) = delete;
bool ensure_2d(int, int, int, eGPUTextureFormat, eGPUTextureUsage, float *) = delete; bool ensure_2d(int, int, int, eGPUTextureFormat, eGPUTextureUsage, float *) = delete;
bool ensure_2d_array(int, int, int, int, eGPUTextureFormat, eGPUTextureUsage, float *) = delete; bool ensure_2d_array(int, int, int, int, eGPUTextureFormat, eGPUTextureUsage, const float *) =
bool ensure_3d(int, int, int, int, eGPUTextureFormat, eGPUTextureUsage, float *) = delete; delete;
bool ensure_cube(int, int, eGPUTextureFormat, eGPUTextureUsage, float *) = delete; bool ensure_3d(int, int, int, int, eGPUTextureFormat, eGPUTextureUsage, const float *) = delete;
bool ensure_cube_array(int, int, int, eGPUTextureFormat, eGPUTextureUsage, float *) = delete; bool ensure_cube(int, int, eGPUTextureFormat, eGPUTextureUsage, const float *) = delete;
bool ensure_cube_array(int, int, int, eGPUTextureFormat, eGPUTextureUsage, const float *) =
delete;
void filter_mode(bool) = delete; void filter_mode(bool) = delete;
void free() = delete; void free() = delete;
GPUTexture *mip_view(int) = delete; GPUTexture *mip_view(int) = delete;
@@ -1145,13 +1147,13 @@ class TextureRef : public Texture {
} }
/** Remove methods that are forbidden with this type of textures. */ /** Remove methods that are forbidden with this type of textures. */
bool ensure_1d(int, int, eGPUTextureFormat, float *) = delete; bool ensure_1d(int, int, eGPUTextureFormat, const float *) = delete;
bool ensure_1d_array(int, int, int, eGPUTextureFormat, float *) = delete; bool ensure_1d_array(int, int, int, eGPUTextureFormat, const float *) = delete;
bool ensure_2d(int, int, int, eGPUTextureFormat, float *) = delete; bool ensure_2d(int, int, int, eGPUTextureFormat, const float *) = delete;
bool ensure_2d_array(int, int, int, int, eGPUTextureFormat, float *) = delete; bool ensure_2d_array(int, int, int, int, eGPUTextureFormat, const float *) = delete;
bool ensure_3d(int, int, int, int, eGPUTextureFormat, float *) = delete; bool ensure_3d(int, int, int, int, eGPUTextureFormat, const float *) = delete;
bool ensure_cube(int, int, eGPUTextureFormat, float *) = delete; bool ensure_cube(int, int, eGPUTextureFormat, const float *) = delete;
bool ensure_cube_array(int, int, int, eGPUTextureFormat, float *) = delete; bool ensure_cube_array(int, int, int, eGPUTextureFormat, const float *) = delete;
void filter_mode(bool) = delete; void filter_mode(bool) = delete;
void free() = delete; void free() = delete;
GPUTexture *mip_view(int) = delete; GPUTexture *mip_view(int) = delete;

View File

@@ -970,7 +970,7 @@ std::string GLShader::workaround_geometry_shader_source_create(
ss << " gpu_pos[2] = gl_in[2].gl_Position;\n"; ss << " gpu_pos[2] = gl_in[2].gl_Position;\n";
} }
for (auto i : IndexRange(3)) { for (auto i : IndexRange(3)) {
for (StageInterfaceInfo *iface : info_modified.vertex_out_interfaces_) { for (const StageInterfaceInfo *iface : info_modified.vertex_out_interfaces_) {
for (auto &inout : iface->inouts) { for (auto &inout : iface->inouts) {
ss << " " << iface->instance_name << "_out." << inout.name; ss << " " << iface->instance_name << "_out." << inout.name;
ss << " = " << iface->instance_name << "_in[" << i << "]." << inout.name << ";\n"; ss << " = " << iface->instance_name << "_in[" << i << "]." << inout.name << ";\n";

View File

@@ -1730,7 +1730,7 @@ int DNA_struct_alignment(const SDNA *sdna, const int struct_nr)
const char *DNA_struct_identifier(struct SDNA *sdna, const int struct_index) const char *DNA_struct_identifier(struct SDNA *sdna, const int struct_index)
{ {
DNA_sdna_alias_data_ensure(sdna); DNA_sdna_alias_data_ensure(sdna);
SDNA_Struct *struct_info = sdna->structs[struct_index]; const SDNA_Struct *struct_info = sdna->structs[struct_index];
return sdna->alias.types[struct_info->type]; return sdna->alias.types[struct_info->type];
} }