[Bf-blender-cvs] [79ec0eec534] temp-gpu-uniform-builtin-structs: Test multiple paths to uniform retrieval.
Jeroen Bakker
noreply at git.blender.org
Fri Jul 9 12:23:19 CEST 2021
Commit: 79ec0eec534f37bc967d9917848a6855def519b1
Author: Jeroen Bakker
Date: Fri Jul 9 11:02:53 2021 +0200
Branches: temp-gpu-uniform-builtin-structs
https://developer.blender.org/rB79ec0eec534f37bc967d9917848a6855def519b1
Test multiple paths to uniform retrieval.
===================================================================
M source/blender/gpu/intern/gpu_shader.cc
M source/blender/gpu/intern/gpu_shader_block.cc
M source/blender/gpu/intern/gpu_shader_block.hh
M source/blender/gpu/tests/gpu_shader_block_test.cc
===================================================================
diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc
index c3a100b17c6..b7cef158d57 100644
--- a/source/blender/gpu/intern/gpu_shader.cc
+++ b/source/blender/gpu/intern/gpu_shader.cc
@@ -126,6 +126,9 @@ GPUShader *GPU_shader_create_ex(const char *vertcode,
if (defines) {
sources.append(defines);
}
+ if (shader->m_shader_struct) {
+ sources.append(shader->m_shader_struct->type_info().defines());
+ }
sources.append(vertcode);
shader->vertex_shader_from_glsl(sources);
@@ -142,6 +145,9 @@ GPUShader *GPU_shader_create_ex(const char *vertcode,
if (defines) {
sources.append(defines);
}
+ if (shader->m_shader_struct) {
+ sources.append(shader->m_shader_struct->type_info().defines());
+ }
if (libcode) {
sources.append(libcode);
}
@@ -157,6 +163,9 @@ GPUShader *GPU_shader_create_ex(const char *vertcode,
if (defines) {
sources.append(defines);
}
+ if (shader->m_shader_struct) {
+ sources.append(shader->m_shader_struct->type_info().defines());
+ }
sources.append(geomcode);
shader->geometry_shader_from_glsl(sources);
@@ -172,6 +181,9 @@ GPUShader *GPU_shader_create_ex(const char *vertcode,
if (libcode) {
sources.append(libcode);
}
+ if (shader->m_shader_struct) {
+ sources.append(shader->m_shader_struct->type_info().defines());
+ }
sources.append(computecode);
shader->compute_shader_from_glsl(sources);
diff --git a/source/blender/gpu/intern/gpu_shader_block.cc b/source/blender/gpu/intern/gpu_shader_block.cc
index c78e73c2057..87c09e94713 100644
--- a/source/blender/gpu/intern/gpu_shader_block.cc
+++ b/source/blender/gpu/intern/gpu_shader_block.cc
@@ -29,6 +29,8 @@
#include "gpu_shader_block.hh"
#include "gpu_shader_interface.hh"
+#include "BLI_string_ref.hh"
+
namespace blender::gpu {
/* -------------------------------------------------------------------- */
@@ -140,7 +142,6 @@ static constexpr std::array<
static constexpr size_t data_size_for(const GPUShaderBlockType block_type)
{
-
switch (block_type) {
case GPU_SHADER_BLOCK_CUSTOM:
case GPU_NUM_SHADER_BLOCK_TYPES:
@@ -152,6 +153,29 @@ static constexpr size_t data_size_for(const GPUShaderBlockType block_type)
return 0;
}
+static constexpr StringRef DEFINES_3D_COLOR = R"(
+ layout(std140) uniform shaderBlock {
+ mat4 ModelMatrix;
+ mat4 ModelViewProjectionMatrix;
+ vec4 color;
+ vec4 WorldClipPlanes[6];
+ bool srgbTarget;
+ };
+)";
+
+static constexpr const char *defines_for(const GPUShaderBlockType type)
+{
+ switch (type) {
+ case GPU_SHADER_BLOCK_CUSTOM:
+ case GPU_NUM_SHADER_BLOCK_TYPES:
+ return nullptr;
+
+ case GPU_SHADER_BLOCK_3D_COLOR:
+ return DEFINES_3D_COLOR.data();
+ };
+ return nullptr;
+}
+
/** \} */
/* -------------------------------------------------------------------- */
@@ -159,7 +183,10 @@ static constexpr size_t data_size_for(const GPUShaderBlockType block_type)
* \{ */
constexpr ShaderBlockType::ShaderBlockType(const GPUShaderBlockType type)
- : type(type), m_attribute_bindings(ATTRIBUTE_BINDINGS[type]), m_data_size(data_size_for(type))
+ : type(type),
+ m_attribute_bindings(ATTRIBUTE_BINDINGS[type]),
+ m_data_size(data_size_for(type)),
+ m_defines(defines_for(type))
{
}
diff --git a/source/blender/gpu/intern/gpu_shader_block.hh b/source/blender/gpu/intern/gpu_shader_block.hh
index 014dd9d2def..d96762a7530 100644
--- a/source/blender/gpu/intern/gpu_shader_block.hh
+++ b/source/blender/gpu/intern/gpu_shader_block.hh
@@ -58,9 +58,15 @@ class ShaderBlockType {
return m_data_size;
}
+ const char *defines() const
+ {
+ return m_defines;
+ }
+
private:
const std::array<const AttributeBinding, GPU_NUM_UNIFORMS> &m_attribute_bindings;
const size_t m_data_size;
+ const char *m_defines;
};
class ShaderBlockBuffer {
diff --git a/source/blender/gpu/tests/gpu_shader_block_test.cc b/source/blender/gpu/tests/gpu_shader_block_test.cc
index a9e878b2391..5bd6a2dc4dc 100644
--- a/source/blender/gpu/tests/gpu_shader_block_test.cc
+++ b/source/blender/gpu/tests/gpu_shader_block_test.cc
@@ -97,7 +97,7 @@ TEST(GPUUniformStruct, struct1)
}
}
-static void test_custom_shader_with_uniform_builtin_struct()
+static void test_shader_block_struct()
{
if (!GPU_compute_shader_support()) {
/* We can't test as a the platform does not support compute shaders. */
@@ -111,14 +111,6 @@ static void test_custom_shader_with_uniform_builtin_struct()
layout(local_size_x = 1, local_size_y = 1) in;
layout(rgba32f, binding = 0) uniform image2D img_output;
-layout(std140) uniform shaderBlock {
- mat4 ModelMatrix;
- mat4 ModelViewProjectionMatrix;
- vec4 color;
- vec4 WorldClipPlanes[6];
- bool SrgbTransform;
-};
-
void main() {
}
@@ -137,12 +129,36 @@ void main() {
__func__);
EXPECT_NE(shader, nullptr);
+ int location;
+
+ location = GPU_shader_get_uniform(shader, "ModelMatrix");
+ EXPECT_NE(location, -1);
+ location = GPU_shader_get_uniform(shader, "ModelViewProjectionMatrix");
+ EXPECT_NE(location, -1);
+ location = GPU_shader_get_uniform(shader, "color");
+ EXPECT_NE(location, -1);
+ location = GPU_shader_get_uniform(shader, "WorldClipPlanes");
+ EXPECT_NE(location, -1);
+ location = GPU_shader_get_uniform(shader, "srgbTarget");
+ EXPECT_NE(location, -1);
+
+ location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODEL);
+ EXPECT_NE(location, -1);
+ location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MVP);
+ EXPECT_NE(location, -1);
+ location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR);
+ EXPECT_NE(location, -1);
+ location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_CLIPPLANES);
+ EXPECT_NE(location, -1);
+ location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_SRGB_TRANSFORM);
+ EXPECT_NE(location, -1);
+
float color[4] = {1.0f, 0.0f, 1.0f, 1.0f};
GPU_shader_uniform_4fv(shader, "color", color);
GPU_shader_free(shader);
}
-GPU_TEST(custom_shader_with_uniform_builtin_struct)
+GPU_TEST(shader_block_struct)
} // namespace blender::gpu::tests
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list