Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lmj01 committed Apr 27, 2024
1 parent a0546d2 commit 5072431
Show file tree
Hide file tree
Showing 212 changed files with 356 additions and 38,262 deletions.
7 changes: 0 additions & 7 deletions books/Learn OpenGL.md

This file was deleted.

5 changes: 0 additions & 5 deletions books/Software Engineering at Google.md

This file was deleted.

9 changes: 0 additions & 9 deletions books/软件设计-从专业到卓越.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 34 additions & 34 deletions blender/dependency-graph.md → cg/blender/dependency-graph.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@

# Blender Dependency Graph
> the depsgraph(dependency graph) and evaluation system in blender is most important one![Depnedency Graph Ideas](https://archive.blender.org/wiki/index.php/User:Brecht/Depsgraph/), [Depsgraph 2012](https://archive.blender.org/wiki/index.php/User:Ton/Depsgraph_2012/)
***

## 介绍
依赖关系图主要的目的就是在改变下的场景数据以更加高效的方式更新,就是只更新改变的数据。依赖关系图节点是场景中的实体对象,边是这些实体对象之间的关系。2.8之前的场景树主要维护的是层次关系,并不能即使更新变动的某些参数,需要重新绘制,这样会导致渲染的帧数降低。
简明的说就是依赖关系图的责任就是动态更新场景,那些随着时间变化的值,不是一次次的重新绘制。

## 总览
![Data Flow 2.8](https://wiki.blender.org/w/images/a/a6/Dev-Blender_2.8_Data_Flow.png)
从2.7x系列的改变有
- 直接从外部存储获得DNA数据
- 依赖关系图作用于所有请求改变的,如修改器,这些都是DNA data的拷贝上产生的
- 依赖关系图自身保存所有evaluation的结果,不对原始DNA data产生任何作用
- 渲染引擎仅使用依赖关系图提供的数据,永不接触到原始DNA data

## 依赖关系图的拥有者
Workspace概念,window拥有依赖关系图,每当更改渲染引擎或场景layer时会重新生成依赖关系图,渲染结构拥有依赖关系图,任何变化都会体现在渲染的结果上。
过去很长一段时间,Blender使用原始对象的DNA结构进行处理,导致有些算法会在不同需求下对数据进行两次执行,产生副作用。改变就是仅有一个API去获取原始数据

## 依赖关系图的数据何时场景?
理想的是所有的数据尽可能延迟创建,新数据的成绩应该发生在线程中。当前2.8版本的依赖关系图的设计是在依赖关系图构建的时候,这里使用的是pointers evaluation functions,即创建影子内存块,不填充数据,所有的数据都是拷贝自evaluation threads。

## 如何避免大量数据的拷贝?
创建一些容器来存放一些轻量的数据结构,如Mesh Structure,这样也可以使用Mesh中的VBOs

## Mesh objects 和 Non-mesh objects
所有被计算的都保持为Mesh,让我们使用单一的API获取产生的数据和消除临时数据,也使得第三方渲染引擎和导出工具更通用
针对curves,NURBS,meta balls等Non-mesh对象的处理,遵循两个原则
- 数据是as-is的关系,不需要改变surface evaluation
- 转换evaluated result到Mesh,除非渲染引擎告诉我们它自己知道如何处理non-mesh objects


# Blender Dependency Graph
> the depsgraph(dependency graph) and evaluation system in blender is most important one![Depnedency Graph Ideas](https://archive.blender.org/wiki/index.php/User:Brecht/Depsgraph/), [Depsgraph 2012](https://archive.blender.org/wiki/index.php/User:Ton/Depsgraph_2012/)
***

## 介绍
依赖关系图主要的目的就是在改变下的场景数据以更加高效的方式更新,就是只更新改变的数据。依赖关系图节点是场景中的实体对象,边是这些实体对象之间的关系。2.8之前的场景树主要维护的是层次关系,并不能即使更新变动的某些参数,需要重新绘制,这样会导致渲染的帧数降低。
简明的说就是依赖关系图的责任就是动态更新场景,那些随着时间变化的值,不是一次次的重新绘制。

## 总览
![Data Flow 2.8](https://wiki.blender.org/w/images/a/a6/Dev-Blender_2.8_Data_Flow.png)
从2.7x系列的改变有
- 直接从外部存储获得DNA数据
- 依赖关系图作用于所有请求改变的,如修改器,这些都是DNA data的拷贝上产生的
- 依赖关系图自身保存所有evaluation的结果,不对原始DNA data产生任何作用
- 渲染引擎仅使用依赖关系图提供的数据,永不接触到原始DNA data

## 依赖关系图的拥有者
Workspace概念,window拥有依赖关系图,每当更改渲染引擎或场景layer时会重新生成依赖关系图,渲染结构拥有依赖关系图,任何变化都会体现在渲染的结果上。
过去很长一段时间,Blender使用原始对象的DNA结构进行处理,导致有些算法会在不同需求下对数据进行两次执行,产生副作用。改变就是仅有一个API去获取原始数据

## 依赖关系图的数据何时场景?
理想的是所有的数据尽可能延迟创建,新数据的成绩应该发生在线程中。当前2.8版本的依赖关系图的设计是在依赖关系图构建的时候,这里使用的是pointers evaluation functions,即创建影子内存块,不填充数据,所有的数据都是拷贝自evaluation threads。

## 如何避免大量数据的拷贝?
创建一些容器来存放一些轻量的数据结构,如Mesh Structure,这样也可以使用Mesh中的VBOs

## Mesh objects 和 Non-mesh objects
所有被计算的都保持为Mesh,让我们使用单一的API获取产生的数据和消除临时数据,也使得第三方渲染引擎和导出工具更通用
针对curves,NURBS,meta balls等Non-mesh对象的处理,遵循两个原则
- 数据是as-is的关系,不需要改变surface evaluation
- 转换evaluated result到Mesh,除非渲染引擎告诉我们它自己知道如何处理non-mesh objects

File renamed without changes.
File renamed without changes.
File renamed without changes
26 changes: 13 additions & 13 deletions blender/index.md → cg/blender/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ grep -rn "XXXFunction" --include="*.c"

### 记录

- [一些概念](./concepts/blender.md)
- [creator](./concepts/creator.md)
- [splash](./concepts/splash.md)
- [module window manager](./concepts/windowmanager.md)
- [module ghost -- General Handy Operating System Toolkit](./concepts/ghost.md)
- [operator](./concepts/operator.md)
- [data api](./concepts/data_api.md)
- [addons](./concepts/addon.md)
- [python](./concepts/python.md)
- [draw and shader](./concepts/index.md)
- [loader -- read and write .blend format](./concepts/loader.md)
- [一些概念](/cg/blender/concepts/blender.md)
- [creator](/cg/blender/concepts/creator.md)
- [splash](/cg/blender/concepts/splash.md)
- [module window manager](/cg/blender/concepts/windowmanager.md)
- [module ghost -- General Handy Operating System Toolkit](/cg/blender/concepts/ghost.md)
- [operator](/cg/blender/concepts/operator.md)
- [data api](/cg/blender/concepts/data_api.md)
- [addons](/cg/blender/concepts/addon.md)
- [python](/cg/blender/concepts/python.md)
- [draw and shader](/cg/blender/concepts/index.md)
- [loader -- read and write .blend format](/cg/blender/concepts/loader.md)
- module editor
- [interface](./editors/interface.md)
- [cycles渲染器](./cycles.md)
- [interface](/cg/blender/editors/interface.md)
- [cycles渲染器](/cg/blender/cycles.md)

## wiki

Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions blender/source/blenkernal.md → cg/blender/source/blenkernal.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# blenkernal

blender kernel,核心代码逻辑

## BKE_context.h


# blenkernal

blender kernel,核心代码逻辑

## BKE_context.h


File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 27 additions & 27 deletions blender/source/thinked.md → cg/blender/source/thinked.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@

# source/blender/makesrna

> RNA definitions and functions. Sits on top of DNA to provide a low level data access and definitin API.
***

## 作用
[2.50](https://archive.blender.org/wiki/index.php/Dev:2.5/Source/Architecture/RNA/)版本的特性,将DNA包装成一个非常nice的API的一套系统,这套API用来读取Blender的数据和属性。

Blender的RNA可以自动生成Python数据访问API,使得一切特性都可以像动画那样。

这样DNA系统放弃文件的可读性,但提高了灵活性和速度。曽传闻XML会替换掉DNA系统,但有趣的是Google内部使用了类似的DNA系统来取代XML。Blender是第一个使用这种DNA系统的应用程序。
可参考[Data API](<https://archive.blender.org/wiki/index.php/BlenderDev/Blender2.5/DataAPI/>)

## 源文件

## 2020-2-11
**关于语言层面的思考**
最近在看UTiCS系列书籍中的关于编程语言模型的那一章,让我明白了很多问题,之前关于DNA的理解还是肤浅的,那就是没法理解到那个时候的那些人对于计算机科学的认识与现在仅对编程这个工作的认识是存在差异的。

既然选择了C作为底层的数据接口,每个数据都是struct结构化的,而其中的ID又是每个关键数据的第一个位置,这就不得不让人思考语言模型的特色了,这样的处理就像面向对象编程的继承方法了,虽然面向对象编程抽象程度高于指令式编程,但底层的实现肯定离不开较低层的语言,就像函数语言还是没法做到immutable对象的,比较在IO层是一个无法回避的问题,即是现在的Rust语言号称内存安全模型的编程语言,也留有unsafe模型来对接其他的编程语言,这就令人需要辩证思维的方式来看待问题了。

常规的流程化的编程,就是写软件的过程,却因为入门是编程语言让人钻入编程语言的逻辑中了,而没有站在软件层面来看问题,语言只是工具,对于软件的成型与最终结果是不关软件用户的事情。反过来,慢慢地发现抽象思维才是区分人物的特定条件,也许之前的文化遗留导致了大家在认知上的一致性,可是真的分类人的天才属性,除掉抽象能力以为真的没有共性了,虽然我没有就这个问题作出科学的那样证明,事实就是如此吧,我把抽象能力是区分天才的公理来使用了。

C语言的模型可以处理很多高级语言的那种固定模式的抽象,C语言的强大是因为它完全可以做到其他语言的能力,只是它需要付出的代价而已,站在工程化上来说它不适合给大众表达抽象能力,但是特定人群使用它还是可以表达出非常高级的抽象能力,这就是我之前的见识短浅的原因吧,C这种编程语言也不是简简单单就可以通过一两本教程能融会贯通的,那肯定是实践出真知。


# source/blender/makesrna

> RNA definitions and functions. Sits on top of DNA to provide a low level data access and definitin API.
***

## 作用
[2.50](https://archive.blender.org/wiki/index.php/Dev:2.5/Source/Architecture/RNA/)版本的特性,将DNA包装成一个非常nice的API的一套系统,这套API用来读取Blender的数据和属性。

Blender的RNA可以自动生成Python数据访问API,使得一切特性都可以像动画那样。

这样DNA系统放弃文件的可读性,但提高了灵活性和速度。曽传闻XML会替换掉DNA系统,但有趣的是Google内部使用了类似的DNA系统来取代XML。Blender是第一个使用这种DNA系统的应用程序。
可参考[Data API](<https://archive.blender.org/wiki/index.php/BlenderDev/Blender2.5/DataAPI/>)

## 源文件

## 2020-2-11
**关于语言层面的思考**
最近在看UTiCS系列书籍中的关于编程语言模型的那一章,让我明白了很多问题,之前关于DNA的理解还是肤浅的,那就是没法理解到那个时候的那些人对于计算机科学的认识与现在仅对编程这个工作的认识是存在差异的。

既然选择了C作为底层的数据接口,每个数据都是struct结构化的,而其中的ID又是每个关键数据的第一个位置,这就不得不让人思考语言模型的特色了,这样的处理就像面向对象编程的继承方法了,虽然面向对象编程抽象程度高于指令式编程,但底层的实现肯定离不开较低层的语言,就像函数语言还是没法做到immutable对象的,比较在IO层是一个无法回避的问题,即是现在的Rust语言号称内存安全模型的编程语言,也留有unsafe模型来对接其他的编程语言,这就令人需要辩证思维的方式来看待问题了。

常规的流程化的编程,就是写软件的过程,却因为入门是编程语言让人钻入编程语言的逻辑中了,而没有站在软件层面来看问题,语言只是工具,对于软件的成型与最终结果是不关软件用户的事情。反过来,慢慢地发现抽象思维才是区分人物的特定条件,也许之前的文化遗留导致了大家在认知上的一致性,可是真的分类人的天才属性,除掉抽象能力以为真的没有共性了,虽然我没有就这个问题作出科学的那样证明,事实就是如此吧,我把抽象能力是区分天才的公理来使用了。

C语言的模型可以处理很多高级语言的那种固定模式的抽象,C语言的强大是因为它完全可以做到其他语言的能力,只是它需要付出的代价而已,站在工程化上来说它不适合给大众表达抽象能力,但是特定人群使用它还是可以表达出非常高级的抽象能力,这就是我之前的见识短浅的原因吧,C这种编程语言也不是简简单单就可以通过一两本教程能融会贯通的,那肯定是实践出真知。

4 changes: 2 additions & 2 deletions blender/source/tmp.md → cg/blender/source/tmp.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# 操作类型

# 操作类型

152 changes: 151 additions & 1 deletion cpl/lua.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,158 @@
# [lua](http://www.lua.org/)

注释

```lua
-- xxx to c // xxx
--[[ xxx ]] to c /* xxx */
```

## 模块与包

lua的模块是由变量,函数等组成的table,其是加载机制通过require来导入

require的路径是全局变量package.path中的,lua启动后,有三个大致范围

```lua
print(package.path) -- 编译后执行的路径,并未安装
-- /usr/local/share/lua/x.y/?.lua;/usr/local/share/lua/x.y/?/init.lua;/usr/local/lib/lua/x.y/?.lua;/usr/local/lib/lua/x.y/?/init.lua;./?.lua;./?/init.lua
-- 添加环境变量 export LUA_PATH="~/lua/?.lua;;" 最后的;;表示加上原来默认的路径
```

C包,使用C为lua写包,是动态库的调用方式

# lua-src

lua把虚拟机执行代码的效率作为一个设计目标。lua的vm是Register based VM。

```c
// register based vm
add a b c;
// stack based vm
push b;
push c;
add
mov a
```

## lopcodes

> 理解lua,直接从这里开始,是最好的,特别是有汇编,C语言的功底后,就相当于先理解lua的汇编指令,再去理解lua的逻辑。
>
> > 汇编的本质是CPU二进制指令的文本形式
lua virtual machine op-codes, 指令是一个32bit的unsigned int

| | 31-24 | 23-16 | 15-8 | 0-7 |
| ----- | -------- | -------- | ------- | -------- |
| iABC | B:9 | C:9 | A:8 | Opcode:6 |
| iABx | Bx:18-1 | Bx:18-2 | A:8 | Opcode:6 |
| iAsBx | sBx:18-1 | sBx:18-2 | A:8 | Opcode:6 |
| iAx | Ax:26-1 | Ax:26-2 | Ax:26-3 | Opcode:6 |

基本的四个指令形式,iABC,iABx,iAsBx,iAx。sBx表示signed int,

```c
pow(2,18)=262144 => [0, 262143]
0 use 131071, -1=-1+0=131070, +1 = +1+131071=131072. // 进行了一个变换,类似二进制取补
```
生成代码对应的指令
```shell
luac -l -l src.lua
```



## 编译系统

编译系统就是将符合语法规则的chunk转成可运行的closure, 即chunk作为输入,closure作为输出。

### 主要概念

#### closure

closure对象是lua运行期一个函数的实例对象,

#### proto

proto对象是lua内部代表一个closure原型的对象,有关函数的大部分信息都保存在它里面

- instructions指令列表,函数编译后生成的虚拟机指令
- constant table常量表,运行期的所有常量,在指令中,常量通过id在常量表中索引
- child proto table子proto表,所有内嵌于函数的proto列表,指令OP_CLOSURE的proto就是在这个表中通过id索引
- local var desc局部变量描述,函数使用的所有局部变量名称,以及生命周期
- upvalue desc,函数使用到的Upvalue的描述

#### chunk

代表一段符合lua语法的代码,lua_load会对chunk编译生成一个mainfunc proto,内部的所有函数都对应一个proto。整个过程就是生成以mainfunc为根节点的proto树结构

注意,lua编译过程中是一次遍历就生成指令,并没有对源码和语法结构多次遍历,是通过指令回填技术来实现支持的。

### 实现逻辑

lua没有使用llex和yacc生成,而是完全手写的词法和语法分析器,按功能划分,主要有三个模块

#### 词法分析模块

llex.h/c

#### 语法分析模块

lparser.h/c


![](./images/lua-opcode.png)


```c
// in lopcodes.c
#define opmode(t,a,b,c,m) (((t)<<7)|((a)<<6)|((b)<<4)|((c)<<2)|(m))
```
- t,表示为test,其后的一定是OP_JMP,共五个指令OP_EQ,OP_LT,OP_LE,OP_TEST,OP_TESTSET
- a,是否为寄存器操作,1表示寄存器
- b,B参数,OpArgMask类型
- c,C参数,OpArgMask类型
- m,op model,就是iABC,iABx,iAsBx,iAx
这里存在些疑惑,Opcode只占6bit,而opmode中的值占8bit,令人不解,多出来的一个bit是什么地方来的?
#### 指令生成模块
lcode.h/c
#### 其他
lprefix.h
luaconf.h
lua.h/c
主要接口
lctype.h/c
针对非ASCII进行定义一些基础字符
lmem.h/c
lzio.h/c
buffered streams,内存是stream形式,与C的File有点类似,核心就是两个函数luaZ_read,luaZ_fill
lobject.h/c
lua的类型定义
## 参考
- [Lua Awesome-lua官方链接上的记录](https://github.com/LewisJEllis/awesome-lua)
- [Quickly view and test GLSL fragment shaders while allowing lua scripting to modify uniforms ](https://github.com/nevilc/ShaderPreview)
- [luafxbuilder is a proof of concept test to use lua as effect file format primarily for shaders](https://github.com/pixeljetstream/luafxbuilder)
- [lua-cpp一个用C++11封装lua的库](https://gitee.com/linuxtongyong/lua-cpp-wrapper)
- [LuaChat is an example of how to combine modern C++ and Lua 5.3/5.4. In particular, LuaChat implements a library of C++ primitives called actions.](https://github.com/bluwireless/LuaChat)
- [LuaChat is an example of how to combine modern C++ and Lua 5.3/5.4. In particular, LuaChat implements a library of C++ primitives called actions.](https://github.com/bluwireless/LuaChat)
- [探索Lua5.2内部实现](https://blog.csdn.net/yuanlin2008/article/category/1307277)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5072431

Please sign in to comment.