Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
ebf64404
Commit
ebf64404
authored
3 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
add loop unrolling glsl support
parent
e5dcc8e5
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mol-gl/shader-code.ts
+27
-3
27 additions, 3 deletions
src/mol-gl/shader-code.ts
src/mol-gl/shader/chunks/common-clip.glsl.ts
+3
-1
3 additions, 1 deletion
src/mol-gl/shader/chunks/common-clip.glsl.ts
with
30 additions
and
4 deletions
src/mol-gl/shader-code.ts
+
27
−
3
View file @
ebf64404
...
@@ -101,7 +101,8 @@ const ShaderChunks: { [k: string]: string } = {
...
@@ -101,7 +101,8 @@ const ShaderChunks: { [k: string]: string } = {
wboit_write
wboit_write
};
};
const
reInclude
=
/^
(?!\/\/)\s
*#include
\s
+
(\S
+
)
/gmi
;
const
reInclude
=
/^
(?!\/\/)\s
*#include
\s
+
(\S
+
)
/gm
;
const
reUnrollLoop
=
/#pragma unroll_loop_start
\s
+for
\s
*
\(\s
*int
\s
+i
\s
*=
\s
*
(\d
+
)\s
*;
\s
*i
\s
*<
\s
*
(\d
+
)\s
*;
\s
*
\+\+
i
\s
*
\s
*
\)\s
*{
([\s\S]
+
?)
}
\s
+#pragma unroll_loop_end/g
;
const
reSingleLineComment
=
/
[
\t]
*
\/\/
.*
\n
/g
;
const
reSingleLineComment
=
/
[
\t]
*
\/\/
.*
\n
/g
;
const
reMultiLineComment
=
/
[
\t]
*
\/\*[\s\S]
*
?\*\/
/g
;
const
reMultiLineComment
=
/
[
\t]
*
\/\*[\s\S]
*
?\*\/
/g
;
const
reMultipleLinebreaks
=
/
\n{2,}
/g
;
const
reMultipleLinebreaks
=
/
\n{2,}
/g
;
...
@@ -119,6 +120,29 @@ function addIncludes(text: string) {
...
@@ -119,6 +120,29 @@ function addIncludes(text: string) {
.
replace
(
reMultipleLinebreaks
,
'
\n
'
);
.
replace
(
reMultipleLinebreaks
,
'
\n
'
);
}
}
function
unrollLoops
(
str
:
string
)
{
return
str
.
replace
(
reUnrollLoop
,
loopReplacer
);
}
function
loopReplacer
(
match
:
string
,
start
:
string
,
end
:
string
,
snippet
:
string
)
{
let
out
=
''
;
for
(
let
i
=
parseInt
(
start
);
i
<
parseInt
(
end
);
++
i
)
{
out
+=
snippet
.
replace
(
/
\[\s
*i
\s
*
\]
/g
,
`[
${
i
}
]`
)
.
replace
(
/UNROLLED_LOOP_INDEX/g
,
`
${
i
}
`
);
}
return
out
;
}
function
replaceCounts
(
str
:
string
,
defines
:
ShaderDefines
)
{
if
(
defines
.
dClipObjectCount
)
str
=
str
.
replace
(
/dClipObjectCount/g
,
`
${
defines
.
dClipObjectCount
.
ref
.
value
}
`
);
return
str
;
}
function
preprocess
(
str
:
string
,
defines
:
ShaderDefines
)
{
return
unrollLoops
(
replaceCounts
(
str
,
defines
));
}
export
function
ShaderCode
(
name
:
string
,
vert
:
string
,
frag
:
string
,
extensions
:
ShaderExtensions
=
{},
outTypes
:
FragOutTypes
=
{}):
ShaderCode
{
export
function
ShaderCode
(
name
:
string
,
vert
:
string
,
frag
:
string
,
extensions
:
ShaderExtensions
=
{},
outTypes
:
FragOutTypes
=
{}):
ShaderCode
{
return
{
id
:
shaderCodeId
(),
name
,
vert
:
addIncludes
(
vert
),
frag
:
addIncludes
(
frag
),
extensions
,
outTypes
};
return
{
id
:
shaderCodeId
(),
name
,
vert
:
addIncludes
(
vert
),
frag
:
addIncludes
(
frag
),
extensions
,
outTypes
};
}
}
...
@@ -278,8 +302,8 @@ export function addShaderDefines(gl: GLRenderingContext, extensions: WebGLExtens
...
@@ -278,8 +302,8 @@ export function addShaderDefines(gl: GLRenderingContext, extensions: WebGLExtens
return
{
return
{
id
:
shaderCodeId
(),
id
:
shaderCodeId
(),
name
:
shaders
.
name
,
name
:
shaders
.
name
,
vert
:
`
${
vertPrefix
}${
header
}${
shaders
.
vert
}
`
,
vert
:
`
${
vertPrefix
}${
header
}${
preprocess
(
shaders
.
vert
,
defines
)
}
`
,
frag
:
`
${
fragPrefix
}${
header
}${
frag
}
`
,
frag
:
`
${
fragPrefix
}${
header
}${
preprocess
(
frag
,
defines
)
}
`
,
extensions
:
shaders
.
extensions
,
extensions
:
shaders
.
extensions
,
outTypes
:
shaders
.
outTypes
outTypes
:
shaders
.
outTypes
};
};
...
...
This diff is collapsed.
Click to expand it.
src/mol-gl/shader/chunks/common-clip.glsl.ts
+
3
−
1
View file @
ebf64404
...
@@ -89,8 +89,9 @@ export const common_clip = `
...
@@ -89,8 +89,9 @@ export const common_clip = `
// flag is a bit-flag for clip-objects to ignore (note, object ids start at 1 not 0)
// flag is a bit-flag for clip-objects to ignore (note, object ids start at 1 not 0)
bool clipTest(vec4 sphere, int flag) {
bool clipTest(vec4 sphere, int flag) {
#pragma unroll_loop_start
for (int i = 0; i < dClipObjectCount; ++i) {
for (int i = 0; i < dClipObjectCount; ++i) {
if (flag == 0 || hasBit(flag,
i
+ 1)) {
if (flag == 0 || hasBit(flag,
UNROLLED_LOOP_INDEX
+ 1)) {
// TODO take sphere radius into account?
// TODO take sphere radius into account?
bool test = getSignedDistance(sphere.xyz, uClipObjectType[i], uClipObjectPosition[i], uClipObjectRotation[i], uClipObjectScale[i]) <= 0.0;
bool test = getSignedDistance(sphere.xyz, uClipObjectType[i], uClipObjectPosition[i], uClipObjectRotation[i], uClipObjectScale[i]) <= 0.0;
if ((!uClipObjectInvert[i] && test) || (uClipObjectInvert[i] && !test)) {
if ((!uClipObjectInvert[i] && test) || (uClipObjectInvert[i] && !test)) {
...
@@ -98,6 +99,7 @@ export const common_clip = `
...
@@ -98,6 +99,7 @@ export const common_clip = `
}
}
}
}
}
}
#pragma unroll_loop_end
return false;
return false;
}
}
#endif
#endif
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment