[Bf-blender-cvs] [f853163a546] tmp-vulkan: Merge commit 'master@{4-weeks-ago}' into tmp-vulkan

Jeroen Bakker noreply at git.blender.org
Mon Jun 28 15:57:47 CEST 2021


Commit: f853163a5461bb0d0ce657df6416c1ea80ad79ad
Author: Jeroen Bakker
Date:   Mon Jun 28 14:47:30 2021 +0200
Branches: tmp-vulkan
https://developer.blender.org/rBf853163a5461bb0d0ce657df6416c1ea80ad79ad

Merge commit 'master@{4-weeks-ago}' into tmp-vulkan

===================================================================



===================================================================

diff --cc source/blender/draw/intern/shaders/common_hair_lib.glsl
index aacfb584280,02c335ddae2..ceccfbe71c0
--- a/source/blender/draw/intern/shaders/common_hair_lib.glsl
+++ b/source/blender/draw/intern/shaders/common_hair_lib.glsl
@@@ -96,9 -123,10 +123,10 @@@ void hair_get_interp_attrs
   */
  
  #if !defined(HAIR_PHASE_SUBDIV) && defined(GPU_VERTEX_SHADER)
+ 
  int hair_get_strand_id(void)
  {
 -  return gl_VertexID / (hairStrandsRes * hairThicknessRes);
 +  return gl_VertexIndex / (hairStrandsRes * hairThicknessRes);
  }
  
  int hair_get_base_id(void)
diff --cc source/blender/draw/intern/shaders/common_hair_refine_vert.glsl
index 59b7e19e200,371d43827b9..151bdf69032
--- a/source/blender/draw/intern/shaders/common_hair_refine_vert.glsl
+++ b/source/blender/draw/intern/shaders/common_hair_refine_vert.glsl
@@@ -56,11 -15,11 +15,11 @@@ void main(void
    vec4 data0, data1, data2, data3;
    hair_get_interp_attrs(data0, data1, data2, data3, interp_time);
  
-   vec4 weights = get_weights_cardinal(interp_time);
-   finalColor = interp_data(data0, data1, data2, data3, weights);
+   vec4 weights = hair_get_weights_cardinal(interp_time);
+   finalColor = hair_interp_data(data0, data1, data2, data3, weights);
  
  #ifdef TF_WORKAROUND
 -  int id = gl_VertexID - idOffset;
 +  int id = gl_VertexIndex - idOffset;
    gl_Position.x = ((float(id % targetWidth) + 0.5) / float(targetWidth)) * 2.0 - 1.0;
    gl_Position.y = ((float(id / targetWidth) + 0.5) / float(targetHeight)) * 2.0 - 1.0;
    gl_Position.z = 0.0;
diff --cc source/blender/gpu/CMakeLists.txt
index d654d4d9575,cf6009c2881..03e44d47690
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@@ -439,8 -394,7 +443,9 @@@ if(WITH_GTESTS
    if(WITH_OPENGL_DRAW_TESTS)
      set(TEST_SRC
        tests/gpu_testing.cc
 +      tests/gpu_shader_compiler_test.cc
 +      tests/gpu_shader_builtin_test.cc
+       tests/gpu_shader_test.cc
  
        tests/gpu_testing.hh
      )
diff --cc source/blender/gpu/intern/gpu_backend.hh
index ff6843c31c3,73792215569..5750b4f81bb
--- a/source/blender/gpu/intern/gpu_backend.hh
+++ b/source/blender/gpu/intern/gpu_backend.hh
@@@ -47,8 -47,9 +47,9 @@@ class GPUBackend 
    static GPUBackend *get(void);
  
    virtual void samplers_update(void) = 0;
+   virtual void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) = 0;
  
 -  virtual Context *context_alloc(void *ghost_window) = 0;
 +  virtual Context *context_alloc(void *ghost_window, void *ghost_context) = 0;
  
    virtual Batch *batch_alloc(void) = 0;
    virtual DrawList *drawlist_alloc(int list_length) = 0;
diff --cc source/blender/gpu/vulkan/vk_backend.hh
index 9c94a2f50ea,e9dcdffced0..a662d9ed782
--- a/source/blender/gpu/vulkan/vk_backend.hh
+++ b/source/blender/gpu/vulkan/vk_backend.hh
@@@ -39,30 -42,39 +39,31 @@@
  namespace blender {
  namespace gpu {
  
 -class GLBackend : public GPUBackend {
 - private:
 -  GLSharedOrphanLists shared_orphan_list_;
 -
 +class VKBackend : public GPUBackend {
   public:
 -  GLBackend()
 +  VKBackend()
    {
      /* platform_init needs to go first. */
 -    GLBackend::platform_init();
 +    VKBackend::platform_init();
  
 -    GLBackend::capabilities_init();
 -    GLTexture::samplers_init();
 +    VKBackend::capabilities_init();
    }
 -  ~GLBackend()
 +  ~VKBackend()
    {
 -    GLTexture::samplers_free();
 -
 -    GLBackend::platform_exit();
 +    VKBackend::platform_exit();
    }
  
 -  static GLBackend *get(void)
 +  static VKBackend *get(void)
    {
 -    return static_cast<GLBackend *>(GPUBackend::get());
 -  }
 -
 -  void samplers_update(void) override
 -  {
 -    GLTexture::samplers_update();
 +    return static_cast<VKBackend *>(GPUBackend::get());
    };
  
 -  Context *context_alloc(void *ghost_window) override
 +  void samplers_update(void) override{};
++  void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override{};
 +
 +  Context *context_alloc(void *ghost_window, void *ghost_context) override
    {
 -    return new GLContext(ghost_window, shared_orphan_list_);
 +    return new VKContext(ghost_window, ghost_context);
    };
  
    Batch *batch_alloc(void) override
diff --cc source/blender/gpu/vulkan/vk_index_buffer.hh
index a13b68f38b3,00000000000..8e1428c66f3
mode 100644,000000..100644
--- a/source/blender/gpu/vulkan/vk_index_buffer.hh
+++ b/source/blender/gpu/vulkan/vk_index_buffer.hh
@@@ -1,39 -1,0 +1,46 @@@
 +/*
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * The Original Code is Copyright (C) 2020 Blender Foundation.
 + * All rights reserved.
 + */
 +
 +/** \file
 + * \ingroup gpu
 + */
 +
 +#pragma once
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "gpu_index_buffer_private.hh"
 +
 +namespace blender::gpu {
 +
 +class VKIndexBuf : public IndexBuf {
 + public:
 +  ~VKIndexBuf(){};
 +
++  void bind_as_ssbo(uint binding) override{};
++
++  const uint32_t *read() const override
++  {
++    return nullptr;
++  };
++
 +  MEM_CXX_CLASS_ALLOC_FUNCS("VKIndexBuf")
 +};
 +
 +}  // namespace blender::gpu
diff --cc source/blender/gpu/vulkan/vk_shader.cc
index e8928640046,00000000000..767ab864461
mode 100644,000000..100644
--- a/source/blender/gpu/vulkan/vk_shader.cc
+++ b/source/blender/gpu/vulkan/vk_shader.cc
@@@ -1,275 -1,0 +1,272 @@@
 +/*
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * The Original Code is Copyright (C) 2021 Blender Foundation.
 + * All rights reserved.
 + */
 +
 +/** \file
 + * \ingroup gpu
 + */
 +
 +#include "vk_shader.hh"
 +
 +#include <string>
 +
 +#include "BLI_vector.hh"
 +
 +#include "shader_compiler.hh"
 +
 +namespace blender::gpu {
 +
 +/* -------------------------------------------------------------------- */
 +/** \name Shader stages
 + * \{ */
 +
 +constexpr StringRef SHADER_STAGE_VERTEX_SHADER = "vertex";
 +constexpr StringRef SHADER_STAGE_GEOMETRY_SHADER = "geometry";
 +constexpr StringRef SHADER_STAGE_FRAGMENT_SHADER = "fragment";
 +constexpr StringRef SHADER_STAGE_COMPUTE_SHADER = "compute";
 +
 +std::ostream &operator<<(std::ostream &os, const VKShaderStageType &stage)
 +{
 +  switch (stage) {
 +    case VKShaderStageType::VertexShader:
 +      os << SHADER_STAGE_VERTEX_SHADER;
 +      break;
 +    case VKShaderStageType::GeometryShader:
 +      os << SHADER_STAGE_GEOMETRY_SHADER;
 +      break;
 +    case VKShaderStageType::FragmentShader:
 +      os << SHADER_STAGE_FRAGMENT_SHADER;
 +      break;
 +    case VKShaderStageType::ComputeShader:
 +      os << SHADER_STAGE_COMPUTE_SHADER;
 +      break;
 +  }
 +  return os;
 +}
 +
 +static shader_compiler::SourceType to_source_type(VKShaderStageType stage)
 +{
 +  switch (stage) {
 +    case VKShaderStageType::VertexShader:
 +      return shader_compiler::SourceType::GlslVertexShader;
 +      break;
 +    case VKShaderStageType::GeometryShader:
 +      return shader_compiler::SourceType::GlslGeometryShader;
 +      break;
 +    case VKShaderStageType::FragmentShader:
 +      return shader_compiler::SourceType::GlslFragmentShader;
 +      break;
 +    case VKShaderStageType::ComputeShader:
 +      return shader_compiler::SourceType::GlslComputeShader;
 +      break;
 +  }
 +  BLI_assert(!"Unknown VKShaderStageType.");
 +  return shader_compiler::SourceType::GlslVertexShader;
 +}
 +
 +/** \} */
 +
 +/* -------------------------------------------------------------------- */
 +/** \name Construction/Destruction
 + * \{ */
 +
 +VKShader::VKShader(const char *name) : Shader(name)
 +{
 +  interface = new VKShaderInterface();
 +  context_ = VKContext::get();
 +};
 +
 +VKShader::~VKShader()
 +{
 +  VkDevice device = context_->device_get();
 +  if (vertex_shader_ != VK_NULL_HANDLE) {
 +    vkDestroyShaderModule(device, vertex_shader_, nullptr);
 +    vertex_shader_ = VK_NULL_HANDLE;
 +  }
 +  if (geometry_shader_ != VK_NULL_HANDLE) {
 +    vkDestroyShaderModule(device, geometry_shader_, nullptr);
 +    geometry_shader_ = VK_NULL_HANDLE;
 +  }
 +  if (fragment_shader_ != VK_NULL_HANDLE) {
 +    vkDestroyShaderModule(device, fragment_shader_, nullptr);
 +    fragment_shader_ = VK_NULL_HANDLE;
 +  }
 +  if (compute_shader_ != VK_NULL_HANDLE) {
 +    vkDestroyShaderModule(device, compute_shader_, nullptr);
 +    compute_shader_ = VK_NULL_HANDLE;
 +  }
 +
 +  delete interface;
 +  context_ = nullptr;
 +};
 +
 +/** \} */
 +
 +/* -------------------------------------------------------------------- */
 +/** \name Compilation
 + * \{ */
 +
 +static std::string to_stage_name(VKShaderStageType stage)
 +{
 +  std::stringstream ss;
 +  ss << stage;
 +  return ss.str();
 +}
 +
 +static std::string to_stage_name(StringRef name, VKShaderStageType stage)
 +{
 +  std::stringstream ss;
 +  ss << name << "." << stage;
 +  return ss.str();
 +}
 +
 +static std::string combine_sources(Span<const char *> sources)
 +{
 +  std::stringstream combined;
 +  for (int 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list