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
b8bf07d3
Commit
b8bf07d3
authored
Jan 10, 2021
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
byto-count info for webgl resources
parent
ea87ac20
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/mol-canvas3d/canvas3d.ts
+8
-1
8 additions, 1 deletion
src/mol-canvas3d/canvas3d.ts
src/mol-gl/webgl/resources.ts
+28
-1
28 additions, 1 deletion
src/mol-gl/webgl/resources.ts
src/mol-gl/webgl/texture.ts
+28
-0
28 additions, 0 deletions
src/mol-gl/webgl/texture.ts
with
64 additions
and
2 deletions
src/mol-canvas3d/canvas3d.ts
+
8
−
1
View file @
b8bf07d3
/**
* Copyright (c) 2018-202
0
mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2018-202
1
mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author David Sehnal <david.sehnal@gmail.com>
...
...
@@ -469,6 +469,13 @@ namespace Canvas3D {
materialId
:
r
.
materialId
,
})));
console
.
log
(
webgl
.
stats
);
const
{
texture
,
attribute
,
elements
}
=
webgl
.
resources
.
getByteCounts
();
console
.
log
({
texture
:
`
${(
texture
/
1024
/
1024
).
toFixed
(
3
)}
MiB`
,
attribute
:
`
${(
attribute
/
1024
/
1024
).
toFixed
(
3
)}
MiB`
,
elements
:
`
${(
elements
/
1024
/
1024
).
toFixed
(
3
)}
MiB`
,
});
}
function
add
(
repr
:
Representation
.
Any
)
{
...
...
This diff is collapsed.
Click to expand it.
src/mol-gl/webgl/resources.ts
+
28
−
1
View file @
b8bf07d3
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2020
-2021
mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
...
...
@@ -45,6 +45,12 @@ interface Resource {
type
ResourceName
=
keyof
WebGLStats
[
'
resourceCounts
'
]
type
ByteCounts
=
{
texture
:
number
attribute
:
number
elements
:
number
}
export
interface
WebGLResources
{
attribute
:
(
array
:
ArrayType
,
itemSize
:
AttributeItemSize
,
divisor
:
number
,
usageHint
?:
UsageHint
)
=>
AttributeBuffer
elements
:
(
array
:
ElementsType
,
usageHint
?:
UsageHint
)
=>
ElementsBuffer
...
...
@@ -55,6 +61,8 @@ export interface WebGLResources {
texture
:
(
kind
:
TextureKind
,
format
:
TextureFormat
,
type
:
TextureType
,
filter
:
TextureFilter
)
=>
Texture
,
vertexArray
:
(
program
:
Program
,
attributeBuffers
:
AttributeBuffers
,
elementsBuffer
?:
ElementsBuffer
)
=>
VertexArray
,
getByteCounts
:
()
=>
ByteCounts
reset
:
()
=>
void
destroy
:
()
=>
void
}
...
...
@@ -128,6 +136,25 @@ export function createResources(gl: GLRenderingContext, state: WebGLState, stats
return
wrap
(
'
vertexArray
'
,
createVertexArray
(
extensions
,
program
,
attributeBuffers
,
elementsBuffer
));
},
getByteCounts
:
()
=>
{
let
texture
=
0
;
sets
.
texture
.
forEach
(
r
=>
{
texture
+=
(
r
as
Texture
).
getByteCount
();
});
let
attribute
=
0
;
sets
.
attribute
.
forEach
(
r
=>
{
attribute
+=
(
r
as
AttributeBuffer
).
length
*
4
;
});
let
elements
=
0
;
sets
.
elements
.
forEach
(
r
=>
{
elements
+=
(
r
as
ElementsBuffer
).
length
*
4
;
});
return
{
texture
,
attribute
,
elements
};
},
reset
:
()
=>
{
sets
.
attribute
.
forEach
(
r
=>
r
.
reset
());
sets
.
elements
.
forEach
(
r
=>
r
.
reset
());
...
...
This diff is collapsed.
Click to expand it.
src/mol-gl/webgl/texture.ts
+
28
−
0
View file @
b8bf07d3
...
...
@@ -90,6 +90,29 @@ export function getInternalFormat(gl: GLRenderingContext, format: TextureFormat,
return
getFormat
(
gl
,
format
,
type
);
}
function
getByteCount
(
format
:
TextureFormat
,
type
:
TextureType
,
width
:
number
,
height
:
number
,
depth
:
number
):
number
{
const
bpe
=
getFormatSize
(
format
)
*
getTypeSize
(
type
);
return
bpe
*
width
*
height
*
(
depth
||
1
);
}
function
getFormatSize
(
format
:
TextureFormat
)
{
switch
(
format
)
{
case
'
alpha
'
:
return
1
;
case
'
rgb
'
:
return
3
;
case
'
rgba
'
:
return
4
;
case
'
depth
'
:
return
4
;
}
}
function
getTypeSize
(
type
:
TextureType
):
number
{
switch
(
type
)
{
case
'
ubyte
'
:
return
1
;
case
'
ushort
'
:
return
2
;
case
'
float
'
:
return
4
;
case
'
fp16
'
:
return
2
;
}
}
export
function
getType
(
gl
:
GLRenderingContext
,
extensions
:
WebGLExtensions
,
type
:
TextureType
):
number
{
switch
(
type
)
{
case
'
ubyte
'
:
return
gl
.
UNSIGNED_BYTE
;
...
...
@@ -147,6 +170,8 @@ export interface Texture {
getHeight
:
()
=>
number
getDepth
:
()
=>
number
getByteCount
:
()
=>
number
define
:
(
width
:
number
,
height
:
number
,
depth
?:
number
)
=>
void
load
:
(
image
:
TextureImage
<
any
>
|
TextureVolume
<
any
>
)
=>
void
bind
:
(
id
:
TextureId
)
=>
void
...
...
@@ -265,6 +290,8 @@ export function createTexture(gl: GLRenderingContext, extensions: WebGLExtension
getHeight
:
()
=>
height
,
getDepth
:
()
=>
depth
,
getByteCount
:
()
=>
getByteCount
(
_format
,
_type
,
width
,
height
,
depth
),
define
,
load
,
bind
:
(
id
:
TextureId
)
=>
{
...
...
@@ -339,6 +366,7 @@ export function createNullTexture(gl: GLRenderingContext, kind: TextureKind): Te
getWidth
:
()
=>
0
,
getHeight
:
()
=>
0
,
getDepth
:
()
=>
0
,
getByteCount
:
()
=>
0
,
define
:
()
=>
{},
load
:
()
=>
{},
...
...
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