mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[d3d11] Triangle test now tests shader resource buffers
This commit is contained in:
parent
e668c65017
commit
533ce13956
@ -16,22 +16,25 @@ struct Vertex {
|
|||||||
float x, y, z, w;
|
float x, y, z, w;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Color {
|
||||||
|
uint8_t r, g, b, a;
|
||||||
|
};
|
||||||
|
|
||||||
const std::string g_vertexShaderCode =
|
const std::string g_vertexShaderCode =
|
||||||
"Buffer<float4> buf : register(t0);\n"
|
"Buffer<float4> buf : register(t0);\n"
|
||||||
"struct vs_out {\n"
|
"struct vs_out {\n"
|
||||||
" float4 pos : SV_POSITION;\n"
|
" float4 pos : SV_POSITION;\n"
|
||||||
" float4 color : COLOR;\n"
|
" float4 color : COLOR;\n"
|
||||||
" uint vid : VID;\n"
|
|
||||||
" uint iid : IID;\n"
|
|
||||||
"};\n"
|
"};\n"
|
||||||
"vs_out main(float4 vsIn : IN_POSITION,\n"
|
"vs_out main(float4 vsIn : IN_POSITION,\n"
|
||||||
" uint vid : SV_VERTEXID,\n"
|
" uint vid : SV_VERTEXID,\n"
|
||||||
" uint iid : SV_INSTANCEID) {\n"
|
" uint iid : SV_INSTANCEID) {\n"
|
||||||
" vs_out result;\n"
|
" vs_out result;\n"
|
||||||
" result.pos = vsIn;\n"
|
" result.pos = vsIn;\n"
|
||||||
" result.color = buf[vid];\n"
|
" result.color.x = buf[vid].x;\n"
|
||||||
" result.vid = vid;\n"
|
" result.color.y = buf[iid * 3].y;\n"
|
||||||
" result.iid = iid;\n"
|
" result.color.z = buf[0].z;\n"
|
||||||
|
" result.color.w = 1.0f;\n"
|
||||||
" return result;\n"
|
" return result;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
@ -39,13 +42,9 @@ const std::string g_pixelShaderCode =
|
|||||||
"struct vs_out {\n"
|
"struct vs_out {\n"
|
||||||
" float4 pos : SV_POSITION;\n"
|
" float4 pos : SV_POSITION;\n"
|
||||||
" float4 color : COLOR;\n"
|
" float4 color : COLOR;\n"
|
||||||
" uint vid : VID;\n"
|
|
||||||
" uint iid : IID;\n"
|
|
||||||
"};\n"
|
"};\n"
|
||||||
"cbuffer c_buffer { float4 ccolor[2]; };\n"
|
|
||||||
"float4 main(vs_out ps_in) : SV_TARGET {\n"
|
"float4 main(vs_out ps_in) : SV_TARGET {\n"
|
||||||
" return ps_in.color;\n"
|
" return ps_in.color;\n"
|
||||||
// " return 0.5f * (ccolor[min(ps_in.vid, 1u)] + ccolor[min(ps_in.iid, 1u)]);\n"
|
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
class TriangleApp {
|
class TriangleApp {
|
||||||
@ -162,37 +161,39 @@ public:
|
|||||||
if (FAILED(m_device->CreateBuffer(&indexDesc, &indexDataInfo, &m_indexBuffer)))
|
if (FAILED(m_device->CreateBuffer(&indexDesc, &indexDataInfo, &m_indexBuffer)))
|
||||||
throw DxvkError("Failed to create index buffer");
|
throw DxvkError("Failed to create index buffer");
|
||||||
|
|
||||||
std::array<Vertex, 3> constantData = {{
|
std::array<Color, 6> resourceData = {{
|
||||||
{ 0.03f, 0.03f, 0.03f, 1.0f },
|
{ 0x20, 0x20, 0x20, 0xFF },
|
||||||
{ 1.00f, 0.00f, 0.00f, 1.0f },
|
{ 0x20, 0x20, 0x20, 0xFF },
|
||||||
{ 1.00f, 1.00f, 0.00f, 1.0f },
|
{ 0x20, 0x20, 0x20, 0xFF },
|
||||||
|
{ 0xFF, 0xFF, 0x00, 0xFF },
|
||||||
|
{ 0xFF, 0xFF, 0x00, 0xFF },
|
||||||
|
{ 0xFF, 0xFF, 0x00, 0xFF },
|
||||||
}};
|
}};
|
||||||
|
|
||||||
D3D11_BUFFER_DESC constantDesc;
|
D3D11_BUFFER_DESC resourceDesc;
|
||||||
constantDesc.ByteWidth = sizeof(Vertex) * constantData.size();
|
resourceDesc.ByteWidth = sizeof(Color) * resourceData.size();
|
||||||
constantDesc.Usage = D3D11_USAGE_IMMUTABLE;
|
resourceDesc.Usage = D3D11_USAGE_IMMUTABLE;
|
||||||
constantDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER
|
resourceDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||||
| D3D11_BIND_SHADER_RESOURCE;
|
resourceDesc.CPUAccessFlags = 0;
|
||||||
constantDesc.CPUAccessFlags = 0;
|
resourceDesc.MiscFlags = 0;
|
||||||
constantDesc.MiscFlags = 0;
|
resourceDesc.StructureByteStride = 0;
|
||||||
constantDesc.StructureByteStride = 0;
|
|
||||||
|
|
||||||
D3D11_SUBRESOURCE_DATA constantDataInfo;
|
D3D11_SUBRESOURCE_DATA resourceDataInfo;
|
||||||
constantDataInfo.pSysMem = constantData.data();
|
resourceDataInfo.pSysMem = resourceData.data();
|
||||||
constantDataInfo.SysMemPitch = 0;
|
resourceDataInfo.SysMemPitch = 0;
|
||||||
constantDataInfo.SysMemSlicePitch = 0;
|
resourceDataInfo.SysMemSlicePitch = 0;
|
||||||
|
|
||||||
if (FAILED(m_device->CreateBuffer(&constantDesc, &constantDataInfo, &m_constantBuffer)))
|
if (FAILED(m_device->CreateBuffer(&resourceDesc, &resourceDataInfo, &m_resourceBuffer)))
|
||||||
throw DxvkError("Failed to create constant buffer");
|
throw DxvkError("Failed to create resource buffer");
|
||||||
|
|
||||||
D3D11_SHADER_RESOURCE_VIEW_DESC constantViewDesc;
|
D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
|
||||||
constantViewDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
resourceViewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
constantViewDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
|
resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
|
||||||
constantViewDesc.Buffer.FirstElement = 0;
|
resourceViewDesc.Buffer.FirstElement = 0;
|
||||||
constantViewDesc.Buffer.NumElements = 3;
|
resourceViewDesc.Buffer.NumElements = resourceData.size();
|
||||||
|
|
||||||
if (FAILED(m_device->CreateShaderResourceView(m_constantBuffer.ptr(), &constantViewDesc, &m_constantView)))
|
if (FAILED(m_device->CreateShaderResourceView(m_resourceBuffer.ptr(), &resourceViewDesc, &m_resourceView)))
|
||||||
throw DxvkError("Failed to create texel buffer view");
|
throw DxvkError("Failed to create resource buffer view");
|
||||||
|
|
||||||
Com<ID3DBlob> vertexShaderBlob;
|
Com<ID3DBlob> vertexShaderBlob;
|
||||||
Com<ID3DBlob> pixelShaderBlob;
|
Com<ID3DBlob> pixelShaderBlob;
|
||||||
@ -266,9 +267,9 @@ public:
|
|||||||
m_context->ClearRenderTargetView(m_bufferView.ptr(), color);
|
m_context->ClearRenderTargetView(m_bufferView.ptr(), color);
|
||||||
|
|
||||||
m_context->VSSetShader(m_vertexShader.ptr(), nullptr, 0);
|
m_context->VSSetShader(m_vertexShader.ptr(), nullptr, 0);
|
||||||
m_context->VSSetShaderResources(0, 1, &m_constantView);
|
|
||||||
m_context->PSSetShader(m_pixelShader.ptr(), nullptr, 0);
|
m_context->PSSetShader(m_pixelShader.ptr(), nullptr, 0);
|
||||||
m_context->PSSetConstantBuffers(0, 1, &m_constantBuffer);
|
|
||||||
|
m_context->VSSetShaderResources(0, 1, &m_resourceView);
|
||||||
|
|
||||||
UINT vsStride = sizeof(Vertex);
|
UINT vsStride = sizeof(Vertex);
|
||||||
UINT vsOffset = 0;
|
UINT vsOffset = 0;
|
||||||
@ -344,8 +345,8 @@ private:
|
|||||||
|
|
||||||
Com<ID3D11Texture2D> m_buffer;
|
Com<ID3D11Texture2D> m_buffer;
|
||||||
Com<ID3D11RenderTargetView> m_bufferView;
|
Com<ID3D11RenderTargetView> m_bufferView;
|
||||||
Com<ID3D11Buffer> m_constantBuffer;
|
Com<ID3D11Buffer> m_resourceBuffer;
|
||||||
Com<ID3D11ShaderResourceView> m_constantView;
|
Com<ID3D11ShaderResourceView> m_resourceView;
|
||||||
Com<ID3D11Buffer> m_indexBuffer;
|
Com<ID3D11Buffer> m_indexBuffer;
|
||||||
Com<ID3D11Buffer> m_vertexBuffer;
|
Com<ID3D11Buffer> m_vertexBuffer;
|
||||||
Com<ID3D11InputLayout> m_vertexFormat;
|
Com<ID3D11InputLayout> m_vertexFormat;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user