Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VkCV Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vulkan2021
VkCV Framework
Commits
58cebb9a
Verified
Commit
58cebb9a
authored
3 years ago
by
Tobias Frisch
Browse files
Options
Downloads
Patches
Plain Diff
[
#56
] Reduced code in first_triangle example
Signed-off-by:
Tobias Frisch
<
tfrisch@uni-koblenz.de
>
parent
4797e147
No related branches found
No related tags found
No related merge requests found
Pipeline
#26289
passed
3 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
projects/first_triangle/src/main.cpp
+2
-104
2 additions, 104 deletions
projects/first_triangle/src/main.cpp
with
2 additions
and
104 deletions
projects/first_triangle/src/main.cpp
+
2
−
104
View file @
58cebb9a
...
...
@@ -27,57 +27,16 @@ int main(int argc, const char** argv) {
{},
{
"VK_KHR_swapchain"
}
);
vkcv
::
gui
::
GUI
gui
(
core
,
window
);
const
auto
&
context
=
core
.
getContext
();
const
vk
::
Instance
&
instance
=
context
.
getInstance
();
const
vk
::
PhysicalDevice
&
physicalDevice
=
context
.
getPhysicalDevice
();
const
vk
::
Device
&
device
=
context
.
getDevice
();
struct
vec3
{
float
x
,
y
,
z
;
};
const
size_t
n
=
5027
;
auto
testBuffer
=
core
.
createBuffer
<
vec3
>
(
vkcv
::
BufferType
::
VERTEX
,
n
,
vkcv
::
BufferMemoryType
::
DEVICE_LOCAL
);
vec3
vec_data
[
n
];
for
(
size_t
i
=
0
;
i
<
n
;
i
++
)
{
vec_data
[
i
]
=
{
42
,
static_cast
<
float
>
(
i
),
7
};
}
testBuffer
.
fill
(
vec_data
);
auto
triangleIndexBuffer
=
core
.
createBuffer
<
uint16_t
>
(
vkcv
::
BufferType
::
INDEX
,
n
,
vkcv
::
BufferMemoryType
::
DEVICE_LOCAL
);
auto
triangleIndexBuffer
=
core
.
createBuffer
<
uint16_t
>
(
vkcv
::
BufferType
::
INDEX
,
3
,
vkcv
::
BufferMemoryType
::
DEVICE_LOCAL
);
uint16_t
indices
[
3
]
=
{
0
,
1
,
2
};
triangleIndexBuffer
.
fill
(
&
indices
[
0
],
sizeof
(
indices
));
/*vec3* m = buffer.map();
m[0] = { 0, 0, 0 };
m[1] = { 0, 0, 0 };
m[2] = { 0, 0, 0 };
buffer.unmap();*/
vkcv
::
SamplerHandle
sampler
=
core
.
createSampler
(
vkcv
::
SamplerFilterType
::
NEAREST
,
vkcv
::
SamplerFilterType
::
NEAREST
,
vkcv
::
SamplerMipmapMode
::
NEAREST
,
vkcv
::
SamplerAddressMode
::
REPEAT
);
std
::
cout
<<
"Physical device: "
<<
physicalDevice
.
getProperties
().
deviceName
<<
std
::
endl
;
switch
(
physicalDevice
.
getProperties
().
vendorID
)
{
case
0x1002
:
std
::
cout
<<
"Running AMD huh? You like underdogs, are you a Linux user?"
<<
std
::
endl
;
break
;
case
0x10DE
:
std
::
cout
<<
"An NVidia GPU, how predictable..."
<<
std
::
endl
;
break
;
case
0x8086
:
std
::
cout
<<
"Poor child, running on an Intel GPU, probably integrated..."
"or perhaps you are from the future with a dedicated one?"
<<
std
::
endl
;
break
;
case
0x13B5
:
std
::
cout
<<
"ARM? What the hell are you running on, next thing I know you're trying to run Vulkan on a leg..."
<<
std
::
endl
;
break
;
default:
std
::
cout
<<
"Unknown GPU vendor?! Either you're on an exotic system or your driver is broken..."
<<
std
::
endl
;
}
// an example attachment for passes that output to the window
const
vkcv
::
AttachmentDescription
present_color_attachment
(
vkcv
::
AttachmentOperation
::
STORE
,
...
...
@@ -123,49 +82,9 @@ int main(int argc, const char** argv) {
std
::
cout
<<
"Error. Could not create graphics pipeline. Exiting."
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
// Compute Pipeline
vkcv
::
ShaderProgram
computeShaderProgram
{};
computeShaderProgram
.
addShader
(
vkcv
::
ShaderStage
::
COMPUTE
,
std
::
filesystem
::
path
(
"shaders/comp.spv"
));
// take care, assuming shader has exactly one descriptor set
vkcv
::
DescriptorSetHandle
computeDescriptorSet
=
core
.
createDescriptorSet
(
computeShaderProgram
.
getReflectedDescriptors
()[
0
]);
vkcv
::
PipelineHandle
computePipeline
=
core
.
createComputePipeline
(
computeShaderProgram
,
{
core
.
getDescriptorSet
(
computeDescriptorSet
).
layout
});
struct
ComputeTestBuffer
{
float
test1
[
10
];
float
test2
[
10
];
float
test3
[
10
];
};
vkcv
::
Buffer
computeTestBuffer
=
core
.
createBuffer
<
ComputeTestBuffer
>
(
vkcv
::
BufferType
::
STORAGE
,
1
);
vkcv
::
DescriptorWrites
computeDescriptorWrites
;
computeDescriptorWrites
.
storageBufferWrites
=
{
vkcv
::
StorageBufferDescriptorWrite
(
0
,
computeTestBuffer
.
getHandle
())
};
core
.
writeDescriptorSet
(
computeDescriptorSet
,
computeDescriptorWrites
);
/*
* BufferHandle triangleVertices = core.createBuffer(vertices);
* BufferHandle triangleIndices = core.createBuffer(indices);
*
* // triangle Model creation goes here
*
*
* // attachment creation goes here
* PassHandle trianglePass = core.CreatePass(presentationPass);
*
* // shader creation goes here
* // material creation goes here
*
* PipelineHandle trianglePipeline = core.CreatePipeline(trianglePipeline);
*/
auto
start
=
std
::
chrono
::
system_clock
::
now
();
vkcv
::
ImageHandle
swapchainImageHandle
=
vkcv
::
ImageHandle
::
createSwapchainImageHandle
();
const
vkcv
::
Mesh
renderMesh
({},
triangleIndexBuffer
.
getVulkanHandle
(),
3
);
vkcv
::
DrawcallInfo
drawcall
(
renderMesh
,
{},
1
);
...
...
@@ -208,29 +127,8 @@ int main(int argc, const char** argv) {
{
drawcall
},
{
swapchainInput
});
const
uint32_t
dispatchSize
[
3
]
=
{
2
,
1
,
1
};
const
float
theMeaningOfLife
=
42
;
vkcv
::
PushConstants
pushConstantsCompute
(
sizeof
(
theMeaningOfLife
));
pushConstantsCompute
.
appendDrawcall
(
theMeaningOfLife
);
core
.
recordComputeDispatchToCmdStream
(
cmdStream
,
computePipeline
,
dispatchSize
,
{
vkcv
::
DescriptorSetUsage
(
0
,
core
.
getDescriptorSet
(
computeDescriptorSet
).
vulkanHandle
)
},
pushConstantsCompute
);
core
.
prepareSwapchainImageForPresent
(
cmdStream
);
core
.
submitCommandStream
(
cmdStream
);
gui
.
beginGUI
();
ImGui
::
Begin
(
"Hello world"
);
ImGui
::
Text
(
"This is a test!"
);
ImGui
::
End
();
gui
.
endGUI
();
core
.
endFrame
();
}
...
...
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