Skip to content

Commit

Permalink
fbsource//xplat/graphics/igl/public/src/igl/vulkan [B] [A]
Browse files Browse the repository at this point in the history
Reviewed By: dtolnay

Differential Revision: D69550566

fbshipit-source-id: 723d3bea9616729be309631ff7245e21ece4da9a
  • Loading branch information
generatedunixname89002005287564 authored and facebook-github-bot committed Feb 13, 2025
1 parent c71b05f commit 5836dc4
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 55 deletions.
8 changes: 4 additions & 4 deletions src/igl/vulkan/PipelineState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace igl::vulkan {

void PipelineState::initializeSpvModuleInfoFromShaderStages(const VulkanContext& ctx,
IShaderStages* stages) {
auto* smComp = static_cast<igl::vulkan::ShaderModule*>(stages->getComputeModule().get());
auto* smComp = static_cast<ShaderModule*>(stages->getComputeModule().get());

VkShaderStageFlags pushConstantMask = 0;

Expand All @@ -33,8 +33,8 @@ void PipelineState::initializeSpvModuleInfoFromShaderStages(const VulkanContext&

stageFlags_ = VK_SHADER_STAGE_COMPUTE_BIT;
} else {
auto* smVert = static_cast<igl::vulkan::ShaderModule*>(stages->getVertexModule().get());
auto* smFrag = static_cast<igl::vulkan::ShaderModule*>(stages->getFragmentModule().get());
auto* smVert = static_cast<ShaderModule*>(stages->getVertexModule().get());
auto* smFrag = static_cast<ShaderModule*>(stages->getFragmentModule().get());

// vertex/fragment
ensureShaderModule(smVert);
Expand Down Expand Up @@ -91,7 +91,7 @@ PipelineState::PipelineState(
bindings.emplace_back(ivkGetDescriptorSetLayoutBinding(
loc, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, stageFlags_));
if (loc < IGL_TEXTURE_SAMPLERS_MAX && immutableSamplers && immutableSamplers[loc]) {
auto* sampler = static_cast<igl::vulkan::SamplerState*>(immutableSamplers[loc].get());
auto* sampler = static_cast<SamplerState*>(immutableSamplers[loc].get());
bindings.back().pImmutableSamplers = &ctx.samplers_.get(sampler->sampler_)->vkSampler;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/igl/vulkan/PlatformDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::shared_ptr<ITexture> PlatformDevice::createTextureFromNativeDepth(uint32_t
TextureDesc::TextureUsageBits::Attachment |
TextureDesc::TextureUsageBits::Sampled,
"SwapChain Texture");
nativeDepthTexture_ = std::make_shared<igl::vulkan::Texture>(device_, std::move(vkTex), desc);
nativeDepthTexture_ = std::make_shared<Texture>(device_, std::move(vkTex), desc);
}

Result::setResult(outResult, Result::Code::Ok);
Expand Down Expand Up @@ -114,7 +114,7 @@ std::shared_ptr<ITexture> PlatformDevice::createTextureFromNativeDrawable(Result
const TextureDesc desc = TextureDesc::new2D(
iglFormat, width, height, TextureDesc::TextureUsageBits::Attachment, "SwapChain Texture");
nativeDrawableTextures_[currentImageIndex] =
std::make_shared<igl::vulkan::Texture>(device_, std::move(vkTex), desc);
std::make_shared<Texture>(device_, std::move(vkTex), desc);
}

Result::setResult(outResult, Result::Code::Ok);
Expand Down
32 changes: 16 additions & 16 deletions src/igl/vulkan/RenderCommandEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void RenderCommandEncoder::initialize(const RenderPassDesc& renderPass,
continue;
}

const auto& colorTexture = static_cast<vulkan::Texture&>(*attachment.texture);
const auto& colorTexture = static_cast<Texture&>(*attachment.texture);

// Specifically using renderPass.colorAttachments.size() in case we somehow
// get into this loop even when renderPass.colorAttachments.empty() == true
Expand Down Expand Up @@ -160,7 +160,7 @@ void RenderCommandEncoder::initialize(const RenderPassDesc& renderPass,
if (descColor.storeAction == StoreAction::MsaaResolve) {
IGL_DEBUG_ASSERT(attachment.resolveTexture,
"Framebuffer attachment should contain a resolve texture");
const auto& colorResolveTexture = static_cast<vulkan::Texture&>(*attachment.resolveTexture);
const auto& colorResolveTexture = static_cast<Texture&>(*attachment.resolveTexture);
builder.addColorResolve(textureFormatToVkFormat(colorResolveTexture.getFormat()),
VK_ATTACHMENT_LOAD_OP_DONT_CARE,
VK_ATTACHMENT_STORE_OP_STORE);
Expand All @@ -177,7 +177,7 @@ void RenderCommandEncoder::initialize(const RenderPassDesc& renderPass,
hasDepthAttachment_ = false;

if (framebuffer->getDepthAttachment()) {
const auto& depthTexture = static_cast<vulkan::Texture&>(*(framebuffer->getDepthAttachment()));
const auto& depthTexture = static_cast<Texture&>(*(framebuffer->getDepthAttachment()));
hasDepthAttachment_ = true;
IGL_DEBUG_ASSERT(descDepth.mipLevel == mipLevel,
"Depth attachment should have the same mip-level as color attachments");
Expand All @@ -198,7 +198,7 @@ void RenderCommandEncoder::initialize(const RenderPassDesc& renderPass,
depthTexture.getVulkanTexture().image_.samples_);
}

const auto& fb = static_cast<vulkan::Framebuffer&>(*framebuffer);
const auto& fb = static_cast<Framebuffer&>(*framebuffer);

auto renderPassHandle = ctx_.findRenderPass(builder);

Expand Down Expand Up @@ -376,7 +376,7 @@ void RenderCommandEncoder::bindRenderPipelineState(
return;
}

rps_ = static_cast<igl::vulkan::RenderPipelineState*>(pipelineState.get());
rps_ = static_cast<RenderPipelineState*>(pipelineState.get());

IGL_DEBUG_ASSERT(rps_);

Expand All @@ -403,7 +403,7 @@ void RenderCommandEncoder::bindDepthStencilState(
return;
}
const igl::vulkan::DepthStencilState* state =
static_cast<igl::vulkan::DepthStencilState*>(depthStencilState.get());
static_cast<DepthStencilState*>(depthStencilState.get());

const igl::DepthStencilStateDesc& desc = state->desc_;

Expand Down Expand Up @@ -439,7 +439,7 @@ void RenderCommandEncoder::bindBuffer(uint32_t index,
return;
}

auto* buf = static_cast<igl::vulkan::Buffer*>(buffer);
auto* buf = static_cast<Buffer*>(buffer);

const bool isUniformBuffer = (buf->getBufferType() & BufferDesc::BufferTypeBits::Uniform) > 0;
const bool isStorageBuffer = (buf->getBufferType() & BufferDesc::BufferTypeBits::Storage) > 0;
Expand Down Expand Up @@ -473,20 +473,20 @@ void RenderCommandEncoder::bindVertexBuffer(uint32_t index, IBuffer& buffer, siz
if (IGL_DEBUG_VERIFY(index < IGL_ARRAY_NUM_ELEMENTS(isVertexBufferBound_))) {
isVertexBufferBound_[index] = true;
}
VkBuffer vkBuf = static_cast<igl::vulkan::Buffer&>(buffer).getVkBuffer();
VkBuffer vkBuf = static_cast<Buffer&>(buffer).getVkBuffer();
const VkDeviceSize offset = bufferOffset;
ctx_.vf_.vkCmdBindVertexBuffers(cmdBuffer_, index, 1, &vkBuf, &offset);
}

void RenderCommandEncoder::bindIndexBuffer(IBuffer& buffer,
IndexFormat format,
size_t bufferOffset) {
const auto& buf = static_cast<igl::vulkan::Buffer&>(buffer);
const auto& buf = static_cast<Buffer&>(buffer);

IGL_DEBUG_ASSERT(buf.getBufferUsageFlags() & VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
"Did you forget to specify BufferTypeBits::Index on your buffer?");

auto indexFormatToVkIndexType = [](igl::IndexFormat fmt, bool has8BitIndices) -> VkIndexType {
auto indexFormatToVkIndexType = [](IndexFormat fmt, bool has8BitIndices) -> VkIndexType {
switch (fmt) {
case igl::IndexFormat::UInt8:
return IGL_DEBUG_VERIFY(has8BitIndices) ? VK_INDEX_TYPE_UINT8_EXT : VK_INDEX_TYPE_UINT16;
Expand Down Expand Up @@ -557,7 +557,7 @@ void RenderCommandEncoder::bindSamplerState(size_t index,
return;
}

binder_.bindSamplerState(index, static_cast<igl::vulkan::SamplerState*>(samplerState));
binder_.bindSamplerState(index, static_cast<SamplerState*>(samplerState));
}

void RenderCommandEncoder::bindTexture(size_t index, uint8_t target, ITexture* texture) {
Expand All @@ -578,7 +578,7 @@ void RenderCommandEncoder::bindTexture(size_t index, uint8_t target, ITexture* t
return;
}

binder_.bindTexture(index, static_cast<igl::vulkan::Texture*>(texture));
binder_.bindTexture(index, static_cast<Texture*>(texture));
}

void RenderCommandEncoder::bindTexture(size_t index, ITexture* texture) {
Expand Down Expand Up @@ -676,7 +676,7 @@ void RenderCommandEncoder::multiDrawIndirect(IBuffer& indirectBuffer,

ctx_.drawCallCount_ += drawCallCountEnabled_;

const igl::vulkan::Buffer* bufIndirect = static_cast<igl::vulkan::Buffer*>(&indirectBuffer);
const igl::vulkan::Buffer* bufIndirect = static_cast<Buffer*>(&indirectBuffer);

ctx_.vf_.vkCmdDrawIndirect(cmdBuffer_,
bufIndirect->getVkBuffer(),
Expand All @@ -701,7 +701,7 @@ void RenderCommandEncoder::multiDrawIndexedIndirect(IBuffer& indirectBuffer,

ctx_.drawCallCount_ += drawCallCountEnabled_;

const igl::vulkan::Buffer* bufIndirect = static_cast<igl::vulkan::Buffer*>(&indirectBuffer);
const igl::vulkan::Buffer* bufIndirect = static_cast<Buffer*>(&indirectBuffer);

ctx_.vf_.vkCmdDrawIndexedIndirect(cmdBuffer_,
bufIndirect->getVkBuffer(),
Expand Down Expand Up @@ -831,8 +831,8 @@ void RenderCommandEncoder::ensureVertexBuffers() {
return;
}

const igl::vulkan::VertexInputState* vi = static_cast<igl::vulkan::VertexInputState*>(
rps_->getRenderPipelineDesc().vertexInputState.get());
const igl::vulkan::VertexInputState* vi =
static_cast<VertexInputState*>(rps_->getRenderPipelineDesc().vertexInputState.get());

if (!vi) {
// no vertex input is perfectly valid
Expand Down
8 changes: 4 additions & 4 deletions src/igl/vulkan/RenderCommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class RenderCommandEncoder : public IRenderCommandEncoder {
return cmdBuffer_;
}

igl::vulkan::ResourcesBinder& binder() {
ResourcesBinder& binder() {
return binder_;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ class RenderCommandEncoder : public IRenderCommandEncoder {
bool hasDepthAttachment_ = false;
std::shared_ptr<IFramebuffer> framebuffer_;

igl::vulkan::ResourcesBinder binder_;
ResourcesBinder binder_;

RenderPipelineDynamicState dynamicState_;

Expand All @@ -152,8 +152,8 @@ class RenderCommandEncoder : public IRenderCommandEncoder {
Dependencies dependencies_ = {};

const igl::vulkan::RenderPipelineState* rps_ = nullptr;
igl::BindGroupTextureHandle pendingBindGroupTexture_ = {};
igl::BindGroupBufferHandle pendingBindGroupBuffer_ = {};
BindGroupTextureHandle pendingBindGroupTexture_ = {};
BindGroupBufferHandle pendingBindGroupBuffer_ = {};
uint32_t numDynamicOffsets_ = 0;
uint32_t dynamicOffsets_[IGL_UNIFORM_BLOCKS_BINDING_MAX] = {};
};
Expand Down
6 changes: 3 additions & 3 deletions src/igl/vulkan/RenderPipelineReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ RenderPipelineReflection::RenderPipelineReflection(std::vector<BufferArgDesc> bu

RenderPipelineReflection::~RenderPipelineReflection() = default;

const std::vector<igl::BufferArgDesc>& RenderPipelineReflection::allUniformBuffers() const {
const std::vector<BufferArgDesc>& RenderPipelineReflection::allUniformBuffers() const {
return bufferArguments_;
}

const std::vector<igl::SamplerArgDesc>& RenderPipelineReflection::allSamplers() const {
const std::vector<SamplerArgDesc>& RenderPipelineReflection::allSamplers() const {
return samplerArguments_;
}

const std::vector<igl::TextureArgDesc>& RenderPipelineReflection::allTextures() const {
const std::vector<TextureArgDesc>& RenderPipelineReflection::allTextures() const {
return textureArguments_;
}

Expand Down
4 changes: 2 additions & 2 deletions src/igl/vulkan/RenderPipelineState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ RenderPipelineState::RenderPipelineState(const igl::vulkan::Device& device,

// Iterate and cache vertex input bindings and attributes
const igl::vulkan::VertexInputState* vstate =
static_cast<igl::vulkan::VertexInputState*>(desc_.vertexInputState.get());
static_cast<VertexInputState*>(desc_.vertexInputState.get());

vertexInputStateCreateInfo_ = ivkGetPipelineVertexInputStateCreateInfo_Empty();

Expand Down Expand Up @@ -531,7 +531,7 @@ int RenderPipelineState::getIndexByName(const std::string& name, ShaderStage sta
return 0;
}

std::shared_ptr<igl::IRenderPipelineReflection> RenderPipelineState::renderPipelineReflection() {
std::shared_ptr<IRenderPipelineReflection> RenderPipelineState::renderPipelineReflection() {
return reflection_;
}

Expand Down
2 changes: 1 addition & 1 deletion src/igl/vulkan/RenderPipelineState.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static_assert(alignof(RenderPipelineDynamicState) == sizeof(uint64_t));
* the pipeline layout in the context. If a pipeline layout change is detected, this class purges
* all the pipelines that have been created so far.
*/
class RenderPipelineState final : public IRenderPipelineState, public vulkan::PipelineState {
class RenderPipelineState final : public IRenderPipelineState, public PipelineState {
public:
/** @brief Caches the render pipeline parameters passed in `desc` for later use. A pipeline isn't
* realized until `getVkPipeline()` is called and all mutable parameters are provided.
Expand Down
15 changes: 7 additions & 8 deletions src/igl/vulkan/ResourcesBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ResourcesBinder::ResourcesBinder(const CommandBuffer* commandBuffer,
: VulkanImmediateCommands::SubmitHandle{}) {}

void ResourcesBinder::bindBuffer(uint32_t index,
igl::vulkan::Buffer* buffer,
Buffer* buffer,
size_t bufferOffset,
size_t bufferSize) {
IGL_PROFILER_FUNCTION();
Expand Down Expand Up @@ -67,16 +67,15 @@ void ResourcesBinder::bindBuffer(uint32_t index,
}
}

void ResourcesBinder::bindSamplerState(uint32_t index, igl::vulkan::SamplerState* samplerState) {
void ResourcesBinder::bindSamplerState(uint32_t index, SamplerState* samplerState) {
IGL_PROFILER_FUNCTION();

if (!IGL_DEBUG_VERIFY(index < IGL_TEXTURE_SAMPLERS_MAX)) {
IGL_DEBUG_ABORT("Invalid sampler index");
return;
}

igl::vulkan::VulkanSampler* newSampler = samplerState ? ctx_.samplers_.get(samplerState->sampler_)
: nullptr;
VulkanSampler* newSampler = samplerState ? ctx_.samplers_.get(samplerState->sampler_) : nullptr;

VkSampler sampler = newSampler ? newSampler->vkSampler : VK_NULL_HANDLE;

Expand All @@ -86,7 +85,7 @@ void ResourcesBinder::bindSamplerState(uint32_t index, igl::vulkan::SamplerState
}
}

void ResourcesBinder::bindTexture(uint32_t index, igl::vulkan::Texture* tex) {
void ResourcesBinder::bindTexture(uint32_t index, Texture* tex) {
IGL_PROFILER_FUNCTION();

if (!IGL_DEBUG_VERIFY(index < IGL_TEXTURE_SAMPLERS_MAX)) {
Expand All @@ -108,7 +107,7 @@ void ResourcesBinder::bindTexture(uint32_t index, igl::vulkan::Texture* tex) {
}
}

igl::vulkan::VulkanTexture* newTexture = tex ? &tex->getVulkanTexture() : nullptr;
VulkanTexture* newTexture = tex ? &tex->getVulkanTexture() : nullptr;

#if IGL_DEBUG
if (newTexture) {
Expand Down Expand Up @@ -142,7 +141,7 @@ void ResourcesBinder::bindTexture(uint32_t index, igl::vulkan::Texture* tex) {
}
}

void ResourcesBinder::bindStorageImage(uint32_t index, igl::vulkan::Texture* tex) {
void ResourcesBinder::bindStorageImage(uint32_t index, Texture* tex) {
IGL_PROFILER_FUNCTION();

if (!IGL_DEBUG_VERIFY(index < IGL_TEXTURE_SAMPLERS_MAX)) {
Expand All @@ -159,7 +158,7 @@ void ResourcesBinder::bindStorageImage(uint32_t index, igl::vulkan::Texture* tex
}
}

igl::vulkan::VulkanTexture* newTexture = tex ? &tex->getVulkanTexture() : nullptr;
VulkanTexture* newTexture = tex ? &tex->getVulkanTexture() : nullptr;

#if IGL_DEBUG
if (newTexture) {
Expand Down
11 changes: 4 additions & 7 deletions src/igl/vulkan/ResourcesBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,14 @@ class ResourcesBinder final {
VkPipelineBindPoint bindPoint);

/// @brief Binds a uniform buffer with an offset to index equal to `index`
void bindBuffer(uint32_t index,
igl::vulkan::Buffer* buffer,
size_t bufferOffset,
size_t bufferSize);
void bindBuffer(uint32_t index, Buffer* buffer, size_t bufferOffset, size_t bufferSize);

/// @brief Binds a sampler state to index equal to `index`
void bindSamplerState(uint32_t index, igl::vulkan::SamplerState* samplerState);
void bindSamplerState(uint32_t index, SamplerState* samplerState);

/// @brief Binds a texture to index equal to `index`
void bindTexture(uint32_t index, igl::vulkan::Texture* tex);
void bindStorageImage(uint32_t index, igl::vulkan::Texture* tex);
void bindTexture(uint32_t index, Texture* tex);
void bindStorageImage(uint32_t index, Texture* tex);

/// @brief Convenience function that updates all bindings in the context for all resource types
/// that have been modified since the last time this function was called
Expand Down
16 changes: 8 additions & 8 deletions src/igl/vulkan/SamplerState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ VkSamplerCreateInfo samplerStateDescToVkSamplerCreateInfo(const igl::SamplerStat

namespace igl::vulkan {

SamplerState::SamplerState(igl::vulkan::Device& device) : device_(device) {}
SamplerState::SamplerState(Device& device) : device_(device) {}

Result SamplerState::create(const SamplerStateDesc& desc) {
IGL_PROFILER_FUNCTION();
Expand All @@ -114,13 +114,13 @@ Result SamplerState::create(const SamplerStateDesc& desc) {
const VulkanContext& ctx = device_.getVulkanContext();

Result result;
sampler_ = igl::Holder<igl::SamplerHandle>(
&device_,
ctx.createSampler(
samplerStateDescToVkSamplerCreateInfo(desc, ctx.getVkPhysicalDeviceProperties().limits),
textureFormatToVkFormat(desc.yuvFormat),
&result,
desc_.debugName.c_str()));
sampler_ =
Holder<SamplerHandle>(&device_,
ctx.createSampler(samplerStateDescToVkSamplerCreateInfo(
desc, ctx.getVkPhysicalDeviceProperties().limits),
textureFormatToVkFormat(desc.yuvFormat),
&result,
desc_.debugName.c_str()));

if (!IGL_DEBUG_VERIFY(result.isOk())) {
return result;
Expand Down

0 comments on commit 5836dc4

Please sign in to comment.