Skip to content

Commit

Permalink
texture view
Browse files Browse the repository at this point in the history
  • Loading branch information
bluesky013 committed Aug 14, 2023
1 parent 333f5d3 commit bb00177
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cocos/asset/assets/simple-texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class SimpleTexture extends TextureBase {
}
}
const textureCreateInfo = this._getGfxTextureCreateInfo({
usage: TextureUsageBit.SAMPLED | TextureUsageBit.TRANSFER_DST,
usage: TextureUsageBit.SAMPLED | TextureUsageBit.TRANSFER_DST | TextureUsageBit.COLOR_ATTACHMENT,
format: this._getGFXFormat(),
levelCount: this._mipmapLevel,
flags,
Expand Down
12 changes: 0 additions & 12 deletions cocos/gfx/base/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,18 +390,6 @@ export enum TextureType {
TEX2D_ARRAY,
}

export enum TextureViewType {
TEX1D,
TEX1D_ARRAY,
TEX2D,
TEX2D_ARRAY,
TEX2DMS,
TEX2DMS_ARRAY,
TEX3D,
CUBE,
CUBE_ARRAY
}

export enum TextureUsageBit {
NONE = 0,
TRANSFER_SRC = 0x1,
Expand Down
2 changes: 2 additions & 0 deletions cocos/rendering/custom/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ export interface BasicPipeline extends PipelineRuntime {
updateBuffer(
name: string,
size: number): void;
importTexture(name: string, texture: Texture, flags: ResourceFlags): number;
updateImportedTexture(name: string, texture: Texture): void;
addTexture (
name: string,
textureType: TextureType,
Expand Down
10 changes: 9 additions & 1 deletion cocos/rendering/custom/web-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/* eslint-disable max-len */
import { systemInfo } from 'pal/system-info';
import { DEBUG } from 'internal:constants';
import { Buffer, DescriptorSetLayout, Device, Feature, Format, FormatFeatureBit, Sampler, Swapchain, Texture, ClearFlagBit, DescriptorSet, deviceManager, Viewport, API, CommandBuffer, Type, SamplerInfo, Filter, Address, DescriptorSetInfo, LoadOp, StoreOp, ShaderStageFlagBit, BufferInfo, TextureInfo, UniformBlock, ResolveMode, SampleCount, Color } from '../../gfx';
import { Buffer, DescriptorSetLayout, Device, Feature, Format, FormatFeatureBit, Sampler, Swapchain, Texture, ClearFlagBit, DescriptorSet, deviceManager, Viewport, API, CommandBuffer, Type, SamplerInfo, Filter, Address, DescriptorSetInfo, LoadOp, StoreOp, ShaderStageFlagBit, BufferInfo, TextureInfo, TextureType, UniformBlock, ResolveMode, SampleCount, Color } from '../../gfx';
import { Mat4, Quat, toRadian, Vec2, Vec3, Vec4, assert, macro, cclegacy, IVec4Like, IMat4Like, IVec2Like, Color as CoreColor } from '../../core';
import { AccessType, AttachmentType, CopyPair, LightInfo, LightingMode, MovePair, QueueHint, ResolvePair, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UpdateFrequency } from './types';
import { ComputeView, RasterView, Blit, ClearView, ComputePass, CopyPass, Dispatch, ManagedBuffer, ManagedResource, MovePass, RasterPass, RasterSubpass, RenderData, RenderGraph, RenderGraphComponent, RenderGraphValue, RenderQueue, RenderSwapchain, ResourceDesc, ResourceGraph, ResourceGraphValue, ResourceStates, ResourceTraits, SceneData, Subpass } from './render-graph';
Expand Down Expand Up @@ -1526,6 +1526,14 @@ export class WebPipeline implements BasicPipeline {
this.updateResource(name, Format.UNKNOWN, size, 0, 0, 0, 0, SampleCount.X1);
}

importTexture(name: string, texture: Texture, flags: ResourceFlags): number {
throw new Error('Method not implemented.');
}

updateImportedTexture(name: string, texture: Texture): void {
throw new Error('Method not implemented.');
}

addTexture(name: string, textureType: TextureType, format: Format, width: number, height: number, depth: number, arraySize: number, mipLevels: number, sampleCount: SampleCount, flags: ResourceFlags, residency: ResourceResidency): number {
const desc = new ResourceDesc();
desc.dimension = getResourceDimension(textureType);
Expand Down
2 changes: 1 addition & 1 deletion native/cocos/core/assets/SimpleTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void SimpleTexture::createTexture(gfx::Device *device) {
}

auto textureCreateInfo = getGfxTextureCreateInfo(
gfx::TextureUsageBit::SAMPLED | gfx::TextureUsageBit::TRANSFER_DST,
gfx::TextureUsageBit::SAMPLED | gfx::TextureUsageBit::TRANSFER_DST | gfx::TextureUsageBit::COLOR_ATTACHMENT,
getGFXFormat(),
_mipmapLevel,
flags);
Expand Down
13 changes: 0 additions & 13 deletions native/cocos/renderer/gfx-base/GFXDef-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,19 +457,6 @@ enum class TextureType : uint32_t {
};
CC_ENUM_CONVERSION_OPERATOR(TextureType);

enum class TextureViewType : uint32_t {
TEX1D,
TEX1D_ARRAY,
TEX2D,
TEX2D_ARRAY,
TEX2DMS,
TEX2DMS_ARRAY,
TEX3D,
CUBE,
CUBE_ARRAY
};
CC_ENUM_CONVERSION_OPERATOR(TextureViewType);

enum class TextureUsageBit : uint32_t {
NONE = 0,
TRANSFER_SRC = 0x1,
Expand Down
41 changes: 41 additions & 0 deletions native/cocos/renderer/pipeline/custom/NativePipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,47 @@ bool NativePipeline::containsResource(const ccstd::string &name) const {
return contains(name.c_str(), resourceGraph);
}

uint32_t NativePipeline::importTexture(const ccstd::string &name, gfx::Texture *texture, ResourceFlags flags) {
auto &texInfo = texture->getInfo();
ResourceDesc desc{};
desc.dimension = getResourceDimension(texInfo.type);
desc.width = texInfo.width;
desc.height = texInfo.height;
desc.depthOrArraySize = desc.dimension == ResourceDimension::TEXTURE3D ? texInfo.depth : texInfo.layerCount;
desc.mipLevels = texInfo.levelCount;
desc.format = texture->getFormat();
desc.sampleCount = gfx::SampleCount::X1;
desc.textureFlags = texture->getInfo().flags;
desc.flags = flags;
desc.viewType = texInfo.type;

return addVertex(
PersistentTextureTag{},
std::forward_as_tuple(name.c_str()),
std::forward_as_tuple(desc),
std::forward_as_tuple(ResourceTraits{ResourceResidency::EXTERNAL}),
std::forward_as_tuple(),
std::forward_as_tuple(),
std::forward_as_tuple(texture),
resourceGraph);
}

void NativePipeline::updateImportedTexture(const ccstd::string &name, gfx::Texture *texture) {
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID == ResourceGraph::null_vertex()) {
return;
}
auto &desc = get(ResourceGraph::DescTag{}, resourceGraph, resID);
visitObject(
resID, resourceGraph,
[&](IntrusivePtr<gfx::Texture> &tex) {
desc.width = texture->getWidth();
desc.height = texture->getHeight();
tex = texture;
},
[](const auto & /*res*/) {});
}

// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
uint32_t NativePipeline::addRenderWindow(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, scene::RenderWindow *renderWindow) {
ResourceDesc desc{};
Expand Down
2 changes: 2 additions & 0 deletions native/cocos/renderer/pipeline/custom/NativePipelineTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,8 @@ class NativePipeline final : public Pipeline {
void beginSetup() override;
void endSetup() override;
bool containsResource(const ccstd::string &name) const override;
uint32_t importTexture(const ccstd::string &name, gfx::Texture *texture, ResourceFlags flags) override;
void updateImportedTexture(const ccstd::string &name, gfx::Texture *texture) override;
uint32_t addRenderWindow(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, scene::RenderWindow *renderWindow) override;
void updateRenderWindow(const ccstd::string &name, scene::RenderWindow *renderWindow) override;
uint32_t addRenderTarget(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) override;
Expand Down
2 changes: 2 additions & 0 deletions native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ class BasicPipeline : public PipelineRuntime {
virtual void updateTexture(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount) = 0;
virtual uint32_t addBuffer(const ccstd::string &name, uint32_t size, ResourceFlags flags, ResourceResidency residency) = 0;
virtual void updateBuffer(const ccstd::string &name, uint32_t size) = 0;
virtual uint32_t importTexture(const ccstd::string &name, gfx::Texture *texture, ResourceFlags flags) = 0;
virtual void updateImportedTexture(const ccstd::string &name, gfx::Texture *texture) = 0;
/**
* @engineInternal
* @en Begin rendering one frame
Expand Down

0 comments on commit bb00177

Please sign in to comment.