GPU: Add Texture::debug_clear
Clear uninitialized textures to NaN/debug values. Enabled for `--debug-gpu` only. Pull Request: https://projects.blender.org/blender/blender/pulls/113781
This commit is contained in:
parent
25c2b17266
commit
6f125661e6
|
@ -64,6 +64,8 @@
|
|||
#include "draw_manager.h"
|
||||
#include "draw_texture_pool.h"
|
||||
|
||||
#include "BKE_global.h"
|
||||
|
||||
#include "BLI_math_vector_types.hh"
|
||||
#include "BLI_span.hh"
|
||||
#include "BLI_utildefines.h"
|
||||
|
@ -858,6 +860,25 @@ class Texture : NonCopyable {
|
|||
GPU_texture_clear(tx_, GPU_DATA_INT, &values[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the texture to NaN for floats, or a to debug value for ints.
|
||||
* (For debugging unitialized data issues)
|
||||
*/
|
||||
void debug_clear()
|
||||
{
|
||||
if (GPU_texture_has_float_format(this->tx_) || GPU_texture_has_normalized_format(this->tx_)) {
|
||||
this->clear(float4(NAN_FLT));
|
||||
}
|
||||
else if (GPU_texture_has_integer_format(this->tx_)) {
|
||||
if (GPU_texture_has_signed_format(this->tx_)) {
|
||||
this->clear(int4(0xF0F0F0F0));
|
||||
}
|
||||
else {
|
||||
this->clear(uint4(0xF0F0F0F0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a buffer containing the texture data for the specified miplvl.
|
||||
* The memory block needs to be manually freed by MEM_freeN().
|
||||
|
@ -923,6 +944,9 @@ class Texture : NonCopyable {
|
|||
}
|
||||
if (tx_ == nullptr) {
|
||||
tx_ = create(w, h, d, mip_len, format, usage, data, layered, cubemap);
|
||||
if (data == nullptr && (G.debug & G_DEBUG_GPU)) {
|
||||
debug_clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -981,6 +1005,10 @@ class TextureFromPool : public Texture, NonMovable {
|
|||
|
||||
this->tx_ = DRW_texture_pool_texture_acquire(
|
||||
DST.vmempool->texture_pool, UNPACK2(extent), format, usage);
|
||||
|
||||
if (G.debug & G_DEBUG_GPU) {
|
||||
debug_clear();
|
||||
}
|
||||
}
|
||||
|
||||
void release()
|
||||
|
|
|
@ -990,6 +990,21 @@ bool GPU_texture_has_stencil_format(const GPUTexture *texture);
|
|||
*/
|
||||
bool GPU_texture_has_integer_format(const GPUTexture *texture);
|
||||
|
||||
/**
|
||||
* Return true if the texture format is a float type.
|
||||
*/
|
||||
bool GPU_texture_has_float_format(const GPUTexture *tex);
|
||||
|
||||
/**
|
||||
* Return true if the texture format is an integer normalized type.
|
||||
*/
|
||||
bool GPU_texture_has_normalized_format(const GPUTexture *tex);
|
||||
|
||||
/**
|
||||
* Return true if the texture format is a signed type.
|
||||
*/
|
||||
bool GPU_texture_has_signed_format(const GPUTexture *tex);
|
||||
|
||||
/**
|
||||
* Returns the pixel dimensions of a texture's mip-map level.
|
||||
* \a size is expected to be a pointer to a vector of dimension matching the texture's dimension
|
||||
|
|
|
@ -920,6 +920,22 @@ bool GPU_texture_has_integer_format(const GPUTexture *tex)
|
|||
return (reinterpret_cast<const Texture *>(tex)->format_flag_get() & GPU_FORMAT_INTEGER) != 0;
|
||||
}
|
||||
|
||||
bool GPU_texture_has_float_format(const GPUTexture *tex)
|
||||
{
|
||||
return (reinterpret_cast<const Texture *>(tex)->format_flag_get() & GPU_FORMAT_FLOAT) != 0;
|
||||
}
|
||||
|
||||
bool GPU_texture_has_normalized_format(const GPUTexture *tex)
|
||||
{
|
||||
return (reinterpret_cast<const Texture *>(tex)->format_flag_get() &
|
||||
GPU_FORMAT_NORMALIZED_INTEGER) != 0;
|
||||
}
|
||||
|
||||
bool GPU_texture_has_signed_format(const GPUTexture *tex)
|
||||
{
|
||||
return (reinterpret_cast<const Texture *>(tex)->format_flag_get() & GPU_FORMAT_SIGNED) != 0;
|
||||
}
|
||||
|
||||
bool GPU_texture_is_cube(const GPUTexture *tex)
|
||||
{
|
||||
return (reinterpret_cast<const Texture *>(tex)->type_get() & GPU_TEXTURE_CUBE) != 0;
|
||||
|
|
Loading…
Reference in New Issue