GPUTexture: Add texture usage flag to all texture creation

All usages are currently placeholder GPU_TEXTURE_USAGE_GENERAL.
This commit is contained in:
2023-02-25 01:49:26 +01:00
committed by Gitea
parent e01b140fb2
commit 3d6578b33e
14 changed files with 75 additions and 166 deletions

View File

@@ -85,7 +85,8 @@ void MorphologicalDistanceFeatherWeights::compute_weights(int radius)
weights[i] /= sum;
}
weights_texture_ = GPU_texture_create_1d("Weights", size, 1, GPU_R16F, weights.data());
weights_texture_ = GPU_texture_create_1d_ex(
"Weights", size, 1, GPU_R16F, GPU_TEXTURE_USAGE_GENERAL, weights.data());
}
/* Computes a falloff that is equal to 1 at an input of zero and decrease to zero at an input of 1,
@@ -128,8 +129,8 @@ void MorphologicalDistanceFeatherWeights::compute_distance_falloffs(int type, in
falloffs[i] = compute_distance_falloff(type, i * scale);
}
distance_falloffs_texture_ = GPU_texture_create_1d(
"Distance Factors", size, 1, GPU_R16F, falloffs.data());
distance_falloffs_texture_ = GPU_texture_create_1d_ex(
"Distance Factors", size, 1, GPU_R16F, GPU_TEXTURE_USAGE_GENERAL, falloffs.data());
}
void MorphologicalDistanceFeatherWeights::bind_weights_as_texture(GPUShader *shader,

View File

@@ -93,7 +93,8 @@ SymmetricBlurWeights::SymmetricBlurWeights(int type, float2 radius)
}
}
texture_ = GPU_texture_create_2d("Weights", size.x, size.y, 1, GPU_R16F, weights.data());
texture_ = GPU_texture_create_2d_ex(
"Weights", size.x, size.y, 1, GPU_R16F, GPU_TEXTURE_USAGE_GENERAL, weights.data());
}
SymmetricBlurWeights::~SymmetricBlurWeights()

View File

@@ -70,7 +70,8 @@ SymmetricSeparableBlurWeights::SymmetricSeparableBlurWeights(int type, float rad
weights[i] /= sum;
}
texture_ = GPU_texture_create_1d("Weights", size, 1, GPU_R16F, weights.data());
texture_ = GPU_texture_create_1d_ex(
"Weights", size, 1, GPU_R16F, GPU_TEXTURE_USAGE_GENERAL, weights.data());
}
SymmetricSeparableBlurWeights::~SymmetricSeparableBlurWeights()

View File

@@ -504,9 +504,11 @@ static bool workbench_render_framebuffers_init(void)
* the other views will reuse these buffers */
if (dtxl->color == nullptr) {
BLI_assert(dtxl->depth == nullptr);
dtxl->color = GPU_texture_create_2d("txl.color", size.x, size.y, 1, GPU_RGBA16F, nullptr);
dtxl->depth = GPU_texture_create_2d(
"txl.depth", size.x, size.y, 1, GPU_DEPTH24_STENCIL8, nullptr);
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL;
dtxl->color = GPU_texture_create_2d_ex(
"txl.color", size.x, size.y, 1, GPU_RGBA16F, usage, nullptr);
dtxl->depth = GPU_texture_create_2d_ex(
"txl.depth", size.x, size.y, 1, GPU_DEPTH24_STENCIL8, usage, nullptr);
}
if (!(dtxl->depth && dtxl->color)) {

View File

@@ -80,8 +80,8 @@ void immDrawPixelsTexScaledFullSize(const IMMDrawPixelsTexState *state,
const bool use_mipmap = use_filter && ((draw_width < img_w) || (draw_height < img_h));
const int mip_len = use_mipmap ? 9999 : 1;
GPUTexture *tex = GPU_texture_create_2d(
"immDrawPixels", img_w, img_h, mip_len, gpu_format, NULL);
GPUTexture *tex = GPU_texture_create_2d_ex(
"immDrawPixels", img_w, img_h, mip_len, gpu_format, GPU_TEXTURE_USAGE_GENERAL, NULL);
const bool use_float_data = ELEM(gpu_format, GPU_RGBA16F, GPU_RGB16F, GPU_R16F);
eGPUDataFormat gpu_data_format = (use_float_data) ? GPU_DATA_FLOAT : GPU_DATA_UBYTE;
@@ -170,7 +170,8 @@ void immDrawPixelsTexTiled_scaling_clipping(IMMDrawPixelsTexState *state,
eGPUDataFormat gpu_data = (use_float_data) ? GPU_DATA_FLOAT : GPU_DATA_UBYTE;
size_t stride = components * ((use_float_data) ? sizeof(float) : sizeof(uchar));
GPUTexture *tex = GPU_texture_create_2d("immDrawPixels", tex_w, tex_h, 1, gpu_format, NULL);
GPUTexture *tex = GPU_texture_create_2d_ex(
"immDrawPixels", tex_w, tex_h, 1, gpu_format, GPU_TEXTURE_USAGE_GENERAL, NULL);
GPU_texture_filter_mode(tex, use_filter);
GPU_texture_wrap_mode(tex, false, true);

View File

@@ -323,8 +323,9 @@ GPUTexture *GPU_texture_create_cube_array_ex(const char *name,
eGPUTextureUsage usage,
const float *data);
/**
* DDS texture loading. Return NULL if support is not available.
* DDS texture loading. Return NULL if compressed texture support is not available.
* \a data should hold all the data for \a mip_len mipmaps.
* The data is expected to be in compressed form. This isn't going to compress un-compress data.
*/
GPUTexture *GPU_texture_create_compressed_2d_ex(const char *name,
int width,
@@ -334,55 +335,6 @@ GPUTexture *GPU_texture_create_compressed_2d_ex(const char *name,
eGPUTextureUsage usage,
const void *data);
/* Standard texture functions. */
GPUTexture *GPU_texture_create_1d(
const char *name, int width, int mip_len, eGPUTextureFormat format, const float *data);
GPUTexture *GPU_texture_create_1d_array(const char *name,
int width,
int layer_len,
int mip_len,
eGPUTextureFormat format,
const float *data);
GPUTexture *GPU_texture_create_2d(const char *name,
int width,
int height,
int mip_len,
eGPUTextureFormat format,
const float *data);
GPUTexture *GPU_texture_create_2d_array(const char *name,
int width,
int height,
int layer_len,
int mip_len,
eGPUTextureFormat format,
const float *data);
GPUTexture *GPU_texture_create_3d(const char *name,
int width,
int height,
int depth,
int mip_len,
eGPUTextureFormat format,
const void *data);
GPUTexture *GPU_texture_create_cube(
const char *name, int width, int mip_len, eGPUTextureFormat format, const float *data);
GPUTexture *GPU_texture_create_cube_array(const char *name,
int width,
int layer_len,
int mip_len,
eGPUTextureFormat format,
const float *data);
/**
* DDS texture loading. Return NULL if compressed texture support is not available.
* \a data should hold all the data for \a mip_len mipmaps.
* The data is expected to be in compressed form. This isn't going to compress un-compress data.
*/
GPUTexture *GPU_texture_create_compressed_2d(const char *name,
int width,
int height,
int mip_len,
eGPUTextureFormat format,
const void *data);
/**
* Create a buffer texture that allow access to a buffer \a vertex_buf through a sampler of type
* `(FLOAT/INT/UINT)_BUFFER`.

View File

@@ -233,13 +233,14 @@ static void gpu_material_sky_texture_build(GPUMaterial *mat)
return;
}
mat->sky_tex = GPU_texture_create_2d_array("mat_sky",
GPU_SKY_WIDTH,
GPU_SKY_HEIGHT,
mat->sky_builder->current_layer,
1,
GPU_RGBA32F,
(float *)mat->sky_builder->pixels);
mat->sky_tex = GPU_texture_create_2d_array_ex("mat_sky",
GPU_SKY_WIDTH,
GPU_SKY_HEIGHT,
mat->sky_builder->current_layer,
1,
GPU_RGBA32F,
GPU_TEXTURE_USAGE_GENERAL,
(float *)mat->sky_builder->pixels);
MEM_freeN(mat->sky_builder);
mat->sky_builder = NULL;

View File

@@ -403,69 +403,6 @@ GPUTexture *GPU_texture_create_compressed_2d_ex(const char *name,
return reinterpret_cast<GPUTexture *>(tex);
}
GPUTexture *GPU_texture_create_1d(
const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
{
return GPU_texture_create_1d_ex(name, w, mip_len, format, GPU_TEXTURE_USAGE_GENERAL, data);
}
GPUTexture *GPU_texture_create_1d_array(
const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
{
return GPU_texture_create_1d_array_ex(
name, w, h, mip_len, format, GPU_TEXTURE_USAGE_GENERAL, data);
}
GPUTexture *GPU_texture_create_2d(
const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data)
{
return GPU_texture_create_2d_ex(name, w, h, mips, format, GPU_TEXTURE_USAGE_GENERAL, data);
}
GPUTexture *GPU_texture_create_2d_array(const char *name,
int w,
int h,
int d,
int mip_len,
eGPUTextureFormat format,
const float *data)
{
return GPU_texture_create_2d_array_ex(
name, w, h, d, mip_len, format, GPU_TEXTURE_USAGE_GENERAL, data);
}
GPUTexture *GPU_texture_create_3d(const char *name,
int w,
int h,
int d,
int mip_len,
eGPUTextureFormat texture_format,
const void *data)
{
return GPU_texture_create_3d_ex(
name, w, h, d, mip_len, texture_format, GPU_TEXTURE_USAGE_GENERAL, data);
}
GPUTexture *GPU_texture_create_cube(
const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
{
return GPU_texture_create_cube_ex(name, w, mip_len, format, GPU_TEXTURE_USAGE_GENERAL, data);
}
GPUTexture *GPU_texture_create_cube_array(
const char *name, int w, int d, int mip_len, eGPUTextureFormat format, const float *data)
{
return GPU_texture_create_cube_array_ex(
name, w, d, mip_len, format, GPU_TEXTURE_USAGE_GENERAL, data);
}
GPUTexture *GPU_texture_create_compressed_2d(
const char *name, int w, int h, int miplen, eGPUTextureFormat format, const void *data)
{
return GPU_texture_create_compressed_2d_ex(
name, w, h, miplen, format, GPU_TEXTURE_USAGE_GENERAL, data);
}
GPUTexture *GPU_texture_create_from_vertbuf(const char *name, GPUVertBuf *vert)
{
#ifndef NDEBUG

View File

@@ -106,8 +106,8 @@ void MTLContext::set_ghost_context(GHOST_ContextHandle ghostCtxHandle)
/* Add default texture for cases where no other framebuffer is bound */
if (!default_fbo_gputexture_) {
default_fbo_gputexture_ = static_cast<gpu::MTLTexture *>(
unwrap(GPU_texture_create_2d(__func__, 16, 16, 1, GPU_RGBA16F, nullptr)));
default_fbo_gputexture_ = static_cast<gpu::MTLTexture *>(unwrap(GPU_texture_create_2d_ex(
__func__, 16, 16, 1, GPU_RGBA16F, GPU_TEXTURE_USAGE_GENERAL, nullptr)));
}
mtl_back_left->add_color_attachment(default_fbo_gputexture_, 0, 0, 0);
@@ -548,27 +548,30 @@ gpu::MTLTexture *MTLContext::get_dummy_texture(eGPUTextureType type,
/* Create dummy texture based on desired type. */
GPUTexture *tex = nullptr;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL;
switch (type) {
case GPU_TEXTURE_1D:
tex = GPU_texture_create_1d("Dummy 1D", 128, 1, format, nullptr);
tex = GPU_texture_create_1d_ex("Dummy 1D", 128, 1, format, usage, nullptr);
break;
case GPU_TEXTURE_1D_ARRAY:
tex = GPU_texture_create_1d_array("Dummy 1DArray", 128, 1, 1, format, nullptr);
tex = GPU_texture_create_1d_array_ex("Dummy 1DArray", 128, 1, 1, format, usage, nullptr);
break;
case GPU_TEXTURE_2D:
tex = GPU_texture_create_2d("Dummy 2D", 128, 128, 1, format, nullptr);
tex = GPU_texture_create_2d_ex("Dummy 2D", 128, 128, 1, format, usage, nullptr);
break;
case GPU_TEXTURE_2D_ARRAY:
tex = GPU_texture_create_2d_array("Dummy 2DArray", 128, 128, 1, 1, format, nullptr);
tex = GPU_texture_create_2d_array_ex(
"Dummy 2DArray", 128, 128, 1, 1, format, usage, nullptr);
break;
case GPU_TEXTURE_3D:
tex = GPU_texture_create_3d("Dummy 3D", 128, 128, 1, 1, format, nullptr);
tex = GPU_texture_create_3d_ex("Dummy 3D", 128, 128, 1, 1, format, usage, nullptr);
break;
case GPU_TEXTURE_CUBE:
tex = GPU_texture_create_cube("Dummy Cube", 128, 1, format, nullptr);
tex = GPU_texture_create_cube_ex("Dummy Cube", 128, 1, format, usage, nullptr);
break;
case GPU_TEXTURE_CUBE_ARRAY:
tex = GPU_texture_create_cube_array("Dummy CubeArray", 128, 1, 1, format, nullptr);
tex = GPU_texture_create_cube_array_ex(
"Dummy CubeArray", 128, 1, 1, format, usage, nullptr);
break;
case GPU_TEXTURE_BUFFER:
if (!dummy_verts_[sampler_format]) {

View File

@@ -42,8 +42,8 @@ static void test_gpu_shader_compute_2d()
EXPECT_NE(shader, nullptr);
/* Create texture to store result and attach to shader. */
GPUTexture *texture = GPU_texture_create_2d(
"gpu_shader_compute_2d", SIZE, SIZE, 1, GPU_RGBA32F, nullptr);
GPUTexture *texture = GPU_texture_create_2d_ex(
"gpu_shader_compute_2d", SIZE, SIZE, 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr);
EXPECT_NE(texture, nullptr);
GPU_shader_bind(shader);
@@ -88,8 +88,8 @@ static void test_gpu_shader_compute_1d()
EXPECT_NE(shader, nullptr);
/* Construct Texture. */
GPUTexture *texture = GPU_texture_create_1d(
"gpu_shader_compute_1d", SIZE, 1, GPU_RGBA32F, nullptr);
GPUTexture *texture = GPU_texture_create_1d_ex(
"gpu_shader_compute_1d", SIZE, 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr);
EXPECT_NE(texture, nullptr);
GPU_shader_bind(shader);

View File

@@ -340,12 +340,13 @@ GPUTexture *IMB_create_gpu_texture(const char *name,
fprintf(stderr, "Unable to load non-power-of-two DXT image resolution,");
}
else {
tex = GPU_texture_create_compressed_2d(name,
ibuf->x,
ibuf->y,
ibuf->dds_data.nummipmaps,
compressed_format,
ibuf->dds_data.data);
tex = GPU_texture_create_compressed_2d_ex(name,
ibuf->x,
ibuf->y,
ibuf->dds_data.nummipmaps,
compressed_format,
GPU_TEXTURE_USAGE_GENERAL,
ibuf->dds_data.data);
if (tex != NULL) {
return tex;

View File

@@ -204,35 +204,38 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *arg
}
else {
const char *name = "python_texture";
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL;
if (is_cubemap) {
if (layers) {
tex = GPU_texture_create_cube_array(
name, size[0], layers, 1, pygpu_textureformat.value_found, data);
tex = GPU_texture_create_cube_array_ex(
name, size[0], layers, 1, pygpu_textureformat.value_found, usage, data);
}
else {
tex = GPU_texture_create_cube(name, size[0], 1, pygpu_textureformat.value_found, data);
tex = GPU_texture_create_cube_ex(
name, size[0], 1, pygpu_textureformat.value_found, usage, data);
}
}
else if (layers) {
if (len == 2) {
tex = GPU_texture_create_2d_array(
name, size[0], size[1], layers, 1, pygpu_textureformat.value_found, data);
tex = GPU_texture_create_2d_array_ex(
name, size[0], size[1], layers, 1, pygpu_textureformat.value_found, usage, data);
}
else {
tex = GPU_texture_create_1d_array(
name, size[0], layers, 1, pygpu_textureformat.value_found, data);
tex = GPU_texture_create_1d_array_ex(
name, size[0], layers, 1, pygpu_textureformat.value_found, usage, data);
}
}
else if (len == 3) {
tex = GPU_texture_create_3d(
name, size[0], size[1], size[2], 1, pygpu_textureformat.value_found, data);
tex = GPU_texture_create_3d_ex(
name, size[0], size[1], size[2], 1, pygpu_textureformat.value_found, usage, data);
}
else if (len == 2) {
tex = GPU_texture_create_2d(
name, size[0], size[1], 1, pygpu_textureformat.value_found, data);
tex = GPU_texture_create_2d_ex(
name, size[0], size[1], 1, pygpu_textureformat.value_found, usage, data);
}
else {
tex = GPU_texture_create_1d(name, size[0], 1, pygpu_textureformat.value_found, data);
tex = GPU_texture_create_1d_ex(
name, size[0], 1, pygpu_textureformat.value_found, usage, data);
}
}

View File

@@ -231,8 +231,9 @@ static void wm_software_cursor_draw_bitmap(const int event_xy[2],
GPU_blend(GPU_BLEND_ALPHA);
float gl_matrix[4][4];
GPUTexture *texture = GPU_texture_create_2d(
"softeare_cursor", bitmap->data_size[0], bitmap->data_size[1], 1, GPU_RGBA8, NULL);
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL;
GPUTexture *texture = GPU_texture_create_2d_ex(
"softeare_cursor", bitmap->data_size[0], bitmap->data_size[1], 1, GPU_RGBA8, usage, NULL);
GPU_texture_update(texture, GPU_DATA_UBYTE, bitmap->data);
GPU_texture_filter_mode(texture, false);