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

Add textures for the pixel shaders #268

Merged
merged 1 commit into from
Aug 18, 2023
Merged
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
85 changes: 72 additions & 13 deletions benchmarks/graphics_pipeline/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ class ProjApp
grfx::QueryPtr timestampQuery;
};

struct Texture
{
grfx::ImagePtr image;
grfx::SampledImageViewPtr sampledImageView;
grfx::SamplerPtr sampler;
};

struct Entity
{
grfx::MeshPtr mesh;
Expand All @@ -142,9 +149,10 @@ class ProjApp
uint64_t mGpuWorkDuration;
grfx::ShaderModulePtr mVS;
grfx::ShaderModulePtr mPS;
grfx::ImagePtr mImage;
grfx::SampledImageViewPtr mSampledImageView;
grfx::SamplerPtr mSampler;
Texture mSkyBoxTexture;
Texture mAlbedoTexture;
Texture mNormalMapTexture;
Texture mMetalRoughnessTexture;
Entity mSkyBox;
Entity mSphere;
bool mEnableMouseMovement = true;
Expand Down Expand Up @@ -268,22 +276,67 @@ void ProjApp::Setup()
// Texture image, view, and sampler
{
// SkyBox
{
grfx_util::ImageOptions options = grfx_util::ImageOptions().MipLevelCount(PPX_REMAINING_MIP_LEVELS);
PPX_CHECKED_CALL(grfx_util::CreateImageFromFile(GetDevice()->GetGraphicsQueue(), GetAssetPath("basic/models/spheres/basic-skybox.jpg"), &mImage, options, true));
grfx_util::ImageOptions options = grfx_util::ImageOptions().MipLevelCount(PPX_REMAINING_MIP_LEVELS);
PPX_CHECKED_CALL(grfx_util::CreateImageFromFile(GetDevice()->GetGraphicsQueue(), GetAssetPath("basic/models/spheres/basic-skybox.jpg"), &mSkyBoxTexture.image, options, true));

grfx::SampledImageViewCreateInfo viewCreateInfo = grfx::SampledImageViewCreateInfo::GuessFromImage(mImage);
PPX_CHECKED_CALL(GetDevice()->CreateSampledImageView(&viewCreateInfo, &mSampledImageView));
}
grfx::SampledImageViewCreateInfo viewCreateInfo = grfx::SampledImageViewCreateInfo::GuessFromImage(mSkyBoxTexture.image);
PPX_CHECKED_CALL(GetDevice()->CreateSampledImageView(&viewCreateInfo, &mSkyBoxTexture.sampledImageView));

grfx::SamplerCreateInfo samplerCreateInfo = {};
samplerCreateInfo.magFilter = grfx::FILTER_LINEAR;
samplerCreateInfo.minFilter = grfx::FILTER_LINEAR;
samplerCreateInfo.mipmapMode = grfx::SAMPLER_MIPMAP_MODE_LINEAR;
samplerCreateInfo.minLod = 0;
samplerCreateInfo.maxLod = FLT_MAX;
PPX_CHECKED_CALL(GetDevice()->CreateSampler(&samplerCreateInfo, &mSkyBoxTexture.sampler));
}
{
// Albedo
grfx_util::ImageOptions options = grfx_util::ImageOptions().MipLevelCount(PPX_REMAINING_MIP_LEVELS);
PPX_CHECKED_CALL(grfx_util::CreateImageFromFile(GetDevice()->GetGraphicsQueue(), GetAssetPath("basic/models/altimeter/albedo.png"), &mAlbedoTexture.image, options, true));

grfx::SampledImageViewCreateInfo viewCreateInfo = grfx::SampledImageViewCreateInfo::GuessFromImage(mAlbedoTexture.image);
PPX_CHECKED_CALL(GetDevice()->CreateSampledImageView(&viewCreateInfo, &mAlbedoTexture.sampledImageView));

grfx::SamplerCreateInfo samplerCreateInfo = {};
samplerCreateInfo.magFilter = grfx::FILTER_LINEAR;
samplerCreateInfo.minFilter = grfx::FILTER_LINEAR;
samplerCreateInfo.mipmapMode = grfx::SAMPLER_MIPMAP_MODE_LINEAR;
samplerCreateInfo.minLod = 0;
samplerCreateInfo.maxLod = FLT_MAX;
PPX_CHECKED_CALL(GetDevice()->CreateSampler(&samplerCreateInfo, &mAlbedoTexture.sampler));
}
{
// NormalMap
grfx_util::ImageOptions options = grfx_util::ImageOptions().MipLevelCount(PPX_REMAINING_MIP_LEVELS);
PPX_CHECKED_CALL(grfx_util::CreateImageFromFile(GetDevice()->GetGraphicsQueue(), GetAssetPath("basic/models/altimeter/normal.png"), &mNormalMapTexture.image, options, true));

grfx::SampledImageViewCreateInfo viewCreateInfo = grfx::SampledImageViewCreateInfo::GuessFromImage(mNormalMapTexture.image);
PPX_CHECKED_CALL(GetDevice()->CreateSampledImageView(&viewCreateInfo, &mNormalMapTexture.sampledImageView));

grfx::SamplerCreateInfo samplerCreateInfo = {};
samplerCreateInfo.magFilter = grfx::FILTER_LINEAR;
samplerCreateInfo.minFilter = grfx::FILTER_LINEAR;
samplerCreateInfo.mipmapMode = grfx::SAMPLER_MIPMAP_MODE_LINEAR;
samplerCreateInfo.minLod = 0;
samplerCreateInfo.maxLod = FLT_MAX;
PPX_CHECKED_CALL(GetDevice()->CreateSampler(&samplerCreateInfo, &mNormalMapTexture.sampler));
}
{
// MetalRoughness
grfx_util::ImageOptions options = grfx_util::ImageOptions().MipLevelCount(PPX_REMAINING_MIP_LEVELS);
PPX_CHECKED_CALL(grfx_util::CreateImageFromFile(GetDevice()->GetGraphicsQueue(), GetAssetPath("basic/models/altimeter/metalness-roughness.png"), &mMetalRoughnessTexture.image, options, true));

grfx::SampledImageViewCreateInfo viewCreateInfo = grfx::SampledImageViewCreateInfo::GuessFromImage(mMetalRoughnessTexture.image);
PPX_CHECKED_CALL(GetDevice()->CreateSampledImageView(&viewCreateInfo, &mMetalRoughnessTexture.sampledImageView));

// Sampler
grfx::SamplerCreateInfo samplerCreateInfo = {};
samplerCreateInfo.magFilter = grfx::FILTER_LINEAR;
samplerCreateInfo.minFilter = grfx::FILTER_LINEAR;
samplerCreateInfo.mipmapMode = grfx::SAMPLER_MIPMAP_MODE_LINEAR;
samplerCreateInfo.minLod = 0;
samplerCreateInfo.maxLod = FLT_MAX;
PPX_CHECKED_CALL(GetDevice()->CreateSampler(&samplerCreateInfo, &mSampler));
PPX_CHECKED_CALL(GetDevice()->CreateSampler(&samplerCreateInfo, &mMetalRoughnessTexture.sampler));
}

// Meshes
Expand Down Expand Up @@ -607,8 +660,8 @@ void ProjApp::Render()
mSkyBox.uniformBuffer->CopyFromSource(sizeof(data), &data);

frame.cmd->PushGraphicsUniformBuffer(mSkyBox.pipelineInterface, /* binding = */ 0, /* set = */ 0, /* bufferOffset = */ 0, mSkyBox.uniformBuffer);
frame.cmd->PushGraphicsSampledImage(mSkyBox.pipelineInterface, /* binding = */ 1, /* set = */ 0, mSampledImageView);
frame.cmd->PushGraphicsSampler(mSkyBox.pipelineInterface, /* binding = */ 2, /* set = */ 0, mSampler);
frame.cmd->PushGraphicsSampledImage(mSkyBox.pipelineInterface, /* binding = */ 1, /* set = */ 0, mSkyBoxTexture.sampledImageView);
frame.cmd->PushGraphicsSampler(mSkyBox.pipelineInterface, /* binding = */ 2, /* set = */ 0, mSkyBoxTexture.sampler);
}
frame.cmd->DrawIndexed(mSkyBox.mesh->GetIndexCount());

Expand All @@ -634,6 +687,12 @@ void ProjApp::Render()
mSphereInstanceUniformBuffers[index]->CopyFromSource(sizeof(data), &data);

frame.cmd->PushGraphicsUniformBuffer(mSphere.pipelineInterface, /* binding = */ 0, /* set = */ 0, /* bufferOffset = */ 0, mSphereInstanceUniformBuffers[index]);
frame.cmd->PushGraphicsSampledImage(mSphere.pipelineInterface, /* binding = */ 1, /* set = */ 0, mAlbedoTexture.sampledImageView);
frame.cmd->PushGraphicsSampler(mSphere.pipelineInterface, /* binding = */ 2, /* set = */ 0, mAlbedoTexture.sampler);
frame.cmd->PushGraphicsSampledImage(mSphere.pipelineInterface, /* binding = */ 3, /* set = */ 0, mNormalMapTexture.sampledImageView);
frame.cmd->PushGraphicsSampler(mSphere.pipelineInterface, /* binding = */ 4, /* set = */ 0, mNormalMapTexture.sampler);
frame.cmd->PushGraphicsSampledImage(mSphere.pipelineInterface, /* binding = */ 5, /* set = */ 0, mMetalRoughnessTexture.sampledImageView);
frame.cmd->PushGraphicsSampler(mSphere.pipelineInterface, /* binding = */ 6, /* set = */ 0, mMetalRoughnessTexture.sampler);
frame.cmd->DrawIndexed(mSphere.mesh->GetIndexCount());
}
}
Expand Down