Vulkan: Push constants #104880

Merged
Jeroen Bakker merged 73 commits from Jeroen-Bakker/blender:vulkan-push-constants into main 2023-03-06 12:29:06 +01:00
80 changed files with 1065 additions and 1214 deletions
Showing only changes of commit 0295a2e2fa - Show all commits

View File

@ -105,11 +105,12 @@ GPUShader *BlenderFallbackDisplayShader::bind(int width, int height)
/* Bind shader now to enable uniform assignment. */
GPU_shader_bind(shader_program_);
GPU_shader_uniform_int(shader_program_, image_texture_location_, 0);
int slot = 0;
GPU_shader_uniform_int_ex(shader_program_, image_texture_location_, 1, 1, &slot);
float size[2];
size[0] = width;
size[1] = height;
GPU_shader_uniform_vector(shader_program_, fullscreen_location_, 2, 1, size);
GPU_shader_uniform_float_ex(shader_program_, fullscreen_location_, 2, 1, size);
return shader_program_;
}

View File

@ -886,7 +886,7 @@ int RenderScheduler::get_num_samples_during_navigation(int resolution_divider) c
{
/* Special trick for fast navigation: schedule multiple samples during fast navigation
* (which will prefer to use lower resolution to keep up with refresh rate). This gives more
* usable visual feedback for artists. There are a couple of tricks though. */
* usable visual feedback for artists. */
if (is_denoise_active_during_update()) {
/* When denoising is used during navigation prefer using a higher resolution with less samples
@ -896,25 +896,12 @@ int RenderScheduler::get_num_samples_during_navigation(int resolution_divider) c
return 1;
}
if (resolution_divider <= pixel_size_) {
/* When resolution divider is at or below pixel size, schedule one sample. This doesn't effect
* the sample count at this resolution division, but instead assists in the calculation of
* the resolution divider. */
return 1;
}
if (resolution_divider == pixel_size_ * 2) {
/* When resolution divider is the previous step to the final resolution, schedule two samples.
* This is so that rendering on lower resolution does not exceed time that it takes to render
* first sample at the full resolution. */
return 2;
}
/* Always render 4 samples, even if scene is configured for less.
* The idea here is to have enough information on the screen. Resolution divider of 2 allows us
* to have 4 time extra samples, so overall worst case timing is the same as the final resolution
* at one sample. */
return 4;
/* Schedule samples equal to the resolution divider up to a maximum of 4.
* The idea is to have enough information on the screen by increasing the sample count as the
* resolution is decreased. */
/* NOTE: Changeing this formula will change the formula in
* "RenderScheduler::calculate_resolution_divider_for_time()"*/
return min(max(1, resolution_divider / pixel_size_), 4);
}
bool RenderScheduler::work_need_adaptive_filter() const
@ -1100,9 +1087,10 @@ void RenderScheduler::update_start_resolution_divider()
/* TODO(sergey): Need to add hysteresis to avoid resolution divider bouncing around when actual
* render time is somewhere on a boundary between two resolutions. */
/* Never increase resolution to higher than the pixel size (which is possible if the scene is
* simple and compute device is fast). */
start_resolution_divider_ = max(resolution_divider_for_update, pixel_size_);
/* Don't let resolution drop below the desired one. It's better to be slow than provide an
* unreadable viewport render. */
start_resolution_divider_ = min(resolution_divider_for_update,
default_start_resolution_divider_);
VLOG_WORK << "Calculated resolution divider is " << start_resolution_divider_;
}
@ -1187,24 +1175,24 @@ void RenderScheduler::check_time_limit_reached()
int RenderScheduler::calculate_resolution_divider_for_time(double desired_time, double actual_time)
{
/* TODO(sergey): There should a non-iterative analytical formula here. */
const double ratio_between_times = actual_time / desired_time;
int resolution_divider = 1;
/* We can pass "ratio_between_times" to "get_num_samples_during_navigation()" to get our
* navigation samples because the equation for calculating the resolution divider is as follows:
* "actual_time / desired_time = sqr(resolution_divider) / sample_count".
* While "resolution_divider" is less than or equal to 4, "resolution_divider = sample_count"
* (This relationship is determined in "get_num_samples_during_navigation()"). With some
* substitution we end up with "actual_time / desired_time = resolution_divider" while the
* resolution divider is less than or equal to 4. Once the resolution divider increases above 4,
* the relationsip of "actual_time / desired_time = resolution_divider" is no longer true,
* however the sample count retrieved from "get_num_samples_during_navigation()" is still
* accurate if we continue using this assumption. It should be noted that the interaction between
* pixel_size, sample count, and resolution divider are automatically accounted for and that's
* why pixel_size isn't included in any of the equations. */
const int navigation_samples = get_num_samples_during_navigation(
ceil_to_int(ratio_between_times));
/* This algorithm iterates through resolution dividers until a divider is found that achieves
* the desired render time. A limit of default_start_resolution_divider_ is put in place as the
* maximum resolution divider to avoid an unreadable viewport due to a low resolution.
* pre_resolution_division_samples and post_resolution_division_samples are used in this
* calculation to better predict the performance impact of changing resolution divisions as
* the sample count can also change between resolution divisions. */
while (actual_time > desired_time && resolution_divider < default_start_resolution_divider_) {
int pre_resolution_division_samples = get_num_samples_during_navigation(resolution_divider);
resolution_divider = resolution_divider * 2;
int post_resolution_division_samples = get_num_samples_during_navigation(resolution_divider);
actual_time /= 4.0 * pre_resolution_division_samples / post_resolution_division_samples;
}
return resolution_divider;
return ceil_to_int(sqrt(navigation_samples * ratio_between_times));
}
int calculate_resolution_divider_for_resolution(int width, int height, int resolution)

View File

@ -370,6 +370,7 @@ const bTheme U_theme_default = {
.clipping_border_3d = RGBA(0x3f3f3fff),
.bundle_solid = RGBA(0xc8c8c8ff),
.camera_path = RGBA(0x000000ff),
.camera_passepartout = RGBA(0x000000),
.gp_vertex_size = 3,
.gp_vertex = RGBA(0x000000ff),
.gp_vertex_select = RGBA(0xff8500ff),

View File

@ -23,11 +23,15 @@ struct ID;
namespace blender::asset_system {
class AssetLibrary;
class AssetRepresentation {
AssetIdentifier identifier_;
/** Indicate if this is a local or external asset, and as such, which of the union members below
* should be used. */
const bool is_local_id_ = false;
/** Asset library that owns this asset representation. */
const AssetLibrary *owner_asset_library_;
struct ExternalAsset {
std::string name;
@ -44,10 +48,13 @@ class AssetRepresentation {
/** Constructs an asset representation for an external ID. The asset will not be editable. */
AssetRepresentation(AssetIdentifier &&identifier,
StringRef name,
std::unique_ptr<AssetMetaData> metadata);
std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library);
/** Constructs an asset representation for an ID stored in the current file. This makes the asset
* local and fully editable. */
AssetRepresentation(AssetIdentifier &&identifier, ID &id);
AssetRepresentation(AssetIdentifier &&identifier,
ID &id,
const AssetLibrary &owner_asset_library);
AssetRepresentation(AssetRepresentation &&other);
/* Non-copyable type. */
AssetRepresentation(const AssetRepresentation &other) = delete;
@ -65,6 +72,7 @@ class AssetRepresentation {
AssetMetaData &get_metadata() const;
/** Returns if this asset is stored inside this current file, and as such fully editable. */
bool is_local_id() const;
const AssetLibrary &owner_asset_library() const;
};
} // namespace blender::asset_system

View File

@ -169,13 +169,14 @@ AssetRepresentation &AssetLibrary::add_external_asset(StringRef relative_asset_p
std::unique_ptr<AssetMetaData> metadata)
{
AssetIdentifier identifier = asset_identifier_from_library(relative_asset_path);
return asset_storage_->add_external_asset(std::move(identifier), name, std::move(metadata));
return asset_storage_->add_external_asset(
std::move(identifier), name, std::move(metadata), *this);
}
AssetRepresentation &AssetLibrary::add_local_id_asset(StringRef relative_asset_path, ID &id)
{
AssetIdentifier identifier = asset_identifier_from_library(relative_asset_path);
return asset_storage_->add_local_id_asset(std::move(identifier), id);
return asset_storage_->add_local_id_asset(std::move(identifier), id, *this);
}
bool AssetLibrary::remove_asset(AssetRepresentation &asset)

View File

@ -17,15 +17,24 @@ namespace blender::asset_system {
AssetRepresentation::AssetRepresentation(AssetIdentifier &&identifier,
StringRef name,
std::unique_ptr<AssetMetaData> metadata)
: identifier_(identifier), is_local_id_(false), external_asset_()
std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library)
: identifier_(identifier),
is_local_id_(false),
owner_asset_library_(&owner_asset_library),
external_asset_()
{
external_asset_.name = name;
external_asset_.metadata_ = std::move(metadata);
}
AssetRepresentation::AssetRepresentation(AssetIdentifier &&identifier, ID &id)
: identifier_(identifier), is_local_id_(true), local_asset_id_(&id)
AssetRepresentation::AssetRepresentation(AssetIdentifier &&identifier,
ID &id,
const AssetLibrary &owner_asset_library)
: identifier_(identifier),
is_local_id_(true),
owner_asset_library_(&owner_asset_library),
local_asset_id_(&id)
{
if (!id.asset_data) {
throw std::invalid_argument("Passed ID is not an asset");
@ -75,6 +84,11 @@ bool AssetRepresentation::is_local_id() const
return is_local_id_;
}
const AssetLibrary &AssetRepresentation::owner_asset_library() const
{
return *owner_asset_library_;
}
} // namespace blender::asset_system
using namespace blender;

View File

@ -15,18 +15,21 @@
namespace blender::asset_system {
AssetRepresentation &AssetStorage::add_local_id_asset(AssetIdentifier &&identifier, ID &id)
AssetRepresentation &AssetStorage::add_local_id_asset(AssetIdentifier &&identifier,
ID &id,
const AssetLibrary &owner_asset_library)
{
return *local_id_assets_.lookup_key_or_add(
std::make_unique<AssetRepresentation>(std::move(identifier), id));
std::make_unique<AssetRepresentation>(std::move(identifier), id, owner_asset_library));
}
AssetRepresentation &AssetStorage::add_external_asset(AssetIdentifier &&identifier,
StringRef name,
std::unique_ptr<AssetMetaData> metadata)
std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library)
{
return *external_assets_.lookup_key_or_add(
std::make_unique<AssetRepresentation>(std::move(identifier), name, std::move(metadata)));
return *external_assets_.lookup_key_or_add(std::make_unique<AssetRepresentation>(
std::move(identifier), name, std::move(metadata), owner_asset_library));
}
bool AssetStorage::remove_asset(AssetRepresentation &asset)

View File

@ -35,9 +35,12 @@ class AssetStorage {
/** See #AssetLibrary::add_external_asset(). */
AssetRepresentation &add_external_asset(AssetIdentifier &&identifier,
StringRef name,
std::unique_ptr<AssetMetaData> metadata);
std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library);
/** See #AssetLibrary::add_external_asset(). */
AssetRepresentation &add_local_id_asset(AssetIdentifier &&identifier, ID &id);
AssetRepresentation &add_local_id_asset(AssetIdentifier &&identifier,
ID &id,
const AssetLibrary &owner_asset_library);
/** See #AssetLibrary::remove_asset(). */
bool remove_asset(AssetRepresentation &asset);

View File

@ -120,7 +120,7 @@ static void fill_mesh_topology(const int vert_offset,
}
}
const bool has_caps = fill_caps && !main_cyclic && profile_cyclic;
const bool has_caps = fill_caps && !main_cyclic && profile_cyclic && profile_point_num > 2;
if (has_caps) {
const int poly_num = main_segment_num * profile_segment_num;
const int cap_loop_offset = loop_offset + poly_num * 4;
@ -271,7 +271,7 @@ static ResultOffsets calculate_result_offsets(const CurvesInfo &info, const bool
const int profile_point_num = profile_offsets.size(i_profile);
const int profile_segment_num = curves::segments_num(profile_point_num, profile_cyclic);
const bool has_caps = fill_caps && !main_cyclic && profile_cyclic;
const bool has_caps = fill_caps && !main_cyclic && profile_cyclic && profile_point_num > 2;
const int tube_face_num = main_segment_num * profile_segment_num;
vert_offset += main_point_num * profile_point_num;

View File

@ -612,6 +612,25 @@ TEST(string, StrFormatIntegerUnits)
EXPECT_STREQ("-2B", size_str);
}
TEST(string, StringNLen)
{
EXPECT_EQ(0, BLI_strnlen("", 0));
EXPECT_EQ(0, BLI_strnlen("", 1));
EXPECT_EQ(0, BLI_strnlen("", 100));
EXPECT_EQ(0, BLI_strnlen("x", 0));
EXPECT_EQ(1, BLI_strnlen("x", 1));
EXPECT_EQ(1, BLI_strnlen("x", 100));
// ü is \xc3\xbc
EXPECT_EQ(2, BLI_strnlen("ü", 100));
EXPECT_EQ(0, BLI_strnlen("this is a longer string", 0));
EXPECT_EQ(1, BLI_strnlen("this is a longer string", 1));
EXPECT_EQ(5, BLI_strnlen("this is a longer string", 5));
EXPECT_EQ(47, BLI_strnlen("This string writes about an agent without name.", 100));
}
struct WordInfo {
WordInfo() = default;
WordInfo(int start, int end) : start(start), end(end)

View File

@ -41,10 +41,10 @@ static float *parallel_reduction_dispatch(Context &context,
GPUTexture *reduced_texture = context.texture_pool().acquire(reduced_size, format);
GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
const int texture_image_unit = GPU_shader_get_texture_binding(shader, "input_tx");
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, "input_tx");
GPU_texture_bind(texture_to_reduce, texture_image_unit);
const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img");
GPU_texture_image_bind(reduced_texture, image_unit);
GPU_compute_dispatch(shader, reduced_size.x, reduced_size.y, 1);

View File

@ -135,7 +135,7 @@ void MorphologicalDistanceFeatherWeights::compute_distance_falloffs(int type, in
void MorphologicalDistanceFeatherWeights::bind_weights_as_texture(GPUShader *shader,
const char *texture_name) const
{
const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name);
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name);
GPU_texture_bind(weights_texture_, texture_image_unit);
}
@ -147,7 +147,7 @@ void MorphologicalDistanceFeatherWeights::unbind_weights_as_texture() const
void MorphologicalDistanceFeatherWeights::bind_distance_falloffs_as_texture(
GPUShader *shader, const char *texture_name) const
{
const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name);
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name);
GPU_texture_bind(distance_falloffs_texture_, texture_image_unit);
}

View File

@ -103,7 +103,7 @@ SymmetricBlurWeights::~SymmetricBlurWeights()
void SymmetricBlurWeights::bind_as_texture(GPUShader *shader, const char *texture_name) const
{
const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name);
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name);
GPU_texture_bind(texture_, texture_image_unit);
}

View File

@ -81,7 +81,7 @@ SymmetricSeparableBlurWeights::~SymmetricSeparableBlurWeights()
void SymmetricSeparableBlurWeights::bind_as_texture(GPUShader *shader,
const char *texture_name) const
{
const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name);
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name);
GPU_texture_bind(texture_, texture_image_unit);
}

View File

@ -82,7 +82,7 @@ void Result::bind_as_texture(GPUShader *shader, const char *texture_name) const
/* Make sure any prior writes to the texture are reflected before reading from it. */
GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name);
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name);
GPU_texture_bind(texture_, texture_image_unit);
}
@ -93,7 +93,7 @@ void Result::bind_as_image(GPUShader *shader, const char *image_name, bool read)
GPU_memory_barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS);
}
const int image_unit = GPU_shader_get_texture_binding(shader, image_name);
const int image_unit = GPU_shader_get_sampler_binding(shader, image_name);
GPU_texture_image_bind(texture_, image_unit);
}

View File

@ -95,14 +95,14 @@ void ShaderOperation::bind_material_resources(GPUShader *shader)
* no uniforms. */
GPUUniformBuf *ubo = GPU_material_uniform_buffer_get(material_);
if (ubo) {
GPU_uniformbuf_bind(ubo, GPU_shader_get_uniform_block_binding(shader, GPU_UBO_BLOCK_NAME));
GPU_uniformbuf_bind(ubo, GPU_shader_get_ubo_binding(shader, GPU_UBO_BLOCK_NAME));
}
/* Bind color band textures needed by curve and ramp nodes. */
ListBase textures = GPU_material_textures(material_);
LISTBASE_FOREACH (GPUMaterialTexture *, texture, &textures) {
if (texture->colorband) {
const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture->sampler_name);
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture->sampler_name);
GPU_texture_bind(*texture->colorband, texture_image_unit);
}
}

View File

@ -409,7 +409,7 @@ void ShadowDirectional::cascade_tilemaps_distribution(Light &light, const Camera
/* Offset in tiles from the origin to the center of the first tile-maps. */
int2 origin_offset = int2(round(float2(near_point) / tile_size));
/* Offset in tiles between the first andlod the last tile-maps. */
/* Offset in tiles between the first and the last tile-maps. */
int2 offset_vector = int2(round(farthest_tilemap_center / tile_size));
light.clipmap_base_offset = (offset_vector * (1 << 16)) / max_ii(levels_range.size() - 1, 1);

View File

@ -259,17 +259,16 @@ void ShadowPass::ShadowView::compute_visibility(ObjectBoundsBuf &bounds,
GPU_shader_uniform_1i(shader, "visibility_word_per_draw", word_per_draw);
GPU_shader_uniform_1b(shader, "force_fail_method", force_fail_method_);
GPU_shader_uniform_3fv(shader, "shadow_direction", light_direction_);
GPU_uniformbuf_bind(extruded_frustum_,
GPU_shader_get_uniform_block_binding(shader, "extruded_frustum"));
GPU_storagebuf_bind(bounds, GPU_shader_get_ssbo(shader, "bounds_buf"));
GPU_uniformbuf_bind(extruded_frustum_, GPU_shader_get_ubo_binding(shader, "extruded_frustum"));
GPU_storagebuf_bind(bounds, GPU_shader_get_ssbo_binding(shader, "bounds_buf"));
if (current_pass_type_ == ShadowPass::FORCED_FAIL) {
GPU_storagebuf_bind(visibility_buf_, GPU_shader_get_ssbo(shader, "visibility_buf"));
GPU_storagebuf_bind(visibility_buf_, GPU_shader_get_ssbo_binding(shader, "visibility_buf"));
}
else {
GPU_storagebuf_bind(pass_visibility_buf_,
GPU_shader_get_ssbo(shader, "pass_visibility_buf"));
GPU_shader_get_ssbo_binding(shader, "pass_visibility_buf"));
GPU_storagebuf_bind(fail_visibility_buf_,
GPU_shader_get_ssbo(shader, "fail_visibility_buf"));
GPU_shader_get_ssbo_binding(shader, "fail_visibility_buf"));
}
GPU_uniformbuf_bind(data_, DRW_VIEW_UBO_SLOT);
GPU_compute_dispatch(shader, divide_ceil_u(resource_len, DRW_VISIBILITY_GROUP_SIZE), 1, 1);

View File

@ -1350,7 +1350,7 @@ static void draw_subdiv_ubo_update_and_bind(const DRWSubdivCache *cache,
GPU_uniformbuf_update(cache->ubo, &storage);
const int binding = GPU_shader_get_uniform_block_binding(shader, "shader_data");
const int binding = GPU_shader_get_ubo_binding(shader, "shader_data");
GPU_uniformbuf_bind(cache->ubo, binding);
}

View File

@ -76,16 +76,16 @@ void PushConstant::execute(RecordingState &state) const
}
switch (type) {
case PushConstant::Type::IntValue:
GPU_shader_uniform_vector_int(state.shader, location, comp_len, array_len, int4_value);
GPU_shader_uniform_int_ex(state.shader, location, comp_len, array_len, int4_value);
break;
case PushConstant::Type::IntReference:
GPU_shader_uniform_vector_int(state.shader, location, comp_len, array_len, int_ref);
GPU_shader_uniform_int_ex(state.shader, location, comp_len, array_len, int_ref);
break;
case PushConstant::Type::FloatValue:
GPU_shader_uniform_vector(state.shader, location, comp_len, array_len, float4_value);
GPU_shader_uniform_float_ex(state.shader, location, comp_len, array_len, float4_value);
break;
case PushConstant::Type::FloatReference:
GPU_shader_uniform_vector(state.shader, location, comp_len, array_len, float_ref);
GPU_shader_uniform_float_ex(state.shader, location, comp_len, array_len, float_ref);
break;
}
}
@ -646,10 +646,10 @@ void DrawMultiBuf::bind(RecordingState &state,
GPU_shader_uniform_1i(shader, "prototype_len", prototype_count_);
GPU_shader_uniform_1i(shader, "visibility_word_per_draw", visibility_word_per_draw);
GPU_shader_uniform_1i(shader, "view_shift", log2_ceil_u(view_len));
GPU_storagebuf_bind(group_buf_, GPU_shader_get_ssbo(shader, "group_buf"));
GPU_storagebuf_bind(visibility_buf, GPU_shader_get_ssbo(shader, "visibility_buf"));
GPU_storagebuf_bind(prototype_buf_, GPU_shader_get_ssbo(shader, "prototype_buf"));
GPU_storagebuf_bind(command_buf_, GPU_shader_get_ssbo(shader, "command_buf"));
GPU_storagebuf_bind(group_buf_, GPU_shader_get_ssbo_binding(shader, "group_buf"));
GPU_storagebuf_bind(visibility_buf, GPU_shader_get_ssbo_binding(shader, "visibility_buf"));
GPU_storagebuf_bind(prototype_buf_, GPU_shader_get_ssbo_binding(shader, "prototype_buf"));
GPU_storagebuf_bind(command_buf_, GPU_shader_get_ssbo_binding(shader, "command_buf"));
GPU_storagebuf_bind(resource_id_buf_, DRW_RESOURCE_ID_SLOT);
GPU_compute_dispatch(shader, divide_ceil_u(prototype_count_, DRW_COMMAND_GROUP_SIZE), 1, 1);
if (GPU_shader_draw_parameters_support() == false) {

View File

@ -523,19 +523,18 @@ void DebugDraw::display_lines()
GPUBatch *batch = drw_cache_procedural_lines_get();
GPUShader *shader = DRW_shader_debug_draw_display_get();
GPU_batch_set_shader(batch, shader);
int slot = GPU_shader_get_builtin_ssbo(shader, GPU_STORAGE_BUFFER_DEBUG_VERTS);
GPU_shader_uniform_mat4(shader, "persmat", persmat.ptr());
if (gpu_draw_buf_used) {
GPU_debug_group_begin("GPU");
GPU_storagebuf_bind(gpu_draw_buf_, slot);
GPU_storagebuf_bind(gpu_draw_buf_, DRW_DEBUG_DRAW_SLOT);
GPU_batch_draw_indirect(batch, gpu_draw_buf_, 0);
GPU_storagebuf_unbind(gpu_draw_buf_);
GPU_debug_group_end();
}
GPU_debug_group_begin("CPU");
GPU_storagebuf_bind(cpu_draw_buf_, slot);
GPU_storagebuf_bind(cpu_draw_buf_, DRW_DEBUG_DRAW_SLOT);
GPU_batch_draw_indirect(batch, cpu_draw_buf_, 0);
GPU_storagebuf_unbind(cpu_draw_buf_);
GPU_debug_group_end();
@ -556,21 +555,20 @@ void DebugDraw::display_prints()
GPUBatch *batch = drw_cache_procedural_points_get();
GPUShader *shader = DRW_shader_debug_print_display_get();
GPU_batch_set_shader(batch, shader);
int slot = GPU_shader_get_builtin_ssbo(shader, GPU_STORAGE_BUFFER_DEBUG_PRINT);
float f_viewport[4];
GPU_viewport_size_get_f(f_viewport);
GPU_shader_uniform_2fv(shader, "viewport_size", &f_viewport[2]);
if (gpu_print_buf_used) {
GPU_debug_group_begin("GPU");
GPU_storagebuf_bind(gpu_print_buf_, slot);
GPU_storagebuf_bind(gpu_print_buf_, DRW_DEBUG_PRINT_SLOT);
GPU_batch_draw_indirect(batch, gpu_print_buf_, 0);
GPU_storagebuf_unbind(gpu_print_buf_);
GPU_debug_group_end();
}
GPU_debug_group_begin("CPU");
GPU_storagebuf_bind(cpu_print_buf_, slot);
GPU_storagebuf_bind(cpu_print_buf_, DRW_DEBUG_PRINT_SLOT);
GPU_batch_draw_indirect(batch, cpu_print_buf_, 0);
GPU_storagebuf_unbind(cpu_print_buf_);
GPU_debug_group_end();

View File

@ -114,9 +114,9 @@ void Manager::end_sync()
GPUShader *shader = DRW_shader_draw_resource_finalize_get();
GPU_shader_bind(shader);
GPU_shader_uniform_1i(shader, "resource_len", resource_len_);
GPU_storagebuf_bind(matrix_buf.current(), GPU_shader_get_ssbo(shader, "matrix_buf"));
GPU_storagebuf_bind(bounds_buf.current(), GPU_shader_get_ssbo(shader, "bounds_buf"));
GPU_storagebuf_bind(infos_buf.current(), GPU_shader_get_ssbo(shader, "infos_buf"));
GPU_storagebuf_bind(matrix_buf.current(), GPU_shader_get_ssbo_binding(shader, "matrix_buf"));
GPU_storagebuf_bind(bounds_buf.current(), GPU_shader_get_ssbo_binding(shader, "bounds_buf"));
GPU_storagebuf_bind(infos_buf.current(), GPU_shader_get_ssbo_binding(shader, "infos_buf"));
GPU_compute_dispatch(shader, thread_groups, 1, 1);
GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE);

View File

@ -256,7 +256,7 @@ void DRW_shgroup_uniform_texture_ex(DRWShadingGroup *shgroup,
eGPUSamplerState sampler_state)
{
BLI_assert(tex != nullptr);
int loc = GPU_shader_get_texture_binding(shgroup->shader, name);
int loc = GPU_shader_get_sampler_binding(shgroup->shader, name);
drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_TEXTURE, tex, sampler_state, 0, 1);
}
@ -271,7 +271,7 @@ void DRW_shgroup_uniform_texture_ref_ex(DRWShadingGroup *shgroup,
eGPUSamplerState sampler_state)
{
BLI_assert(tex != nullptr);
int loc = GPU_shader_get_texture_binding(shgroup->shader, name);
int loc = GPU_shader_get_sampler_binding(shgroup->shader, name);
drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_TEXTURE_REF, tex, sampler_state, 0, 1);
}
@ -283,14 +283,14 @@ void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name,
void DRW_shgroup_uniform_image(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex)
{
BLI_assert(tex != nullptr);
int loc = GPU_shader_get_texture_binding(shgroup->shader, name);
int loc = GPU_shader_get_sampler_binding(shgroup->shader, name);
drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_IMAGE, tex, GPU_SAMPLER_DEFAULT, 0, 1);
}
void DRW_shgroup_uniform_image_ref(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex)
{
BLI_assert(tex != nullptr);
int loc = GPU_shader_get_texture_binding(shgroup->shader, name);
int loc = GPU_shader_get_sampler_binding(shgroup->shader, name);
drw_shgroup_uniform_create_ex(
shgroup, loc, DRW_UNIFORM_IMAGE_REF, tex, GPU_SAMPLER_DEFAULT, 0, 1);
}
@ -300,7 +300,7 @@ void DRW_shgroup_uniform_block_ex(DRWShadingGroup *shgroup,
const GPUUniformBuf *ubo DRW_DEBUG_FILE_LINE_ARGS)
{
BLI_assert(ubo != nullptr);
int loc = GPU_shader_get_uniform_block_binding(shgroup->shader, name);
int loc = GPU_shader_get_ubo_binding(shgroup->shader, name);
if (loc == -1) {
#ifdef DRW_UNUSED_RESOURCE_TRACKING
printf("%s:%d: Unable to locate binding of shader uniform buffer object: %s.\n",
@ -321,7 +321,7 @@ void DRW_shgroup_uniform_block_ref_ex(DRWShadingGroup *shgroup,
GPUUniformBuf **ubo DRW_DEBUG_FILE_LINE_ARGS)
{
BLI_assert(ubo != nullptr);
int loc = GPU_shader_get_uniform_block_binding(shgroup->shader, name);
int loc = GPU_shader_get_ubo_binding(shgroup->shader, name);
if (loc == -1) {
#ifdef DRW_UNUSED_RESOURCE_TRACKING
printf("%s:%d: Unable to locate binding of shader uniform buffer object: %s.\n",
@ -344,7 +344,7 @@ void DRW_shgroup_storage_block_ex(DRWShadingGroup *shgroup,
{
BLI_assert(ssbo != nullptr);
/* TODO(@fclem): Fix naming inconsistency. */
int loc = GPU_shader_get_ssbo(shgroup->shader, name);
int loc = GPU_shader_get_ssbo_binding(shgroup->shader, name);
if (loc == -1) {
#ifdef DRW_UNUSED_RESOURCE_TRACKING
printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n",
@ -367,7 +367,7 @@ void DRW_shgroup_storage_block_ref_ex(DRWShadingGroup *shgroup,
{
BLI_assert(ssbo != nullptr);
/* TODO(@fclem): Fix naming inconsistency. */
int loc = GPU_shader_get_ssbo(shgroup->shader, name);
int loc = GPU_shader_get_ssbo_binding(shgroup->shader, name);
if (loc == -1) {
#ifdef DRW_UNUSED_RESOURCE_TRACKING
printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n",
@ -539,7 +539,7 @@ void DRW_shgroup_vertex_buffer_ex(DRWShadingGroup *shgroup,
const char *name,
GPUVertBuf *vertex_buffer DRW_DEBUG_FILE_LINE_ARGS)
{
int location = GPU_shader_get_ssbo(shgroup->shader, name);
int location = GPU_shader_get_ssbo_binding(shgroup->shader, name);
if (location == -1) {
#ifdef DRW_UNUSED_RESOURCE_TRACKING
printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n",
@ -564,7 +564,7 @@ void DRW_shgroup_vertex_buffer_ref_ex(DRWShadingGroup *shgroup,
const char *name,
GPUVertBuf **vertex_buffer DRW_DEBUG_FILE_LINE_ARGS)
{
int location = GPU_shader_get_ssbo(shgroup->shader, name);
int location = GPU_shader_get_ssbo_binding(shgroup->shader, name);
if (location == -1) {
#ifdef DRW_UNUSED_RESOURCE_TRACKING
printf("%s:%d: Unable to locate binding of shader storage buffer object: %s.\n",
@ -589,7 +589,7 @@ void DRW_shgroup_buffer_texture(DRWShadingGroup *shgroup,
const char *name,
GPUVertBuf *vertex_buffer)
{
int location = GPU_shader_get_texture_binding(shgroup->shader, name);
int location = GPU_shader_get_sampler_binding(shgroup->shader, name);
if (location == -1) {
return;
}
@ -606,7 +606,7 @@ void DRW_shgroup_buffer_texture_ref(DRWShadingGroup *shgroup,
const char *name,
GPUVertBuf **vertex_buffer)
{
int location = GPU_shader_get_texture_binding(shgroup->shader, name);
int location = GPU_shader_get_sampler_binding(shgroup->shader, name);
if (location == -1) {
return;
}
@ -698,7 +698,7 @@ static void drw_call_obinfos_init(DRWObjectInfos *ob_infos, Object *ob)
drw_call_calc_orco(ob, ob_infos->orcotexfac);
/* Random float value. */
uint random = (DST.dupli_source) ?
DST.dupli_source->random_id :
DST.dupli_source->random_id :
/* TODO(fclem): this is rather costly to do at runtime. Maybe we can
* put it in ob->runtime and make depsgraph ensure it is up to date. */
BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0);
@ -1719,36 +1719,6 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
1);
}
#ifdef DEBUG
/* TODO(Metal): Support Shader debug print.
* This is not currently supported by Metal Backend. */
if (GPU_backend_get_type() != GPU_BACKEND_METAL) {
int debug_print_location = GPU_shader_get_builtin_ssbo(shader, GPU_STORAGE_BUFFER_DEBUG_PRINT);
if (debug_print_location != -1) {
GPUStorageBuf *buf = drw_debug_gpu_print_buf_get();
drw_shgroup_uniform_create_ex(shgroup,
debug_print_location,
DRW_UNIFORM_STORAGE_BLOCK,
buf,
GPU_SAMPLER_DEFAULT,
0,
1);
# ifndef DISABLE_DEBUG_SHADER_PRINT_BARRIER
/* Add a barrier to allow multiple shader writing to the same buffer. */
DRW_shgroup_barrier(shgroup, GPU_BARRIER_SHADER_STORAGE);
# endif
}
int debug_draw_location = GPU_shader_get_builtin_ssbo(shader, GPU_STORAGE_BUFFER_DEBUG_VERTS);
if (debug_draw_location != -1) {
GPUStorageBuf *buf = drw_debug_gpu_draw_buf_get();
drw_shgroup_uniform_create_ex(
shgroup, debug_draw_location, DRW_UNIFORM_STORAGE_BLOCK, buf, GPU_SAMPLER_DEFAULT, 0, 1);
/* NOTE(fclem): No barrier as ordering is not important. */
}
}
#endif
/* Not supported. */
BLI_assert(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW_INV) == -1);
BLI_assert(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW) == -1);
@ -1850,15 +1820,14 @@ void DRW_shgroup_add_material_resources(DRWShadingGroup *grp, GPUMaterial *mater
const GPUUniformAttrList *uattrs = GPU_material_uniform_attributes(material);
if (uattrs != nullptr) {
int loc = GPU_shader_get_uniform_block_binding(grp->shader, GPU_ATTRIBUTE_UBO_BLOCK_NAME);
int loc = GPU_shader_get_ubo_binding(grp->shader, GPU_ATTRIBUTE_UBO_BLOCK_NAME);
drw_shgroup_uniform_create_ex(
grp, loc, DRW_UNIFORM_BLOCK_OBATTRS, uattrs, GPU_SAMPLER_DEFAULT, 0, 1);
grp->uniform_attrs = uattrs;
}
if (GPU_material_layer_attributes(material) != nullptr) {
int loc = GPU_shader_get_uniform_block_binding(grp->shader,
GPU_LAYER_ATTRIBUTE_UBO_BLOCK_NAME);
int loc = GPU_shader_get_ubo_binding(grp->shader, GPU_LAYER_ATTRIBUTE_UBO_BLOCK_NAME);
drw_shgroup_uniform_create_ex(
grp, loc, DRW_UNIFORM_BLOCK_VLATTRS, nullptr, GPU_SAMPLER_DEFAULT, 0, 1);
}

View File

@ -522,10 +522,10 @@ BLI_INLINE void draw_legacy_matrix_update(DRWShadingGroup *shgroup,
/* Still supported for compatibility with gpu_shader_* but should be forbidden. */
DRWObjectMatrix *ob_mats = DRW_memblock_elem_from_handle(DST.vmempool->obmats, handle);
if (obmat_loc != -1) {
GPU_shader_uniform_vector(shgroup->shader, obmat_loc, 16, 1, (float *)ob_mats->model);
GPU_shader_uniform_float_ex(shgroup->shader, obmat_loc, 16, 1, (float *)ob_mats->model);
}
if (obinv_loc != -1) {
GPU_shader_uniform_vector(shgroup->shader, obinv_loc, 16, 1, (float *)ob_mats->modelinverse);
GPU_shader_uniform_float_ex(shgroup->shader, obinv_loc, 16, 1, (float *)ob_mats->modelinverse);
}
}
@ -549,7 +549,7 @@ BLI_INLINE void draw_geometry_execute(DRWShadingGroup *shgroup,
if (baseinst_loc != -1) {
/* Fallback when ARB_shader_draw_parameters is not supported. */
GPU_shader_uniform_vector_int(shgroup->shader, baseinst_loc, 1, 1, (int *)&inst_first);
GPU_shader_uniform_int_ex(shgroup->shader, baseinst_loc, 1, 1, (int *)&inst_first);
/* Avoids VAO reconfiguration on older hardware. (see GPU_batch_draw_advanced) */
inst_first = 0;
}
@ -615,7 +615,7 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup,
memcpy(&mat4_stack[array_index], uni->fvalue, sizeof(float) * uni->length);
/* Flush array data to shader. */
if (array_index <= 0) {
GPU_shader_uniform_vector(shgroup->shader, uni->location, 16, 1, mat4_stack);
GPU_shader_uniform_float_ex(shgroup->shader, uni->location, 16, 1, mat4_stack);
array_uniform_loc = -1;
}
continue;
@ -626,23 +626,23 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup,
case DRW_UNIFORM_INT_COPY:
BLI_assert(uni->arraysize == 1);
if (uni->arraysize == 1) {
GPU_shader_uniform_vector_int(
GPU_shader_uniform_int_ex(
shgroup->shader, uni->location, uni->length, uni->arraysize, uni->ivalue);
}
break;
case DRW_UNIFORM_INT:
GPU_shader_uniform_vector_int(
GPU_shader_uniform_int_ex(
shgroup->shader, uni->location, uni->length, uni->arraysize, uni->pvalue);
break;
case DRW_UNIFORM_FLOAT_COPY:
BLI_assert(uni->arraysize == 1);
if (uni->arraysize == 1) {
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
shgroup->shader, uni->location, uni->length, uni->arraysize, uni->fvalue);
}
break;
case DRW_UNIFORM_FLOAT:
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
shgroup->shader, uni->location, uni->length, uni->arraysize, uni->pvalue);
break;
case DRW_UNIFORM_TEXTURE:
@ -687,10 +687,12 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup,
state->vlattrs_loc = uni->location;
GPU_uniformbuf_bind(drw_ensure_layer_attribute_buffer(), uni->location);
break;
case DRW_UNIFORM_RESOURCE_CHUNK:
case DRW_UNIFORM_RESOURCE_CHUNK: {
state->chunkid_loc = uni->location;
GPU_shader_uniform_int(shgroup->shader, uni->location, 0);
int zero = 0;
GPU_shader_uniform_int_ex(shgroup->shader, uni->location, 1, 1, &zero);
break;
}
case DRW_UNIFORM_RESOURCE_ID:
state->resourceid_loc = uni->location;
break;
@ -807,7 +809,7 @@ static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHa
int chunk = DRW_handle_chunk_get(handle);
if (state->resource_chunk != chunk) {
if (state->chunkid_loc != -1) {
GPU_shader_uniform_int(DST.shader, state->chunkid_loc, chunk);
GPU_shader_uniform_int_ex(DST.shader, state->chunkid_loc, 1, 1, &chunk);
}
if (state->obmats_loc != -1) {
GPU_uniformbuf_unbind(DST.vmempool->matrices_ubo[state->resource_chunk]);
@ -827,7 +829,7 @@ static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHa
if (state->resourceid_loc != -1) {
int id = DRW_handle_id_get(handle);
if (state->resource_id != id) {
GPU_shader_uniform_int(DST.shader, state->resourceid_loc, id);
GPU_shader_uniform_int_ex(DST.shader, state->resourceid_loc, 1, 1, &id);
state->resource_id = id;
}
}

View File

@ -861,42 +861,42 @@ template<class T> inline int PassBase<T>::push_constant_offset(const char *name)
template<class T> inline void PassBase<T>::bind_ssbo(const char *name, GPUStorageBuf *buffer)
{
this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer);
this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer);
}
template<class T> inline void PassBase<T>::bind_ssbo(const char *name, GPUUniformBuf *buffer)
{
this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer);
this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer);
}
template<class T> inline void PassBase<T>::bind_ssbo(const char *name, GPUUniformBuf **buffer)
{
this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer);
this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer);
}
template<class T> inline void PassBase<T>::bind_ssbo(const char *name, GPUVertBuf *buffer)
{
this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer);
this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer);
}
template<class T> inline void PassBase<T>::bind_ssbo(const char *name, GPUVertBuf **buffer)
{
this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer);
this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer);
}
template<class T> inline void PassBase<T>::bind_ssbo(const char *name, GPUIndexBuf *buffer)
{
this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer);
this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer);
}
template<class T> inline void PassBase<T>::bind_ssbo(const char *name, GPUIndexBuf **buffer)
{
this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer);
this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer);
}
template<class T> inline void PassBase<T>::bind_ubo(const char *name, GPUUniformBuf *buffer)
{
this->bind_ubo(GPU_shader_get_uniform_block_binding(shader_, name), buffer);
this->bind_ubo(GPU_shader_get_ubo_binding(shader_, name), buffer);
}
template<class T>
@ -904,22 +904,22 @@ inline void PassBase<T>::bind_texture(const char *name,
GPUTexture *texture,
eGPUSamplerState state)
{
this->bind_texture(GPU_shader_get_texture_binding(shader_, name), texture, state);
this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), texture, state);
}
template<class T> inline void PassBase<T>::bind_texture(const char *name, GPUVertBuf *buffer)
{
this->bind_texture(GPU_shader_get_texture_binding(shader_, name), buffer);
this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), buffer);
}
template<class T> inline void PassBase<T>::bind_texture(const char *name, GPUVertBuf **buffer)
{
this->bind_texture(GPU_shader_get_texture_binding(shader_, name), buffer);
this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), buffer);
}
template<class T> inline void PassBase<T>::bind_image(const char *name, GPUTexture *image)
{
this->bind_image(GPU_shader_get_texture_binding(shader_, name), image);
this->bind_image(GPU_shader_get_sampler_binding(shader_, name), image);
}
template<class T> inline void PassBase<T>::bind_ssbo(int slot, GPUStorageBuf *buffer)
@ -991,12 +991,12 @@ template<class T> inline void PassBase<T>::bind_image(int slot, GPUTexture *imag
template<class T> inline void PassBase<T>::bind_ssbo(const char *name, GPUStorageBuf **buffer)
{
this->bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer);
this->bind_ssbo(GPU_shader_get_ssbo_binding(shader_, name), buffer);
}
template<class T> inline void PassBase<T>::bind_ubo(const char *name, GPUUniformBuf **buffer)
{
this->bind_ubo(GPU_shader_get_uniform_block_binding(shader_, name), buffer);
this->bind_ubo(GPU_shader_get_ubo_binding(shader_, name), buffer);
}
template<class T>
@ -1004,12 +1004,12 @@ inline void PassBase<T>::bind_texture(const char *name,
GPUTexture **texture,
eGPUSamplerState state)
{
this->bind_texture(GPU_shader_get_texture_binding(shader_, name), texture, state);
this->bind_texture(GPU_shader_get_sampler_binding(shader_, name), texture, state);
}
template<class T> inline void PassBase<T>::bind_image(const char *name, GPUTexture **image)
{
this->bind_image(GPU_shader_get_texture_binding(shader_, name), image);
this->bind_image(GPU_shader_get_sampler_binding(shader_, name), image);
}
template<class T> inline void PassBase<T>::bind_ssbo(int slot, GPUStorageBuf **buffer)

View File

@ -244,7 +244,7 @@ void View::compute_procedural_bounds()
GPUShader *shader = DRW_shader_draw_view_finalize_get();
GPU_shader_bind(shader);
GPU_uniformbuf_bind_as_ssbo(culling_, GPU_shader_get_ssbo(shader, "view_culling_buf"));
GPU_uniformbuf_bind_as_ssbo(culling_, GPU_shader_get_ssbo_binding(shader, "view_culling_buf"));
GPU_uniformbuf_bind(data_, DRW_VIEW_UBO_SLOT);
GPU_compute_dispatch(shader, 1, 1, 1);
GPU_memory_barrier(GPU_BARRIER_UNIFORM);
@ -289,8 +289,8 @@ void View::compute_visibility(ObjectBoundsBuf &bounds, uint resource_len, bool d
GPU_shader_uniform_1i(shader, "resource_len", resource_len);
GPU_shader_uniform_1i(shader, "view_len", view_len_);
GPU_shader_uniform_1i(shader, "visibility_word_per_draw", word_per_draw);
GPU_storagebuf_bind(bounds, GPU_shader_get_ssbo(shader, "bounds_buf"));
GPU_storagebuf_bind(visibility_buf_, GPU_shader_get_ssbo(shader, "visibility_buf"));
GPU_storagebuf_bind(bounds, GPU_shader_get_ssbo_binding(shader, "bounds_buf"));
GPU_storagebuf_bind(visibility_buf_, GPU_shader_get_ssbo_binding(shader, "visibility_buf"));
GPU_uniformbuf_bind(frozen_ ? data_freeze_ : data_, DRW_VIEW_UBO_SLOT);
GPU_uniformbuf_bind(frozen_ ? culling_freeze_ : culling_, DRW_VIEW_CULLING_UBO_SLOT);
GPU_compute_dispatch(shader, divide_ceil_u(resource_len, DRW_VISIBILITY_GROUP_SIZE), 1, 1);

View File

@ -18,7 +18,7 @@ GPU_SHADER_INTERFACE_INFO(draw_debug_print_display_iface, "").flat(Type::UINT, "
GPU_SHADER_CREATE_INFO(draw_debug_print_display)
.do_static_compilation(true)
.typedef_source("draw_shader_shared.h")
.storage_buf(7, Qualifier::READ, "uint", "drw_debug_print_buf[]")
.storage_buf(DRW_DEBUG_PRINT_SLOT, Qualifier::READ, "uint", "drw_debug_print_buf[]")
.vertex_out(draw_debug_print_display_iface)
.fragment_out(0, Type::VEC4, "out_color")
.push_constant(Type::VEC2, "viewport_size")
@ -46,7 +46,7 @@ GPU_SHADER_INTERFACE_INFO(draw_debug_draw_display_iface, "interp").flat(Type::VE
GPU_SHADER_CREATE_INFO(draw_debug_draw_display)
.do_static_compilation(true)
.typedef_source("draw_shader_shared.h")
.storage_buf(6, Qualifier::READ, "DRWDebugVert", "drw_debug_verts_buf[]")
.storage_buf(DRW_DEBUG_DRAW_SLOT, Qualifier::READ, "DRWDebugVert", "drw_debug_verts_buf[]")
.vertex_out(draw_debug_draw_display_iface)
.fragment_out(0, Type::VEC4, "out_color")
.push_constant(Type::MAT4, "persmat")

View File

@ -22,6 +22,7 @@
#include "DNA_scene_types.h"
#include "GPU_immediate.h"
#include "GPU_shader_shared.h"
#include "GPU_state.h"
#include "UI_interface.h"

View File

@ -959,55 +959,60 @@ static int gizmo_cage2d_invoke(bContext *C, wmGizmo *gz, const wmEvent *event)
return OPERATOR_RUNNING_MODAL;
}
static void gizmo_rect_pivot_from_scale_part(int part, float r_pt[2], bool r_constrain_axis[2])
static void gizmo_constrain_from_scale_part(int part, bool r_constrain_axis[2])
{
r_constrain_axis[0] = (part > ED_GIZMO_CAGE2D_PART_SCALE_MAX_X &&
part < ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y) ?
true :
false;
r_constrain_axis[1] = (part > ED_GIZMO_CAGE2D_PART_SCALE &&
part < ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y) ?
true :
false;
}
static void gizmo_pivot_from_scale_part(int part, float r_pt[2])
{
bool x = true, y = true;
switch (part) {
case ED_GIZMO_CAGE2D_PART_SCALE: {
ARRAY_SET_ITEMS(r_pt, 0.0, 0.0);
break;
}
case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X: {
ARRAY_SET_ITEMS(r_pt, 0.5, 0.0);
x = false;
break;
}
case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X: {
ARRAY_SET_ITEMS(r_pt, -0.5, 0.0);
x = false;
break;
}
case ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y: {
ARRAY_SET_ITEMS(r_pt, 0.0, 0.5);
y = false;
break;
}
case ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y: {
ARRAY_SET_ITEMS(r_pt, 0.0, -0.5);
y = false;
break;
}
case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y: {
ARRAY_SET_ITEMS(r_pt, 0.5, 0.5);
x = y = false;
break;
}
case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y: {
ARRAY_SET_ITEMS(r_pt, 0.5, -0.5);
x = y = false;
break;
}
case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y: {
ARRAY_SET_ITEMS(r_pt, -0.5, 0.5);
x = y = false;
break;
}
case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y: {
ARRAY_SET_ITEMS(r_pt, -0.5, -0.5);
x = y = false;
break;
}
default:
BLI_assert(0);
}
r_constrain_axis[0] = x;
r_constrain_axis[1] = y;
}
static int gizmo_cage2d_modal(bContext *C,
@ -1105,46 +1110,55 @@ static int gizmo_cage2d_modal(bContext *C,
else {
/* scale */
copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
float pivot[2];
bool constrain_axis[2] = {false};
const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
float pivot[2];
if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE) {
gizmo_rect_pivot_from_scale_part(gz->highlight_part, pivot, constrain_axis);
gizmo_pivot_from_scale_part(gz->highlight_part, pivot);
}
else {
zero_v2(pivot);
}
/* Cursor deltas scaled to (-0.5..0.5). */
float delta_orig[2], delta_curr[2];
for (int i = 0; i < 2; i++) {
delta_orig[i] = ((data->orig_mouse[i] - data->orig_matrix_offset[3][i]) / dims[i]) -
pivot[i];
delta_curr[i] = ((point_local[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
}
bool constrain_axis[2] = {false};
gizmo_constrain_from_scale_part(gz->highlight_part, constrain_axis);
float scale[2] = {1.0f, 1.0f};
for (int i = 0; i < 2; i++) {
if (constrain_axis[i] == false) {
if (delta_orig[i] < 0.0f) {
delta_orig[i] *= -1.0f;
delta_curr[i] *= -1.0f;
}
const int sign = signum_i(scale[i]);
scale[i] = 1.0f + ((delta_curr[i] - delta_orig[i]) / len_v3(data->orig_matrix_offset[i]));
/* Original cursor position relative to pivot, remapped to [-1, 1] */
const float delta_orig = (data->orig_mouse[i] - data->orig_matrix_offset[3][i]) /
(dims[i] * len_v3(data->orig_matrix_offset[i])) -
pivot[i];
const float delta_curr = (point_local[i] - data->orig_matrix_offset[3][i]) /
(dims[i] * len_v3(data->orig_matrix_offset[i])) -
pivot[i];
if ((transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_SCALE_SIGNED) == 0) {
if (sign != signum_i(scale[i])) {
if (signum_i(delta_orig) != signum_i(delta_curr)) {
scale[i] = 0.0f;
continue;
}
}
if (delta_orig < 0) {
scale[i] = -delta_curr / (pivot[i] + 0.5f);
}
else {
scale[i] = delta_curr / (0.5f - pivot[i]);
}
}
}
if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM) {
if (constrain_axis[0] == false && constrain_axis[1] == false) {
scale[1] = scale[0] = (scale[1] + scale[0]) / 2.0f;
if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE) {
/* So that the cursor lies on the circle. */
scale[1] = scale[0] = len_v2(scale);
}
else {
scale[1] = scale[0] = (scale[1] + scale[0]) / 2.0f;
}
}
else if (constrain_axis[0] == false) {
scale[1] = scale[0];

View File

@ -88,7 +88,10 @@ static void gizmo_calc_rect_view_margin(const wmGizmo *gz, const float dims[3],
/* -------------------------------------------------------------------- */
static void gizmo_rect_pivot_from_scale_part(int part, float r_pt[3], bool r_constrain_axis[3])
static void gizmo_rect_pivot_from_scale_part(int part,
float r_pt[3],
bool r_constrain_axis[3],
bool has_translation)
{
if (part >= ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z &&
part <= ED_GIZMO_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z) {
@ -102,7 +105,7 @@ static void gizmo_rect_pivot_from_scale_part(int part, float r_pt[3], bool r_con
const float sign[3] = {0.5f, 0.0f, -0.5f};
for (int i = 0; i < 3; i++) {
r_pt[i] = sign[range[i]];
r_pt[i] = has_translation ? sign[range[i]] : 0.0f;
r_constrain_axis[i] = (range[i] == 1);
}
}
@ -512,41 +515,36 @@ static int gizmo_cage3d_modal(bContext *C,
else {
/* scale */
copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
float pivot[3];
bool constrain_axis[3] = {false};
if (transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE) {
gizmo_rect_pivot_from_scale_part(gz->highlight_part, pivot, constrain_axis);
}
else {
zero_v3(pivot);
}
/* Cursor deltas scaled to (-0.5..0.5). */
float delta_orig[3], delta_curr[3];
for (int i = 0; i < 3; i++) {
delta_orig[i] = ((data->orig_mouse[i] - data->orig_matrix_offset[3][i]) / dims[i]) -
pivot[i];
delta_curr[i] = ((point_local[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
}
bool has_translation = transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE;
gizmo_rect_pivot_from_scale_part(gz->highlight_part, pivot, constrain_axis, has_translation);
float scale[3] = {1.0f, 1.0f, 1.0f};
for (int i = 0; i < 3; i++) {
if (constrain_axis[i] == false) {
if (delta_orig[i] < 0.0f) {
delta_orig[i] *= -1.0f;
delta_curr[i] *= -1.0f;
}
const int sign = signum_i(scale[i]);
scale[i] = 1.0f + ((delta_curr[i] - delta_orig[i]) / len_v3(data->orig_matrix_offset[i]));
/* Original cursor position relative to pivot, remapped to [-1, 1] */
const float delta_orig = (data->orig_mouse[i] - data->orig_matrix_offset[3][i]) /
(dims[i] * len_v3(data->orig_matrix_offset[i])) -
pivot[i];
const float delta_curr = (point_local[i] - data->orig_matrix_offset[3][i]) /
(dims[i] * len_v3(data->orig_matrix_offset[i])) -
pivot[i];
if ((transform_flag & ED_GIZMO_CAGE_XFORM_FLAG_SCALE_SIGNED) == 0) {
if (sign != signum_i(scale[i])) {
if (signum_i(delta_orig) != signum_i(delta_curr)) {
scale[i] = 0.0f;
continue;
}
}
if (delta_orig < 0) {
scale[i] = -delta_curr / (pivot[i] + 0.5f);
}
else {
scale[i] = delta_curr / (0.5f - pivot[i]);
}
}
}

View File

@ -1003,8 +1003,8 @@ static void draw_mouse_position(tGPDfill *tgpf)
uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
/* Draw mouse click position in Blue. */
immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR);
GPU_point_size(point_size);
immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
immUniform1f("size", point_size * M_SQRT2);
immBegin(GPU_PRIM_POINTS, 1);
immAttr4ubv(col, mouse_color);
immVertex3fv(pos, &pt->x);

View File

@ -34,7 +34,7 @@ typedef struct IMMDrawPixelsTexState {
* To be used before calling #immDrawPixelsTex
* Default shader is #GPU_SHADER_2D_IMAGE_COLOR
* You can still set uniforms with:
* `GPU_shader_uniform_int(shader, GPU_shader_get_uniform(shader, "name"), 0);`
* `GPU_shader_uniform_*(shader, "name", value);`
*/
IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin);

View File

@ -236,6 +236,7 @@ typedef enum ThemeColorID {
TH_PATH_KEYFRAME_BEFORE,
TH_PATH_KEYFRAME_AFTER,
TH_CAMERA_PATH,
TH_CAMERA_PASSEPARTOUT,
TH_LOCK_MARKER,
TH_STITCH_PREVIEW_FACE,

View File

@ -9039,7 +9039,7 @@ static void ui_handle_button_activate(bContext *C,
*/
static bool ui_handle_button_activate_by_type(bContext *C, ARegion *region, uiBut *but)
{
if (but->type == UI_BTYPE_BUT_MENU) {
if (ELEM(but->type, UI_BTYPE_BUT_MENU, UI_BTYPE_ROW)) {
/* mainly for operator buttons */
ui_handle_button_activate(C, region, but, BUTTON_ACTIVATE_APPLY);
}

View File

@ -1620,12 +1620,12 @@ static void icon_draw_cache_texture_flush_ex(GPUTexture *texture,
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR);
GPU_shader_bind(shader);
const int data_binding = GPU_shader_get_uniform_block_binding(shader, "multi_rect_data");
const int data_binding = GPU_shader_get_ubo_binding(shader, "multi_rect_data");
GPUUniformBuf *ubo = GPU_uniformbuf_create_ex(
sizeof(MultiRectCallData), texture_draw_calls->drawcall_cache, __func__);
GPU_uniformbuf_bind(ubo, data_binding);
const int img_binding = GPU_shader_get_texture_binding(shader, "image");
const int img_binding = GPU_shader_get_sampler_binding(shader, "image");
GPU_texture_bind_ex(texture, GPU_SAMPLER_ICON, img_binding, false);
GPUBatch *quad = GPU_batch_preset_quad();
@ -1797,25 +1797,25 @@ static void icon_draw_texture(float x,
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_ICON);
GPU_shader_bind(shader);
const int img_binding = GPU_shader_get_texture_binding(shader, "image");
const int img_binding = GPU_shader_get_sampler_binding(shader, "image");
const int color_loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR);
const int rect_tex_loc = GPU_shader_get_uniform(shader, "rect_icon");
const int rect_geom_loc = GPU_shader_get_uniform(shader, "rect_geom");
if (rgb) {
const float color[4] = {rgb[0], rgb[1], rgb[2], alpha};
GPU_shader_uniform_vector(shader, color_loc, 4, 1, color);
GPU_shader_uniform_float_ex(shader, color_loc, 4, 1, color);
}
else {
const float color[4] = {alpha, alpha, alpha, alpha};
GPU_shader_uniform_vector(shader, color_loc, 4, 1, color);
GPU_shader_uniform_float_ex(shader, color_loc, 4, 1, color);
}
const float tex_color[4] = {x1, y1, x2, y2};
const float geom_color[4] = {x, y, x + w, y + h};
GPU_shader_uniform_vector(shader, rect_tex_loc, 4, 1, tex_color);
GPU_shader_uniform_vector(shader, rect_geom_loc, 4, 1, geom_color);
GPU_shader_uniform_float_ex(shader, rect_tex_loc, 4, 1, tex_color);
GPU_shader_uniform_float_ex(shader, rect_geom_loc, 4, 1, geom_color);
GPU_shader_uniform_1f(shader, "text_width", text_width);
GPU_texture_bind_ex(texture, GPU_SAMPLER_ICON, img_binding, false);

View File

@ -803,6 +803,9 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
case TH_CAMERA_PATH:
cp = ts->camera_path;
break;
case TH_CAMERA_PASSEPARTOUT:
cp = ts->camera_passepartout;
break;
case TH_LOCK_MARKER:
cp = ts->lock_marker;
break;

View File

@ -722,7 +722,7 @@ void ED_mask_draw_region(
GPU_matrix_mul(stabmat);
}
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, buf_col);
if (overlay_mode == MASK_OVERLAY_COMBINED) {

View File

@ -966,9 +966,8 @@ static void min_distance_edit_draw(bContext *C, int /*x*/, int /*y*/, void *cust
const uint pos3d = GPU_vertformat_attr_add(format3d, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
const uint col3d = GPU_vertformat_attr_add(format3d, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR);
GPU_point_size(3.0f);
immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
immUniform1f("size", 4.0f);
immBegin(GPU_PRIM_POINTS, points_wo.size());
float3 brush_origin_wo = math::transform_point(op_data.curves_to_world_mat, op_data.pos_cu);

View File

@ -51,6 +51,7 @@
#include "GPU_immediate.h"
#include "GPU_immediate_util.h"
#include "GPU_matrix.h"
#include "GPU_shader_shared.h"
#include "GPU_state.h"
#include "GPU_viewport.h"

View File

@ -1022,6 +1022,7 @@ static void view3d_widgets()
WM_gizmogrouptype_append_and_link(gzmap_type, VIEW3D_GGT_xform_gizmo_context);
WM_gizmogrouptype_append_and_link(gzmap_type, VIEW3D_GGT_light_spot);
WM_gizmogrouptype_append_and_link(gzmap_type, VIEW3D_GGT_light_point);
WM_gizmogrouptype_append_and_link(gzmap_type, VIEW3D_GGT_light_area);
WM_gizmogrouptype_append_and_link(gzmap_type, VIEW3D_GGT_light_target);
WM_gizmogrouptype_append_and_link(gzmap_type, VIEW3D_GGT_force_field);

View File

@ -585,7 +585,7 @@ static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region,
alpha = ca->passepartalpha;
}
immUniformColor4f(0.0f, 0.0f, 0.0f, alpha);
immUniformThemeColorAlpha(TH_CAMERA_PASSEPARTOUT, alpha);
if (x1i > 0.0f) {
immRectf(shdr_pos, 0.0f, winy, x1i, 0.0f);
@ -1104,8 +1104,8 @@ static void draw_rotation_guide(const RegionView3D *rv3d)
immUnbindProgram();
/* -- draw rotation center -- */
immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR);
GPU_point_size(5.0f);
immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
immUniform1f("size", 7.0f);
immBegin(GPU_PRIM_POINTS, 1);
immAttr4ubv(col, color);
immVertex3fv(pos, o);

View File

@ -42,6 +42,7 @@
typedef struct LightSpotWidgetGroup {
wmGizmo *spot_angle;
wmGizmo *spot_blend;
wmGizmo *spot_radius;
} LightSpotWidgetGroup;
static void gizmo_spot_blend_prop_matrix_get(const wmGizmo *UNUSED(gz),
@ -94,6 +95,48 @@ static void gizmo_spot_blend_prop_matrix_set(const wmGizmo *UNUSED(gz),
RNA_property_update_main(CTX_data_main(C), scene, &light_ptr, spot_blend_prop);
}
/* Used by spot light and point light. */
static void gizmo_light_radius_prop_matrix_get(const wmGizmo *UNUSED(gz),
wmGizmoProperty *gz_prop,
void *value_p)
{
BLI_assert(gz_prop->type->array_length == 16);
float(*matrix)[4] = value_p;
const bContext *C = gz_prop->custom_func.user_data;
ViewLayer *view_layer = CTX_data_view_layer(C);
BKE_view_layer_synced_ensure(CTX_data_scene(C), view_layer);
const Light *la = BKE_view_layer_active_object_get(view_layer)->data;
/* Draw gizmo even when radius is zero. */
const float diameter = fmaxf(2.0f * la->radius, 1e-2f);
matrix[0][0] = diameter;
matrix[1][1] = diameter;
}
static void gizmo_light_radius_prop_matrix_set(const wmGizmo *UNUSED(gz),
wmGizmoProperty *gz_prop,
const void *value_p)
{
const float(*matrix)[4] = value_p;
BLI_assert(gz_prop->type->array_length == 16);
const bContext *C = gz_prop->custom_func.user_data;
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
BKE_view_layer_synced_ensure(scene, view_layer);
Light *la = BKE_view_layer_active_object_get(view_layer)->data;
const float radius = 0.5f * len_v3(matrix[0]);
PointerRNA light_ptr;
RNA_pointer_create(&la->id, &RNA_Light, la, &light_ptr);
PropertyRNA *radius_prop = RNA_struct_find_property(&light_ptr, "shadow_soft_size");
RNA_property_float_set(&light_ptr, radius_prop, radius);
RNA_property_update_main(CTX_data_main(C), scene, &light_ptr, radius_prop);
}
static bool WIDGETGROUP_light_spot_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzgt))
{
View3D *v3d = CTX_wm_view3d(C);
@ -154,6 +197,28 @@ static void WIDGETGROUP_light_spot_setup(const bContext *C, wmGizmoGroup *gzgrou
.user_data = (void *)C,
});
}
/* Spot radius gizmo. */
{
ls_gzgroup->spot_radius = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, NULL);
wmGizmo *gz = ls_gzgroup->spot_radius;
RNA_enum_set(gz->ptr,
"transform",
ED_GIZMO_CAGE_XFORM_FLAG_SCALE | ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM);
RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_CAGE2D_STYLE_CIRCLE);
WM_gizmo_set_flag(gz, WM_GIZMO_DRAW_HOVER, true);
UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, gz->color);
UI_GetThemeColor3fv(TH_GIZMO_HI, gz->color_hi);
WM_gizmo_target_property_def_func(gz,
"matrix",
&(const struct wmGizmoPropertyFnParams){
.value_get_fn = gizmo_light_radius_prop_matrix_get,
.value_set_fn = gizmo_light_radius_prop_matrix_set,
.range_get_fn = NULL,
.user_data = (void *)C,
});
}
}
static void WIDGETGROUP_light_spot_refresh(const bContext *C, wmGizmoGroup *gzgroup)
@ -165,6 +230,7 @@ static void WIDGETGROUP_light_spot_refresh(const bContext *C, wmGizmoGroup *gzgr
Object *ob = BKE_view_layer_active_object_get(view_layer);
Light *la = ob->data;
/* Spot angle gizmo. */
{
PointerRNA lamp_ptr;
RNA_pointer_create(&la->id, &RNA_Light, la, &lamp_ptr);
@ -179,6 +245,7 @@ static void WIDGETGROUP_light_spot_refresh(const bContext *C, wmGizmoGroup *gzgr
WM_gizmo_target_property_def_rna(gz, "offset", &lamp_ptr, propname, -1);
}
/* Spot blend gizmo. */
{
wmGizmo *gz = ls_gzgroup->spot_blend;
@ -192,6 +259,23 @@ static void WIDGETGROUP_light_spot_refresh(const bContext *C, wmGizmoGroup *gzgr
}
}
static void WIDGETGROUP_light_spot_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup)
{
LightSpotWidgetGroup *ls_gzgroup = gzgroup->customdata;
ViewLayer *view_layer = CTX_data_view_layer(C);
BKE_view_layer_synced_ensure(CTX_data_scene(C), view_layer);
Object *ob = BKE_view_layer_active_object_get(view_layer);
/* Spot radius gizmo. */
wmGizmo *gz = ls_gzgroup->spot_radius;
/* Draw circle in the screen space. */
RegionView3D *rv3d = CTX_wm_region(C)->regiondata;
WM_gizmo_set_matrix_rotation_from_z_axis(gz, rv3d->viewinv[2]);
WM_gizmo_set_matrix_location(gz, ob->object_to_world[3]);
}
void VIEW3D_GGT_light_spot(wmGizmoGroupType *gzgt)
{
gzgt->name = "Spot Light Widgets";
@ -203,6 +287,93 @@ void VIEW3D_GGT_light_spot(wmGizmoGroupType *gzgt)
gzgt->setup = WIDGETGROUP_light_spot_setup;
gzgt->setup_keymap = WM_gizmogroup_setup_keymap_generic_maybe_drag;
gzgt->refresh = WIDGETGROUP_light_spot_refresh;
gzgt->draw_prepare = WIDGETGROUP_light_spot_draw_prepare;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Point Light Gizmo
* \{ */
static bool WIDGETGROUP_light_point_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzgt))
{
const View3D *v3d = CTX_wm_view3d(C);
if (v3d->gizmo_flag & (V3D_GIZMO_HIDE | V3D_GIZMO_HIDE_CONTEXT)) {
return false;
}
if ((v3d->gizmo_show_light & V3D_GIZMO_SHOW_LIGHT_SIZE) == 0) {
return false;
}
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
BKE_view_layer_synced_ensure(scene, view_layer);
const Base *base = BKE_view_layer_active_base_get(view_layer);
if (base && BASE_SELECTABLE(v3d, base)) {
const Object *ob = base->object;
if (ob->type == OB_LAMP) {
const Light *la = ob->data;
return (la->type == LA_LOCAL);
}
}
return false;
}
static void WIDGETGROUP_light_point_setup(const bContext *C, wmGizmoGroup *gzgroup)
{
wmGizmoWrapper *wwrapper = MEM_mallocN(sizeof(wmGizmoWrapper), __func__);
wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, NULL);
/* Point radius gizmo. */
wmGizmo *gz = wwrapper->gizmo;
gzgroup->customdata = wwrapper;
RNA_enum_set(gz->ptr,
"transform",
ED_GIZMO_CAGE_XFORM_FLAG_SCALE | ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM);
RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_CAGE2D_STYLE_CIRCLE);
WM_gizmo_set_flag(gz, WM_GIZMO_DRAW_HOVER, true);
UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, gz->color);
UI_GetThemeColor3fv(TH_GIZMO_HI, gz->color_hi);
WM_gizmo_target_property_def_func(gz,
"matrix",
&(const struct wmGizmoPropertyFnParams){
.value_get_fn = gizmo_light_radius_prop_matrix_get,
.value_set_fn = gizmo_light_radius_prop_matrix_set,
.range_get_fn = NULL,
.user_data = (void *)C,
});
}
static void WIDGETGROUP_light_point_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup)
{
wmGizmoWrapper *wwrapper = gzgroup->customdata;
ViewLayer *view_layer = CTX_data_view_layer(C);
BKE_view_layer_synced_ensure(CTX_data_scene(C), view_layer);
const Object *ob = BKE_view_layer_active_object_get(view_layer);
/* Point radius gizmo. */
wmGizmo *gz = wwrapper->gizmo;
/* Draw circle in the screen space. */
const RegionView3D *rv3d = CTX_wm_region(C)->regiondata;
WM_gizmo_set_matrix_rotation_from_z_axis(gz, rv3d->viewinv[2]);
WM_gizmo_set_matrix_location(gz, ob->object_to_world[3]);
}
void VIEW3D_GGT_light_point(wmGizmoGroupType *gzgt)
{
gzgt->name = "Point Light Widgets";
gzgt->idname = "VIEW3D_GGT_light_point";
gzgt->flag |= (WM_GIZMOGROUPTYPE_PERSISTENT | WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_DEPTH_3D);
gzgt->poll = WIDGETGROUP_light_point_poll;
gzgt->setup = WIDGETGROUP_light_point_setup;
gzgt->setup_keymap = WM_gizmogroup_setup_keymap_generic_maybe_drag;
gzgt->draw_prepare = WIDGETGROUP_light_point_draw_prepare;
}
/** \} */

View File

@ -212,6 +212,7 @@ extern const char *view3d_context_dir[]; /* doc access */
/* view3d_widgets.c */
void VIEW3D_GGT_light_spot(struct wmGizmoGroupType *gzgt);
void VIEW3D_GGT_light_point(struct wmGizmoGroupType *gzgt);
void VIEW3D_GGT_light_area(struct wmGizmoGroupType *gzgt);
void VIEW3D_GGT_light_target(struct wmGizmoGroupType *gzgt);
void VIEW3D_GGT_camera(struct wmGizmoGroupType *gzgt);

View File

@ -70,7 +70,7 @@ set(SRC
intern/gpu_select_pick.c
intern/gpu_select_sample_query.cc
intern/gpu_shader.cc
intern/gpu_shader_builtin.c
intern/gpu_shader_builtin.cc
intern/gpu_shader_create_info.cc
intern/gpu_shader_dependency.cc
intern/gpu_shader_interface.cc
@ -391,7 +391,6 @@ set(GLSL_SRC
shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl
shaders/gpu_shader_point_varying_color_varying_outline_aa_frag.glsl
shaders/gpu_shader_point_varying_color_frag.glsl
shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl
shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl
shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl
shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl

View File

@ -263,9 +263,9 @@ void GPU_batch_program_set_imm_shader(GPUBatch *batch);
#define GPU_batch_uniform_mat4(batch, name, val) \
GPU_shader_uniform_mat4((batch)->shader, name, val);
#define GPU_batch_uniformbuf_bind(batch, name, ubo) \
GPU_uniformbuf_bind(ubo, GPU_shader_get_uniform_block_binding((batch)->shader, name));
GPU_uniformbuf_bind(ubo, GPU_shader_get_ubo_binding((batch)->shader, name));
#define GPU_batch_texture_bind(batch, name, tex) \
GPU_texture_bind(tex, GPU_shader_get_texture_binding((batch)->shader, name));
GPU_texture_bind(tex, GPU_shader_get_sampler_binding((batch)->shader, name));
/** \} */

View File

@ -3,10 +3,14 @@
/** \file
* \ingroup gpu
*
* A #GPUShader is a container for backend specific shader program.
*/
#pragma once
#include "GPU_shader_builtin.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -18,6 +22,161 @@ typedef struct GPUShaderCreateInfo GPUShaderCreateInfo;
/** Opaque type hiding #blender::gpu::Shader */
typedef struct GPUShader GPUShader;
/* Hardware limit is 16. Position attribute is always needed so we reduce to 15.
* This makes sure the GPUVertexFormat name buffer does not overflow. */
#define GPU_MAX_ATTR 15
/* Determined by the maximum uniform buffer size divided by chunk size. */
#define GPU_MAX_UNIFORM_ATTR 8
/* -------------------------------------------------------------------- */
/** \name Creation
* \{ */
/**
* Create a shader using the given #GPUShaderCreateInfo.
* Can return a NULL pointer if compilation fails.
*/
GPUShader *GPU_shader_create_from_info(const GPUShaderCreateInfo *_info);
/**
* Create a shader using a named #GPUShaderCreateInfo registered at startup.
* These are declared inside `*_info.hh` files using the `GPU_SHADER_CREATE_INFO()` macro.
* They are also expected to have been flagged using `do_static_compilation`.
* Can return a NULL pointer if compilation fails.
*/
GPUShader *GPU_shader_create_from_info_name(const char *info_name);
/**
* Fetch a named #GPUShaderCreateInfo registered at startup.
* These are declared inside `*_info.hh` files using the `GPU_SHADER_CREATE_INFO()` macro.
* Can return a NULL pointer if no match is found.
*/
const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name);
/**
* Error checking for user created shaders.
* \return true is create info is valid.
*/
bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128]);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Free
* \{ */
void GPU_shader_free(GPUShader *shader);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Binding
* \{ */
/**
* Set the given shader as active shader for the active GPU context.
* It replaces any already bound shader.
* All following draw-calls and dispatches will use this shader.
* Uniform functions need to have the shader bound in order to work. (TODO: until we use
* glProgramUniform)
*/
void GPU_shader_bind(GPUShader *shader);
/**
* Unbind the active shader.
* \note this is a no-op in release builds. But it make sense to actually do it in user land code
* to detect incorrect API usage.
*/
void GPU_shader_unbind(void);
/**
* Return the currently bound shader to the active GPU context.
* \return NULL pointer if no shader is bound of if no context is active.
*/
GPUShader *GPU_shader_get_bound(void);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Debugging introspection API.
* \{ */
const char *GPU_shader_get_name(GPUShader *shader);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Uniform API.
* \{ */
/**
* Returns binding point location.
* Binding location are given to be set at shader compile time and immutable.
*/
int GPU_shader_get_ubo_binding(GPUShader *shader, const char *name);
int GPU_shader_get_ssbo_binding(GPUShader *shader, const char *name);
int GPU_shader_get_sampler_binding(GPUShader *shader, const char *name);
/**
* Returns uniform location.
* If cached, it is faster than querying the interface for each uniform assignment.
*/
int GPU_shader_get_uniform(GPUShader *shader, const char *name);
/**
* Sets a generic push constant (a.k.a. uniform).
* \a length and \a array_size should match the create info push_constant declaration.
*/
void GPU_shader_uniform_float_ex(
GPUShader *shader, int location, int length, int array_size, const float *value);
void GPU_shader_uniform_int_ex(
GPUShader *shader, int location, int length, int array_size, const int *value);
/**
* Sets a generic push constant (a.k.a. uniform).
* \a length and \a array_size should match the create info push_constant declaration.
* These functions need to have the shader bound in order to work. (TODO: until we use
* glProgramUniform)
*/
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value);
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value);
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value);
void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y);
void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z);
void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w);
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2]);
void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3]);
void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4]);
void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2]);
void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4]);
void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3]);
void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2]);
void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4]);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Attribute API.
*
* Used to create #GPUVertexFormat from the shader's vertex input layout.
* \{ */
unsigned int GPU_shader_get_attribute_len(const GPUShader *shader);
int GPU_shader_get_attribute(const GPUShader *shader, const char *name);
bool GPU_shader_get_attribute_info(const GPUShader *shader,
int attr_location,
char r_name[256],
int *r_type);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Legacy API
*
* All of this section is deprecated and should be ported to use the API described above.
* \{ */
typedef enum eGPUShaderTFBType {
GPU_SHADER_TFB_NONE = 0, /* Transform feedback unsupported. */
GPU_SHADER_TFB_POINTS = 1,
@ -51,54 +210,6 @@ GPUShader *GPU_shader_create_ex(const char *vertcode,
const char **tf_names,
int tf_count,
const char *shname);
GPUShader *GPU_shader_create_from_info(const GPUShaderCreateInfo *_info);
GPUShader *GPU_shader_create_from_info_name(const char *info_name);
const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name);
bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128]);
struct GPU_ShaderCreateFromArray_Params {
const char **vert, **geom, **frag, **defs;
};
/**
* Use via #GPU_shader_create_from_arrays macro (avoids passing in param).
*
* Similar to #DRW_shader_create_with_lib with the ability to include libraries for each type of
* shader.
*
* It has the advantage that each item can be conditionally included
* without having to build the string inline, then free it.
*
* \param params: NULL terminated arrays of strings.
*
* Example:
* \code{.c}
* sh = GPU_shader_create_from_arrays({
* .vert = (const char *[]){shader_lib_glsl, shader_vert_glsl, NULL},
* .geom = (const char *[]){shader_geom_glsl, NULL},
* .frag = (const char *[]){shader_frag_glsl, NULL},
* .defs = (const char *[]){"#define DEFINE\n", test ? "#define OTHER_DEFINE\n" : "", NULL},
* });
* \endcode
*/
struct GPUShader *GPU_shader_create_from_arrays_impl(
const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line);
#define GPU_shader_create_from_arrays(...) \
GPU_shader_create_from_arrays_impl( \
&(const struct GPU_ShaderCreateFromArray_Params)__VA_ARGS__, __func__, __LINE__)
#define GPU_shader_create_from_arrays_named(name, ...) \
GPU_shader_create_from_arrays_impl( \
&(const struct GPU_ShaderCreateFromArray_Params)__VA_ARGS__, name, 0)
void GPU_shader_free(GPUShader *shader);
void GPU_shader_bind(GPUShader *shader);
void GPU_shader_unbind(void);
GPUShader *GPU_shader_get_bound(void);
const char *GPU_shader_get_name(GPUShader *shader);
/**
* Returns true if transform feedback was successfully enabled.
@ -109,6 +220,9 @@ void GPU_shader_transform_feedback_disable(GPUShader *shader);
/** DEPRECATED: Kept only because of BGL API. */
int GPU_shader_get_program(GPUShader *shader);
/**
* Indexed commonly used uniform name for faster lookup into the uniform cache.
*/
typedef enum {
GPU_UNIFORM_MODEL = 0, /* mat4 ModelMatrix */
GPU_UNIFORM_VIEW, /* mat4 ViewMatrix */
@ -132,16 +246,19 @@ typedef enum {
GPU_UNIFORM_RESOURCE_CHUNK, /* int resourceChunk */
GPU_UNIFORM_RESOURCE_ID, /* int resourceId */
GPU_UNIFORM_SRGB_TRANSFORM, /* bool srgbTarget */
GPU_NUM_UNIFORMS, /* Special value, denotes number of builtin uniforms. */
} GPUUniformBuiltin;
#define GPU_NUM_UNIFORMS (GPU_UNIFORM_SRGB_TRANSFORM + 1)
/** TODO: To be moved as private API. Not really used outside of gpu_matrix.cc and doesn't really
* offer a noticeable perf boost. */
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin);
/** DEPRECATED: Use hardcoded buffer location instead. */
typedef enum {
/** Deprecated */
GPU_UNIFORM_BLOCK_VIEW = 0, /* viewBlock */
GPU_UNIFORM_BLOCK_MODEL, /* modelBlock */
GPU_UNIFORM_BLOCK_INFO, /* infoBlock */
/** New ones */
GPU_UNIFORM_BLOCK_DRW_VIEW,
GPU_UNIFORM_BLOCK_DRW_MODEL,
GPU_UNIFORM_BLOCK_DRW_INFOS,
@ -150,260 +267,13 @@ typedef enum {
GPU_NUM_UNIFORM_BLOCKS, /* Special value, denotes number of builtin uniforms block. */
} GPUUniformBlockBuiltin;
typedef enum {
GPU_STORAGE_BUFFER_DEBUG_VERTS = 0, /* drw_debug_verts_buf */
GPU_STORAGE_BUFFER_DEBUG_PRINT, /* drw_debug_print_buf */
GPU_NUM_STORAGE_BUFFERS, /* Special value, denotes number of builtin buffer blocks. */
} GPUStorageBufferBuiltin;
void GPU_shader_set_srgb_uniform(GPUShader *shader);
int GPU_shader_get_uniform(GPUShader *shader, const char *name);
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin);
/** DEPRECATED: Use hardcoded buffer location instead. */
int GPU_shader_get_builtin_block(GPUShader *shader, int builtin);
int GPU_shader_get_builtin_ssbo(GPUShader *shader, int builtin);
/** DEPRECATED: Kept only because of Python GPU API. */
int GPU_shader_get_uniform_block(GPUShader *shader, const char *name);
int GPU_shader_get_ssbo(GPUShader *shader, const char *name);
int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name);
int GPU_shader_get_texture_binding(GPUShader *shader, const char *name);
void GPU_shader_uniform_vector(
GPUShader *shader, int location, int length, int arraysize, const float *value);
void GPU_shader_uniform_vector_int(
GPUShader *shader, int location, int length, int arraysize, const int *value);
void GPU_shader_uniform_float(GPUShader *shader, int location, float value);
void GPU_shader_uniform_int(GPUShader *shader, int location, int value);
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value);
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value);
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value);
void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y);
void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z);
void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w);
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2]);
void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3]);
void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4]);
void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2]);
void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4]);
void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3]);
void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2]);
void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4]);
unsigned int GPU_shader_get_attribute_len(const GPUShader *shader);
int GPU_shader_get_attribute(GPUShader *shader, const char *name);
bool GPU_shader_get_attribute_info(const GPUShader *shader,
int attr_location,
char r_name[256],
int *r_type);
void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear);
/* Builtin/Non-generated shaders */
typedef enum eGPUBuiltinShader {
/* specialized drawing */
GPU_SHADER_TEXT,
GPU_SHADER_KEYFRAME_SHAPE,
GPU_SHADER_SIMPLE_LIGHTING,
/**
* Draw an icon, leaving a semi-transparent rectangle on top of the icon.
*/
GPU_SHADER_ICON,
/**
* Take a 2D position and color for each vertex with linear interpolation in window space.
*
* \param color: in vec4
* \param pos: in vec2
*/
GPU_SHADER_2D_IMAGE_DESATURATE_COLOR,
GPU_SHADER_2D_IMAGE_RECT_COLOR,
GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR,
GPU_SHADER_2D_CHECKER,
GPU_SHADER_2D_DIAG_STRIPES,
/* for simple 3D drawing */
/**
* Take a single color for all the vertices and a 3D position for each vertex.
*
* \param color: uniform vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_UNIFORM_COLOR,
GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR,
/**
* Take a 3D position and color for each vertex without color interpolation.
*
* \param color: in vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_FLAT_COLOR,
/**
* Take a 3D position and color for each vertex with perspective correct interpolation.
*
* \param color: in vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_SMOOTH_COLOR,
/**
* Take a single color for all the vertices and a 3D position for each vertex.
* Used for drawing wide lines.
*
* \param color: uniform vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR,
GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR,
/**
* Take a 3D position and color for each vertex without color interpolation.
* Used for drawing wide lines.
*
* \param color: in vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POLYLINE_FLAT_COLOR,
/**
* Take a 3D position and color for each vertex with perspective correct interpolation.
* Used for drawing wide lines.
*
* \param color: in vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR,
/**
* Take a 3D position for each vertex and output only depth.
* Used for drawing wide lines.
*
* \param pos: in vec3
*/
GPU_SHADER_3D_DEPTH_ONLY,
/* basic image drawing */
GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE,
GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE,
GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR,
/**
* Draw a texture in 3D. Take a 3D position and a 2D texture coordinate for each vertex.
*
* Exposed via Python-API for add-ons.
*
* \param image: uniform sampler2D
* \param texCoord: in vec2
* \param pos: in vec3
*/
GPU_SHADER_3D_IMAGE,
/**
* Take a 3D position and color for each vertex with linear interpolation in window space.
*
* \param color: uniform vec4
* \param image: uniform sampler2D
* \param texCoord: in vec2
* \param pos: in vec3
*/
GPU_SHADER_3D_IMAGE_COLOR,
/* points */
/**
* Draw round points with a constant size.
* Take a single color for all the vertices and a 2D position for each vertex.
*
* \param size: uniform float
* \param color: uniform vec4
* \param pos: in vec2
*/
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
/**
* Draw round points with a constant size and an outline.
* Take a single color for all the vertices and a 2D position for each vertex.
*
* \param size: uniform float
* \param outlineWidth: uniform float
* \param color: uniform vec4
* \param outlineColor: uniform vec4
* \param pos: in vec2
*/
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
/**
* Draw round points with a hardcoded size.
* Take a single color for all the vertices and a 3D position for each vertex.
*
* \param color: uniform vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR,
/**
* Draw round points with a constant size.
* Take a single color for all the vertices and a 3D position for each vertex.
*
* \param size: uniform float
* \param color: uniform vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
/**
* Draw round points with a constant size and an outline.
* Take a 3D position and a color for each vertex.
*
* \param size: in float
* \param color: in vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
/* lines */
GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR,
/* grease pencil drawing */
GPU_SHADER_GPENCIL_STROKE,
/* specialized for widget drawing */
GPU_SHADER_2D_AREA_BORDERS,
GPU_SHADER_2D_WIDGET_BASE,
GPU_SHADER_2D_WIDGET_BASE_INST,
GPU_SHADER_2D_WIDGET_SHADOW,
GPU_SHADER_2D_NODELINK,
GPU_SHADER_2D_NODELINK_INST,
} eGPUBuiltinShader;
#define GPU_SHADER_BUILTIN_LEN (GPU_SHADER_2D_NODELINK_INST + 1)
/** Support multiple configurations. */
typedef enum eGPUShaderConfig {
GPU_SHADER_CFG_DEFAULT = 0,
GPU_SHADER_CFG_CLIPPED = 1,
} eGPUShaderConfig;
#define GPU_SHADER_CFG_LEN (GPU_SHADER_CFG_CLIPPED + 1)
typedef struct GPUShaderConfigData {
const char *lib;
const char *def;
} GPUShaderConfigData;
/* gpu_shader.c */
extern const GPUShaderConfigData GPU_shader_cfg_data[GPU_SHADER_CFG_LEN];
GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
eGPUShaderConfig sh_cfg);
GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader);
void GPU_shader_free_builtin_shaders(void);
/* Vertex attributes for shaders */
/* Hardware limit is 16. Position attribute is always needed so we reduce to 15.
* This makes sure the GPUVertexFormat name buffer does not overflow. */
#define GPU_MAX_ATTR 15
/* Determined by the maximum uniform buffer size divided by chunk size. */
#define GPU_MAX_UNIFORM_ATTR 8
typedef enum eGPUKeyframeShapes {
GPU_KEYFRAME_SHAPE_DIAMOND = (1 << 0),
GPU_KEYFRAME_SHAPE_CIRCLE = (1 << 1),
GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL = (1 << 2),
GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL = (1 << 3),
GPU_KEYFRAME_SHAPE_INNER_DOT = (1 << 4),
GPU_KEYFRAME_SHAPE_ARROW_END_MAX = (1 << 8),
GPU_KEYFRAME_SHAPE_ARROW_END_MIN = (1 << 9),
GPU_KEYFRAME_SHAPE_ARROW_END_MIXED = (1 << 10),
} eGPUKeyframeShapes;
#define GPU_KEYFRAME_SHAPE_SQUARE \
(GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL)
/** \} */
#ifdef __cplusplus
}

View File

@ -0,0 +1,147 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2023 Blender Foundation. All rights reserved. */
/** \file
* \ingroup gpu
*
* Set of shaders used for interface drawing.
*
* 2D shaders are not expected to work in 3D.
* 3D shaders can work with 2D geometry and matrices.
*
* `INST` suffix means instance, which means the shader is build to leverage instancing
* capabilities to reduce the number of draw-calls.
*
* For full list of parameters, search for the the associated #ShaderCreateInfo.
* Example: `GPU_SHADER_ICON` is defined by `GPU_SHADER_CREATE_INFO(gpu_shader_icon)`
* Some parameters are builtins and are set automatically (ex: `ModelViewProjectionMatrix`).
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
struct GPUShader;
typedef enum eGPUBuiltinShader {
/** Glyph drawing shader used by the BLF module. */
GPU_SHADER_TEXT,
/** Draws keyframe markers. All markers shapes are supported through a single shader. */
GPU_SHADER_KEYFRAME_SHAPE,
/** Draw solid mesh with a single distant light using a clamped simple dot product. */
GPU_SHADER_SIMPLE_LIGHTING,
/** Draw an icon, leaving a semi-transparent rectangle on top of the icon. */
GPU_SHADER_ICON,
/** Draw a texture with a uniform color multiplied. */
GPU_SHADER_2D_IMAGE_RECT_COLOR,
/** Draw a texture with a desaturation factor. */
GPU_SHADER_2D_IMAGE_DESATURATE_COLOR,
/** Draw a group of texture rectangle with an associated color multiplied. */
GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR,
/** Draw a two color checker based on screen position (not UV coordinates). */
GPU_SHADER_2D_CHECKER,
/** Draw diagonal stripes with two alternating colors. */
GPU_SHADER_2D_DIAG_STRIPES,
/** Draw dashed lines with custom dash length and uniform color. */
GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR,
/** Draw triangles / lines / points with only depth output. */
GPU_SHADER_3D_DEPTH_ONLY,
/** Merge viewport overlay texture with the render output. */
GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE,
GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE,
/** Merge viewport overlay texture with the render output. */
GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR,
/** Used for drawing of annotations (former grease pencil). */
GPU_SHADER_GPENCIL_STROKE,
/** Draw rounded area borders with silky smooth anti-aliasing without any over-draw. */
GPU_SHADER_2D_AREA_BORDERS,
/** Multi usage widget shaders for drawing buttons and other UI elements. */
GPU_SHADER_2D_WIDGET_BASE,
GPU_SHADER_2D_WIDGET_BASE_INST,
GPU_SHADER_2D_WIDGET_SHADOW,
/** Draw a node link given an input quadratic Bezier curve. */
GPU_SHADER_2D_NODELINK,
GPU_SHADER_2D_NODELINK_INST,
/** Draw round points with per vertex size and color. */
GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
/** Draw round points with a uniform size. Disabling blending will disable AA. */
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
/** Draw round points with a uniform size and an outline. Disabling blending will disable AA. */
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
/** Draw geometry with uniform color. Has an additional clip plane parameter. */
GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR,
/** Draw wide lines with uniform color. Has an additional clip plane parameter. */
GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR,
/**
* ----------------------- Shaders exposed through pyGPU module -----------------------
*
* Avoid breaking the interface of these shaders as they are used by addons.
* Polyline versions are used for drawing wide lines (> 1px width).
*/
/**
* Take a 3D position and color for each vertex without color interpolation.
*
* \param color: in vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_FLAT_COLOR,
GPU_SHADER_3D_POLYLINE_FLAT_COLOR,
/**
* Take a 3D position and color for each vertex with perspective correct interpolation.
*
* \param color: in vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_SMOOTH_COLOR,
GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR,
/**
* Take a single color for all the vertices and a 3D position for each vertex.
*
* \param color: uniform vec4
* \param pos: in vec3
*/
GPU_SHADER_3D_UNIFORM_COLOR,
GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR,
/**
* Draw a texture in 3D. Take a 3D position and a 2D texture coordinate for each vertex.
*
* \param image: uniform sampler2D
* \param texCoord: in vec2
* \param pos: in vec3
*/
GPU_SHADER_3D_IMAGE,
/**
* Take a 3D position and color for each vertex with linear interpolation in window space.
*
* \param color: uniform vec4
* \param image: uniform sampler2D
* \param texCoord: in vec2
* \param pos: in vec3
*/
GPU_SHADER_3D_IMAGE_COLOR,
} eGPUBuiltinShader;
#define GPU_SHADER_BUILTIN_LEN (GPU_SHADER_3D_IMAGE_COLOR + 1)
/** Support multiple configurations. */
typedef enum eGPUShaderConfig {
GPU_SHADER_CFG_DEFAULT = 0,
GPU_SHADER_CFG_CLIPPED = 1,
} eGPUShaderConfig;
#define GPU_SHADER_CFG_LEN (GPU_SHADER_CFG_CLIPPED + 1)
struct GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
eGPUShaderConfig sh_cfg);
struct GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader);
void GPU_shader_free_builtin_shaders(void);
#ifdef __cplusplus
}
#endif

View File

@ -11,6 +11,19 @@
typedef struct TestOutputRawData TestOutputRawData;
#endif
enum eGPUKeyframeShapes {
GPU_KEYFRAME_SHAPE_DIAMOND = (1u << 0u),
GPU_KEYFRAME_SHAPE_CIRCLE = (1u << 1u),
GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL = (1u << 2u),
GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL = (1u << 3u),
GPU_KEYFRAME_SHAPE_INNER_DOT = (1u << 4u),
GPU_KEYFRAME_SHAPE_ARROW_END_MAX = (1u << 8u),
GPU_KEYFRAME_SHAPE_ARROW_END_MIN = (1u << 9u),
GPU_KEYFRAME_SHAPE_ARROW_END_MIXED = (1u << 10u),
GPU_KEYFRAME_SHAPE_SQUARE = (GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL |
GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL),
};
struct NodeLinkData {
float4 colors[3];
/* bezierPts Is actually a float2, but due to std140 each element needs to be aligned to 16

View File

@ -54,7 +54,7 @@ void immBindShader(GPUShader *shader)
GPU_shader_bind(shader);
GPU_matrix_bind(shader);
GPU_shader_set_srgb_uniform(shader);
Shader::set_srgb_uniform(shader);
}
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
@ -602,19 +602,19 @@ void immUniform1i(const char *name, int x)
void immBindTexture(const char *name, GPUTexture *tex)
{
int binding = GPU_shader_get_texture_binding(imm->shader, name);
int binding = GPU_shader_get_sampler_binding(imm->shader, name);
GPU_texture_bind(tex, binding);
}
void immBindTextureSampler(const char *name, GPUTexture *tex, eGPUSamplerState state)
{
int binding = GPU_shader_get_texture_binding(imm->shader, name);
int binding = GPU_shader_get_sampler_binding(imm->shader, name);
GPU_texture_bind_ex(tex, state, binding, true);
}
void immBindUniformBuf(const char *name, GPUUniformBuf *ubo)
{
int binding = GPU_shader_get_uniform_block_binding(imm->shader, name);
int binding = GPU_shader_get_ubo_binding(imm->shader, name);
GPU_uniformbuf_bind(ubo, binding);
}
@ -625,7 +625,7 @@ void immUniformColor4f(float r, float g, float b, float a)
int32_t uniform_loc = GPU_shader_get_builtin_uniform(imm->shader, GPU_UNIFORM_COLOR);
BLI_assert(uniform_loc != -1);
float data[4] = {r, g, b, a};
GPU_shader_uniform_vector(imm->shader, uniform_loc, 4, 1, data);
GPU_shader_uniform_float_ex(imm->shader, uniform_loc, 4, 1, data);
/* For wide Line workaround. */
copy_v4_v4(imm->uniform_color, data);
}

View File

@ -623,30 +623,31 @@ void GPU_matrix_bind(GPUShader *shader)
int32_t P_inv = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_PROJECTION_INV);
if (MV != -1) {
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
shader, MV, 16, 1, (const float *)GPU_matrix_model_view_get(nullptr));
}
if (P != -1) {
GPU_shader_uniform_vector(shader, P, 16, 1, (const float *)GPU_matrix_projection_get(nullptr));
GPU_shader_uniform_float_ex(
shader, P, 16, 1, (const float *)GPU_matrix_projection_get(nullptr));
}
if (MVP != -1) {
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
shader, MVP, 16, 1, (const float *)GPU_matrix_model_view_projection_get(nullptr));
}
if (N != -1) {
GPU_shader_uniform_vector(shader, N, 9, 1, (const float *)GPU_matrix_normal_get(nullptr));
GPU_shader_uniform_float_ex(shader, N, 9, 1, (const float *)GPU_matrix_normal_get(nullptr));
}
if (MV_inv != -1) {
Mat4 m;
GPU_matrix_model_view_get(m);
invert_m4(m);
GPU_shader_uniform_vector(shader, MV_inv, 16, 1, (const float *)m);
GPU_shader_uniform_float_ex(shader, MV_inv, 16, 1, (const float *)m);
}
if (P_inv != -1) {
Mat4 m;
GPU_matrix_projection_get(m);
invert_m4(m);
GPU_shader_uniform_vector(shader, P_inv, 16, 1, (const float *)m);
GPU_shader_uniform_float_ex(shader, P_inv, 16, 1, (const float *)m);
}
gpu_matrix_state_active_set_dirty(false);

View File

@ -46,8 +46,6 @@ std::string Shader::defines_declare(const shader::ShaderCreateInfo &info) const
using namespace blender;
using namespace blender::gpu;
static bool gpu_shader_srgb_uniform_dirty_get();
/* -------------------------------------------------------------------- */
/** \name Creation / Destruction
* \{ */
@ -443,58 +441,6 @@ GPUShader *GPU_shader_create_from_python(const char *vertcode,
return sh;
}
static const char *string_join_array_maybe_alloc(const char **str_arr, bool *r_is_alloc)
{
bool is_alloc = false;
if (str_arr == nullptr) {
*r_is_alloc = false;
return nullptr;
}
/* Skip empty strings (avoid alloc if we can). */
while (str_arr[0] && str_arr[0][0] == '\0') {
str_arr++;
}
int i;
for (i = 0; str_arr[i]; i++) {
if (i != 0 && str_arr[i][0] != '\0') {
is_alloc = true;
}
}
*r_is_alloc = is_alloc;
if (is_alloc) {
return BLI_string_join_arrayN(str_arr, i);
}
return str_arr[0];
}
struct GPUShader *GPU_shader_create_from_arrays_impl(
const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line)
{
struct {
const char *str;
bool is_alloc;
} str_dst[4] = {{nullptr}};
const char **str_src[4] = {params->vert, params->frag, params->geom, params->defs};
for (int i = 0; i < ARRAY_SIZE(str_src); i++) {
str_dst[i].str = string_join_array_maybe_alloc(str_src[i], &str_dst[i].is_alloc);
}
char name[64];
BLI_snprintf(name, sizeof(name), "%s_%d", func, line);
GPUShader *sh = GPU_shader_create(
str_dst[0].str, str_dst[1].str, str_dst[2].str, nullptr, str_dst[3].str, name);
for (auto &i : str_dst) {
if (i.is_alloc) {
MEM_freeN((void *)i.str);
}
}
return sh;
}
/** \} */
/* -------------------------------------------------------------------- */
@ -511,11 +457,11 @@ void GPU_shader_bind(GPUShader *gpu_shader)
ctx->shader = shader;
shader->bind();
GPU_matrix_bind(gpu_shader);
GPU_shader_set_srgb_uniform(gpu_shader);
Shader::set_srgb_uniform(gpu_shader);
}
else {
if (gpu_shader_srgb_uniform_dirty_get()) {
GPU_shader_set_srgb_uniform(gpu_shader);
if (Shader::srgb_uniform_dirty_get()) {
Shader::set_srgb_uniform(gpu_shader);
}
if (GPU_matrix_dirty_get()) {
GPU_matrix_bind(gpu_shader);
@ -580,66 +526,60 @@ void GPU_shader_transform_feedback_disable(GPUShader *shader)
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
{
ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInput *uniform = interface->uniform_get(name);
return uniform ? uniform->location : -1;
}
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
{
ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInterface *interface = unwrap(shader)->interface;
return interface->uniform_builtin((GPUUniformBuiltin)builtin);
}
int GPU_shader_get_builtin_block(GPUShader *shader, int builtin)
{
ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInterface *interface = unwrap(shader)->interface;
return interface->ubo_builtin((GPUUniformBlockBuiltin)builtin);
}
int GPU_shader_get_builtin_ssbo(GPUShader *shader, int builtin)
int GPU_shader_get_ssbo_binding(GPUShader *shader, const char *name)
{
ShaderInterface *interface = unwrap(shader)->interface;
return interface->ssbo_builtin((GPUStorageBufferBuiltin)builtin);
}
int GPU_shader_get_ssbo(GPUShader *shader, const char *name)
{
ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInput *ssbo = interface->ssbo_get(name);
return ssbo ? ssbo->location : -1;
}
int GPU_shader_get_uniform_block(GPUShader *shader, const char *name)
{
ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInput *ubo = interface->ubo_get(name);
return ubo ? ubo->location : -1;
}
int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name)
int GPU_shader_get_ubo_binding(GPUShader *shader, const char *name)
{
ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInput *ubo = interface->ubo_get(name);
return ubo ? ubo->binding : -1;
}
int GPU_shader_get_texture_binding(GPUShader *shader, const char *name)
int GPU_shader_get_sampler_binding(GPUShader *shader, const char *name)
{
ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInput *tex = interface->uniform_get(name);
return tex ? tex->binding : -1;
}
uint GPU_shader_get_attribute_len(const GPUShader *shader)
{
ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInterface *interface = unwrap(shader)->interface;
return interface->attr_len_;
}
int GPU_shader_get_attribute(GPUShader *shader, const char *name)
int GPU_shader_get_attribute(const GPUShader *shader, const char *name)
{
ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInput *attr = interface->attr_get(name);
return attr ? attr->location : -1;
}
@ -649,7 +589,7 @@ bool GPU_shader_get_attribute_info(const GPUShader *shader,
char r_name[256],
int *r_type)
{
ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInterface *interface = unwrap(shader)->interface;
const ShaderInput *attr = interface->attr_get(attr_location);
if (!attr) {
@ -678,32 +618,22 @@ int GPU_shader_get_program(GPUShader *shader)
/** \name Uniforms setters
* \{ */
void GPU_shader_uniform_vector(
GPUShader *shader, int loc, int len, int arraysize, const float *value)
void GPU_shader_uniform_float_ex(
GPUShader *shader, int loc, int len, int array_size, const float *value)
{
unwrap(shader)->uniform_float(loc, len, arraysize, value);
unwrap(shader)->uniform_float(loc, len, array_size, value);
}
void GPU_shader_uniform_vector_int(
GPUShader *shader, int loc, int len, int arraysize, const int *value)
void GPU_shader_uniform_int_ex(
GPUShader *shader, int loc, int len, int array_size, const int *value)
{
unwrap(shader)->uniform_int(loc, len, arraysize, value);
}
void GPU_shader_uniform_int(GPUShader *shader, int location, int value)
{
GPU_shader_uniform_vector_int(shader, location, 1, 1, &value);
}
void GPU_shader_uniform_float(GPUShader *shader, int location, float value)
{
GPU_shader_uniform_vector(shader, location, 1, 1, &value);
unwrap(shader)->uniform_int(loc, len, array_size, value);
}
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_int(sh, loc, value);
GPU_shader_uniform_int_ex(sh, loc, 1, 1, &value);
}
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
@ -732,37 +662,37 @@ void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, fl
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_float(sh, loc, value);
GPU_shader_uniform_float_ex(sh, loc, 1, 1, &value);
}
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 2, 1, data);
GPU_shader_uniform_float_ex(sh, loc, 2, 1, data);
}
void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 3, 1, data);
GPU_shader_uniform_float_ex(sh, loc, 3, 1, data);
}
void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 4, 1, data);
GPU_shader_uniform_float_ex(sh, loc, 4, 1, data);
}
void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector_int(sh, loc, 2, 1, data);
GPU_shader_uniform_int_ex(sh, loc, 2, 1, data);
}
void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 16, 1, (const float *)data);
GPU_shader_uniform_float_ex(sh, loc, 16, 1, (const float *)data);
}
void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3])
@ -775,13 +705,13 @@ void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const floa
void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 2, len, (const float *)val);
GPU_shader_uniform_float_ex(sh, loc, 2, len, (const float *)val);
}
void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4])
{
const int loc = GPU_shader_get_uniform(sh, name);
GPU_shader_uniform_vector(sh, loc, 4, len, (const float *)val);
GPU_shader_uniform_float_ex(sh, loc, 4, len, (const float *)val);
}
/** \} */
@ -797,24 +727,26 @@ void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, cons
* frame-buffer color-space.
* \{ */
namespace blender::gpu {
static int g_shader_builtin_srgb_transform = 0;
static bool g_shader_builtin_srgb_is_dirty = false;
static bool gpu_shader_srgb_uniform_dirty_get()
bool Shader::srgb_uniform_dirty_get()
{
return g_shader_builtin_srgb_is_dirty;
}
void GPU_shader_set_srgb_uniform(GPUShader *shader)
void Shader::set_srgb_uniform(GPUShader *shader)
{
int32_t loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_SRGB_TRANSFORM);
if (loc != -1) {
GPU_shader_uniform_vector_int(shader, loc, 1, 1, &g_shader_builtin_srgb_transform);
GPU_shader_uniform_int_ex(shader, loc, 1, 1, &g_shader_builtin_srgb_transform);
}
g_shader_builtin_srgb_is_dirty = false;
}
void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear)
void Shader::set_framebuffer_srgb_target(int use_srgb_to_linear)
{
if (g_shader_builtin_srgb_transform != use_srgb_to_linear) {
g_shader_builtin_srgb_transform = use_srgb_to_linear;
@ -822,4 +754,6 @@ void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear)
}
}
} // namespace blender::gpu
/** \} */

View File

@ -1,404 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2005 Blender Foundation. All rights reserved. */
/** \file
* \ingroup gpu
*/
#include "BLI_utildefines.h"
#include "GPU_shader.h"
/* Adjust these constants as needed. */
#define MAX_DEFINE_LENGTH 256
#define MAX_EXT_DEFINE_LENGTH 512
/* Non-generated shaders */
extern char datatoc_gpu_shader_depth_only_frag_glsl[];
extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
extern char datatoc_gpu_shader_checker_frag_glsl[];
extern char datatoc_gpu_shader_diag_stripes_frag_glsl[];
extern char datatoc_gpu_shader_simple_lighting_frag_glsl[];
extern char datatoc_gpu_shader_flat_color_frag_glsl[];
extern char datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl[];
extern char datatoc_gpu_shader_flat_id_frag_glsl[];
extern char datatoc_gpu_shader_2D_area_borders_vert_glsl[];
extern char datatoc_gpu_shader_2D_area_borders_frag_glsl[];
extern char datatoc_gpu_shader_2D_vert_glsl[];
extern char datatoc_gpu_shader_2D_smooth_color_uniform_alpha_vert_glsl[];
extern char datatoc_gpu_shader_2D_image_vert_glsl[];
extern char datatoc_gpu_shader_2D_image_rect_vert_glsl[];
extern char datatoc_gpu_shader_2D_image_multi_rect_vert_glsl[];
extern char datatoc_gpu_shader_2D_widget_base_vert_glsl[];
extern char datatoc_gpu_shader_2D_widget_base_frag_glsl[];
extern char datatoc_gpu_shader_2D_widget_shadow_vert_glsl[];
extern char datatoc_gpu_shader_2D_widget_shadow_frag_glsl[];
extern char datatoc_gpu_shader_2D_nodelink_frag_glsl[];
extern char datatoc_gpu_shader_2D_nodelink_vert_glsl[];
extern char datatoc_gpu_shader_3D_image_vert_glsl[];
extern char datatoc_gpu_shader_image_frag_glsl[];
extern char datatoc_gpu_shader_image_overlays_merge_frag_glsl[];
extern char datatoc_gpu_shader_image_overlays_stereo_merge_frag_glsl[];
extern char datatoc_gpu_shader_image_color_frag_glsl[];
extern char datatoc_gpu_shader_image_desaturate_frag_glsl[];
extern char datatoc_gpu_shader_image_modulate_alpha_frag_glsl[];
extern char datatoc_gpu_shader_image_varying_color_frag_glsl[];
extern char datatoc_gpu_shader_image_shuffle_color_frag_glsl[];
extern char datatoc_gpu_shader_3D_vert_glsl[];
extern char datatoc_gpu_shader_3D_normal_vert_glsl[];
extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[];
extern char datatoc_gpu_shader_3D_polyline_frag_glsl[];
extern char datatoc_gpu_shader_3D_polyline_geom_glsl[];
extern char datatoc_gpu_shader_3D_polyline_vert_glsl[];
extern char datatoc_gpu_shader_3D_smooth_color_vert_glsl[];
extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
extern char datatoc_gpu_shader_3D_passthrough_vert_glsl[];
extern char datatoc_gpu_shader_3D_clipped_uniform_color_vert_glsl[];
extern char datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl[];
extern char datatoc_gpu_shader_point_uniform_color_aa_frag_glsl[];
extern char datatoc_gpu_shader_point_uniform_color_outline_aa_frag_glsl[];
extern char datatoc_gpu_shader_point_varying_color_varying_outline_aa_frag_glsl[];
extern char datatoc_gpu_shader_point_varying_color_frag_glsl[];
extern char datatoc_gpu_shader_3D_point_fixed_size_varying_color_vert_glsl[];
extern char datatoc_gpu_shader_3D_point_varying_size_varying_color_vert_glsl[];
extern char datatoc_gpu_shader_3D_point_uniform_size_aa_vert_glsl[];
extern char datatoc_gpu_shader_2D_point_uniform_size_aa_vert_glsl[];
extern char datatoc_gpu_shader_2D_point_uniform_size_outline_aa_vert_glsl[];
extern char datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl[];
extern char datatoc_gpu_shader_2D_line_dashed_frag_glsl[];
extern char datatoc_gpu_shader_3D_line_dashed_uniform_color_vert_glsl[];
extern char datatoc_gpu_shader_text_vert_glsl[];
extern char datatoc_gpu_shader_text_frag_glsl[];
extern char datatoc_gpu_shader_keyframe_shape_vert_glsl[];
extern char datatoc_gpu_shader_keyframe_shape_frag_glsl[];
extern char datatoc_gpu_shader_gpencil_stroke_vert_glsl[];
extern char datatoc_gpu_shader_gpencil_stroke_frag_glsl[];
extern char datatoc_gpu_shader_gpencil_stroke_geom_glsl[];
extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
extern char datatoc_gpu_shader_colorspace_lib_glsl[];
const struct GPUShaderConfigData GPU_shader_cfg_data[GPU_SHADER_CFG_LEN] = {
[GPU_SHADER_CFG_DEFAULT] =
{
.lib = "",
.def = "#define blender_srgb_to_framebuffer_space(a) a\n",
},
[GPU_SHADER_CFG_CLIPPED] =
{
.lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl,
.def = "#define USE_WORLD_CLIP_PLANES\n"
"#define blender_srgb_to_framebuffer_space(a) a\n",
},
};
/* cache of built-in shaders (each is created on first use) */
static GPUShader *builtin_shaders[GPU_SHADER_CFG_LEN][GPU_SHADER_BUILTIN_LEN] = {{NULL}};
typedef struct {
const char *name;
const char *vert;
/** Optional. */
const char *geom;
const char *frag;
/** Optional. */
const char *defs;
const char *create_info;
const char *clipped_create_info;
} GPUShaderStages;
static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
[GPU_SHADER_TEXT] =
{
.name = "GPU_SHADER_TEXT",
.create_info = "gpu_shader_text",
},
[GPU_SHADER_KEYFRAME_SHAPE] =
{
.name = "GPU_SHADER_KEYFRAME_SHAPE",
.create_info = "gpu_shader_keyframe_shape",
},
[GPU_SHADER_SIMPLE_LIGHTING] =
{
.name = "GPU_SHADER_SIMPLE_LIGHTING",
.create_info = "gpu_shader_simple_lighting",
},
[GPU_SHADER_3D_IMAGE] =
{
.name = "GPU_SHADER_3D_IMAGE",
.create_info = "gpu_shader_3D_image",
},
[GPU_SHADER_3D_IMAGE_COLOR] =
{
.name = "GPU_SHADER_3D_IMAGE_COLOR",
.create_info = "gpu_shader_3D_image_color",
},
[GPU_SHADER_2D_CHECKER] =
{
.name = "GPU_SHADER_2D_CHECKER",
.create_info = "gpu_shader_2D_checker",
},
[GPU_SHADER_2D_DIAG_STRIPES] =
{
.name = "GPU_SHADER_2D_DIAG_STRIPES",
.create_info = "gpu_shader_2D_diag_stripes",
},
[GPU_SHADER_ICON] =
{
.name = "GPU_SHADER_ICON",
.create_info = "gpu_shader_icon",
},
[GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE] =
{
.name = "GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE",
.create_info = "gpu_shader_2D_image_overlays_merge",
},
[GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE] =
{
.name = "GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE",
.create_info = "gpu_shader_2D_image_overlays_stereo_merge",
},
[GPU_SHADER_2D_IMAGE_DESATURATE_COLOR] =
{
.name = "GPU_SHADER_2D_IMAGE_DESATURATE_COLOR",
.create_info = "gpu_shader_2D_image_desaturate_color",
},
[GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR] =
{
.name = "GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR",
.create_info = "gpu_shader_2D_image_shuffle_color",
},
[GPU_SHADER_2D_IMAGE_RECT_COLOR] =
{
.name = "GPU_SHADER_2D_IMAGE_RECT_COLOR",
.create_info = "gpu_shader_2D_image_rect_color",
},
[GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR] =
{
.name = "GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR",
.create_info = "gpu_shader_2D_image_multi_rect_color",
},
[GPU_SHADER_3D_UNIFORM_COLOR] =
{
.name = "GPU_SHADER_3D_UNIFORM_COLOR",
.create_info = "gpu_shader_3D_uniform_color",
.clipped_create_info = "gpu_shader_3D_uniform_color_clipped",
},
[GPU_SHADER_3D_FLAT_COLOR] =
{
.name = "GPU_SHADER_3D_FLAT_COLOR",
.create_info = "gpu_shader_3D_flat_color",
.clipped_create_info = "gpu_shader_3D_flat_color_clipped",
},
[GPU_SHADER_3D_SMOOTH_COLOR] =
{
.name = "GPU_SHADER_3D_SMOOTH_COLOR",
.create_info = "gpu_shader_3D_smooth_color",
.clipped_create_info = "gpu_shader_3D_smooth_color_clipped",
},
[GPU_SHADER_3D_DEPTH_ONLY] =
{
.name = "GPU_SHADER_3D_DEPTH_ONLY",
.create_info = "gpu_shader_3D_depth_only",
.clipped_create_info = "gpu_shader_3D_depth_only_clipped",
},
[GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR] =
{
.name = "GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR",
.create_info = "gpu_shader_3D_clipped_uniform_color",
},
[GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR] =
{
.name = "GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR",
.create_info = "gpu_shader_3D_polyline_uniform_color",
},
[GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR] =
{
.name = "GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR",
.create_info = "gpu_shader_3D_polyline_uniform_color_clipped",
},
[GPU_SHADER_3D_POLYLINE_FLAT_COLOR] =
{
.name = "GPU_SHADER_3D_POLYLINE_FLAT_COLOR",
.create_info = "gpu_shader_3D_polyline_flat_color",
},
[GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR] =
{
.name = "GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR",
.create_info = "gpu_shader_3D_polyline_smooth_color",
},
[GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR] =
{
.name = "GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR",
.create_info = "gpu_shader_3D_line_dashed_uniform_color",
.clipped_create_info = "gpu_shader_3D_line_dashed_uniform_color_clipped",
},
[GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA] =
{
.name = "GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA",
.create_info = "gpu_shader_2D_point_uniform_size_uniform_color_aa",
},
[GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA] =
{
.name = "GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA",
.create_info = "gpu_shader_2D_point_uniform_size_uniform_color_outline_aa",
},
[GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR] =
{
.name = "GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR",
.create_info = "gpu_shader_3D_point_fixed_size_varying_color",
},
[GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR] =
{
.name = "GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR",
.create_info = "gpu_shader_3D_point_varying_size_varying_color",
},
[GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA] =
{
.name = "GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA",
.create_info = "gpu_shader_3D_point_uniform_size_uniform_color_aa",
.clipped_create_info = "gpu_shader_3D_point_uniform_size_uniform_color_aa_clipped",
},
[GPU_SHADER_2D_AREA_BORDERS] =
{
.name = "GPU_SHADER_2D_AREA_BORDERS",
.create_info = "gpu_shader_2D_area_borders",
},
[GPU_SHADER_2D_WIDGET_BASE] =
{
.name = "GPU_SHADER_2D_WIDGET_BASE",
.create_info = "gpu_shader_2D_widget_base",
},
[GPU_SHADER_2D_WIDGET_BASE_INST] =
{
.name = "GPU_SHADER_2D_WIDGET_BASE_INST",
.defs = "#define USE_INSTANCE\n",
.create_info = "gpu_shader_2D_widget_base_inst",
},
[GPU_SHADER_2D_WIDGET_SHADOW] =
{
.name = "GPU_SHADER_2D_WIDGET_SHADOW",
.create_info = "gpu_shader_2D_widget_shadow",
},
[GPU_SHADER_2D_NODELINK] =
{
.name = "GPU_SHADER_2D_NODELINK",
.create_info = "gpu_shader_2D_nodelink",
},
[GPU_SHADER_2D_NODELINK_INST] =
{
.name = "GPU_SHADER_2D_NODELINK_INST",
.create_info = "gpu_shader_2D_nodelink_inst",
},
[GPU_SHADER_GPENCIL_STROKE] =
{
.name = "GPU_SHADER_GPENCIL_STROKE",
.create_info = "gpu_shader_gpencil_stroke",
},
};
GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
eGPUShaderConfig sh_cfg)
{
BLI_assert(shader < GPU_SHADER_BUILTIN_LEN);
BLI_assert(sh_cfg < GPU_SHADER_CFG_LEN);
GPUShader **sh_p = &builtin_shaders[sh_cfg][shader];
if (*sh_p == NULL) {
const GPUShaderStages *stages = &builtin_shader_stages[shader];
/* common case */
if (sh_cfg == GPU_SHADER_CFG_DEFAULT) {
if (stages->create_info != NULL) {
*sh_p = GPU_shader_create_from_info_name(stages->create_info);
if (ELEM(shader,
GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR,
GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR,
GPU_SHADER_3D_POLYLINE_FLAT_COLOR,
GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR)) {
/* Set a default value for `lineSmooth`.
* Ideally this value should be set by the caller. */
GPU_shader_bind(*sh_p);
GPU_shader_uniform_1i(*sh_p, "lineSmooth", 1);
}
}
else {
*sh_p = GPU_shader_create_from_arrays_named(
stages->name,
{
.vert = (const char *[]){stages->vert, NULL},
.geom = (const char *[]){stages->geom, NULL},
.frag =
(const char *[]){datatoc_gpu_shader_colorspace_lib_glsl, stages->frag, NULL},
.defs = (const char *[]){stages->defs, NULL},
});
}
}
else if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
/* Remove eventually, for now ensure support for each shader has been added. */
BLI_assert(ELEM(shader,
GPU_SHADER_3D_UNIFORM_COLOR,
GPU_SHADER_3D_SMOOTH_COLOR,
GPU_SHADER_3D_DEPTH_ONLY,
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
GPU_SHADER_3D_FLAT_COLOR,
GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR));
/* In rare cases geometry shaders calculate clipping themselves. */
if (stages->clipped_create_info != NULL) {
*sh_p = GPU_shader_create_from_info_name(stages->clipped_create_info);
}
else {
const char *world_clip_lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl;
const char *world_clip_def = "#define USE_WORLD_CLIP_PLANES\n";
*sh_p = GPU_shader_create_from_arrays_named(
stages->name,
{
.vert = (const char *[]){world_clip_lib, stages->vert, NULL},
.geom = (const char *[]){stages->geom ? world_clip_lib : NULL, stages->geom, NULL},
.frag =
(const char *[]){datatoc_gpu_shader_colorspace_lib_glsl, stages->frag, NULL},
.defs = (const char *[]){world_clip_def, stages->defs, NULL},
});
}
}
else {
BLI_assert(0);
}
}
return *sh_p;
}
GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader)
{
return GPU_shader_get_builtin_shader_with_config(shader, GPU_SHADER_CFG_DEFAULT);
}
void GPU_shader_free_builtin_shaders(void)
{
for (int i = 0; i < GPU_SHADER_CFG_LEN; i++) {
for (int j = 0; j < GPU_SHADER_BUILTIN_LEN; j++) {
if (builtin_shaders[i][j]) {
GPU_shader_free(builtin_shaders[i][j]);
builtin_shaders[i][j] = NULL;
}
}
}
}

View File

@ -0,0 +1,164 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2005 Blender Foundation. All rights reserved. */
/** \file
* \ingroup gpu
*/
#include "BLI_utildefines.h"
#include "GPU_shader.h"
/* Cache of built-in shaders (each is created on first use). */
static GPUShader *builtin_shaders[GPU_SHADER_CFG_LEN][GPU_SHADER_BUILTIN_LEN] = {{nullptr}};
static const char *builtin_shader_create_info_name(eGPUBuiltinShader shader)
{
switch (shader) {
case GPU_SHADER_TEXT:
return "gpu_shader_text";
case GPU_SHADER_KEYFRAME_SHAPE:
return "gpu_shader_keyframe_shape";
case GPU_SHADER_SIMPLE_LIGHTING:
return "gpu_shader_simple_lighting";
case GPU_SHADER_3D_IMAGE:
return "gpu_shader_3D_image";
case GPU_SHADER_3D_IMAGE_COLOR:
return "gpu_shader_3D_image_color";
case GPU_SHADER_2D_CHECKER:
return "gpu_shader_2D_checker";
case GPU_SHADER_2D_DIAG_STRIPES:
return "gpu_shader_2D_diag_stripes";
case GPU_SHADER_ICON:
return "gpu_shader_icon";
case GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE:
return "gpu_shader_2D_image_overlays_merge";
case GPU_SHADER_2D_IMAGE_OVERLAYS_STEREO_MERGE:
return "gpu_shader_2D_image_overlays_stereo_merge";
case GPU_SHADER_2D_IMAGE_DESATURATE_COLOR:
return "gpu_shader_2D_image_desaturate_color";
case GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR:
return "gpu_shader_2D_image_shuffle_color";
case GPU_SHADER_2D_IMAGE_RECT_COLOR:
return "gpu_shader_2D_image_rect_color";
case GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR:
return "gpu_shader_2D_image_multi_rect_color";
case GPU_SHADER_3D_UNIFORM_COLOR:
return "gpu_shader_3D_uniform_color";
case GPU_SHADER_3D_FLAT_COLOR:
return "gpu_shader_3D_flat_color";
case GPU_SHADER_3D_SMOOTH_COLOR:
return "gpu_shader_3D_smooth_color";
case GPU_SHADER_3D_DEPTH_ONLY:
return "gpu_shader_3D_depth_only";
case GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR:
return "gpu_shader_3D_clipped_uniform_color";
case GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR:
return "gpu_shader_3D_polyline_uniform_color";
case GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR:
return "gpu_shader_3D_polyline_uniform_color_clipped";
case GPU_SHADER_3D_POLYLINE_FLAT_COLOR:
return "gpu_shader_3D_polyline_flat_color";
case GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR:
return "gpu_shader_3D_polyline_smooth_color";
case GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR:
return "gpu_shader_3D_line_dashed_uniform_color";
case GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA:
return "gpu_shader_2D_point_uniform_size_uniform_color_aa";
case GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA:
return "gpu_shader_2D_point_uniform_size_uniform_color_outline_aa";
case GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR:
return "gpu_shader_3D_point_varying_size_varying_color";
case GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA:
return "gpu_shader_3D_point_uniform_size_uniform_color_aa";
case GPU_SHADER_2D_AREA_BORDERS:
return "gpu_shader_2D_area_borders";
case GPU_SHADER_2D_WIDGET_BASE:
return "gpu_shader_2D_widget_base";
case GPU_SHADER_2D_WIDGET_BASE_INST:
return "gpu_shader_2D_widget_base_inst";
case GPU_SHADER_2D_WIDGET_SHADOW:
return "gpu_shader_2D_widget_shadow";
case GPU_SHADER_2D_NODELINK:
return "gpu_shader_2D_nodelink";
case GPU_SHADER_2D_NODELINK_INST:
return "gpu_shader_2D_nodelink_inst";
case GPU_SHADER_GPENCIL_STROKE:
return "gpu_shader_gpencil_stroke";
default:
BLI_assert_unreachable();
return "";
}
}
static const char *builtin_shader_create_info_name_clipped(eGPUBuiltinShader shader)
{
switch (shader) {
case GPU_SHADER_3D_UNIFORM_COLOR:
return "gpu_shader_3D_uniform_color_clipped";
case GPU_SHADER_3D_FLAT_COLOR:
return "gpu_shader_3D_flat_color_clipped";
case GPU_SHADER_3D_SMOOTH_COLOR:
return "gpu_shader_3D_smooth_color_clipped";
case GPU_SHADER_3D_DEPTH_ONLY:
return "gpu_shader_3D_depth_only_clipped";
case GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR:
return "gpu_shader_3D_line_dashed_uniform_color_clipped";
case GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA:
return "gpu_shader_3D_point_uniform_size_uniform_color_aa_clipped";
default:
BLI_assert_unreachable();
return "";
}
}
GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
eGPUShaderConfig sh_cfg)
{
BLI_assert(shader < GPU_SHADER_BUILTIN_LEN);
BLI_assert(sh_cfg < GPU_SHADER_CFG_LEN);
GPUShader **sh_p = &builtin_shaders[sh_cfg][shader];
if (*sh_p == nullptr) {
if (sh_cfg == GPU_SHADER_CFG_DEFAULT) {
/* Common case. */
*sh_p = GPU_shader_create_from_info_name(builtin_shader_create_info_name(shader));
if (ELEM(shader,
GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR,
GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR,
GPU_SHADER_3D_POLYLINE_FLAT_COLOR,
GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR)) {
/* Set a default value for `lineSmooth`.
* Ideally this value should be set by the caller. */
GPU_shader_bind(*sh_p);
GPU_shader_uniform_1i(*sh_p, "lineSmooth", 1);
}
}
else if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
/* In rare cases geometry shaders calculate clipping themselves. */
*sh_p = GPU_shader_create_from_info_name(builtin_shader_create_info_name_clipped(shader));
}
else {
BLI_assert(0);
}
}
return *sh_p;
}
GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader)
{
return GPU_shader_get_builtin_shader_with_config(shader, GPU_SHADER_CFG_DEFAULT);
}
void GPU_shader_free_builtin_shaders(void)
{
for (int i = 0; i < GPU_SHADER_CFG_LEN; i++) {
for (int j = 0; j < GPU_SHADER_BUILTIN_LEN; j++) {
if (builtin_shaders[i][j]) {
GPU_shader_free(builtin_shaders[i][j]);
builtin_shaders[i][j] = nullptr;
}
}
}
}

View File

@ -57,7 +57,6 @@ class ShaderInterface {
/** Location of builtin uniforms. Fast access, no lookup needed. */
int32_t builtins_[GPU_NUM_UNIFORMS];
int32_t builtin_blocks_[GPU_NUM_UNIFORM_BLOCKS];
int32_t builtin_buffers_[GPU_NUM_STORAGE_BUFFERS];
/**
* Currently only used for `GPU_shader_get_attribute_info`.
@ -128,17 +127,9 @@ class ShaderInterface {
return builtin_blocks_[builtin];
}
/* Returns binding position. */
inline int32_t ssbo_builtin(const GPUStorageBufferBuiltin builtin) const
{
BLI_assert(builtin >= 0 && builtin < GPU_NUM_STORAGE_BUFFERS);
return builtin_buffers_[builtin];
}
protected:
static inline const char *builtin_uniform_name(GPUUniformBuiltin u);
static inline const char *builtin_uniform_block_name(GPUUniformBlockBuiltin u);
static inline const char *builtin_storage_block_name(GPUStorageBufferBuiltin u);
inline uint32_t set_input_name(ShaderInput *input, char *name, uint32_t name_len) const;
inline void copy_input_name(ShaderInput *input,
@ -234,18 +225,6 @@ inline const char *ShaderInterface::builtin_uniform_block_name(GPUUniformBlockBu
}
}
inline const char *ShaderInterface::builtin_storage_block_name(GPUStorageBufferBuiltin u)
{
switch (u) {
case GPU_STORAGE_BUFFER_DEBUG_VERTS:
return "drw_debug_verts_buf";
case GPU_STORAGE_BUFFER_DEBUG_PRINT:
return "drw_debug_print_buf";
default:
return nullptr;
}
}
/* Returns string length including '\0' terminator. */
inline uint32_t ShaderInterface::set_input_name(ShaderInput *input,
char *name,

View File

@ -71,6 +71,10 @@ class Shader {
return name;
};
static bool srgb_uniform_dirty_get();
static void set_srgb_uniform(GPUShader *shader);
static void set_framebuffer_srgb_target(int use_srgb_to_linear);
protected:
void print_log(
Span<const char *> sources, char *log, const char *stage, bool error, GPULogParser *parser);

View File

@ -530,16 +530,16 @@ id<MTLRenderCommandEncoder> MTLBatch::bind(uint v_first, uint v_count, uint i_fi
/* Set SSBO-fetch-mode status uniforms. */
BLI_assert(active_shader_->uni_ssbo_input_prim_type_loc != -1);
BLI_assert(active_shader_->uni_ssbo_input_vert_count_loc != -1);
GPU_shader_uniform_vector_int(reinterpret_cast<GPUShader *>(wrap(active_shader_)),
active_shader_->uni_ssbo_input_prim_type_loc,
1,
1,
(const int *)(&final_prim_type));
GPU_shader_uniform_vector_int(reinterpret_cast<GPUShader *>(wrap(active_shader_)),
active_shader_->uni_ssbo_input_vert_count_loc,
1,
1,
(const int *)(&v_count));
GPU_shader_uniform_int_ex(reinterpret_cast<GPUShader *>(wrap(active_shader_)),
active_shader_->uni_ssbo_input_prim_type_loc,
1,
1,
(const int *)(&final_prim_type));
GPU_shader_uniform_int_ex(reinterpret_cast<GPUShader *>(wrap(active_shader_)),
active_shader_->uni_ssbo_input_vert_count_loc,
1,
1,
(const int *)(&v_count));
}
/* Ensure Context Render Pipeline State is fully setup and ready to execute the draw.

View File

@ -109,7 +109,7 @@ void MTLFrameBuffer::bind(bool enabled_srgb)
this->mark_dirty();
}
enabled_srgb_ = enabled_srgb;
GPU_shader_set_framebuffer_srgb_target(enabled_srgb && srgb_);
Shader::set_framebuffer_srgb_target(enabled_srgb && srgb_);
}
/* Reset clear state on bind -- Clears and load/store ops are set after binding. */

View File

@ -248,16 +248,16 @@ void MTLImmediate::end()
"ssbo_input_prim_type uniform location invalid!");
BLI_assert_msg(active_mtl_shader->uni_ssbo_input_vert_count_loc != -1,
"ssbo_input_vert_count uniform location invalid!");
GPU_shader_uniform_vector_int(reinterpret_cast<GPUShader *>(wrap(active_mtl_shader)),
active_mtl_shader->uni_ssbo_input_prim_type_loc,
1,
1,
(const int *)(&this->prim_type));
GPU_shader_uniform_vector_int(reinterpret_cast<GPUShader *>(wrap(active_mtl_shader)),
active_mtl_shader->uni_ssbo_input_vert_count_loc,
1,
1,
(const int *)(&this->vertex_idx));
GPU_shader_uniform_int_ex(reinterpret_cast<GPUShader *>(wrap(active_mtl_shader)),
active_mtl_shader->uni_ssbo_input_prim_type_loc,
1,
1,
(const int *)(&this->prim_type));
GPU_shader_uniform_int_ex(reinterpret_cast<GPUShader *>(wrap(active_mtl_shader)),
active_mtl_shader->uni_ssbo_input_vert_count_loc,
1,
1,
(const int *)(&this->vertex_idx));
}
MTLPrimitiveType mtl_prim_type = gpu_prim_type_to_metal(this->prim_type);

View File

@ -280,7 +280,7 @@ void GLFrameBuffer::bind(bool enabled_srgb)
else {
glDisable(GL_FRAMEBUFFER_SRGB);
}
GPU_shader_set_framebuffer_srgb_target(enabled_srgb && srgb_);
Shader::set_framebuffer_srgb_target(enabled_srgb && srgb_);
}
if (context_->active_fb != this) {

View File

@ -371,13 +371,6 @@ GLShaderInterface::GLShaderInterface(GLuint program)
builtin_blocks_[u] = (block != nullptr) ? block->binding : -1;
}
/* Builtin Storage Buffers */
for (int32_t u_int = 0; u_int < GPU_NUM_STORAGE_BUFFERS; u_int++) {
GPUStorageBufferBuiltin u = static_cast<GPUStorageBufferBuiltin>(u_int);
const ShaderInput *block = this->ssbo_get(builtin_storage_block_name(u));
builtin_buffers_[u] = (block != nullptr) ? block->binding : -1;
}
MEM_freeN(uniforms_from_blocks);
/* Resize name buffer to save some memory. */
@ -550,13 +543,6 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI
builtin_blocks_[u] = (block != nullptr) ? block->binding : -1;
}
/* Builtin Storage Buffers */
for (int32_t u_int = 0; u_int < GPU_NUM_STORAGE_BUFFERS; u_int++) {
GPUStorageBufferBuiltin u = static_cast<GPUStorageBufferBuiltin>(u_int);
const ShaderInput *block = this->ssbo_get(builtin_storage_block_name(u));
builtin_buffers_[u] = (block != nullptr) ? block->binding : -1;
}
this->sort_inputs();
// this->debug_print();

View File

@ -1,6 +0,0 @@
void main()
{
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
finalColor = color;
}

View File

@ -1,16 +1,4 @@
/* Values in GPU_shader.h. */
#define GPU_KEYFRAME_SHAPE_DIAMOND (1u << 0)
#define GPU_KEYFRAME_SHAPE_CIRCLE (1u << 1)
#define GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL (1u << 2)
#define GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL (1u << 3)
#define GPU_KEYFRAME_SHAPE_INNER_DOT (1u << 4)
#define GPU_KEYFRAME_SHAPE_ARROW_END_MAX (1u << 8)
#define GPU_KEYFRAME_SHAPE_ARROW_END_MIN (1u << 9)
#define GPU_KEYFRAME_SHAPE_ARROW_END_MIXED (1u << 10)
#define GPU_KEYFRAME_SHAPE_SQUARE \
(GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL)
const float diagonal_scale = sqrt(0.5);
const float minmax_bias = 0.7;

View File

@ -1,16 +1,4 @@
/* Values in GPU_shader.h. */
#define GPU_KEYFRAME_SHAPE_DIAMOND (1u << 0)
#define GPU_KEYFRAME_SHAPE_CIRCLE (1u << 1)
#define GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL (1u << 2)
#define GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL (1u << 3)
#define GPU_KEYFRAME_SHAPE_INNER_DOT (1u << 4)
#define GPU_KEYFRAME_SHAPE_ARROW_END_MAX (1u << 8)
#define GPU_KEYFRAME_SHAPE_ARROW_END_MIN (1u << 9)
#define GPU_KEYFRAME_SHAPE_ARROW_END_MIXED (1u << 10)
#define GPU_KEYFRAME_SHAPE_SQUARE \
(GPU_KEYFRAME_SHAPE_CLIPPED_VERTICAL | GPU_KEYFRAME_SHAPE_CLIPPED_HORIZONTAL)
const float line_falloff = 1.0;
const float circle_scale = sqrt(2.0 / 3.1416);
const float square_scale = sqrt(0.5);

View File

@ -7,16 +7,6 @@
#include "gpu_shader_create_info.hh"
GPU_SHADER_CREATE_INFO(gpu_shader_3D_point_fixed_size_varying_color)
.vertex_in(0, Type::VEC3, "pos")
.vertex_in(1, Type::VEC4, "color")
.vertex_out(smooth_color_iface)
.fragment_out(0, Type::VEC4, "fragColor")
.push_constant(Type::MAT4, "ModelViewProjectionMatrix")
.vertex_source("gpu_shader_3D_point_fixed_size_varying_color_vert.glsl")
.fragment_source("gpu_shader_point_varying_color_frag.glsl")
.do_static_compilation(true);
GPU_SHADER_CREATE_INFO(gpu_shader_3D_point_varying_size_varying_color)
.vertex_in(0, Type::VEC3, "pos")
.vertex_in(1, Type::VEC4, "color")

View File

@ -15,6 +15,7 @@ GPU_SHADER_INTERFACE_INFO(keyframe_shape_iface, "")
.flat(Type::UINT, "finalFlags");
GPU_SHADER_CREATE_INFO(gpu_shader_keyframe_shape)
.typedef_source("GPU_shader_shared.h")
.vertex_in(0, Type::VEC4, "color")
.vertex_in(1, Type::VEC4, "outlineColor")
.vertex_in(2, Type::VEC2, "pos")

View File

@ -52,8 +52,6 @@ static void test_shader_builtin()
GPU_SHADER_CFG_DEFAULT);
test_compile_builtin_shader(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
GPU_SHADER_CFG_DEFAULT);
test_compile_builtin_shader(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR,
GPU_SHADER_CFG_DEFAULT);
test_compile_builtin_shader(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
GPU_SHADER_CFG_DEFAULT);
test_compile_builtin_shader(GPU_SHADER_GPENCIL_STROKE, GPU_SHADER_CFG_DEFAULT);

View File

@ -47,7 +47,7 @@ static void test_gpu_shader_compute_2d()
EXPECT_NE(texture, nullptr);
GPU_shader_bind(shader);
GPU_texture_image_bind(texture, GPU_shader_get_texture_binding(shader, "img_output"));
GPU_texture_image_bind(texture, GPU_shader_get_sampler_binding(shader, "img_output"));
/* Dispatch compute task. */
GPU_compute_dispatch(shader, SIZE, SIZE, 1);
@ -93,7 +93,7 @@ static void test_gpu_shader_compute_1d()
EXPECT_NE(texture, nullptr);
GPU_shader_bind(shader);
GPU_texture_image_bind(texture, GPU_shader_get_texture_binding(shader, "img_output"));
GPU_texture_image_bind(texture, GPU_shader_get_sampler_binding(shader, "img_output"));
/* Dispatch compute task. */
GPU_compute_dispatch(shader, SIZE, 1, 1);
@ -142,7 +142,7 @@ static void test_gpu_shader_compute_vbo()
GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
GPUVertBuf *vbo = GPU_vertbuf_create_with_format_ex(&format, GPU_USAGE_DEVICE_ONLY);
GPU_vertbuf_data_alloc(vbo, SIZE);
GPU_vertbuf_bind_as_ssbo(vbo, GPU_shader_get_ssbo(shader, "out_positions"));
GPU_vertbuf_bind_as_ssbo(vbo, GPU_shader_get_ssbo_binding(shader, "out_positions"));
/* Dispatch compute task. */
GPU_compute_dispatch(shader, SIZE, 1, 1);
@ -186,7 +186,7 @@ static void test_gpu_shader_compute_ibo()
/* Construct IBO. */
GPUIndexBuf *ibo = GPU_indexbuf_build_on_device(SIZE);
GPU_indexbuf_bind_as_ssbo(ibo, GPU_shader_get_ssbo(shader, "out_indices"));
GPU_indexbuf_bind_as_ssbo(ibo, GPU_shader_get_ssbo_binding(shader, "out_indices"));
/* Dispatch compute task. */
GPU_compute_dispatch(shader, SIZE, 1, 1);
@ -228,7 +228,7 @@ static void test_gpu_shader_compute_ssbo()
/* Construct IBO. */
GPUStorageBuf *ssbo = GPU_storagebuf_create_ex(
SIZE * sizeof(uint32_t), nullptr, GPU_USAGE_DEVICE_ONLY, __func__);
GPU_storagebuf_bind(ssbo, GPU_shader_get_ssbo(shader, "data_out"));
GPU_storagebuf_bind(ssbo, GPU_shader_get_ssbo_binding(shader, "out_indices"));
/* Dispatch compute task. */
GPU_compute_dispatch(shader, SIZE, 1, 1);
@ -264,8 +264,8 @@ static void test_gpu_shader_ssbo_binding()
EXPECT_NE(shader, nullptr);
GPU_shader_bind(shader);
EXPECT_EQ(0, GPU_shader_get_ssbo(shader, "data0"));
EXPECT_EQ(1, GPU_shader_get_ssbo(shader, "data1"));
EXPECT_EQ(0, GPU_shader_get_ssbo_binding(shader, "data0"));
EXPECT_EQ(1, GPU_shader_get_ssbo_binding(shader, "data1"));
/* Cleanup. */
GPU_shader_unbind();

View File

@ -354,7 +354,8 @@ typedef struct ThemeSpace {
unsigned char path_before[4], path_after[4];
unsigned char path_keyframe_before[4], path_keyframe_after[4];
unsigned char camera_path[4];
unsigned char _pad1[6];
unsigned char camera_passepartout[4];
unsigned char _pad1[2];
unsigned char gp_vertex_size;
unsigned char gp_vertex[4], gp_vertex_select[4];

View File

@ -341,7 +341,7 @@ static void rna_def_light_shadow(StructRNA *srna, bool sun)
RNA_def_property_ui_range(prop, 0, 100, 0.1, 3);
RNA_def_property_ui_text(
prop, "Shadow Soft Size", "Light size for ray shadow sampling (Raytraced shadows)");
RNA_def_property_update(prop, 0, "rna_Light_update");
RNA_def_property_update(prop, 0, "rna_Light_draw_update");
/* Eevee */
prop = RNA_def_property(srna, "use_contact_shadow", PROP_BOOLEAN, PROP_NONE);

View File

@ -120,10 +120,7 @@ static void engine_bind_display_space_shader(RenderEngine *UNUSED(engine), Scene
{
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
GPU_shader_bind(shader);
int img_loc = GPU_shader_get_uniform(shader, "image");
GPU_shader_uniform_int(shader, img_loc, 0);
/** \note "image" binding slot is 0. */
}
static void engine_unbind_display_space_shader(RenderEngine *UNUSED(engine))

View File

@ -2345,6 +2345,11 @@ static void rna_def_userdef_theme_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Camera Path", "");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "camera_passepartout", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Camera Passepartout", "");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "skin_root", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Skin Root", "");

View File

@ -94,7 +94,7 @@ class CompositeOperation : public NodeOperation {
image.bind_as_texture(shader, "input_tx");
GPUTexture *output_texture = context().get_output_texture();
const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img");
GPU_texture_image_bind(output_texture, image_unit);
const int2 compositing_region_size = context().get_compositing_region_size();
@ -122,7 +122,7 @@ class CompositeOperation : public NodeOperation {
image.bind_as_texture(shader, "input_tx");
GPUTexture *output_texture = context().get_output_texture();
const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img");
GPU_texture_image_bind(output_texture, image_unit);
const int2 compositing_region_size = context().get_compositing_region_size();
@ -152,7 +152,7 @@ class CompositeOperation : public NodeOperation {
alpha.bind_as_texture(shader, "alpha_tx");
GPUTexture *output_texture = context().get_output_texture();
const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img");
GPU_texture_image_bind(output_texture, image_unit);
const int2 compositing_region_size = context().get_compositing_region_size();

View File

@ -122,7 +122,7 @@ class DilateErodeOperation : public NodeOperation {
const int2 transposed_domain = int2(domain.size.y, domain.size.x);
GPUTexture *horizontal_pass_result = texture_pool().acquire_color(transposed_domain);
const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img");
GPU_texture_image_bind(horizontal_pass_result, image_unit);
compute_dispatch_threads_at_least(shader, domain.size);
@ -143,7 +143,7 @@ class DilateErodeOperation : public NodeOperation {
GPU_shader_uniform_1i(shader, "radius", math::abs(get_distance()));
GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
const int texture_image_unit = GPU_shader_get_texture_binding(shader, "input_tx");
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, "input_tx");
GPU_texture_bind(horizontal_pass_result, texture_image_unit);
const Domain domain = compute_domain();
@ -273,7 +273,7 @@ class DilateErodeOperation : public NodeOperation {
const int2 transposed_domain = int2(domain.size.y, domain.size.x);
GPUTexture *horizontal_pass_result = texture_pool().acquire_color(transposed_domain);
const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img");
GPU_texture_image_bind(horizontal_pass_result, image_unit);
compute_dispatch_threads_at_least(shader, domain.size);
@ -293,7 +293,7 @@ class DilateErodeOperation : public NodeOperation {
GPU_shader_bind(shader);
GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
const int texture_image_unit = GPU_shader_get_texture_binding(shader, "input_tx");
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, "input_tx");
GPU_texture_bind(horizontal_pass_result, texture_image_unit);
const MorphologicalDistanceFeatherWeights &weights =

View File

@ -525,7 +525,7 @@ class ImageOperation : public NodeOperation {
GPUShader *shader = shader_manager().get(get_shader_name(identifier));
GPU_shader_bind(shader);
const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx");
const int input_unit = GPU_shader_get_sampler_binding(shader, "input_tx");
GPU_texture_bind(image_texture, input_unit);
result.bind_as_image(shader, "output_img");
@ -859,7 +859,7 @@ class RenderLayerOperation : public NodeOperation {
const int2 lower_bound = int2(compositing_region.xmin, compositing_region.ymin);
GPU_shader_uniform_2iv(shader, "compositing_region_lower_bound", lower_bound);
const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx");
const int input_unit = GPU_shader_get_sampler_binding(shader, "input_tx");
GPU_texture_bind(pass_texture, input_unit);
const int2 compositing_region_size = context().get_compositing_region_size();
@ -889,7 +889,7 @@ class RenderLayerOperation : public NodeOperation {
const int2 lower_bound = int2(compositing_region.xmin, compositing_region.ymin);
GPU_shader_uniform_2iv(shader, "compositing_region_lower_bound", lower_bound);
const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx");
const int input_unit = GPU_shader_get_sampler_binding(shader, "input_tx");
GPU_texture_bind(pass_texture, input_unit);
const int2 compositing_region_size = context().get_compositing_region_size();

View File

@ -128,7 +128,7 @@ class MovieClipOperation : public NodeOperation {
GPUShader *shader = shader_manager().get("compositor_convert_color_to_half_color");
GPU_shader_bind(shader);
const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx");
const int input_unit = GPU_shader_get_sampler_binding(shader, "input_tx");
GPU_texture_bind(movie_clip_texture, input_unit);
result.bind_as_image(shader, "output_img");
@ -162,7 +162,7 @@ class MovieClipOperation : public NodeOperation {
GPUShader *shader = shader_manager().get("compositor_extract_alpha_from_color");
GPU_shader_bind(shader);
const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx");
const int input_unit = GPU_shader_get_sampler_binding(shader, "input_tx");
GPU_texture_bind(movie_clip_texture, input_unit);
result.bind_as_image(shader, "output_img");

View File

@ -77,7 +77,7 @@ class ViewerOperation : public NodeOperation {
second_image.bind_as_texture(shader, "second_image_tx");
GPUTexture *output_texture = context().get_output_texture();
const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img");
GPU_texture_image_bind(output_texture, image_unit);
compute_dispatch_threads_at_least(shader, compositing_region_size);

View File

@ -123,7 +123,7 @@ class ViewerOperation : public NodeOperation {
image.bind_as_texture(shader, "input_tx");
GPUTexture *output_texture = context().get_output_texture();
const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img");
GPU_texture_image_bind(output_texture, image_unit);
const int2 compositing_region_size = context().get_compositing_region_size();
@ -151,7 +151,7 @@ class ViewerOperation : public NodeOperation {
image.bind_as_texture(shader, "input_tx");
GPUTexture *output_texture = context().get_output_texture();
const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img");
GPU_texture_image_bind(output_texture, image_unit);
const int2 compositing_region_size = context().get_compositing_region_size();
@ -181,7 +181,7 @@ class ViewerOperation : public NodeOperation {
alpha.bind_as_texture(shader, "alpha_tx");
GPUTexture *output_texture = context().get_output_texture();
const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
const int image_unit = GPU_shader_get_sampler_binding(shader, "output_img");
GPU_texture_image_bind(output_texture, image_unit);
const int2 compositing_region_size = context().get_compositing_region_size();

View File

@ -269,7 +269,7 @@ static PyObject *pygpu_shader_uniform_vector_float(BPyGPUShader *self, PyObject
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_vector(self->shader, location, length, count, pybuffer.buf);
GPU_shader_uniform_float_ex(self->shader, location, length, count, pybuffer.buf);
PyBuffer_Release(&pybuffer);
@ -292,7 +292,7 @@ static PyObject *pygpu_shader_uniform_vector_int(BPyGPUShader *self, PyObject *a
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_vector_int(self->shader, location, length, count, pybuffer.buf);
GPU_shader_uniform_int_ex(self->shader, location, length, count, pybuffer.buf);
PyBuffer_Release(&pybuffer);
@ -367,7 +367,7 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args)
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_vector_int(self->shader, location, length, 1, values);
GPU_shader_uniform_int_ex(self->shader, location, length, 1, values);
Py_RETURN_NONE;
}
@ -437,7 +437,7 @@ static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args)
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_vector(self->shader, location, length, 1, values);
GPU_shader_uniform_float_ex(self->shader, location, length, 1, values);
Py_RETURN_NONE;
}
@ -509,7 +509,7 @@ static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args)
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_vector_int(self->shader, location, length, 1, values);
GPU_shader_uniform_int_ex(self->shader, location, length, 1, values);
Py_RETURN_NONE;
}
@ -533,7 +533,7 @@ static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args
}
GPU_shader_bind(self->shader);
int slot = GPU_shader_get_texture_binding(self->shader, name);
int slot = GPU_shader_get_sampler_binding(self->shader, name);
GPU_texture_bind(py_texture->tex, slot);
GPU_shader_uniform_1i(self->shader, name, slot);
@ -559,7 +559,7 @@ static PyObject *pygpu_shader_uniform_block(BPyGPUShader *self, PyObject *args)
return NULL;
}
int binding = GPU_shader_get_uniform_block_binding(self->shader, name);
int binding = GPU_shader_get_ubo_binding(self->shader, name);
if (binding == -1) {
PyErr_SetString(
PyExc_BufferError,

View File

@ -842,13 +842,13 @@ void wm_draw_region_blend(ARegion *region, int view, bool blend)
int color_loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR);
int rect_tex_loc = GPU_shader_get_uniform(shader, "rect_icon");
int rect_geo_loc = GPU_shader_get_uniform(shader, "rect_geom");
int texture_bind_loc = GPU_shader_get_texture_binding(shader, "image");
int texture_bind_loc = GPU_shader_get_sampler_binding(shader, "image");
GPU_texture_bind(texture, texture_bind_loc);
GPU_shader_uniform_vector(shader, rect_tex_loc, 4, 1, rectt);
GPU_shader_uniform_vector(shader, rect_geo_loc, 4, 1, rectg);
GPU_shader_uniform_vector(shader, color_loc, 4, 1, (const float[4]){1, 1, 1, 1});
GPU_shader_uniform_float_ex(shader, rect_tex_loc, 4, 1, rectt);
GPU_shader_uniform_float_ex(shader, rect_geo_loc, 4, 1, rectg);
GPU_shader_uniform_float_ex(shader, color_loc, 4, 1, (const float[4]){1, 1, 1, 1});
GPUBatch *quad = GPU_batch_preset_quad();
GPU_batch_set_shader(quad, shader);

View File

@ -326,7 +326,7 @@ static void draw_filled_lasso(wmGesture *gt)
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
GPU_shader_bind(state.shader);
GPU_shader_uniform_vector(
GPU_shader_uniform_float_ex(
state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
immDrawPixelsTexTiled(