Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpu profiler. #16319

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cocos/gfx/base/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,19 @@ export enum PassType {
PRESENT,
}

export enum PipelineStatisticFlagBit {
NONE = 0,
IA_VERTICES = 0x01,
IA_PRIMITIVES = 0x02,
VS_INVOCATIONS = 0x04,
CLIP_INVOCATIONS = 0x08,
CLIP_PRIMITIVES = 0x10,
FS_INVOCATIONS = 0x20,
CS_INVOCATIONS = 0x40,
ALL = IA_VERTICES | IA_PRIMITIVES | VS_INVOCATIONS | CLIP_INVOCATIONS | CLIP_PRIMITIVES
| FS_INVOCATIONS | CS_INVOCATIONS,
}

export type BufferUsage = BufferUsageBit;
export type BufferFlags = BufferFlagBit;
export type MemoryAccess = MemoryAccessBit;
Expand All @@ -713,6 +726,7 @@ export type ShaderStageFlags = ShaderStageFlagBit;
export type AccessFlags = AccessFlagBit;
export type DynamicStateFlags = DynamicStateFlagBit;
export type ClearFlags = ClearFlagBit;
export type PipelineStatisticFlags = PipelineStatisticFlagBit;

export class Size {
declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object
Expand Down Expand Up @@ -755,6 +769,7 @@ export class DeviceCaps {
public maxComputeWorkGroupInvocations: number = 0,
public maxComputeWorkGroupSize: Size = new Size(),
public maxComputeWorkGroupCount: Size = new Size(),
public timestampPeriod: number = 1,
public supportQuery: boolean = false,
public clipSpaceMinZ: number = -1,
public screenSpaceSignY: number = 1,
Expand Down
16 changes: 14 additions & 2 deletions cocos/gfx/base/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
ShaderInfo, InputAssemblerInfo, RenderPassInfo, FramebufferInfo, DescriptorSetLayoutInfo, PipelineLayoutInfo,
QueueInfo, BufferTextureCopy, DeviceInfo, DeviceCaps, GeneralBarrierInfo, TextureBarrierInfo, BufferBarrierInfo,
SwapchainInfo, BindingMappingInfo, Format, FormatFeature, TextureType, TextureUsageBit,
TextureFlagBit, Offset, Extent, SampleCount, TextureSubresLayers, TextureUsage, TextureFlags,
TextureFlagBit, Offset, Extent, SampleCount, TextureSubresLayers, TextureUsage, TextureFlags, PipelineStatisticFlags,
} from './define';
import { Buffer } from './buffer';
import { CommandBuffer } from './command-buffer';
Expand Down Expand Up @@ -358,7 +358,9 @@ export abstract class Device {
* @zh 是否开启自动GFX内部barrier推导,web无影响。
* @param format The GFX format to be queried.
*/
public enableAutoBarrier (en: boolean): void {}
public enableAutoBarrier (en: boolean): void {
// noop
}

/**
* @en Get maximum supported sample count.
Expand All @@ -370,6 +372,16 @@ export abstract class Device {
public getMaxSampleCount (format: Format, usage: TextureUsage, flags: TextureFlags): SampleCount {
return SampleCount.X1;
}

/**
* @en Get supported pipeline statistic flags by device query.
* @zh 获取可通过设备查询获取的管线硬件数据类型
* @param flags Pipeline statistic flag to be tested.
* @param outFlags Pipeline statistic flag test result.
*/
public getSupportedPipelineStatisticFlags (flags: Readonly<PipelineStatisticFlags>, outFlags: PipelineStatisticFlags): number {
return 0;
}
}

export class DefaultResource {
Expand Down
27 changes: 16 additions & 11 deletions editor/assets/effects/internal/builtin-debug-renderer.effect
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
CCEffect %{
techniques:
- passes:
- vert: debug-renderer-vs:vert
frag: debug-renderer-fs:frag
- vert: debug-renderer-vs
frag: debug-renderer-fs
pass: debug-profiler
priority: max
depthStencilState:
depthTest: false
Expand All @@ -20,8 +21,13 @@ CCEffect %{

CCProgram debug-renderer-vs %{
precision mediump float;
#include <builtin/uniforms/cc-global>
#include <common/common-define>
#pragma rate CCProfiler pass
layout(std140, set = 0, binding = 0) uniform CCProfiler {
mediump vec4 cc_surfaceTransform; // 0: orientation, 1: flip
mediump vec4 cc_screenSize;
};

#define CC_HANDLE_GET_CLIP_FLIP(uv) uv = cc_surfaceTransform.y == 0.0 ? vec2(uv.x, -uv.y) : uv

in vec2 a_position;
in vec2 a_texCoord;
Expand All @@ -30,7 +36,7 @@ CCProgram debug-renderer-vs %{
out vec2 v_texCoord;
out vec4 v_color;

vec4 vert () {
void main () {
int orientation = int(cc_surfaceTransform.x);
vec4 transform = vec4(1.0, 0.0, 0.0, 1.0);

Expand All @@ -43,7 +49,6 @@ CCProgram debug-renderer-vs %{
} else if (orientation == 3) {
transform = vec4(0.0, -1.0, 1.0, 0.0);
}

vec2 invScreenSize = (orientation == 1 || orientation == 3) ? cc_screenSize.wz : cc_screenSize.zw;
vec2 position = a_position * invScreenSize;
position = position * vec2(2.0, -2.0) + vec2(-1.0, 1.0);
Expand All @@ -54,21 +59,21 @@ CCProgram debug-renderer-vs %{
v_texCoord = a_texCoord;
v_color = a_color;

return vec4(clipPos, 0.0, 1.0);
gl_Position = vec4(clipPos, 0.0, 1.0);
}
}%

CCProgram debug-renderer-fs %{
precision mediump float;
#include <legacy/output>

in vec2 v_texCoord;
in vec4 v_color;

uniform sampler2D mainTexture;

vec4 frag () {
vec4 color = vec4(v_color.rgb, v_color.a * texture(mainTexture, v_texCoord).r);
return CCFragOutput(color);
layout(location = 0) out vec4 outColor;

void main () {
outColor = vec4(v_color.rgb, v_color.a * texture(mainTexture, v_texCoord).r);
}
}%
8 changes: 7 additions & 1 deletion native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,12 @@ cocos_source_files(
cocos/renderer/pipeline/custom/details/SerializationUtils.h
cocos/renderer/pipeline/custom/details/Set.h
cocos/renderer/pipeline/custom/details/Utility.h
cocos/renderer/pipeline/profile/GPUTimeQuery.cpp
cocos/renderer/pipeline/profile/GPUTimeQuery.h
cocos/renderer/pipeline/profile/GPUStatisticsQuery.cpp
cocos/renderer/pipeline/profile/GPUStatisticsQuery.h
cocos/renderer/pipeline/profile/PipelineProfiler.cpp
cocos/renderer/pipeline/profile/PipelineProfiler.h
Comment on lines +1475 to +1480
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might rename folder profile to profiler. Profile as noun has different meaning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should be the profiler.

)

if (USE_GEOMETRY_RENDERER)
Expand Down Expand Up @@ -3350,7 +3356,7 @@ set(COCOS_SOURCE_LIST_EXCLUDE_GENRATED ${COCOS_SOURCE_LIST})
set(COCOS_GENERATED_LIST)
foreach(src IN LISTS COCOS_SOURCE_LIST_EXCLUDE_GENRATED)
get_source_file_property(IS_GENERATED ${src} GENERATED)
if(IS_GENERATED)
if(IS_GENERATED)
list(REMOVE_ITEM COCOS_SOURCE_LIST_EXCLUDE_GENRATED ${src})
list(APPEND COCOS_GENERATED_LIST ${src})
endif()
Expand Down
4 changes: 1 addition & 3 deletions native/cocos/core/assets/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ FontFace::FontFace(Font *font)
}

FontFace::~FontFace() {
for (auto *texture : _textures) {
CC_SAFE_DESTROY_AND_DELETE(texture);
}
_textures.clear();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions native/cocos/core/assets/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once
#include "base/std/container/unordered_map.h"
#include "base/std/container/vector.h"
#include "base/Ptr.h"
#include "core/assets/Asset.h"

namespace cc {
Expand Down Expand Up @@ -107,7 +108,7 @@ class FontFace {
inline Font *getFont() const { return _font; }
inline uint32_t getFontSize() const { return _fontSize; }
inline uint32_t getLineHeight() const { return _lineHeight; }
inline const ccstd::vector<gfx::Texture *> &getTextures() const { return _textures; }
inline const ccstd::vector<IntrusivePtr<gfx::Texture>> &getTextures() const { return _textures; }
inline gfx::Texture *getTexture(uint32_t page) const { return _textures[page]; }
inline uint32_t getTextureWidth() const { return _textureWidth; }
inline uint32_t getTextureHeight() const { return _textureHeight; }
Expand All @@ -120,7 +121,7 @@ class FontFace {
uint32_t _lineHeight{0U};
ccstd::unordered_map<uint32_t, FontGlyph> _glyphs;
ccstd::unordered_map<KerningPair, float, KerningHash> _kernings;
ccstd::vector<gfx::Texture *> _textures;
ccstd::vector<IntrusivePtr<gfx::Texture>> _textures;
uint32_t _textureWidth{0U};
uint32_t _textureHeight{0U};
};
Expand Down
Loading
Loading