Rise
The Vieneo Province
Loading...
Searching...
No Matches
Program11.h
Go to the documentation of this file.
1#pragma once
2#include <d3d11.h>
3#include <d3d11shader.h>
4#include <wrl/client.h>
5#include <map>
6#include <string>
7#include <vector>
8#include <cstdint>
9
10namespace Rendering
11{
12 // Logical effect values persist across passes; native buffers are reflected
13 // from each compiled shader. CPU arrays stay tightly packed here.
15 {
16 public:
17 Parameters11() = default;
18 Parameters11(const Parameters11& other);
19 Parameters11& operator=(const Parameters11& other);
20 Parameters11(Parameters11&& other) noexcept;
21 Parameters11& operator=(Parameters11&& other) noexcept;
22 void Set(const std::string& name, const void* data, size_t bytes);
23 template<class T> void Set(const std::string& name, const T& value) { Set(name, &value, sizeof(value)); }
24 // Conservative proof for optional zero-default raster offsets. Nonzero
25 // bytes (including negative zero) keep the caller on the guarded path.
26 bool ZeroOrUnset(const std::string& name) const
27 {
28 const auto found=values.find(name);if(found==values.end())return true;
29 for(unsigned char byte:found->second.data)if(byte)return false;
30 return true;
31 }
32 void Texture(const std::string& name, ID3D11ShaderResourceView* value);
33 ID3D11ShaderResourceView* Texture(const std::string& name) const
34 { const auto found=textures.find(name);return found==textures.end() ? nullptr : found->second.resource.Get(); }
35 void Sampler(const std::string& name, ID3D11SamplerState* value);
36 void ClearTextures();
37 private:
38 friend class Program11;
39 struct Value { std::vector<unsigned char> data; uint64_t version = 0; };
41 {
42 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> resource;
43 D3D11_SRV_DIMENSION dimension = D3D11_SRV_DIMENSION_UNKNOWN;
44 };
45 uint64_t version = 0;
46 // Changes when map nodes can move/disappear or a missing value appears.
47 // Globally unique across parameter sets; programs never retain a pointer
48 // from an older layout, including after assignment/address reuse.
49 uint64_t layoutVersion = 0;
50 std::map<std::string, Value> values;
51 std::map<std::string, TextureValue> textures;
52 std::map<std::string, Microsoft::WRL::ComPtr<ID3D11SamplerState>> samplers;
53 };
54
56 {
57 public:
58 HRESULT Create(ID3D11Device* device, const void* vertexCode, size_t vertexSize,
59 const void* pixelCode, size_t pixelSize,
60 const D3D11_INPUT_ELEMENT_DESC* elements = nullptr, UINT elementCount = 0,
61 UINT bgraColorMask = 0);
62 // Each bit selects a COLOR semantic index whose R8G8B8A8 attribute
63 // contains legacy packed BGRA bytes. Native RGBA/FLOAT4 inputs use 0.
64 HRESULT Bind(ID3D11DeviceContext* context, const Parameters11& parameters);
65 void Reset();
66 bool Ready() const { return ready; }
67 const std::string& Status() const { return status; }
68
69 private:
70 bool ready=false;
71 struct Variable
72 {
73 std::string name;
74 UINT offset = 0, size = 0, elements = 0, rows = 0, columns = 0;
75 D3D_SHADER_VARIABLE_CLASS typeClass = D3D_SVC_SCALAR;
76 uint64_t packedVersion = UINT64_MAX;
77 const Parameters11::Value* source = nullptr;
78 };
80 {
81 UINT slot = 0;
82 std::vector<Variable> variables;
83 std::vector<unsigned char> data, defaults, packed;
84 uint64_t packedVersion = UINT64_MAX;
85 Microsoft::WRL::ComPtr<ID3D11Buffer> buffer;
86 };
87 struct Resource
88 {
89 std::string name;
90 UINT slot = 0;
91 D3D_SRV_DIMENSION dimension = D3D_SRV_DIMENSION_UNKNOWN;
93 const Microsoft::WRL::ComPtr<ID3D11SamplerState>* sampler = nullptr;
94 };
95 struct Stage
96 {
97 uint64_t layoutVersion = UINT64_MAX;
98 std::vector<ConstantBuffer> constants;
99 std::vector<Resource> textures, samplers;
100 };
101 HRESULT Reflect(ID3D11Device* device, const void* code, size_t size, Stage& stage);
102 HRESULT BindStage(ID3D11DeviceContext* context, const Parameters11& parameters, Stage& stage, bool vertexStage);
103 HRESULT Error(const std::string& message, HRESULT hr);
106 Microsoft::WRL::ComPtr<ID3D11VertexShader> vertex;
107 Microsoft::WRL::ComPtr<ID3D11PixelShader> pixel;
108 Microsoft::WRL::ComPtr<ID3D11InputLayout> layout;
109 std::string status;
110 };
111}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
Parameters11 & operator=(const Parameters11 &other)
Definition Program11.cpp:20
std::map< std::string, Value > values
Definition Program11.h:50
void Set(const std::string &name, const void *data, size_t bytes)
Definition Program11.cpp:45
std::map< std::string, Microsoft::WRL::ComPtr< ID3D11SamplerState > > samplers
Definition Program11.h:52
ID3D11ShaderResourceView * Texture(const std::string &name) const
Definition Program11.h:33
std::map< std::string, TextureValue > textures
Definition Program11.h:51
void Set(const std::string &name, const T &value)
Definition Program11.h:23
void Texture(const std::string &name, ID3D11ShaderResourceView *value)
Definition Program11.cpp:55
friend class Program11
Definition Program11.h:38
bool ZeroOrUnset(const std::string &name) const
Definition Program11.h:26
void Sampler(const std::string &name, ID3D11SamplerState *value)
Definition Program11.cpp:66
HRESULT Create(ID3D11Device *device, const void *vertexCode, size_t vertexSize, const void *pixelCode, size_t pixelSize, const D3D11_INPUT_ELEMENT_DESC *elements=nullptr, UINT elementCount=0, UINT bgraColorMask=0)
Microsoft::WRL::ComPtr< ID3D11InputLayout > layout
Definition Program11.h:108
HRESULT Reflect(ID3D11Device *device, const void *code, size_t size, Stage &stage)
Definition Program11.cpp:84
std::string status
Definition Program11.h:109
bool Ready() const
Definition Program11.h:66
HRESULT BindStage(ID3D11DeviceContext *context, const Parameters11 &parameters, Stage &stage, bool vertexStage)
Microsoft::WRL::ComPtr< ID3D11VertexShader > vertex
Definition Program11.h:106
Microsoft::WRL::ComPtr< ID3D11PixelShader > pixel
Definition Program11.h:107
const std::string & Status() const
Definition Program11.h:67
HRESULT Bind(ID3D11DeviceContext *context, const Parameters11 &parameters)
HRESULT Error(const std::string &message, HRESULT hr)
Definition Program11.cpp:79
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > resource
Definition Program11.h:42
std::vector< unsigned char > data
Definition Program11.h:39
std::vector< unsigned char > data
Definition Program11.h:83
Microsoft::WRL::ComPtr< ID3D11Buffer > buffer
Definition Program11.h:85
std::vector< Variable > variables
Definition Program11.h:82
std::vector< unsigned char > defaults
Definition Program11.h:83
std::vector< unsigned char > packed
Definition Program11.h:83
D3D_SRV_DIMENSION dimension
Definition Program11.h:91
const Microsoft::WRL::ComPtr< ID3D11SamplerState > * sampler
Definition Program11.h:93
const Parameters11::TextureValue * texture
Definition Program11.h:92
std::vector< ConstantBuffer > constants
Definition Program11.h:98
std::vector< Resource > samplers
Definition Program11.h:99
std::vector< Resource > textures
Definition Program11.h:99
const Parameters11::Value * source
Definition Program11.h:77
D3D_SHADER_VARIABLE_CLASS typeClass
Definition Program11.h:75